The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
docs(mcp.md): document new openapi to mcp tool support
Krrish Dholakiae2b7b05774ba
diff --git a/docs/my-website/docs/mcp.md b/docs/my-website/docs/mcp.mdindex 9365b0a5542..462306e961d 100644--- a/docs/my-website/docs/mcp.md+++ b/docs/my-website/docs/mcp.md@@ -246,6 +246,201 @@ litellm_settings:</TabItem></Tabs>+## Converting OpenAPI Specs to MCP Servers++LiteLLM can automatically convert OpenAPI specifications into MCP servers, allowing you to expose any REST API as MCP tools. This is useful when you have existing APIs with OpenAPI/Swagger documentation and want to make them available as MCP tools.++### Benefits++- **Rapid Integration**: Convert existing APIs to MCP tools without writing custom MCP server code+- **Automatic Tool Generation**: LiteLLM automatically generates MCP tools from your OpenAPI spec+- **Unified Interface**: Use the same MCP interface for both native MCP servers and OpenAPI-based APIs+- **Easy Testing**: Test and iterate on API integrations quickly++### Configuration++Add your OpenAPI-based MCP server to your `config.yaml`:++```yaml title="config.yaml - OpenAPI to MCP" showLineNumbers+model_list:+ - model_name: gpt-4o+ litellm_params:+ model: openai/gpt-4o+ api_key: sk-xxxxxxx++mcp_servers:+ # OpenAPI Spec Example - Petstore API+ petstore_mcp:+ url: "https://petstore.swagger.io/v2"+ spec_path: "/path/to/openapi.json"+ auth_type: "none"++ # OpenAPI Spec with API Key Authentication+ 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"++ # OpenAPI Spec with Bearer Token+ secured_api_mcp:+ url: "https://api.example.com"+ spec_path: "/path/to/openapi.json"+ auth_type: "bearer_token"+ auth_value: "your-bearer-token"+```++### Configuration Parameters++| Parameter | Required | Description |+|-----------|----------|-------------|+| `url` | Yes | The base URL of your API endpoint |+| `spec_path` | Yes | Path or URL to your OpenAPI specification file (JSON or YAML) |+| `auth_type` | No | Authentication type: `none`, `api_key`, `bearer_token`, `basic`, `authorization` |+| `auth_value` | No | Authentication value (required if `auth_type` is set) |+| `description` | No | Optional description for the MCP server |+| `allowed_tools` | No | List of specific tools to allow (see [MCP Tool Filtering](#mcp-tool-filtering)) |+| `disallowed_tools` | No | List of specific tools to block (see [MCP Tool Filtering](#mcp-tool-filtering)) |++### Usage Example++Once configured, you can use the OpenAPI-based MCP server just like any other MCP server:++<Tabs>+<TabItem value="fastmcp" label="Python FastMCP">++```python title="Using OpenAPI-based MCP Server" showLineNumbers+from fastmcp import Client+import asyncio++# Standard MCP configuration+config = {+ "mcpServers": {+ "petstore": {+ "url": "http://localhost:4000/petstore_mcp/mcp",+ "headers": {+ "x-litellm-api-key": "Bearer sk-1234"+ }+ }+ }+}++# Create a client that connects to the server+client = Client(config)++async def main():+ async with client:+ # List available tools generated from OpenAPI spec+ tools = await client.list_tools()+ print(f"Available tools: {[tool.name for tool in tools]}")++ # Example: Get a pet by ID (from Petstore API)+ response = await client.call_tool(+ name="getpetbyid",+ arguments={"petId": "1"}+ )+ print(f"Response:\n{response}\n")++ # Example: Find pets by status+ response = await client.call_tool(+ name="findpetsbystatus",+ arguments={"status": "available"}+ )+ print(f"Response:\n{response}\n")++if __name__ == "__main__":+ asyncio.run(main())+```++</TabItem>++<TabItem value="cursor" label="Cursor IDE">++```json title="Cursor MCP Configuration for OpenAPI Server" showLineNumbers+{+ "mcpServers": {+ "Petstore": {+ "url": "http://localhost:4000/petstore_mcp/mcp",+ "headers": {+ "x-litellm-api-key": "Bearer $LITELLM_API_KEY"+ }+ }+ }+}+```++</TabItem>++<TabItem value="openai" label="OpenAI Responses API">++```bash title="Using OpenAPI MCP Server with OpenAI" showLineNumbers+curl --location 'https://api.openai.com/v1/responses' \+--header 'Content-Type: application/json' \+--header "Authorization: Bearer $OPENAI_API_KEY" \+--data '{+ "model": "gpt-4o",+ "tools": [+ {+ "type": "mcp",+ "server_label": "petstore",+ "server_url": "http://localhost:4000/petstore_mcp/mcp",+ "require_approval": "never",+ "headers": {+ "x-litellm-api-key": "Bearer YOUR_LITELLM_API_KEY"+ }+ }+ ],+ "input": "Find all available pets in the petstore",+ "tool_choice": "required"+}'+```++</TabItem>+</Tabs>++### How It Works++1. **Spec Loading**: LiteLLM loads your OpenAPI specification from the provided `spec_path`+2. **Tool Generation**: Each API endpoint in the spec becomes an MCP tool+3. **Parameter Mapping**: OpenAPI parameters are automatically mapped to MCP tool parameters+4. **Request Handling**: When a tool is called, LiteLLM converts the MCP request to the appropriate HTTP request+5. **Response Translation**: API responses are converted back to MCP format++### OpenAPI Spec Requirements++Your OpenAPI specification should follow standard OpenAPI/Swagger conventions:+- **Supported versions**: OpenAPI 3.0.x, OpenAPI 3.1.x, Swagger 2.0+- **Required fields**: `paths`, `info` sections should be properly defined+- **Operation IDs**: Each operation should have a unique `operationId` (this becomes the tool name)+- **Parameters**: Request parameters should be properly documented with types and descriptions++### Example OpenAPI Spec Structure++```yaml title="sample-openapi.yaml" showLineNumbers+openapi: 3.0.0+info:+ title: My API+ version: 1.0.0+paths:+ /pets/{petId}:+ get:+ operationId: getPetById+ summary: Get a pet by ID+ parameters:+ - name: petId+ in: path+ required: true+ schema:+ type: integer+ responses:+ '200':+ description: Successful response+ content:+ application/json:+ schema:+ type: object+```+## MCP Tool FilteringControl which tools are available from your MCP servers. You can either allow only specific tools or block dangerous ones.