Engineering Guides5 min readUpdated: 2026-11-24

OpenAPI to MCP: Exposing REST APIs as Model Context Protocol Tools

Turn internal OpenAPI 3.x YAML/JSON specs into Model Context Protocol (MCP) TypeScript tools and Zod v4 input schemas locally without uploading internal APIs.

Quick Answer

To expose a REST API via Model Context Protocol (MCP), parse OpenAPI paths and components.schemas, sanitize each operationId to <=64 [a-zA-Z0-9_-] characters, merge path/query/body schemas into Zod v4 objects, and wire safe read-only or write handlers.

Why internal OpenAPI specs should never be pasted into cloud generators

Internal Swagger and OpenAPI documents expose private endpoints, auth schemes, internal hostnames, and business entity models. DataTo OpenAPI to MCP parses both YAML and JSON specs strictly in browser memory with zero network traffic.

Generate MCP server from OpenAPI locally →

Tool naming limits, $ref resolution, and Zod v4 generation

AI hosts enforce strict 64-character identifier limits (^[a-zA-Z0-9_-]{1,64}$) on MCP tool names. DataTo automatically normalizes operationId (or HTTP method + path), resolves components.schemas $ref pointers, and generates clean McpServer.tool(...) TypeScript boilerplate with optional Zod v4 input validators.

server.tool(
  "listOrders",
  "List recent customer orders",
  { limit: z.number().int().optional() },
  async (args) => ({ content: [{ type: "text", text: JSON.stringify(args) }] })
);

Convert component schemas to Zod v4 →

Tools used in this guide

Schemas & MCP →

Related formats

Related Comparisons

Frequently asked questions

Can I restrict generated MCP tools to read-only GET endpoints?

Yes. Toggle Include GET endpoints only to prevent AI agents from invoking POST, PUT, PATCH, or DELETE operations.

Does OpenAPI to MCP support both OpenAPI 3.0 YAML and JSON?

Yes. Drop or paste either .yaml, .yml, or .json OpenAPI 3.x specifications.

What if my OpenAPI path lacks an explicit operationId?

DataTo synthesizes a clean, deterministic tool name from the HTTP verb and path segments within the 64-character MCP limit.

Authoritative References

More engineering guides