Lessons from generating an MCP server from a FastAPI OpenAPI spec: 130 tools was too many
Both_Toe2688 · reddit · 2026-12-01
The author of an open-source GST billing app shares hands-on lessons from building its MCP server so Claude/ChatGPT can query invoices and create documents:
- Tools auto-generated from app.openapi() so MCP can't drift from the API, plus a hand-written names/descriptions/exclusions file and build-time tests (unique tool names ≤64 chars, no leftover $ref, no body/query clashes).
- 130 tools was too many — default curated profile of 40, ?profile=all for everything.
- Hand-rolled 80-line Streamable HTTP instead of the SDK: session manager tied to app lifespan, 401 challenge ordering, and Starlette version conflicts.
- Use addroute, not mount — mounting causes a 307 redirect to /mcp/ that drops POST bodies in some clients.
- Never return HTTP 401 for permission errors — clients treat it as expired token and loop OAuth forever.
- Per-company OAuth grants with read/write/admin/sendemail scopes; write tools off by default on self-hosted installs.
MIT-licensed code and setup guide included; works as a custom connector in Claude and ChatGPT without Developer Mode.
More from coding & agent
- Antigravity + Neon + Obsidian: a dev setup that 'feels like a cheat code' — osanseviero · 2026-12-01
- Microsoft demos 'multiplayer AI' at ESPC26: humans and agents collaborating in Copilot and Teams — donasarkar · 2026-12-01
- iMCP 1.9.0 adds Photos and Files services for Claude Code and Codex clients — pcuenq · 2026-12-01
- Microsoft exec lays out 3-pillar enterprise AI stack: Copilot UX, Microsoft IQ, Agent 365 governance — donasarkar · 2026-12-01
- Progress-Aware On-Policy Distillation Cuts Wasted Turns in Long-Horizon Multimodal Agents — ATH-MaaS · 2026-12-01
- Harness RL LoRA benchmarked: 42% faster in-agent, zero degradation on raw API calls — yb2698 · 2026-12-01