DEV Community

Bhavy Shekhaliya
Bhavy Shekhaliya

Posted on

How to Turn an OpenAPI Specification into MCP Tools

If you already maintain an API, you probably have most of the information needed to create an MCP interface.

Your OpenAPI specification already describes:

  • available operations;
  • paths and methods;
  • required and optional parameters;
  • request bodies;
  • response formats; and
  • authentication schemes.

The work is not simply renaming an HTTP endpoint. An MCP tool needs to be understandable to an AI client: it needs a clear name, an accurate description, a useful input schema, and controlled access to the underlying API.

This guide walks through that mapping with a small support-ticket API example.

OpenAPI to MCP: the basic mapping

An OpenAPI operation can provide the foundation for one MCP capability:

OpenAPI MCP tool
operationId Starting point for the tool name
summary and description Tool description
Path parameters Usually required tool inputs
Query parameters Optional or required tool inputs
Request body schema Structured tool input
Response schema Information about the returned result
Security scheme Runtime authentication for the API request
Selected operations The allowlist of capabilities exposed to the AI client

The exact presentation can vary by implementation, but the important principle is stable: the tool should preserve the API's real contract instead of hiding it behind a vague "call endpoint" action.

Start with a useful OpenAPI operation

Here is a shortened but concrete OpenAPI example for a support API:

openapi: 3.0.3
info:
  title: Support API
  version: 1.0.0
servers:
  - url: https://api.example.com

paths:
  /tickets/{ticket_id}:
    get:
      operationId: getTicket
      summary: Get a support ticket
      description: Return the status, priority, requester, and latest update for one ticket.
      parameters:
        - name: ticket_id
          in: path
          required: true
          schema:
            type: string
        - name: include_comments
          in: query
          required: false
          schema:
            type: boolean
            default: false
      responses:
        "200":
          description: Ticket returned
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Ticket"
      security:
        - bearerAuth: []

  /tickets:
    post:
      operationId: createTicket
      summary: Create a support ticket
      description: Create a ticket for a customer issue.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - title
                - description
              properties:
                title:
                  type: string
                description:
                  type: string
                priority:
                  type: string
                  enum: [low, normal, high]
      responses:
        "201":
          description: Ticket created
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Ticket"
      security:
        - bearerAuth: []

components:
  schemas:
    Ticket:
      type: object
      properties:
        id:
          type: string
        status:
          type: string
        priority:
          type: string
        title:
          type: string

  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
Enter fullscreen mode Exit fullscreen mode

This example gives an MCP generator enough information to create two candidate tools:

  • getTicket, which needs ticket_id and can optionally receive include_comments;
  • createTicket, which needs title and description and accepts a constrained priority value.

The API remains responsible for business logic. MCP adds a structured interface through which an AI client can discover and call the selected capabilities.

1. Validate the specification before importing it

Fix the API definition before you use it as the source for tools. At minimum, check that:

  • every operation has a unique, meaningful identifier;
  • summaries and descriptions explain what an operation does;
  • parameter types match the values the API actually accepts;
  • required fields are marked as required;
  • request and response schemas match real JSON responses;
  • authentication schemes are documented; and
  • references such as #/components/schemas/Ticket resolve correctly.

An incomplete specification can still look valid to a human while producing confusing tools. A missing description, an incorrectly optional field, or a stale response schema gives the AI client the wrong information at the moment it chooses an action.

0mcp supports Swagger 2.0, OpenAPI 3.0, OpenAPI 3.1, and Postman collections. For an OpenAPI workflow, import the specification rather than treating a raw REST base URL as the source. 0mcp validates the imported definition and shows warnings or errors before you publish the server.

For more detail on the supported OpenAPI path, see the OpenAPI-to-MCP documentation.

2. Choose the operations that should become tools

Do not expose every endpoint just because it exists.

Start with the smallest set that represents a useful workflow. For the support API above, that might be:

  1. getTicket for reading the current state of a ticket;
  2. createTicket for opening a new issue; and
  3. a separate operation for adding an internal note, if that action is genuinely needed.

This selection is an access-control decision as well as a usability decision. Internal administration endpoints, destructive actions, debugging routes, and duplicate operations should not automatically become AI capabilities.

HTTP methods are useful clues, but they do not decide the tool boundary by themselves. A GET operation might provide data for a tool or resource, while a POST operation might represent a state-changing tool. Consider what the capability means to the user, what permissions it needs, and whether an AI client can use it safely.

In 0mcp, you can review the detected operations and select which API functions to expose. You can also create or update tools, resources, and prompts as the integration becomes more deliberate.

3. Map parameters into one tool schema

HTTP APIs distribute inputs across several locations. An MCP tool presents the inputs as one structured schema.

For the getTicket operation:

  • ticket_id comes from the path and is required;
  • include_comments comes from the query string and is optional;
  • the bearer credential is used for authentication, not exposed as a normal tool argument.

A conceptual MCP tool schema could look like this:

{
  "name": "get_ticket",
  "description": "Return the status, priority, requester, and latest update for one support ticket.",
  "inputSchema": {
    "type": "object",
    "properties": {
      "ticket_id": {
        "type": "string",
        "description": "The ID of the ticket to retrieve."
      },
      "include_comments": {
        "type": "boolean",
        "description": "Whether to include ticket comments.",
        "default": false
      }
    },
    "required": ["ticket_id"]
  }
}
Enter fullscreen mode Exit fullscreen mode

