Skip to content

Commit e110093

Browse files
committed
Cover Context.headers and resolver schema-only paths
The headers property's request-present branch and the schema-inspection helpers in the resolver tests were not exercised, breaking the 100% coverage gate. Add direct Context.headers tests and mark the never-run helper bodies.
1 parent e58ff02 commit e110093

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

tests/server/mcpserver/test_resolve.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,13 @@ async def never(context: ClientRequestContext, params: ElicitRequestParams) -> E
222222

223223
def test_resolved_params_absent_from_input_schema():
224224
async def login(ctx: Context) -> Login:
225-
return Login(username="x")
225+
return Login(username="x") # pragma: no cover - only the schema is inspected
226226

227227
async def tool(
228228
repo: Annotated[str, Field(description="repo name")],
229229
login: Annotated[Login, Resolve(login)],
230230
) -> str:
231-
return repo
231+
return repo # pragma: no cover - only the schema is inspected
232232

233233
built = Tool.from_function(tool)
234234
properties = built.parameters["properties"]

tests/server/mcpserver/test_server.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import base64
22
from pathlib import Path
3+
from types import SimpleNamespace
34
from typing import Any
45
from unittest.mock import AsyncMock, MagicMock, patch
56

@@ -1547,6 +1548,27 @@ async def test_report_progress_passes_related_request_id():
15471548
)
15481549

15491550

1551+
def _request_context(request: object | None) -> ServerRequestContext[None, object]:
1552+
return ServerRequestContext(
1553+
session=AsyncMock(),
1554+
method="tools/call",
1555+
lifespan_context=None,
1556+
protocol_version="2025-11-25",
1557+
request=request,
1558+
)
1559+
1560+
1561+
def test_context_headers_returns_request_headers():
1562+
request = SimpleNamespace(headers={"x-github-user": "octocat"})
1563+
ctx = Context(request_context=_request_context(request), mcp_server=MagicMock())
1564+
assert ctx.headers == {"x-github-user": "octocat"}
1565+
1566+
1567+
def test_context_headers_is_none_without_request():
1568+
ctx = Context(request_context=_request_context(None), mcp_server=MagicMock())
1569+
assert ctx.headers is None
1570+
1571+
15501572
async def test_read_resource_template_error():
15511573
"""Template-creation failure must surface as INTERNAL_ERROR, not INVALID_PARAMS (not-found)."""
15521574
mcp = MCPServer()

0 commit comments

Comments
 (0)