Skip to content

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]

Merge branch 'main' into litellm_dev_10_08_2025_p2

Krish Dholakiaa02b3caef3cf
diff --cc docs/my-website/docs/mcp.md
index bb0759598af,462306e961d..6333f7f0913
--- a/docs/my-website/docs/mcp.md
+++ b/docs/my-website/docs/mcp.md
@@@ -246,8 -246,203 +246,203 @@@ litellm_settings
</TabItem>
</Tabs>
- ## Allow/Disallow MCP Tools
+ ## 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 Filtering
-
++## Allow/Disallow MCP Tools
++
Control which tools are available from your MCP servers. You can either allow only specific tools or block dangerous ones.
<Tabs>
diff --cc litellm/proxy/_experimental/mcp_server/mcp_server_manager.py
index 8070bedbc79,3c27a65f06a..ffdcfe8679f
--- a/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py
+++ b/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py
@@@ -598,63 -760,17 +761,69 @@@ class MCPServerManager
Check if the tool is allowed or banned for the given server
"""
if server.allowed_tools:
- return tool_name in server.allowed_tools
+ return (
+ tool_name in server.allowed_tools
+ or f"{server.name}-{tool_name}" in server.allowed_tools
+ )
if server.disallowed_tools:
- return tool_name not in server.disallowed_tools
+ return (
+ tool_name not in server.disallowed_tools
+ and f"{server.name}-{tool_name}" not in server.disallowed_tools
+ )
return True
+ def validate_allowed_params(
+ self, tool_name: str, arguments: Dict[str, Any], server: MCPServer
+ ) -> None:
+ """
+ Filter arguments to only include allowed parameters for the given tool.
+
+ Args:
+ tool_name: Name of the tool (with or without prefix)
+ arguments: Dictionary of arguments to filter
+ server: MCPServer configuration
+
+ Returns:
+ Filtered dictionary containing only allowed parameters
+
+ Raises:
+ HTTPException: If allowed_params is configured for this tool but arguments contain disallowed params
+ """
+ from litellm.proxy._experimental.mcp_server.utils import (
+ get_server_name_prefix_tool_mcp,
+ )
+
+ # If no allowed_params configured, return all arguments
+ if not server.allowed_params:
+ return
+
+ # Get the unprefixed tool name to match against config
+ unprefixed_tool_name, _ = get_server_name_prefix_tool_mcp(tool_name)
+
+ # Check both prefixed and unprefixed tool names
+ allowed_params_list = server.allowed_params.get(
+ tool_name
+ ) or server.allowed_params.get(unprefixed_tool_name)
+
+ # If this tool doesn't have allowed_params specified, allow all params
+ if allowed_params_list is None:
+ return None
+
+ # Filter arguments to only include allowed parameters
+ disallowed_params = [
+ param for param in arguments.keys() if param not in allowed_params_list
+ ]
+
+ if disallowed_params:
+ raise HTTPException(
+ status_code=403,
+ detail={
+ "error": f"Parameters {disallowed_params} are not allowed for tool {tool_name}. "
+ f"Allowed parameters: {allowed_params_list}. "
+ f"Contact proxy admin to allow these parameters."
+ },
+ )
+
async def check_tool_permission_for_key_team(
self,
tool_name: str,