For createTicket, the request body becomes a structured input with required title and description fields. The priority enum should stay an enum. Preserving constraints helps the AI client form a valid request instead of guessing at allowed values.

When a path parameter and a body field have the same name, resolve the collision deliberately. When a schema is reused through $ref, make sure the generated tool still presents the fields and descriptions the client needs. When an API uses pagination, document the cursor or page inputs clearly; the API owner remains responsible for pagination behavior and rate-limit handling.

In 0mcp, tool names and descriptions can be edited in the dashboard. The underlying API schema should be corrected in the original OpenAPI definition so the API contract and the MCP interface do not drift apart.

4. Keep authentication out of the tool input

The example uses a bearer security scheme. That tells the integration how the original API expects requests to be authenticated, but the token should not appear in a tool description, example payload, or ordinary user argument.

0mcp supports API key, Bearer token, and OAuth authentication. Credentials are provided by the user through the MCP client at request time and passed through to the original API. 0mcp does not store those API keys, Bearer tokens, or OAuth credentials.

You should still apply the same security practices you use for the API itself:

  • use least-privilege credentials;
  • test with a staging account before exposing write operations;
  • avoid placing secrets in the OpenAPI description;
  • verify which operations each credential can access; and
  • review error responses for accidental sensitive data.

The 0mcp Trust page explains the platform's credential pass-through and data-minimization approach.

5. Import, configure, and create the hosted server

The managed workflow is straightforward:

  1. Create an 0mcp account.
  2. Import the OpenAPI specification.
  3. Review detected operations and any validation warnings.
  4. Select the operations to expose.
  5. Edit tool names and descriptions where the API wording is not clear enough for an AI client.
  6. Create the MCP server.

0mcp hosts the resulting server and provides a Streamable HTTP endpoint. The default endpoint has this shape:

yourservername.0mcp.dev/mcp
Enter fullscreen mode Exit fullscreen mode

The endpoint can be used by an MCP-compatible client. 0mcp does not require you to run a local stdio server, and local/stdio MCP servers are not currently supported by the platform.

6. Test the tools before sharing the endpoint

A successful import does not prove that the resulting tools are useful. Test the interface in the 0mcp Playground before connecting it to a production workflow. Inspect the available capabilities, call the tools with realistic inputs, verify authentication, and review the individual usage logs.

For the support-ticket example, a useful test matrix looks like this:

Test What to verify
getTicket with a valid ID The path parameter is placed correctly and the returned JSON is understandable
getTicket without ticket_id The tool rejects an incomplete request before the API receives it
getTicket with an unauthorized credential The authentication failure is visible and does not look like a successful empty result
createTicket with the minimum valid body Required fields and the request body are mapped correctly
createTicket with an invalid priority The enum constraint prevents or clearly reports an invalid value
A response containing pagination The tool description makes the next-page behavior clear

Also test the failure paths that matter to your users: expired credentials, missing records, permission errors, API timeouts, and validation failures. A tool that only works on the happy path is not ready for an AI workflow.

If you need a lower-level protocol inspection, the MCP Inspector guide is a useful companion to application-level tests.

7. Plan for API changes

The first tool call is only the start of the integration. APIs change, and those changes can affect:

  • required parameters;
  • operation names and descriptions;
  • authentication schemes;
  • response shapes;
  • pagination; and
  • permissions.

When the API changes, update the source OpenAPI specification, review the affected operations, and test the tools again. In 0mcp, configuration versions let you save changes, review them, and restore an earlier configuration when needed. Saving an MCP configuration updates the hosted server without requiring a rebuild or changing its URL.

Do not assume that an old MCP tool remains correct just because its name still exists. A schema change can turn a previously valid tool call into a bad request or cause the AI client to misunderstand the result.

Common problems

An operation did not become a tool

Check the import warnings, the operation's HTTP method and path, whether the operation was selected, and whether required schema references resolve.

The tool has poor or generic descriptions

Improve the OpenAPI summary, description, operationId, parameter descriptions, and response documentation. AI clients rely on this text when deciding which capability to call.

Calls fail with authentication errors

Compare the OpenAPI security scheme with the credential supplied at runtime. Check whether the API expects a bearer header, an API key in a specific location, or an OAuth flow. Do not solve the problem by putting the credential into the tool schema.

The server exposes too many tools

Reduce the selected operation set or separate unrelated product areas into different MCP servers. A large API surface is not automatically a useful AI interface.

The response is not usable

Check that the endpoint returns the JSON data your workflow needs. 0mcp currently focuses on JSON-based API responses; file uploads, file downloads, and binary API responses are not supported.

A practical launch checklist

Before sharing an API-derived MCP server, confirm that:

  • the OpenAPI specification is valid and uses a supported version;
  • operations have clear names and descriptions;
  • only necessary capabilities are exposed;
  • path, query, body, and response schemas match real API behavior;
  • authentication is documented and credentials are passed at runtime;
  • valid and invalid calls have been tested;
  • pagination, rate limits, and permissions are understood; and
  • a versioned update process exists for future API changes.

An OpenAPI specification is not an MCP server by itself. It is a strong source for building one when the contract is accurate and the exposed capability surface is intentional.

If you want to take the hosted route, explore the 0mcp API-to-MCP workflow or follow the OpenAPI-to-MCP documentation to review the implementation path.

Top comments (0)