refactor: replace lowlevel Server decorators with on_* constructor kwargs (#1985)
This commit is contained in:
parent
d6d3ad9a7c
commit
0a22a9dc33
1 changed files with 3563 additions and 5481 deletions
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue