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]

fix(mcp): make list page cap a plain constant and use a real ListToolsResult in the unit mock

Devin AId32f8a07c88e
diff --git a/litellm/constants.py b/litellm/constants.py
index 11f35177636..07914934495 100644
--- a/litellm/constants.py
+++ b/litellm/constants.py
@@ -136,7 +136,7 @@ MCP_CLIENT_TIMEOUT: Final = float(os.getenv("LITELLM_MCP_CLIENT_TIMEOUT", "60.0"
MCP_TOOL_LISTING_TIMEOUT: Final = float(os.getenv("LITELLM_MCP_TOOL_LISTING_TIMEOUT", "30.0"))
MCP_METADATA_TIMEOUT: Final = float(os.getenv("LITELLM_MCP_METADATA_TIMEOUT", "10.0"))
MCP_HEALTH_CHECK_TIMEOUT: Final = float(os.getenv("LITELLM_MCP_HEALTH_CHECK_TIMEOUT", "10.0"))
-MCP_LIST_MAX_PAGES: Final = int(os.getenv("LITELLM_MCP_LIST_MAX_PAGES", "100"))
+MCP_LIST_MAX_PAGES: Final = 100
# Allowlist of commands permitted for MCP stdio transport.
# Prevents arbitrary command execution via /mcp-rest/test/* endpoints or server creation.
diff --git a/litellm/experimental_mcp_client/pagination.py b/litellm/experimental_mcp_client/pagination.py
index 8852715aba5..85f46268f92 100644
--- a/litellm/experimental_mcp_client/pagination.py
+++ b/litellm/experimental_mcp_client/pagination.py
@@ -42,7 +42,7 @@ async def collect_pages(
return items
if pages_read >= MCP_LIST_MAX_PAGES:
verbose_logger.warning(
- "MCP %s from %s still paginating after %s pages (LITELLM_MCP_LIST_MAX_PAGES); returning what was read",
+ "MCP %s from %s still paginating after %s pages (MCP_LIST_MAX_PAGES); returning what was read",
method,
server,
pages_read,
diff --git a/tests/mcp_tests/test_mcp_client_unit.py b/tests/mcp_tests/test_mcp_client_unit.py
index aadaadd510e..ef4231fe1d9 100644
--- a/tests/mcp_tests/test_mcp_client_unit.py
+++ b/tests/mcp_tests/test_mcp_client_unit.py
@@ -11,7 +11,7 @@ from unittest.mock import AsyncMock, MagicMock, patch, ANY
import litellm.experimental_mcp_client.client as mcp_client_module
from litellm.experimental_mcp_client.client import MCPClient
from litellm.types.mcp import MCPAuth, MCPTransport
-from mcp.types import Tool as MCPTool, CallToolResult as MCPCallToolResult
+from mcp.types import Tool as MCPTool, CallToolResult as MCPCallToolResult, ListToolsResult
def test_mcp_client_uses_configurable_default_timeout():
@@ -174,9 +174,7 @@ class TestMCPClientUnitTests:
},
)
]
- mock_result = MagicMock()
- mock_result.tools = mock_tools
- mock_session_instance.list_tools.return_value = mock_result
+ mock_session_instance.list_tools.return_value = ListToolsResult(tools=mock_tools)
client = MCPClient("http://example.com")
result = await client.list_tools()
diff --git a/tests/test_litellm/experimental_mcp_client/test_pagination.py b/tests/test_litellm/experimental_mcp_client/test_pagination.py
index a76f410ac3c..93952c176a8 100644
--- a/tests/test_litellm/experimental_mcp_client/test_pagination.py
+++ b/tests/test_litellm/experimental_mcp_client/test_pagination.py
@@ -79,4 +79,4 @@ async def test_collect_pages_honors_the_page_cap(monkeypatch, caplog):
assert len(upstream.cursors_seen) == 3
assert len(tools) == 30
- assert any("LITELLM_MCP_LIST_MAX_PAGES" in record.getMessage() for record in caplog.records)
+ assert any("MCP_LIST_MAX_PAGES" in record.getMessage() for record in caplog.records)