OpenAPI to MCP Server: How to Turn REST APIs Into Reliable AI Tools Without Tool Bloat
From the publisher’s feed, collected in the ZeroLabs newsroom.
OpenAPI to MCP ServerIf your company already has an API, the next question is obvious: can AI assistants use it safely without a developer writing custom glue for every workflow?That question became harder to ignore after Anthropic announced its acquisition of Stainless on May 18, 2026. Stainless is known for generating SDKs, CLIs, and MCP servers from API specs. The signal is not subtle. The API layer is becoming the tool layer for AI systems.But there is a trap. A raw OpenAPI-to-MCP conversion can make a demo look magical and a production system look confused. If every REST endpoint becomes a model-visible tool, your assistant may inherit hundreds of actions, noisy parameters, auth details it should never see, response fields it cannot interpret, and destructive operations it should not be trusted to call directly.The practical goal is not “generate an MCP server.” The goal is to design a small, clear, testable, permission-aware tool surface that happens to be backed by your existing OpenAPI spec.Why This Topic Matters NowDevelopers are moving from chat interfaces to systems that can read, decide, and act. That changes the role of API documentation. A human developer can scan docs, ignore irrelevant fields, ask another engineer about edge cases, and write a wrapper. A model needs a narrower path. It needs tool names that describe intent, schemas that remove ambiguity, response shapes that fit the next reasoning step, and guardrails that prevent accidental damage.The current search landscape is still fragmented. Existing content often falls into one of three buckets: vendor docs that show how to generate an MCP server, product announcements that frame the trend, or community threads arguing about whether generated servers are useful. The missing practical value is the middle layer: how to take an OpenAPI spec and turn it into a production-grade MCP interface that agents can actually use.That is the gap this guide covers.OpenAPI and MCP Solve Different ProblemsOpenAPI describes how software can call an HTTP API. It is excellent for SDK generation, documentation, validation, mocks, and client tooling. It usually thinks in endpoints: paths, methods, request bodies, response schemas, and auth schemes.MCP, or Model Context Protocol, describes how an AI application can discover and call external capabilities through tools, resources, prompts, and transports. It thinks less like a REST client and more like an execution surface for model-driven work.The difference matters. A REST endpoint might be named POST /v1/customers/{id}/subscriptions. A model-facing tool should probably be named something closer to create_customer_subscription, with a short description that says when to use it, what permission it requires, and what success returns.A human sees a long OpenAPI schema and filters it mentally. A model sees every parameter as a possible decision. That is why the conversion step needs design judgment.Do not mirror your API. Translate your API into task-shaped tools.The Problem With Naive OpenAPI-to-MCP GenerationOpenAPI specs are often written for human developers and SDK generators, not for model reasoning. They commonly include internal metadata, legacy endpoints, overloaded request bodies, inconsistent descriptions, optional fields that are not really optional, and response schemas that expose everything the backend knows.When you convert that directly into MCP tools, five problems show up quickly.1. Too Many ToolsLarge APIs can have hundreds or thousands of endpoints. If every endpoint becomes a tool, the model spends context and attention on tool selection before it can solve the user’s task. Smaller models struggle even more because the tool catalog competes with the conversation itself.2. Endpoint Names Are Not User IntentREST naming reflects backend structure. Tool naming should reflect user goals. The model should not have to infer that PATCH /orders/{id} with a specific enum means “cancel an order.” Give it a tool named cancel_order if cancellation is a first-class task.3. Parameters Leak Implementation DetailOpenAPI specs often contain pagination knobs, vendor headers, tracing fields, response-only objects, deprecated options, or authentication-related parameters. The model should not reason about those unless they are essential to the task.4. Response Payloads Are Too LargeAn API response that is perfect for an application may be bad for an LLM. A model often needs a summary object, a status, a few identifiers, and the next available action. Dumping the full API object into context increases cost and makes the next step less reliable.5. Safety Is Not Implied by a SchemaOpenAPI can describe that a request is valid. It cannot decide whether an autonomous system should be allowed to execute it. A production MCP server needs policy checks, scoped credentials, rate limits, approvals for high-risk actions, audit logs, and clear failure modes.A good conversion process filters endpoints by intent, risk, schema quality, and test coverage before exposing them as tools.A Better Architecture: Spec, Curator, Adapter, Policy, EvaluatorThe cleanest pattern is to separate generation from publication. Use the OpenAPI spec as input, but do not treat generated tools as final. Put a curation layer in between.A practical architecture has five layers:Spec source: the canonical OpenAPI file, ideally generated from your backend code or contract tests.Curator: a build step that selects endpoints, renames tools, removes noise, compresses schemas, and attaches risk metadata.Adapter: the MCP server code that maps model tool calls to your internal API client or SDK.Policy layer: auth scopes, allowlists, approvals, tenant isolation, rate limits, and audit logs.Evaluator: tests and task-based evals that measure whether the model chooses and calls tools correctly.FastMCP’s OpenAPI integration, for example, explicitly warns that mirroring a complex API to LLM clients can be a bad fit and recommends using OpenAPI conversion for bootstrapping and prototyping rather than blindly exposing everything. Stainless documentation also frames MCP generation as tied to SDK quality and auth behavior, not just schema translation.Step 1: Start With a Spec AuditBefore generating anything, audit the OpenAPI document. Your goal is to find the parts that will confuse a model or weaken production reliability.Look for endpoints with missing operationId values, vague descriptions, ambiguous request bodies, overloaded enums, undocumented error responses, inconsistent pagination, nullable fields that are not explained, and sensitive operations such as delete, transfer, invite, refund, publish, or send.Create a simple classification for each endpoint:Expose: safe, useful, task-shaped, and well documented.Wrap: useful, but needs a custom tool that combines or simplifies endpoints.Hide: internal, dangerous, too noisy, deprecated, or rarely useful to an AI assistant.Human approval: useful but risky enough to require confirmation.This is where many teams should stop and fix their API spec. If your OpenAPI file is not good enough to generate a clean SDK, it is not good enough to generate a reliable MCP server.Step 2: Design Tools Around Tasks, Not RoutesThe fastest way to reduce tool bloat is to ask what the assistant should actually do. A billing API might have dozens of subscription, invoice, coupon, customer, tax, and payment methods. Your AI interface may only need eight workflows:Find a customer by email.Summarize current subscription status.Create a draft invoice.Preview a plan change.Cancel a subscription with approval.List recent failed payments.Open a support-safe customer timeline.Generate a handoff note for a human operator.Some of those map to one endpoint. Some combine several calls. Some should never execute the final write automatically. The tool surface should represent the workflow boundary, not the database boundary.A good tool description answers four questions:When should the model use this tool?What inputs are required?What does the tool return?What risk or permission level does the tool carry?Keep descriptions short, but make them operational. Avoid marketing language. A model does not need a sales pitch. It needs a decision rule.Step 3: Strip Parameters the Model Should Never TouchParameter hygiene is where generated servers often fail. If the model sees an optional field, it may try to use it. If it sees auth plumbing, it may hallucinate tokens. If it sees response-only fields, it may send them back in a write request.For each tool, separate parameters into three groups:Model-controlled: user intent fields such as customer email, issue summary, date range, quantity, or plan ID.Server-controlled: tenant ID, auth token, account scope, request ID, pagination defaults, idempotency key, and audit metadata.Hidden or removed: deprecated flags, vendor internals, fields irrelevant to the workflow, and response-only objects.Here is a simplified example of a curated tool schema:{ "name": "preview_subscription_change", "description": "Use when a user asks what would happen if an existing customer changed plans. Returns a preview only; it does not modify billing.", "risk": "read_preview", "inputSchema": { "type": "object", "required": ["customer_email", "target_plan_id"], "properties": { "customer_email": { "type": "string", "description": "The customer's account email." }, "target_plan_id": { "type": "string", "description": "The plan to preview." } } }}The upstream API might need customer IDs, idempotency keys, tax region, current subscription lookup, and auth headers. The model does not need to provide those. The MCP server can resolve them.Step 4: Add Output Schemas, Not Just Input SchemasTool input gets most of the attention, but output design often decides whether the next model step works. If your server returns a giant raw JSON object, the model has to infer which fields matter. If it returns a task-shaped result, the model can continue reliably.A useful output should include:A concise status such as success, not_found, needs_approval, or ambiguous.The minimum fields required for the next step.Human-readable summary text when helpful.Explicit next actions, especially for approval flows.Safe error messages that do not expose secrets or internals.For example:{ "status": "success", "customer_id": "cus_123", "current_plan": "team_monthly", "target_plan": "enterprise_monthly", "estimated_proration": "$42.18", "requires_human_approval": true, "next_action": "Ask the user to confirm before applying the change."}This is cheaper, clearer, and safer than returning the complete billing object.Step 5: Treat Auth as a Product SurfaceAn MCP server that connects to real systems is not just a wrapper. It is a permission boundary.Do not pass long-lived credentials through model-visible context. Do not ask the model to choose OAuth scopes. Do not expose tenant selection as a free-form string if the server can derive it from the user session. Keep credentials server-side, map users to scoped tokens, and record every tool call with actor, tenant, tool name, input hash, result status, and approval state.For higher-risk operations, use staged execution:The model calls a preview tool.The server returns the planned change and risk label.The user or operator approves.The server executes with an idempotency key.The audit log stores the final result.This feels slower in a demo, but it is what makes the tool usable inside a real company.Step 6: Build With Generation, Then Own the ContractGeneration is still useful. It can save days of boilerplate. It can create an initial server, map schemas, produce SDK calls, and expose a local development target. The mistake is treating generation as the final design step.A safe workflow looks like this:Generate a draft server from OpenAPI.Run a spec audit and remove low-value endpoints.Rename tools around intent.Compress input and output schemas.Move auth, tenant, pagination, and idempotency fields server-side.Add risk labels and approval requirements.Write contract tests for every exposed tool.Run model evals against realistic tasks.The generated code is scaffolding. The published MCP contract is product design.Step 7: Test the Tool Surface With Real TasksUnit tests tell you whether the server calls the API correctly. They do not tell you whether a model can choose the right tool.Add task-based evals. Write prompts that represent real user requests, then measure the model’s behavior. Did it choose the right tool? Did it fill only valid parameters? Did it ask for clarification when needed? Did it avoid destructive actions? Did it summarize the result accurately?Here are useful eval categories:Happy path: common workflows with complete information.Ambiguous input: missing IDs, multiple matching users, unclear time ranges.Permission boundary: requests the user is not allowed to execute.Dangerous action: deletion, payment, publish, invite, send, refund, or account change.Tool confusion: two similar tools where only one is correct.Large response: API returns more data than the model should receive.Measure more than pass or fail. Track tool selection accuracy, invalid call rate, clarification rate, approval bypass attempts, average response payload size, latency, and cost per successful task.Production MCP servers need observability: traces, retries, auth decisions, payload size, and task-level eval results.When Not to Generate an MCP Server From OpenAPISometimes OpenAPI is the wrong starting point. If the workflow requires long-running orchestration, heavy business logic, complex approvals, multi-step human review, or private internal state that is not represented in the public API, build a custom server by hand.You should also avoid raw generation when the API is extremely large and most endpoints are irrelevant, when the OpenAPI spec is stale, when auth depends on complicated user delegation, or when the action is high-stakes enough that every operation needs explicit policy review.In those cases, use OpenAPI as reference material. Do not publish it directly as the agent interface.A Practical Checklist for OpenAPI-to-MCP ReadinessBefore you ship, walk through this checklist:Every exposed tool maps to a real user or operator task.No model-visible tool exists only because an endpoint exists.Tool names use verbs and domain language a model can understand.Descriptions explain when to use the tool and when not to use it.Inputs include only fields the model should control.Outputs are summarized and structured for the next reasoning step.Credentials, tenant IDs, request IDs, and idempotency keys stay server-side.High-risk actions require preview and approval.Every tool has contract tests, negative tests, and at least a few model evals.Logs are sufficient for debugging without leaking sensitive data.If you cannot satisfy these items, the server is probably not ready for production use. It may still be useful for a prototype, but keep it scoped accordingly.The TakeawayThe future of AI developer tooling will not be just better models. It will be better interfaces between models and the systems they need to use. OpenAPI gives teams a huge head start because the API contract already exists. MCP gives AI applications a standard way to reach tools. The hard part is the translation between them.Teams that win here will not expose the most tools. They will expose the clearest tools. They will hide irrelevant parameters, compress responses, enforce permissions, test model behavior, and treat the agent-facing API as a real product surface.That is the difference between “our API has an MCP server” and “AI systems can use our API reliably.”FAQWhat is the best primary keyword for this topic?The strongest practical keyword is “OpenAPI to MCP server.” Useful long-tail variants include “generate MCP server from OpenAPI spec,” “REST API to MCP tools,” and “OpenAPI MCP server best practices.”Should every REST endpoint become an MCP tool?No. Most production APIs include endpoints that are irrelevant, internal, risky, or too low-level for model use. Curate around tasks, not routes.Can I use generated MCP code in production?Yes, but treat it as a starting point. Review tool names, inputs, outputs, auth behavior, approvals, and tests before exposing the server to real users or autonomous workflows.What makes an MCP tool reliable for AI assistants?A reliable tool has a clear name, a short decision-oriented description, a narrow input schema, a predictable output schema, strong policy checks, good errors, and eval coverage for realistic tasks.How do I reduce token usage in generated MCP servers?Expose fewer tools, remove unnecessary parameters, summarize large responses, add output filters, and use task-specific wrappers instead of raw endpoint mirrors.When should I hand-write an MCP server instead of generating one?Hand-write the server when workflows are high-risk, multi-step, approval-heavy, or poorly represented by the OpenAPI spec. Generation works best when the API contract is clean and the exposed tasks are simple.OpenAPI to MCP Server: How to Turn REST APIs Into Reliable AI Tools Without Tool Bloat was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.