DEV Community

Christopher Dondici
Christopher Dondici

Posted on

I turned a real OpenAPI into an MCP server in 5 min (without losing custom code on regen)

I built an OpenAPI to MCP server generator for TypeScript, Python and Go.

The v1 mistake: 1 endpoint = 1 tool. On a real API with 200 operations, you get a 200-tool server. Nobody can use that. That was the exact feedback I got on Reddit, and it was right.

What I changed in 2.1.5:

1. Grouping by tag or path

200 operations across 8 tags become ~8 tools. Each group routes internally by action.

node dist/cli/index.js generate -i api.yaml -o ./out --group-by tag
node dist/cli/index.js generate -i api.yaml -o ./out --include-tags pets --group-by tag

  1. Filter before you generate
    Only generate what you will use:
    node dist/cli/index.js generate -i api.yaml -o ./out --path-prefix "/users/"
    node dist/cli/index.js generate -i api.yaml -o ./out --include-paths "/users/
    ,/orders/" --exclude-paths "/users/internal/"
    node dist/cli/index.js generate -i api.yaml -o ./out --operation-allowlist listPets,createPet

  2. Regen without losing custom code
    Your code lives between markers and survives regen with a 3-way merge:
    // @@mcp-gen:start:get_pets
    const user = await db.users.findById(args.id);
    return { content: [{ type: "text", text: JSON.stringify(user) }] };
    // @@mcp-gen๐Ÿ”šget_pets
    node dist/cli/index.js generate -i api.yaml -o ./out --incremental
    Reusable logic goes in handlers.custom.* โ€” never overwritten without --force.

  3. Fase 0 P0 fixes in 2.1.5

  4. TypeScript: real query serialization (get_pets({ limit: 5 }) -> /pets?limit=5)

  5. Python: _build_query / _build_headers in --http mode, including grouped tools

  6. Go: --http wired to the real APIClient, no more not yet wired stubs

  7. Registry is v3-only with actionable errors for removed keys and v2 specs

Try it with the repo example
git clone https://github.com/ChristopherDond/MCP-Generator.git
cd MCP-Generator
npm ci
npm run build
node dist/cli/index.js generate -i examples/petstore.yaml -l typescript -o ./my-server
node dist/cli/index.js validate -i examples/petstore.yaml
Or install directly:

npm install -g @christopher_dondici/mcp-gen@2.1.5
Repo: https://github.com/ChristopherDond/MCP-Generator

Validated with npm run build + npm test (11 suites, 196 tests).

Top comments (0)