Stop pasting API docs into AI ... Note

Stop pasting API docs into AI coding agents: serve the spec over MCP

Engineers repeatedly struggle when using coding agents against unfamiliar APIs, a process marked by manual context assembly that quickly decays. The core issue lies in using prose documentation as the transport mechanism for API contracts, leading to problems like staleness, repeated token costs, and a lack of enforcement. Prose documentation provides a snapshot that quickly becomes outdated, forces re-uploading the same information in every conversation, and fails to validate calls until runtime errors occur.A structural fix involves providing the agent with the API contract as callable tools over an MCP (Microservice Contract Protocol) server, generated directly from the OpenAPI document. This approach transforms each API operation into a tool with a defined input schema, enabling structured discovery and pre-flight validation. Unlike prose, MCP tools allow for immediate error correction by the agent, centralize authentication, and ensure the contract updates in one place for all attached agents. Streaming operations also become usable, as the tool handles opening the stream and collecting events.Local development utilizes a local MCP server over the spec file, while shared environments can use a hosted MCP endpoint with version pinning and per-user tokens, emphasizing token scoping for minimal access. MCP genuinely wins in scenarios involving repeated integration work against internal APIs, environments with many small operations, enforcement-heavy domains like billing, and fast-moving specifications. It is not, however, a universal replacement for narrative documentation or high-performance SDKs.MCP is less suitable for one-off exploration, performance-critical or batch clients, and operations not explicitly defined in the OpenAPI spec. A well-maintained OpenAPI document is crucial, as the tools are only as accurate as the spec itself. The ideal setup involves maintaining a single OpenAPI document, from which three distinct renderings are derived: rendered documentation for human learning, generated SDKs for production code, and an MCP server for agent integration and exploration. This approach prevents redundant descriptions across different teams and tools.