{
  "openapi": "3.1.0",
  "info": {
    "title": "AgentDefi API",
    "description": "DeFi protocol TVL, yield/APY pools, and blockchain chain data powered by DefiLlama. Pay-per-call via x402 micropayments.",
    "version": "1.0.0",
    "contact": {
      "name": "Ocean Digital Group",
      "url": "https://memoryapi.org"
    }
  },
  "servers": [
    {
      "url": "https://defi.memoryapi.org",
      "description": "Production"
    }
  ],
  "paths": {
    "/x402/defi/protocols": {
      "get": {
        "summary": "DeFi Protocol TVL",
        "description": "Top DeFi protocols sorted by Total Value Locked. Filter by chain, minimum TVL, or fetch a single protocol by slug.",
        "x-price": "$0.001 USDC",
        "parameters": [
          {
            "name": "chain",
            "in": "query",
            "description": "Filter by chain (ethereum, bsc, solana, arbitrum, etc.)",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Number of results (default 20, max 100)",
            "schema": {
              "type": "integer",
              "default": 20
            }
          },
          {
            "name": "min_tvl",
            "in": "query",
            "description": "Minimum TVL in USD",
            "schema": {
              "type": "number"
            }
          },
          {
            "name": "slug",
            "in": "query",
            "description": "Single protocol slug (e.g. aave, uniswap, lido)",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Protocol TVL data",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "count": {
                      "type": "integer"
                    },
                    "total_tvl_usd": {
                      "type": "number"
                    },
                    "protocols": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "name": {
                            "type": "string"
                          },
                          "symbol": {
                            "type": "string"
                          },
                          "tvl": {
                            "type": "number"
                          },
                          "chain": {
                            "type": "string"
                          },
                          "category": {
                            "type": "string"
                          },
                          "change_1d": {
                            "type": "number"
                          },
                          "change_7d": {
                            "type": "number"
                          },
                          "url": {
                            "type": "string"
                          }
                        }
                      }
                    },
                    "source": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "402": {
            "description": "Payment required"
          }
        }
      }
    },
    "/x402/defi/yields": {
      "get": {
        "summary": "DeFi Yield Pools",
        "description": "DeFi yield and APY pool data from 19,000+ pools. Filter by chain, project, token symbol, or minimum APY.",
        "x-price": "$0.001 USDC",
        "parameters": [
          {
            "name": "chain",
            "in": "query",
            "description": "Blockchain filter (ethereum, bsc, solana, etc.)",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "project",
            "in": "query",
            "description": "Protocol name (aave, compound, curve, etc.)",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "symbol",
            "in": "query",
            "description": "Token symbol (USDC, ETH, BTC, etc.)",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "min_apy",
            "in": "query",
            "description": "Minimum APY percentage",
            "schema": {
              "type": "number"
            }
          },
          {
            "name": "min_tvl",
            "in": "query",
            "description": "Minimum pool TVL in USD",
            "schema": {
              "type": "number"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Number of results (default 20, max 50)",
            "schema": {
              "type": "integer",
              "default": 20
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Yield pool data",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "count": {
                      "type": "integer"
                    },
                    "filters_applied": {
                      "type": "object"
                    },
                    "pools": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "pool": {
                            "type": "string"
                          },
                          "project": {
                            "type": "string"
                          },
                          "chain": {
                            "type": "string"
                          },
                          "symbol": {
                            "type": "string"
                          },
                          "apy": {
                            "type": "number"
                          },
                          "tvl_usd": {
                            "type": "number"
                          },
                          "apy_7d": {
                            "type": "number"
                          },
                          "il_risk": {
                            "type": "string"
                          },
                          "stable_coin": {
                            "type": "boolean"
                          }
                        }
                      }
                    },
                    "source": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "402": {
            "description": "Payment required"
          }
        }
      }
    },
    "/x402/defi/chains": {
      "get": {
        "summary": "Blockchain Chain TVL",
        "description": "All blockchains ranked by Total Value Locked, or historical TVL for a specific chain.",
        "x-price": "$0.001 USDC",
        "parameters": [
          {
            "name": "chain",
            "in": "query",
            "description": "Chain name for history (Ethereum, BSC, Solana). Omit for all chains.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "History data points (default 10, max 30)",
            "schema": {
              "type": "integer",
              "default": 10
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Chain TVL data",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "count": {
                      "type": "integer"
                    },
                    "chains": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "name": {
                            "type": "string"
                          },
                          "tvl_usd": {
                            "type": "number"
                          },
                          "token_symbol": {
                            "type": "string"
                          }
                        }
                      }
                    },
                    "source": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "402": {
            "description": "Payment required"
          }
        }
      }
    },
    "/mcp": {
      "get": {
        "summary": "MCP Server Info",
        "description": "Model Context Protocol server information and available tools.",
        "security": [],
        "responses": {
          "200": {
            "description": "MCP server info"
          }
        }
      },
      "post": {
        "summary": "MCP Tool Call",
        "description": "Execute MCP tools: get_defi_protocols, get_yield_pools, get_chain_tvl",
        "security": [],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "method": {
                    "type": "string"
                  },
                  "params": {
                    "type": "object"
                  },
                  "id": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "MCP JSON-RPC response"
          }
        }
      }
    },
    "/health": {
      "get": {
        "summary": "Health Check",
        "description": "Service health status.",
        "security": [],
        "responses": {
          "200": {
            "description": "Service is healthy"
          }
        }
      }
    }
  }
}