MCP from OpenAPI Specs
LiteLLM can convert any OpenAPI/Swagger spec into an MCP server, with no custom MCP server code required.
Step 1: Add the MCP Server
Add your OpenAPI-based server in config.yaml:
mcp_servers:
petstore_mcp:
url: "https://petstore.swagger.io/v2"
spec_path: "/path/to/openapi.json"
auth_type: "none"
my_api_mcp:
url: "http://0.0.0.0:8090"
spec_path: "/path/to/openapi.json"
auth_type: "api_key"
auth_value: "your-api-key-here"
secured_api_mcp:
url: "https://api.example.com"
spec_path: "/path/to/openapi.json"
auth_type: "bearer_token"
auth_value: "your-bearer-token"
Or from the UI: go to MCP Servers → Add New MCP Server, fill in the URL and spec path, and LiteLLM will fetch the spec and load all endpoints as tools.
Configuration parameters:
| Parameter | Required | Description |
|---|---|---|
url | Yes | Base URL of your API |
spec_path | Yes | Path or URL to your OpenAPI spec (JSON or YAML) |
auth_type | No | none, api_key, bearer_token, basic, authorization, oauth2 |
auth_value | No | Auth value (required if auth_type is set) |
description | No | Optional description |
allowed_tools | No | Allowlist of specific tools |
disallowed_tools | No | Blocklist of specific tools |
Supported spec versions: OpenAPI 3.0.x, 3.1.x, Swagger 2.0. Each operation's operationId becomes the tool name, so make sure they're unique.
Internal spec URLs (SSRF)
When spec_path is an http:// or https:// URL, the LiteLLM proxy fetches it with SSRF protection enabled by default: the hostname is resolved and the request is rejected if any resolved address is not globally routable (e.g. 10.x, 192.168.x, 127.0.0.1), unless you allowlist the hostname from the URL (not the resolved IP).
Typical cases:
- Spec URL uses
https://api.example.com/...but DNS inside your network returns a private IP. Addapi.example.comto the allowlist (orapi.example.com:443if you pin the port). - Spec URL is
http://127.0.0.1:8080/openapi.json. Add127.0.0.1or127.0.0.1:8080.
Configure under litellm_settings in your proxy config.yaml (this is not read from general_settings):
litellm_settings:
user_url_validation: true # default; set false only if you fully trust URL sources
user_url_allowed_hosts:
- "api.example.com"
- "127.0.0.1"
- "127.0.0.1:8080"
For a full reference of these fields, see config settings: litellm_settings.
Once tools are loaded, you'll see them in the Tool Configuration section:
Step 2: Optionally Override Tool Names and Descriptions
By default, tool names and descriptions come from the operationId and description fields in your spec. You can rename or rewrite them so MCP clients see something cleaner, without touching the upstream spec.