{"id":47882989,"url":"https://github.com/agoda-com/api-agent","last_synced_at":"2026-06-19T02:01:45.736Z","repository":{"id":334712969,"uuid":"1131997674","full_name":"agoda-com/api-agent","owner":"agoda-com","description":"Universal MCP server for GraphQL/REST APIs","archived":false,"fork":false,"pushed_at":"2026-06-02T00:00:13.000Z","size":382,"stargazers_count":277,"open_issues_count":5,"forks_count":43,"subscribers_count":4,"default_branch":"main","last_synced_at":"2026-06-02T01:21:36.065Z","etag":null,"topics":["api","mcp"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/agoda-com.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-01-11T05:25:14.000Z","updated_at":"2026-06-01T08:19:12.000Z","dependencies_parsed_at":"2026-04-19T09:02:00.251Z","dependency_job_id":null,"html_url":"https://github.com/agoda-com/api-agent","commit_stats":null,"previous_names":["agoda-com/api-agent"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/agoda-com/api-agent","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agoda-com%2Fapi-agent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agoda-com%2Fapi-agent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agoda-com%2Fapi-agent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agoda-com%2Fapi-agent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/agoda-com","download_url":"https://codeload.github.com/agoda-com/api-agent/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agoda-com%2Fapi-agent/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34514285,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-19T02:00:06.005Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","mcp"],"created_at":"2026-04-04T02:00:27.570Z","updated_at":"2026-06-19T02:01:45.672Z","avatar_url":"https://github.com/agoda-com.png","language":"Python","funding_links":[],"categories":["Api Integration Mcp Servers"],"sub_categories":[],"readme":"# API Agent\n\n**Turn any API into an MCP server. Query in English. Get results—even when the API can't.**\n\nPoint 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, JOINs work **even if the API doesn't support them**.\n\n## What Makes It Different\n\n**🎯 Zero config.** No custom MCP code per API. Point at a GraphQL endpoint or OpenAPI spec — schema introspected automatically.\n\n**✨ SQL post-processing.** API returns 10,000 unsorted rows? Agent ranks top 10. No GROUP BY? Agent aggregates. Need JOINs across endpoints? Agent combines.\n\n**🔒 Safe by default.** Read-only. Mutations blocked unless explicitly allowed.\n\n**🧠 Recipe learning.** Successful queries become cached pipelines. Reuse instantly without LLM reasoning.\n\n## Quick Start\n\n**1. Run (choose one):**\n\n```bash\n# Direct run (no clone needed)\nOPENAI_API_KEY=your_key uvx --from git+https://github.com/agoda-com/api-agent api-agent\n\n# Or clone \u0026 run\ngit clone https://github.com/agoda-com/api-agent.git \u0026\u0026 cd api-agent\nuv sync \u0026\u0026 OPENAI_API_KEY=your_key uv run api-agent\n\n# Or Docker\ngit clone https://github.com/agoda-com/api-agent\ndocker build -t api-agent .\ndocker run -p 3000:3000 -e OPENAI_API_KEY=your_key api-agent\n```\n\n**2. Add to any MCP client:**\n```json\n{\n  \"mcpServers\": {\n    \"rickandmorty\": {\n      \"url\": \"http://localhost:3000/mcp\",\n      \"headers\": {\n        \"X-Target-URL\": \"https://rickandmortyapi.com/graphql\",\n        \"X-API-Type\": \"graphql\"\n      }\n    }\n  }\n}\n```\n\n**3. Ask questions:**\n- *\"Show characters from Earth, only alive ones, group by species\"*\n- *\"Top 10 characters by episode count\"*\n- *\"Compare alive vs dead by species, only species with 10+ characters\"*\n\nThat's it. Agent introspects schema, generates queries, runs SQL post-processing.\n\n## More Examples\n\n**REST API (Petstore — OpenAPI 3.x):**\n```json\n{\n  \"mcpServers\": {\n    \"petstore\": {\n      \"url\": \"http://localhost:3000/mcp\",\n      \"headers\": {\n        \"X-Target-URL\": \"https://petstore3.swagger.io/api/v3/openapi.json\",\n        \"X-API-Type\": \"rest\"\n      }\n    }\n  }\n}\n```\n\n**REST API (Petstore — Swagger 2.0):**\n```json\n{\n  \"mcpServers\": {\n    \"petstore\": {\n      \"url\": \"http://localhost:3000/mcp\",\n      \"headers\": {\n        \"X-Target-URL\": \"https://petstore.swagger.io/v2/swagger.json\",\n        \"X-API-Type\": \"rest\"\n      }\n    }\n  }\n}\n```\n\n**Your own API with auth:**\n```json\n{\n  \"mcpServers\": {\n    \"myapi\": {\n      \"url\": \"http://localhost:3000/mcp\",\n      \"headers\": {\n        \"X-Target-URL\": \"https://api.example.com/graphql\",\n        \"X-API-Type\": \"graphql\",\n        \"X-Target-Headers\": \"{\\\"Authorization\\\": \\\"Bearer YOUR_TOKEN\\\"}\"\n      }\n    }\n  }\n}\n```\n\n---\n\n## Reference\n\n### Headers\n\n| Header                 | Required | Description                                                |\n| ---------------------- | -------- | ---------------------------------------------------------- |\n| `X-Target-URL`         | Yes      | GraphQL endpoint OR OpenAPI/Swagger spec URL (3.x and 2.0) |\n| `X-API-Type`           | Yes      | `graphql` or `rest`                                        |\n| `X-Target-Headers`     | No       | JSON auth headers, e.g. `{\"Authorization\": \"Bearer xxx\"}`  |\n| `X-API-Name`           | No       | Override tool name prefix (default: auto-generated)        |\n| `X-Base-URL`           | No       | Override base URL for REST API calls                       |\n| `X-Allow-Unsafe-Paths` | No       | Header string containing JSON array of `fnmatch` globs (`*`, `?`) for POST/PUT/DELETE/PATCH |\n| `X-Poll-Paths`         | No       | Header string containing JSON array of polling path patterns (enables poll tool) |\n| `X-Include-Result`     | No       | Include full uncapped `result` field in output             |\n\n#### Header value examples\n\n`X-Allow-Unsafe-Paths` and `X-Poll-Paths` use the same escaping format: JSON array encoded as a header string.\n\n**MCP config (JSON):**\n```json\n{\n  \"headers\": {\n    \"X-Allow-Unsafe-Paths\": \"[\\\"/search\\\", \\\"/api/*/query\\\", \\\"/jobs/*/cancel\\\"]\",\n    \"X-Poll-Paths\": \"[\\\"/search\\\", \\\"/trips/*/status\\\"]\"\n  }\n}\n```\n\n**`X-Allow-Unsafe-Paths` pattern examples:**\n- `\"/search\"` exact path\n- `\"/api/*/query\"` one wildcard segment\n- `\"/jobs/*\"` any suffix under `/jobs/`\n\n**`X-Poll-Paths` pattern examples:**\n- `\"/search\"` exact polling path\n- `\"/trips/*/status\"` wildcard polling path\n\n`X-Poll-Paths` enables polling guidance/tooling; `X-Allow-Unsafe-Paths` controls unsafe method allowlist.\n\n**Escaping quick check (same for both headers):**\n- wrong: `\"X-Allow-Unsafe-Paths\": \"[\"/search\"]\"`\n- right: `\"X-Allow-Unsafe-Paths\": \"[\\\"/search\\\"]\"`\n\n### MCP Tools\n\n**Core tools** (2 per API):\n\n| Tool               | Input                                                          | Output                          |\n| ------------------ | -------------------------------------------------------------- | ------------------------------- |\n| `{prefix}_query`   | Natural language question                                      | `{ok, data, queries/api_calls}` |\n| `{prefix}_execute` | GraphQL: `query`, `variables` / REST: `method`, `path`, params | `{ok, data}`                    |\n\nTool names auto-generated from URL (e.g., `example_query`). Override with `X-API-Name`.\n\n**Recipe tools** (dynamic, added as recipes are learned):\n\n| Tool               | Input                              | Output |\n| ------------------ | ---------------------------------- | ------ |\n| `r_{recipe_slug}`  | flat recipe-specific params, `return_directly` (bool) | CSV or `{ok, data, executed_queries/calls}` |\n\nCached pipelines, no LLM reasoning. Appear after successful queries. Clients notified via `tools/list_changed`.\n\n### Configuration\n\n| Variable                      | Required | Default                   | Description                        |\n| ----------------------------- | -------- | ------------------------- | ---------------------------------- |\n| `OPENAI_API_KEY`              | **Yes**  | -                         | OpenAI API key (or custom LLM key) |\n| `OPENAI_BASE_URL`             | No       | https://api.openai.com/v1 | Custom LLM endpoint                |\n| `API_AGENT_MODEL_NAME`        | No       | gpt-5.2                   | Model (e.g., gpt-5.2)              |\n| `API_AGENT_PORT`              | No       | 3000                      | Server port                        |\n| `API_AGENT_ENABLE_RECIPES`    | No       | true                      | Enable recipe learning \u0026 caching   |\n| `API_AGENT_RECIPE_CACHE_SIZE` | No       | 64                        | Max cached recipes (LRU eviction)  |\n| `OTEL_EXPORTER_OTLP_ENDPOINT` | No       | -                         | OpenTelemetry tracing endpoint     |\n\n---\n\n## How It Works\n\n```mermaid\nsequenceDiagram\n    participant U as User\n    participant M as MCP Server\n    participant A as Agent\n    participant G as Target API\n\n    U-\u003e\u003eM: Question + Headers\n    M-\u003e\u003eG: Schema introspection\n    G--\u003e\u003eM: Schema\n    M-\u003e\u003eA: Schema + question\n    A-\u003e\u003eG: API call\n    G--\u003e\u003eA: Data → stored in DuckDB\n    A-\u003e\u003eA: SQL post-processing\n    A--\u003e\u003eM: Summary\n    M--\u003e\u003eU: {ok, data, queries[]}\n```\n\n## Architecture\n\n```mermaid\nflowchart TB\n    subgraph Client[\"MCP Client\"]\n        H[\"Headers: X-Target-URL, X-API-Type\"]\n    end\n\n    subgraph MCP[\"MCP Server (FastMCP)\"]\n        Q[\"{prefix}_query\"]\n        E[\"{prefix}_execute\"]\n        R[\"r_{recipe} (dynamic)\"]\n    end\n\n    subgraph Agent[\"Agents (OpenAI Agents SDK)\"]\n        GA[\"GraphQL Agent\"]\n        RA[\"REST Agent\"]\n    end\n\n    subgraph Exec[\"Executors\"]\n        HTTP[\"HTTP Client\"]\n        Duck[\"DuckDB\"]\n    end\n\n    Client --\u003e|NL + headers| MCP\n    Q --\u003e|graphql| GA\n    Q --\u003e|rest| RA\n    E --\u003e HTTP\n    R --\u003e|\"no LLM\"| HTTP\n    R --\u003e Duck\n    GA --\u003e HTTP\n    RA --\u003e HTTP\n    GA --\u003e Duck\n    RA --\u003e Duck\n    HTTP --\u003e API[Target API]\n```\n\n**Stack:** [FastMCP](https://github.com/jlowin/fastmcp) • [OpenAI Agents SDK](https://openai.github.io/openai-agents-python/) • [DuckDB](https://duckdb.org)\n\n---\n\n## Recipe Learning\n\nAgent learns reusable patterns from successful queries:\n\n1. **Executes** — API calls + SQL via LLM reasoning\n2. **Extracts** — LLM converts trace into parameterized template\n3. **Caches** — Stores recipe keyed by (API, schema hash)\n4. **Exposes** — Recipe becomes MCP tool (`r_{name}`) callable without LLM\n\n```mermaid\nflowchart LR\n    subgraph First[\"First Query via {prefix}_query\"]\n        Q1[\"'Top 5 users by age'\"]\n        A1[\"Agent reasons\"]\n        E1[\"API + SQL\"]\n        R1[\"Recipe extracted\"]\n    end\n\n    subgraph Tools[\"MCP Tools\"]\n        T[\"r_get_top_users\u003cbr/\u003eparams: {limit}\"]\n    end\n\n    subgraph Reuse[\"Direct Call\"]\n        Q2[\"r_get_top_users({limit: 10})\"]\n        X[\"Execute directly\"]\n    end\n\n    Q1 --\u003e A1 --\u003e E1 --\u003e R1 --\u003e T\n    Q2 --\u003e T --\u003e X\n```\n\nRecipes auto-expire on schema changes. Disable with `API_AGENT_ENABLE_RECIPES=false`.\n\n---\n\n## Development\n\n```bash\ngit clone https://github.com/agoda-com/api-agent.git\ncd api-agent\nuv sync --group dev\nuv run pytest tests/ -v      # Tests\nuv run ruff check api_agent/  # Lint\nuv run ty check               # Type check\n```\n\n## Observability\n\nSet `OTEL_EXPORTER_OTLP_ENDPOINT` to enable OpenTelemetry tracing. Works with Jaeger, Zipkin, Grafana Tempo, Arize Phoenix.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagoda-com%2Fapi-agent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fagoda-com%2Fapi-agent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagoda-com%2Fapi-agent/lists"}