OpenAPI specs as MCP tools
Many internal services have an OpenAPI description but no MCP server. The gateway can act as that server. Register a server whose spec_path points at the OpenAPI document and the gateway reads the operations, turns each one into an MCP tool with an input schema built from the operation's parameters and request body, and performs the HTTP call itself when a client or model invokes the tool. Nothing has to be deployed next to the service.
A real-world scenario
The finance team's billing API has an OpenAPI document and a service token. An analyst wants an assistant that answers "which invoices are overdue for customer X". The admin registers the billing API as an OpenAPI server with the token, allows the list_invoices and get_invoice operations and nothing that writes, and grants the server to the analyst's key. The assistant calls billing-api-list_invoices like any MCP tool, the gateway sends the HTTP request with the token, and the analyst never sees the credential.
Register an API as a server
-
In the Admin UI, open MCP Servers, click + Add New MCP Server, then + Custom Server. Set Transport Type to OpenAPI Spec. Pick a tile under Popular APIs or paste the document address into OpenAPI Spec URL, and set the Authentication the API expects. The Connection Status card lists the operations it found as tools, and Tool Configuration lets you untick the ones users must not call. Click Add MCP Server.
-
Or register it with the API.
urlis the base address the calls are sent to andspec_pathis a URL or a local file path:curl -X POST http://localhost:4000/v1/mcp/server \-H "Authorization: Bearer $SPANWAY_MASTER_KEY" -H "Content-Type: application/json" \-d '{"server_name": "billing_api","url": "https://billing.internal.example.com","spec_path": "https://billing.internal.example.com/openapi.json","auth_type": "bearer_token","credentials": {"auth_value": "os.environ/BILLING_API_TOKEN"},"allowed_tools": ["list_invoices", "get_invoice"]}'Expected result, with status 201, is the stored server with its
server_idand thespec_pathyou sent. The card on MCP Servers shows the OPENAPI badge and the spec address. -
List the tools a key sees, which are the allowed operations named after their
operationId:curl "http://localhost:4000/mcp-rest/tools/list?mcp_server_name=billing_api" \-H "Authorization: Bearer $SPANWAY_API_KEY"{"tools": [{"name": "billing_api-list_invoices", "description": "List invoices", "inputSchema": {"type": "object", "properties": {"customer_id": {"type": "string"}, "status": {"type": "string"}}}, "mcp_info": {"server_name": "billing_api"}}, {"name": "billing_api-get_invoice", "description": "Get one invoice", "inputSchema": {"type": "object", "properties": {"invoice_id": {"type": "string"}}, "required": ["invoice_id"]}, "mcp_info": {"server_name": "billing_api"}}], "error": null, "message": "Successfully retrieved tools"}
The same server in config.yaml:
mcp_servers:
billing_api:
url: https://billing.internal.example.com
spec_path: https://billing.internal.example.com/openapi.json
auth_type: bearer_token
authentication_token: os.environ/BILLING_API_TOKEN
allowed_tools: ["list_invoices", "get_invoice"]
Tool names come from each operation's operationId, lowercased, with any character outside letters, digits, underscore and hyphen replaced by an underscore and capped at 128 characters so the names are accepted by every model provider. Operations without an operationId get a name derived from the method and path. The usual server fields apply, so allowed_tools, tool_name_to_description, static_headers and the per-user credential options all work on an OpenAPI backed server. A BYOK switch on the form lets each user bring their own API key for the service, see per-user credentials.
User supplied spec URLs go through the gateway's SSRF guard. A spec on a private network address is rejected unless the host is listed in general_settings.user_url_allowed_hosts, see the settings reference.
Registry
GET /v1/mcp/openapi-registry returns the catalogue of well-known APIs that the Popular APIs tiles show. An entry that carries OAuth settings fills in the authorization and token URLs and switches the form to interactive OAuth.
| Method | Path | Summary |
|---|---|---|
| GET | /v1/mcp/openapi-registry | Browse well-known OpenAPI APIs |
Errors
| Status | Where | Meaning | Fix |
|---|---|---|---|
| "No tools loaded from spec" | Connection Status card, POST /mcp-rest/test/tools/list | The document could not be fetched or parsed, or it has no operations. The message carries the parser error. | Open the spec address in a browser and check it is valid JSON OpenAPI 3. The gateway reads JSON only, so convert a YAML spec to JSON first. |
| "No tools loaded from spec" on a private address | Connection Status card and the server's health | Saving the server does not fetch the spec. When the tools load, a spec on a private address not listed in user_url_allowed_hosts is refused, so the server has no tools. | Add the host to the allow list, or serve the spec from a public address. |
| Tool error with an upstream status code | Any tool call | The API answered with an HTTP error. The body is masked. | Check the arguments against the operation's parameters. |
| Tool error reporting an authentication failure | Any tool call | The API rejected the credential. On a BYOK server the user's own key is wrong or expired. | Update the server's credential, or have the user store a new key. |
| 403 on a tool | Any tool call | The operation is not in allowed_tools or is hidden by a per-key tool grant. | Add it to the allow list or the grant, see access control. |
Logs
| Level | Line | What it means | Action |
|---|---|---|---|
| INFO | Loading OpenAPI spec from <path> for server <name> | The gateway is building the server's tools from the spec, at start and when the server is saved. | None. If no tools appear afterwards, see the errors above. |
Related
- MCP gateway for the common server fields.
- MCP per-user credentials for APIs where each user has their own key.
- MCP tools over REST for the listing and test routes used above.
- Settings reference for
user_url_allowed_hosts.