Expose an internal REST API as an MCP in under an hour
When to use: You have a company API that agents should be able to call, and you don't want to write a client spec from scratch.
Prerequisites
- Python 3.10+ —
python --version - uv installed —
curl -LsSf https://astral.sh/uv/install.sh | sh
Flow
-
Bootstrap the projectScaffold a FastMCP server project called 'acme-api-mcp' with one starter tool. Use uv for dependency management.✓ Copied→ pyproject.toml + server.py with a working @mcp.tool example
-
Wrap the 3 highest-value endpointsMy internal API has endpoints /orders/{id}, /customers/search, /invoices/{id}/pdf. Write a FastMCP tool for each, using httpx.AsyncClient and reading AUTH_TOKEN from env.✓ Copied→ 3 decorated functions with type hints + docstrings that become tool descriptions
-
Test locally with the MCP InspectorRun the server with
uv run mcp dev server.py. Open the inspector and call each tool with a realistic input.✓ Copied→ Tools return expected JSON, no stack traces
Outcome: A working MCP server you can point Claude Desktop or any MCP client at.
Pitfalls
- Secrets leak into tool descriptions because you printed them in docstrings — Use docstrings to describe behavior, not examples with real tokens. Load secrets via
os.environand never echo them in errors - Async + sync mixed, causes event loop errors — Pick one — if your HTTP client is async, make the whole tool async; don't call
asyncio.runinside a tool