test(mcp): pin that only x-litellm-tags carries tags on the MCP gateway

Codecov flagged the branch where a request carries headers but no tag header. The case
matters beyond coverage: it is what stops an unrelated header from being read as tags,
and it pins that an empty value attributes nothing
This commit is contained in:
onatozmenn 2026-08-04 19:44:04 +03:00
parent 56d7096f51
commit f410580e1b
No known key found for this signature in database

View file

@ -4631,6 +4631,28 @@ async def test_get_tools_from_mcp_servers_prefers_explicit_request_tags_over_the
assert function_setup_kwargs["metadata"]["tags"] == ["explicit"]
@pytest.mark.parametrize(
"raw_headers, expected",
[
(None, None),
({"mcp-session-id": "abc"}, None),
({"x-litellm-tags": ""}, None),
({"X-LiteLLM-Tags": "application:orders, service:checkout"}, ["application:orders", "service:checkout"]),
],
)
def test_request_tags_from_raw_headers_only_reads_the_tag_header(raw_headers, expected):
"""Only `x-litellm-tags` carries tags, whatever its casing, and an empty value is not a tag.
A request whose headers are unrelated must attribute nothing rather than the first value seen."""
try:
from litellm.proxy._experimental.mcp_server.server import (
_request_tags_from_raw_headers,
)
except ImportError:
pytest.skip("MCP server not available")
assert _request_tags_from_raw_headers(raw_headers) == expected
@pytest.mark.asyncio
async def test_get_tools_from_mcp_servers_returns_tools_when_success_logging_fails():
"""