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
fix listing mcp tools
Ishaan Jaff10486dd17ebe
diff --git a/litellm/proxy/_experimental/mcp_server/server.py b/litellm/proxy/_experimental/mcp_server/server.pyindex 603370711f0..fe1eccb048f 100644--- a/litellm/proxy/_experimental/mcp_server/server.py+++ b/litellm/proxy/_experimental/mcp_server/server.py@@ -8,16 +8,14 @@ from typing import Any, Dict, List, Optional, Unionfrom anyio import BrokenResourceErrorfrom fastapi import APIRouter, Depends, HTTPException, Requestfrom fastapi.responses import StreamingResponse-from pydantic import ValidationError+from pydantic import ConfigDict, ValidationErrorfrom litellm._logging import verbose_loggerfrom litellm.constants import MCP_TOOL_NAME_PREFIXfrom litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObjfrom litellm.proxy._types import UserAPIKeyAuthfrom litellm.proxy.auth.user_api_key_auth import user_api_key_auth-from litellm.types.mcp_server.mcp_server_manager import (- ListMCPToolsRestAPIResponseObject,-)+from litellm.types.mcp_server.mcp_server_manager import MCPInfofrom litellm.types.utils import StandardLoggingMCPToolCallfrom litellm.utils import client@@ -49,6 +47,19 @@ if MCP_AVAILABLE:from .sse_transport import SseServerTransportfrom .tool_registry import global_mcp_tool_registry+ ######################################################+ ############ MCP Tools List REST API Response Object #+ # Defined here because we don't want to add `mcp` as a+ # required dependency for `litellm` pip package+ ######################################################+ class ListMCPToolsRestAPIResponseObject(MCPTool):+ """+ Object returned by the /tools/list REST API route.+ """++ mcp_info: Optional[MCPInfo] = None+ model_config = ConfigDict(arbitrary_types_allowed=True)+#################################################################### Initialize the MCP Server #########################################################################@@ -224,7 +235,7 @@ if MCP_AVAILABLE:############ MCP Server REST API Routes #########################################################################@router.get("/tools/list", dependencies=[Depends(user_api_key_auth)])- async def list_tool_rest_api():+ async def list_tool_rest_api() -> List[ListMCPToolsRestAPIResponseObject]:"""List all available tools with information about the server they belong to.diff --git a/litellm/types/mcp_server/mcp_server_manager.py b/litellm/types/mcp_server/mcp_server_manager.pyindex 9752423e7e6..aecd11aa1ae 100644--- a/litellm/types/mcp_server/mcp_server_manager.py+++ b/litellm/types/mcp_server/mcp_server_manager.py@@ -3,14 +3,6 @@ from typing import TYPE_CHECKING, Optionalfrom pydantic import BaseModel, ConfigDictfrom typing_extensions import TypedDict-if TYPE_CHECKING:- from mcp import ClientSession- from mcp.types import Tool as MCPTool-else:- # Provide fallback types for runtime incase `mcp` is not installed- ClientSession = None- MCPTool = object-class MCPInfo(TypedDict, total=False):server_name: str@@ -22,12 +14,3 @@ class MCPSSEServer(BaseModel):url: strmcp_info: Optional[MCPInfo] = Nonemodel_config = ConfigDict(arbitrary_types_allowed=True)---class ListMCPToolsRestAPIResponseObject(MCPTool):- """- Object returned by the /tools/list REST API route.- """-- mcp_info: Optional[MCPInfo] = None- model_config = ConfigDict(arbitrary_types_allowed=True)