Turn messy API documentation into a curated, task-shaped MCP server, and measure whether agents actually do better with it.
Results (Claude Haiku, 840 runs): on the three APIs with an official OpenAPI file, docs2mcp's task-shaped tools solved 98.3% of tasks, against 95.0% for tools converted from the OpenAPI file and 90.0% for FastMCP's
from_openapi, with 22% fewer tokens than the conversion. Across all six APIs they were level with docs2mcp's own one-tool-per-endpoint design. Details and limits.Live demo: docs2mcp.vercel.app. It shows the results, every task, and the four tool lists side by side, with no login.
Status: week 4 of 4. Ingest, extract, design, approve, generate and the agent eval all work. Released on PyPI as
docs2mcp-cli.
Most OpenAPI-to-MCP generators map each endpoint to one tool. Agents then see dozens of thinly described tools and have to chain calls themselves. docs2mcp reads the documentation directly (no OpenAPI file needed) and groups endpoints into a few tools shaped around real tasks, with descriptions written for an LLM. The reasoning is in ADR 0001.
flowchart LR
D["API docs URL"] --> I["Ingest<br/>fetch and clean pages"]
I --> X["Extract<br/>typed spec of endpoints"]
X --> S["Design<br/>task-shaped tools"]
S --> A{"Human approval"}
A --> G["Generate<br/>MCP server"]
G --> E["Eval<br/>100 tasks, 5 APIs"]
| Week | Milestone |
|---|---|
| 1 | Ingest and extract: a docs URL becomes a validated, structured spec for five public APIs |
| 2 | Design and generate: a working MCP server per API, runnable locally |
| 3 | Eval harness: 100 tasks, an agent runner, and results against direct conversion |
| 4 | Demo and release: web playground, package on PyPI (uvx docs2mcp-cli), write-up |
Eval APIs (public, no key needed): Open-Meteo (forecast and geocoding, scored separately because they are on different hosts), PokéAPI, Postcodes.io, Open Library and Frankfurter. Postcodes.io replaced REST Countries, whose open v3.1 API was retired in favour of a keyed v5.
Metrics: task success rate, tool calls per task, tokens per task, and the share of invalid tool calls.
On the three APIs with an official OpenAPI file, an agent (Claude Haiku) using docs2mcp's task-shaped tools solved 98.3% of tasks, against 95.0% with tools converted from the OpenAPI file and 90.0% with FastMCP's from_openapi. It used 22% fewer tokens than the OpenAPI conversion and 63% fewer than FastMCP, and on complex tasks it scored 100% against 83%. Across all six APIs, the task-shaped design was level with docs2mcp's own one-tool-per-endpoint design (94.7% against 95.7%): better on PokéAPI and worse on Open Library. The eval also found four real bugs, all now fixed. The redirect fix came after the run, so the Open Library numbers above still include that bug. Details, failures and limits: evals/agent.
A single agent run traced in Langfuse: the agent calls the task-shaped tool FindOutcode, which goes through MCP tools/call, and then returns the answer. The run took 2.15 s, cost $0.001 and used about 17k tokens.
The package is docs2mcp-cli on PyPI (docs2mcp there is an unrelated project). It needs Python 3.14.
uvx docs2mcp-cli --help # run without installing
uv tool install docs2mcp-cli # or install the docs2mcp commandExtraction and design call Claude, so they need ANTHROPIC_API_KEY. Generating a server from a reviewed tools.json doesn't.
git clone https://github.com/dpelezo/docs2mcp.git
cd docs2mcp
just setup # install dependencies and pre-commit hooks
just check # lint, type check and unit tests, the same as CISettings are read from environment variables; see .env.example.
uv run docs2mcp ingest https://pokeapi.co/docs/v2 --out ingest/pokeapi
# Docs split across sibling folders: pass each one
uv run docs2mcp ingest https://openlibrary.org/dev/docs/api/search \
https://openlibrary.org/dev/docs/api/books --out ingest/open_library
# Only the pages given, no links followed
uv run docs2mcp ingest https://frankfurter.dev/ --out ingest/frankfurter --depth 0This writes pages.jsonl and chunks.jsonl: Markdown sections labelled with their heading path and a link back to the source. Pages are cached in .cache/, so re-runs are offline; pass --refresh to refetch. The crawl follows in-scope links up to --max-pages (default 20); --depth N limits it to N links from a start URL. just integration runs the live tests against real sites. How it works: ADR 0003.
Needs ANTHROPIC_API_KEY in .env.
uv run docs2mcp extract ingest/pokeapi --out specs/pokeapi/spec.json --record recordings/pokeapi
uv run docs2mcp extract ingest/pokeapi --out specs/pokeapi/spec.json --replay recordings/pokeapi # no API callsClaude reads the chunks in batches and fills a flat schema; code validates each endpoint, repairs what is mechanical, sends the rest back to Claude with the errors, and merges everything into spec.json. extraction_report.json lists calls, tokens, merged duplicates, repairs and rejected endpoints. How it works: ADR 0004.
uv run docs2mcp design specs/frankfurter/spec.json --out tools/frankfurter/tools.json
uv run docs2mcp check-tools tools/frankfurter/tools.json --spec specs/frankfurter/spec.json
uv run docs2mcp approve tools/frankfurter/tools.json --all --except provider_rates --note "checked"design asks Claude to group the endpoints into task-shaped tools, such as one pokemon tool that gets one Pokémon by name or lists them. Claude names and describes the tools and their arguments, and code copies types, enums and defaults from the spec. Validation problems go back to Claude for another try, and anything still broken after the last try gets a plain one-tool-per-endpoint fallback, listed in design_report.json. --direct makes that one-tool-per-endpoint design for the whole API, with no LLM. Design uses claude-sonnet-5-5 by default (DOCS2MCP_DESIGN_MODEL); on the eval APIs it turns 129 tools into 69 and cuts the tool list an agent loads by about 28%, while keeping 245 of 248 parameters (results).
The output is tools.json: each tool's arguments, the API request each call makes, and any endpoints left out, with the reason. Review it and approve tools one by one with approve. generate builds only approved, valid tools, and reports every tool it skips with the reason. check-tools reports every problem after a hand edit. Rules: ADR 0011 and ADR 0012; schema: docs/tools.schema.json.
uv run docs2mcp generate tools/frankfurter/tools.json --spec specs/frankfurter/spec.json --out servers/frankfurter
uv run --directory servers/frankfurter server.py # stdio
uv run --directory servers/frankfurter server.py --http # streamable HTTP on :8000/mcp
uv run python scripts/try_server.py servers/frankfurter exchange_rates '{"base": "EUR"}'generate writes one server.py, built on the official MCP Python SDK (MCPServer). It has one typed function per approved tool. Each call picks the route that takes the most of the arguments given, and names any it cannot take. It makes one request with httpx, following redirects on the API's own host, and returns the JSON within 20,000 characters. A longer response first loses the second half of its biggest lists and nested objects, again and again, so fields that come after a long list still show. Only then is it cut. A note says what was left out. HTTP and network errors come back as tool errors.
Next to the server are a pyproject.toml, a README listing every skipped tool, excluded endpoint and unreachable endpoint with its reason, and generation_report.json. scripts/try_server.py starts a server, lists its tools and makes one real call. CI also runs every generated server through Ruff and strict Pyright, and runs the official MCP conformance suite against one of them (just conformance). The scenarios that don't apply to a tools-only server are listed in evals/conformance/baseline.yml.
uv run docs2mcp score specs/frankfurter/spec.json --reference evals/extraction/reference/frankfurter.jsonThis compares the extracted endpoints and parameters with a reference built from the API's own OpenAPI file. Results and the baseline: evals/extraction. Rules: ADR 0005.
uv run docs2mcp measure tools/frankfurter.json --spec specs/frankfurter/spec.jsonThis counts tools, routes, covered and excluded endpoints, and the estimated tokens an agent loads to see the tools. A person also reviews each design against a pass/fail checklist. Baseline and rules: evals/design.
uv run docs2mcp check-tasks evals/agent/tasks/*.tomlThe agent eval asks an agent the same questions through three servers per API, and scores each answer with a fixed rule, never a model. This command validates the task files and counts tasks by level. Format and rules: evals/agent and ADR 0013.
Tracing is off by default. Turn it on by setting either:
- Langfuse keys (
LANGFUSE_PUBLIC_KEYandLANGFUSE_SECRET_KEY). The default host is Langfuse's EU region. For a US, Japan or self-hosted project, also setLANGFUSE_BASE_URL(orLANGFUSE_HOST), for examplehttps://us.cloud.langfuse.com. A401from the exporter usually means the keys belong to another region; - or any OpenTelemetry collector (
OTEL_EXPORTER_OTLP_ENDPOINT).
export LANGFUSE_PUBLIC_KEY=pk-lf-... LANGFUSE_SECRET_KEY=sk-lf-...
uv run docs2mcp extract ingest/frankfurter --out specs/frankfurter/spec.jsonEach command is one trace. It has spans for:
- each page fetch, including cache hits and HTTP status;
- each extraction batch;
- each model call, using the OpenTelemetry GenAI attributes (model and input, output and cached tokens), which Langfuse shows as generations;
- each validation step and design repair, and generation.
Prompts and model replies stay out of traces unless DOCS2MCP_TRACE_CONTENT=true, so documentation text is not sent anywhere by default.
I build with AI coding agents and review everything they produce. The working rules every agent follows are in AGENTS.md: run the baseline before changing code, keep unit tests off the network, never change an eval task in the same pull request as the code it measures, and report what was and was not verified. Changes to anything the eval measures follow the eval-driven change procedure, which agents load as a skill: name the failing case, re-run every API on the same inputs, and show before/after numbers.
