Back to blog
Conceptopenapiswagger

How to turn an OpenAPI spec into MCP tools

Your API already has an OpenAPI (Swagger) spec. Here's how each operation maps to an MCP tool, what gets lost or transformed, and how to generate a working server without writing code.

June 18, 2026·8 min read

If your API already publishes an OpenAPI (formerly Swagger) specification, you're most of the way to an MCP server. An OpenAPI spec describes every endpoint, its parameters, and its responses in a machine-readable format — which is exactly what an AI client needs to call a tool. This guide explains how each part of a spec maps to MCP, what gets transformed, and how to generate a working server without writing code.

Key takeaways
  • Each OpenAPI operation (a method + path) becomes one MCP tool.
  • operationId becomes the tool name; summary/description become the tool description the model reads.
  • Path, query, and body parameters become the tool's JSON input schema.
  • You choose which operations to expose — keep reads on, destructive writes off until ready.
  • Cast does this conversion automatically: upload the spec, get callable tools.

Why OpenAPI is a perfect source for MCP

Both OpenAPI and MCP exist to describe capabilities in a structured way. OpenAPI tells human developers and codegen tools how to call an API; MCP tells AI models how to call a tool. The overlap is large: an operation's inputs and a tool's input schema are nearly the same thing. That's why converting one to the other is mostly a mechanical mapping.

How each part of the spec maps to a tool

Operations → tools

Every path/method combination in your spec — like GET /products/{id} — becomes a single MCP tool. An API with 30 operations yields up to 30 tools.

operationId → tool name

The operationId field becomes the tool's name (e.g. getProduct). If a spec omits it, a name is derived from the method and path. Clear, verb-based operation IDs make the model far better at picking the right tool.

summary / description → tool description

This is the text the model actually reads to decide whether a tool fits the user's request. Good descriptions in your spec translate directly into a smarter agent. Vague ones lead to wrong tool choices.

parameters & requestBody → input schema

Path parameters, query parameters, and the request body schema combine into the tool's input JSON schema. The model fills these in when it calls the tool. Consider this snippet:

openapi.yaml (excerpt)
paths:
  /products/{id}:
    get:
      operationId: getProduct
      summary: Fetch a single product by its ID
      parameters:
        - name: id
          in: path
          required: true
          schema: { type: string }

That becomes a tool named getProduct, described as "Fetch a single product by its ID," with one required string input called id.

📝

Spend ten minutes improving the summary and operationId fields in your spec before converting. It's the single highest-leverage thing you can do for tool accuracy.

Doing it with Cast

Rather than hand-coding the mapping, you can upload the spec and let Cast generate the tools. Point it at a file or a URL like https://api.example.com/openapi.json:

Workspace navigationactual UI
overview
upload
configure
connect
analytics
logs

Once parsing completes, every operation appears as a toggleable tool. This is where you decide what agents can actually do — enable the reads, leave destructive writes off until you've tested:

Configure → Toolsactual UI
GET

listProducts

/products

GET

getProduct

/products/{id}

POST

createProduct

/products

PUT

updateProduct

/products/{id}

DELETE

deleteProduct

/products/{id}

Save changes

Configure how Cast authenticates to your API, then grab the MCP URL from the Connect tab:

Connect → Your MCP URLactual UI
Claude Desktop
Cursor
Windsurf
Cline
claude_desktop_config.json Copy
{
  "mcpServers": {
    "products-api": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-remote@latest",
        "https://mcp.getcast.io/products-api-cmpz99kk01"
      ]
    }
  }
}
Server active · 0 errors

What doesn't map cleanly (and how to handle it)

  • Auth — OpenAPI describes security schemes, but you still supply the actual credentials. Cast handles this in the Configure tab.
  • Huge specs — exposing hundreds of tools can overwhelm a model. Curate down to the operations that matter.
  • Complex polymorphic bodies — deeply nested oneOf/allOf schemas still work, but simpler inputs lead to more reliable tool calls.

Have an OpenAPI spec? Get an MCP server from it

Upload an OpenAPI spec, configure auth, and get a live MCP endpoint in minutes — no infrastructure to manage.

Upload your spec

Frequently asked questions

Does Swagger work, or only OpenAPI 3?

OpenAPI is the current name for what used to be called Swagger. Modern OpenAPI 3.x specs are the target; many Swagger 2.0 specs can be converted or upgraded first.

Do I have to expose every endpoint?

No. You toggle individual operations on or off. A common pattern is exposing read operations broadly and keeping create/update/delete disabled until reviewed.

What if I don't have an OpenAPI spec?

Many frameworks can generate one from your code (annotations or introspection). Once you have a spec, the rest is automatic.

Will the tool names match my endpoints?

They're derived from operationId where present, so well-named operations produce clean, predictable tool names.