feat: backwards-compatible create_message overloads for SEP-1577 (#1713)
This commit is contained in:
parent
f82b0c9371
commit
fa851d93a2
1 changed files with 209 additions and 32 deletions
|
|
@ -8,6 +8,7 @@ from mcp.types import (
|
|||
ClientRequest,
|
||||
CreateMessageRequestParams,
|
||||
CreateMessageResult,
|
||||
CreateMessageResultWithTools,
|
||||
Implementation,
|
||||
InitializeRequest,
|
||||
InitializeRequestParams,
|
||||
|
|
@ -239,7 +240,7 @@ async def test_create_message_request_params_with_tools():
|
|||
|
||||
@pytest.mark.anyio
|
||||
async def test_create_message_result_with_tool_use():
|
||||
"""Test CreateMessageResult with tool use content for SEP-1577."""
|
||||
"""Test CreateMessageResultWithTools with tool use content for SEP-1577."""
|
||||
result_data = {
|
||||
"role": "assistant",
|
||||
"content": {"type": "tool_use", "name": "search", "id": "call_123", "input": {"query": "test"}},
|
||||
|
|
@ -247,7 +248,8 @@ async def test_create_message_result_with_tool_use():
|
|||
"stopReason": "toolUse",
|
||||
}
|
||||
|
||||
result = CreateMessageResult.model_validate(result_data)
|
||||
# Tool use content uses CreateMessageResultWithTools
|
||||
result = CreateMessageResultWithTools.model_validate(result_data)
|
||||
assert result.role == "assistant"
|
||||
assert isinstance(result.content, ToolUseContent)
|
||||
assert result.stopReason == "toolUse"
|
||||
|
|
@ -259,6 +261,25 @@ async def test_create_message_result_with_tool_use():
|
|||
assert content_list[0] == result.content
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_create_message_result_basic():
|
||||
"""Test CreateMessageResult with basic text content (backwards compatible)."""
|
||||
result_data = {
|
||||
"role": "assistant",
|
||||
"content": {"type": "text", "text": "Hello!"},
|
||||
"model": "claude-3",
|
||||
"stopReason": "endTurn",
|
||||
}
|
||||
|
||||
# Basic content uses CreateMessageResult (single content, no arrays)
|
||||
result = CreateMessageResult.model_validate(result_data)
|
||||
assert result.role == "assistant"
|
||||
assert isinstance(result.content, TextContent)
|
||||
assert result.content.text == "Hello!"
|
||||
assert result.stopReason == "endTurn"
|
||||
assert result.model == "claude-3"
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_client_capabilities_with_sampling_tools():
|
||||
"""Test ClientCapabilities with nested sampling capabilities for SEP-1577."""
|
||||
|
|
|
|||
Loading…
Reference in a new issue