|
1 | 1 | # openapi-toolkit |
2 | 2 | openapi-toolkit is an open-source tool designed to streamline the integration of OpenAPI (formerly known as Swagger) specifications into your development workflow. By taking an OpenAPI/Swagger file as input, the OpenAPI Toolkit automatically generates server and client code, enabling seamless integration of APIs. This automation accelerates development processes, ensures consistency across different platforms, and reduces the risk of manual errors. Whether you're building a new service or integrating with existing APIs, OpenAPI Toolkit simplifies the process by providing ready-to-use code tailored to your OpenAPI specifications. |
3 | 3 |
|
| 4 | +# Generate MCP Server |
| 5 | + |
| 6 | +openapi-toolkit generates a fully functional [MCP SDK FastMCP](https://github.com/modelcontextprotocol/python-sdk) server from any OpenAPI/Swagger spec — one MCP tool per API endpoint, grouped by controller, with the async Pydantic v2 client bundled inline. |
| 7 | + |
| 8 | +## Generate |
| 9 | + |
| 10 | +```bash |
| 11 | +# no install required |
| 12 | +npx openapi-toolkit -i https://petstore3.swagger.io/api/v3/openapi.json -g python-mcp-server -t server -o ./my-api-mcp |
| 13 | + |
| 14 | +# or with global install |
| 15 | +npm i -g openapi-toolkit |
| 16 | +openapi-toolkit -i https://petstore3.swagger.io/api/v3/openapi.json -g python-mcp-server -t server -o ./my-api-mcp |
| 17 | +``` |
| 18 | + |
| 19 | +Generated layout: |
| 20 | +``` |
| 21 | +my-api-mcp/ |
| 22 | + pyproject.toml # uv project: mcp, httpx, pydantic |
| 23 | + README.md |
| 24 | + src/ |
| 25 | + mcp_server.py # FastMCP entry point, tool registration, transport CLI |
| 26 | + client/ # generated async httpx + Pydantic v2 client (inline) |
| 27 | + __init__.py |
| 28 | + client.py |
| 29 | + models/ |
| 30 | + controllers/ |
| 31 | + server/ |
| 32 | + tools/ |
| 33 | + <controller>.py # one file per API controller tag |
| 34 | +``` |
| 35 | + |
| 36 | +## Install and run |
| 37 | + |
| 38 | +```bash |
| 39 | +cd my-api-mcp |
| 40 | +uv sync |
| 41 | +BASE_URL=https://api.example.com uv run python src/mcp_server.py |
| 42 | +``` |
| 43 | + |
| 44 | +## Transport options |
| 45 | + |
| 46 | +```bash |
| 47 | +# stdio (default — for Claude Desktop and most MCP clients) |
| 48 | +BASE_URL=https://api.example.com uv run python src/mcp_server.py --transport stdio |
| 49 | + |
| 50 | +# SSE |
| 51 | +BASE_URL=https://api.example.com uv run python src/mcp_server.py --transport sse --host 0.0.0.0 --port 8000 |
| 52 | + |
| 53 | +# Streamable HTTP |
| 54 | +BASE_URL=https://api.example.com uv run python src/mcp_server.py --transport streamable-http --host 0.0.0.0 --port 8000 --path /mcp |
| 55 | +``` |
| 56 | + |
| 57 | +A fully generated example (Petstore API) is available in this repo: [examples/pet-store-mcp](https://github.com/barnuri/openapi-toolkit/tree/master/examples/pet-store-mcp) |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | +## Environment variables |
| 62 | + |
| 63 | +| Variable | Description | |
| 64 | +|---|---| |
| 65 | +| `BASE_URL` | Base URL of the target API (required at runtime) | |
| 66 | +| `TOOL_FILTER_ROUTES` | Comma-separated controller names to load (e.g. `pet,store`). Loads all if unset. | |
| 67 | +| `TOOL_FILTER_METHODS` | Comma-separated tool function names to register (e.g. `getPetById,addPet`). Registers all if unset. | |
| 68 | + |
4 | 69 | # Install |
5 | 70 |
|
6 | 71 | [](https://github.com/barnuri/openapi-toolkit/actions/workflows/runTests.yaml) [](https://github.com/barnuri/openapi-toolkit/actions/workflows/createTagAndReleaseAndPublish.yaml) |
|
0 commit comments