Keep the sampling conformance scenario live; fix roots example URIs

This commit is contained in:
Jeremiah Lowin 2026-07-27 09:35:30 -04:00
commit 0172e4c4d4
No known key found for this signature in database
3 changed files with 27 additions and 8 deletions

View file

@ -24,7 +24,7 @@ from fastmcp import Client
client = Client(
"my_mcp_server.py",
roots=["/path/to/root1", "/path/to/root2"]
roots=["file:///path/to/root1", "file:///path/to/root2"]
)
```
@ -38,7 +38,7 @@ from fastmcp.client.roots import RequestContext
async def roots_callback(context: RequestContext) -> list[str]:
print(f"Server requested roots (Request ID: {context.request_id})")
return ["/path/to/root1", "/path/to/root2"]
return ["file:///path/to/root1", "file:///path/to/root2"]
client = Client(
"my_mcp_server.py",

View file

@ -21,9 +21,3 @@ server:
# need the tool to declare which one it wants, which is an unmade API
# decision rather than a bug.
- tasks-mrtr-composition
# Server-initiated sampling was removed from the server API (SEP-2577), so the
# fixture has no `test_sampling` tool for this handshake-era scenario to drive.
# Modern sampling rides the guard pattern and is covered by
# input-required-result-basic-sampling.
- tools-call-sampling

View file

@ -173,6 +173,31 @@ async def test_tool_with_progress(ctx: Context) -> str:
return "Progress test complete."
@server.tool(name="test_sampling")
async def test_sampling(prompt: str, ctx: Context) -> str:
"""Requests LLM sampling via the client.
`Context` has no `sample()` server-initiated sampling is not part of
FastMCP's server API. The handshake-era wire path is still supported and
still shipped (the proxy relay uses it), so this fixture reaches the SDK
session directly to keep the scenario covered.
"""
result = await ctx.session.create_message( # ty: ignore[deprecated]
messages=[
mcp_types.SamplingMessage(
role="user",
content=mcp_types.TextContent(type="text", text=prompt),
)
],
max_tokens=512,
related_request_id=ctx.origin_request_id,
)
text = (
result.content.text if isinstance(result.content, mcp_types.TextContent) else ""
)
return f"Sampling result: {text}"
class _UserInfo(BaseModel):
username: str
email: str