fastapi-gql-mcp: one GraphQL MCP surface cuts tool tokens from ~11k to ~2.5k and stops payload bloat
tangkikodo · reddit · 2026-10-05
The author of fastapi-gql-mcp addresses two context costs when exposing FastAPI apps via MCP: one-tool-per-endpoint catalogs (10,950 tokens at 100 routes) and huge list responses (1-2 MB per call, with community threads showing MCP tools wasting 40% of Claude's context).
The fix: derive a GraphQL schema from the FastAPI app (no decorators, no model changes) and expose a tiny constant MCP toolset — getschema + graphqlquery, or a 4-layer drill-down (listdomains → listqueries → getqueryschema → graphqlquery) for large APIs.
- Tool catalog: 2,480/1,480 tokens and it stops growing
- Field projection: { id name } returns 610 B vs 2,875 B on the benchmark app; on 1-2 MB endpoints it's the difference between a dead session and a three-line answer
- Guardrails by default: depth limit, bounded fan-out, per-call timeout, doc cache (1.52ms → 0.69ms)
- Auth stays real: queries run through the actual ASGI app in-process, so Depends, middleware and JWT behave as over HTTP
Repo includes benchmark methodology and a reproduce script. Install via pip install fastapi-gql-mcp.
More from coding & agent
- Agent fails: Dots subagent refuses user approval passed via main agent — xeophon · 2026-10-05
- Personal agents hackathon: 100+ ideas signal an agent explosion as infra matures — jamdac · 2026-10-05
- Browser agents' worst failure mode isn't hallucination, it's fake success — Comfortable_Oven6576 · 2026-10-05
- Power user review: ChatGPT Dots hit abuse-prevention limits even on the $200 plan — invertednz · 2026-10-05
- dots developer books daily user interviews to steer its personal assistant roadmap — pvncher · 2026-10-05
- FDE playbook: build agents inside clients' existing systems of record, not AI-native stacks — vasuman · 2026-10-05