AC

agoda-com/api-agent

API 开发

本页由 AI 翻译,技术细节请以原文为准。 查看原文

298 stars 44 forks 质量 83 趋势 33MIT

agoda-com/api-agent 是从 https://github.com/agoda-com/api-agent. 导入的 MCP 服务器候选

概览

agoda-com/api-agent 是从 https://github.com/agoda-com/api-agent. 导入的 MCP 服务器候选

概述(AI 翻译)

将任何API变成MCP服务器。用英语查询。即使API无法获得结果。

指向任何GraphQL或REST API。用自然语言提问。代理获取数据,存储在DuckDB,并运行SQL后处理。排名、筛选和对返回数据的连接都能正常工作即使API不支持。

它有什么不同

** 🎯 零配置。** 每个API不自定义MCP代码。指向GraphQL端点、OpenAPI 3.x规范或Swagger 2.0规范。代理会自动内省/加载模式。

** ✨ SQL 后处理。** API 返回 10,000 行未排序?代理排名前十。没有 GROUP BY?代理聚合。需要加入返回的表吗?代理合并。API 不需要支持——代理需要。

** 🔒 默认安全。** 只读。除非明确允许,否则阻挡突变。

** 🧠 配方学习。** 代理将成功的查询采样到可重用的工作流程中。请求一次,重用缓存流水线,这些流水线无需大型语言模型推理即可执行。学习到的配方会以名为r_ 的工具形式公开。

快速启动

1.跑:

在环境中设置OpenAI秘密:

直接 uvx 运行使用内置默认值,除非 API_AGENT_CONFIG 指向 TOML文件。

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 README 节选,完整内容请查看原文。

API Agent

Turn any API into an MCP server. Query in English. Get results even when the API can’t.

Point at any GraphQL or REST API. Ask questions in natural language. The agent fetches data, stores it in DuckDB, and runs SQL post-processing. Rankings, filters, and joins over returned data work even if the API doesn’t support them.

What Makes It Different

🎯 Zero config. No custom MCP code per API. Point at a GraphQL endpoint, OpenAPI 3.x spec, or Swagger 2.0 spec. The agent introspects/loads schema automatically.

✨ SQL post-processing. API returns 10,000 unsorted rows? Agent ranks top 10. No GROUP BY? Agent aggregates. Need to join returned tables? Agent combines. The API doesn’t need to support it—the agent does.

🔒 Safe by default. Read-only. Mutations blocked unless explicitly allowed.

SQL runs sandboxed: no file, network, or extension access. REST calls stay under the API base URL; GraphQL allows only query operations. Recipes are scoped per target and credentials. Report vulnerabilities via SECURITY.md.

🧠 Recipe learning. Agent samples successful queries into reusable workflows. Ask once, reuse cached pipelines that execute without LLM reasoning. Learned recipes are exposed as tools named r_.

Quick Start

1. Run:

# Direct run (no clone needed)
OPENAI_API_KEY=your_key uvx --from git+https://github.com/agoda-com/api-agent api-agent

# Or clone
git clone https://github.com/agoda-com/api-agent.git && cd api-agent
uv sync --group dev

Set the OpenAI secret in env:

export OPENAI_API_KEY=your_key

Direct uvx runs use built-in defaults unless API_AGENT_CONFIG points to a TOML file. A cloned checkout uses api-agent.toml from the repository root by default.

2. Start local clone:

uv run api-agent

# Or Docker
docker build -t api-agent .
docker run -p 3000:3000 -e OPENAI_API_KEY=your_key api-agent

3. Add to any MCP client:

{
  "mcpServers": {
    "rickandmorty": {
      "url": "http://localhost:3000/mcp",
      "headers": {
        "X-Target-URL": "https://rickandmortyapi.com/graphql",
        "X-API-Type": "graphql"
      }
    }
  }
}

4. Ask questions:

  • “Show characters from Earth, only alive ones, group by species”
  • “Top 10 characters by episode count”
  • “Compare alive vs dead by species, only species with 10+ characters”

That’s it. Agent introspects schema, generates calls, runs SQL post-processing.

More Examples

REST API (Petstore):

{
  "mcpServers": {
    "petstore": {
      "url": "http://localhost:3000/mcp",
      "headers": {
        "X-Target-URL": "https://petstore3.swagger.io/api/v3/openapi.json",
        "X-API-Type": "rest"
      }
    }
  }
}

Your own API with auth:

{
  "mcpServers": {
    "myapi": {
      "url": "http://localhost:3000/mcp",
      "headers": {
        "X-Target-URL": "https://api.example.com/graphql",
        "X-API-Type": "graphql",
在 GitHub 查看完整 README

安装

docker run -p 3000:3000 -e OPENAI_API_KEY=your_key api-agent
新手?先看 mcpskill.org 教程 →

配置

{ "mcpServers": { "rickandmorty": { "url": "http://localhost:3000/mcp", "headers": { "X-Target-URL": "https://rickandmortyapi.com/graphql", "X-API-Type": "graphql" } } } }