MCPServer.fromOpenAPI() creates an MCP server from a parsed OpenAPI document. Each included OpenAPI operation is registered as an MCP tool that calls the matching HTTP endpoint.
Basic Usage
Load or import an OpenAPI document, then pass it toMCPServer.fromOpenAPI():
- Server name and version, unless you override them
- Tool names, based on
operationIdwhen available - Tool descriptions, from
summary,description, and the HTTP route - Input schemas, from parameters and JSON request bodies
- HTTP method, path, query string, headers, and request body
When to Use It
fromOpenAPI() is useful when you want to quickly expose an existing HTTP API to an MCP client:
- Prototyping an MCP integration before designing custom tools
- Wrapping a small internal API for trusted users
- Testing whether an API’s operations are useful in an LLM workflow
- Bootstrapping a hand-crafted MCP server from an existing OpenAPI spec
Authentication and Headers
fromOpenAPI() supports two simple upstream authentication patterns:
- Bearer token auth
- Static header auth, such as an API key header
headers for static headers that should be sent with every upstream request:
The
auth and headers options authenticate requests from your MCP server to the upstream API. They do not add authentication to the MCP server itself. To protect the MCP endpoint, configure server authentication separately.Request and Response Mapping
Generated tools flatten OpenAPI parameters into a single input object:pathparameters become required top-level fieldsqueryparameters become optional or required top-level fieldsheaderparameters become top-level fields and are sent as HTTP headerscookieparameters are ignored- JSON request bodies become a
bodyfield
GET /users/{userId}/projects?limit=10 becomes a tool with userId and limit inputs.
JSON responses are returned with the object() response helper. Non-JSON responses are returned as text. If the upstream API returns a non-2xx response, the generated tool returns an MCP error response containing the upstream response text.
Naming and Descriptions
Tool quality depends heavily on the OpenAPI document. Before exposing generated tools to users, review the spec for:- Clear
operationIdvalues - Human-readable
summaryanddescriptionfields - Helpful parameter descriptions
- Small, accurate schemas
- Tags that match useful task areas
search_customer_orders tool may be better than separate generated tools for listCustomers, getCustomer, listOrders, and getOrder.
Options
| Option | Description |
|---|---|
spec | Parsed OpenAPI document. This is required. |
baseUrl | Upstream API base URL. Defaults to spec.servers[0].url when present. |
name | MCP server name. Defaults to spec.info.title. |
version | MCP server version. Defaults to spec.info.version or 1.0.0. |
auth | Bearer token or static header auth for upstream API requests. |
headers | Static headers sent with every upstream API request. |
tags | Include only operations with one of these OpenAPI tags. |
exclude | Exclude operations by operation ID, path, method, or tag. |
fetch | Custom fetch implementation, useful for tests or custom transports. |
Limitations
fromOpenAPI() is intentionally simple. It currently focuses on straightforward REST-style APIs with JSON request and response bodies.
- It does not design model-friendly workflows for you
- It does not add MCP server authentication
- It does not support cookie parameters
- It only maps JSON request bodies into tool input
- It does not automatically bundle remote
$refvalues outside the loaded document
server.tool() definitions.
Example
OpenAPI Server Example
Complete runnable example that generates MCP tools from the National Weather Service OpenAPI document.
Next Steps
Tools
Learn how to create hand-crafted MCP tools with Zod schemas and custom handlers.
Examples
Browse runnable server examples, including the OpenAPI feature example.