refactor: replace lowlevel Server decorators with on_* constructor kwargs (#1985)

This commit is contained in:
Max Isbey 2026-02-12 15:55:54 +00:00 • committed by GitHub
commit 0a22a9dc33
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -21,6 +21,9 @@ from mcp.shared.exceptions import MCPError
from mcp.types import (
AudioContent,
BlobResourceContents,
Completion,
CompletionArgument,
CompletionContext,
ContentBlock,
EmbeddedResource,
GetPromptResult,
@ -30,6 +33,7 @@ from mcp.types import (
Prompt,
PromptArgument,
PromptMessage,
PromptReference,
ReadResourceResult,
Resource,
ResourceTemplate,
@ -1401,6 +1405,23 @@ class TestServerPrompts:
await client.get_prompt("prompt_fn")
async def test_completion_decorator() -> None:
"""Test that the completion decorator registers a working handler."""
mcp = MCPServer()
@mcp.completion()
async def handle_completion(
ref: PromptReference, argument: CompletionArgument, context: CompletionContext | None
) -> Completion:
assert argument.name == "style"
return Completion(values=["bold", "italic", "underline"])
async with Client(mcp) as client:
ref = PromptReference(type="ref/prompt", name="test")
result = await client.complete(ref=ref, argument={"name": "style", "value": "b"})
assert result.completion.values == ["bold", "italic", "underline"]
def test_streamable_http_no_redirect() -> None:
"""Test that streamable HTTP routes are correctly configured."""
mcp = MCPServer()