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(mcp): log only the origin of the upstream MCP url in tool-call metadata
Tind0f1c38d6a99
diff --git a/litellm/proxy/_experimental/mcp_server/server.py b/litellm/proxy/_experimental/mcp_server/server.pyindex 938cc2bc43b..3550237dd65 100644--- a/litellm/proxy/_experimental/mcp_server/server.py+++ b/litellm/proxy/_experimental/mcp_server/server.py@@ -107,11 +107,12 @@ _MCP_ROUTING_PEEK_MAX_BYTES = 4096def _redact_mcp_resource_url(url: Optional[str]) -> Optional[str]:- """Reduce an MCP server URL to its bare resource identifier for logging.+ """Reduce an MCP server URL to its origin (scheme + host + port) for logging.- Keeps scheme, host, and path; drops userinfo (``user:pass@``), the query string,- and the fragment, so an upstream URL carrying an embedded token, userinfo, or a- secret query parameter never reaches spend-log metadata or logging callbacks.+ Everything else is dropped: userinfo (``user:pass@``), the query string, the+ fragment, and the path, because hosted MCP servers routinely embed the+ credential in the path (e.g. ``/mcp/s/<token>``) and this value is persisted+ in spend-log metadata that a caller who can invoke the tool can read back.Returns None when the URL has no host to identify (nothing safe to log)."""if not isinstance(url, str) or not url:@@ -123,7 +124,7 @@ def _redact_mcp_resource_url(url: Optional[str]) -> Optional[str]:if not parts.hostname:return Nonenetloc = f"{parts.hostname}:{parts.port}" if parts.port else parts.hostname- return urlunsplit((parts.scheme, netloc, parts.path, "", "")) or None+ return urlunsplit((parts.scheme, netloc, "", "", "")) or Nonedef _invalidate_byok_cred_cache(user_id: str, server_id: str) -> None:diff --git a/tests/test_litellm/proxy/_experimental/mcp_server/test_mcp_server.py b/tests/test_litellm/proxy/_experimental/mcp_server/test_mcp_server.pyindex 0db36e75e48..bba0eb31cfb 100644--- a/tests/test_litellm/proxy/_experimental/mcp_server/test_mcp_server.py+++ b/tests/test_litellm/proxy/_experimental/mcp_server/test_mcp_server.py@@ -6859,11 +6859,13 @@ async def test_call_tool_with_legacy_db_m2m_server_resolves_oauth2_flow():@pytest.mark.parametrize("url, expected",[- # userinfo + secret query param must both be stripped from the logged resource- ("https://user:[email protected]/mcp?token=abcd1234&x=1", "https://mcp.example.com/mcp"),- ("https://mcp.example.com/mcp#frag", "https://mcp.example.com/mcp"),- ("https://host:8443/a/b?q=1", "https://host:8443/a/b"),- ("https://mcp.notion.com/mcp", "https://mcp.notion.com/mcp"),+ # only the origin may be logged: userinfo, query, fragment, and the PATH are all stripped,+ # because hosted MCP servers routinely embed the credential in the path (e.g. /mcp/s/<token>)+ ("https://user:[email protected]/mcp?token=abcd1234&x=1", "https://mcp.example.com"),+ ("https://mcp.example.com/mcp#frag", "https://mcp.example.com"),+ ("https://host:8443/a/b?q=1", "https://host:8443"),+ ("https://mcp.zapier.com/api/mcp/s/NDgzcret-token/mcp", "https://mcp.zapier.com"),+ ("https://mcp.notion.com/mcp", "https://mcp.notion.com"),(None, None),("", None),("not a url", None),