docs2mcp
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.Status: week 4 of 4. Ingest, extract, design, approve, generate and the agent eval all work. The demo and the PyPI release (
docs2mcp-cli) are in progress.
Why
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.
Planned
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), 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.
Results so far
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, three of them now fixed. Details, failures and limits: evals/agent.
Install
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 command
Extraction and design call Claude, so they need ANTHROPIC_API_KEY. Generating a server from a reviewed tools.json doesn't.
Develop
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 CI
Settings are read from environment variables; see .env.example.
Ingest a documentation site
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 0
This 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.
Extract an API spec
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 calls
Claude 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.
Design the tools
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.
Generate the server
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.
Score an extraction
uv run docs2mcp score specs/frankfurter/spec.json --reference evals/extraction/reference/frankfurter.json
This 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.
Measure a design
uv run docs2mcp measure tools/frankfurter.json --spec specs/frankfurter/spec.json
This 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.
Check agent eval tasks
uv run docs2mcp check-tasks evals/agent/tasks/*.toml
The 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.
Trace a run
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.json
Each 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.
How this repo is built
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.
License
Metadata
Release files for docs2mcp-cli 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| docs2mcp_cli-0.1.0.tar.gz | 83.9 kB | With provenance | Details for docs2mcp_cli-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| docs2mcp_cli-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for docs2mcp_cli-0.1.0-py3-none-any.whl |
Total release size: 184.5 kB
Release files / docs2mcp_cli-0.1.0.tar.gz
| Download URL | docs2mcp_cli-0.1.0.tar.gz |
|---|---|
| Size | 83.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
38faf26acfcc7c970cc0efd7e17537f3938d812c7a46d2a67eec6829f87a6da4
|
|
BLAKE2b-256 checksum How to use checksums |
e03ef445c610813f7603085e540a33e5be6f02640f128fd39a90459c4d5c5eb2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logRelease files / docs2mcp_cli-0.1.0-py3-none-any.whl
| Download URL | docs2mcp_cli-0.1.0-py3-none-any.whl |
|---|---|
| Size | 100.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bc36fbab4e0b58986663b6105c3479040391efa15aa00f2a189495e90f138dba
|
|
BLAKE2b-256 checksum How to use checksums |
77c453b3a9da85b6b110a86d3276f96c4ca87305da5b0b3ba46ed988323d69e2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logSecurity for docs2mcp-cli 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for docs2mcp_cli-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.