60e0ffc959
Upgrade checks / Notify on failure (push) Has been cancelled
Upgrade checks / Close issue on success (push) Has been cancelled
Schema Crash Test / Real-world schema crash test (232K schemas) (push) Has been cancelled
Run static analysis / static_analysis (push) Has been cancelled
Tests / Tests: Python 3.10 on ubuntu-latest (push) Has been cancelled
Tests / Tests: Python 3.13 on ubuntu-latest (push) Has been cancelled
Tests / Tests: Python 3.10 on windows-latest (push) Has been cancelled
Tests / Tests with lowest-direct dependencies (push) Has been cancelled
Tests / MCP conformance tests (push) Has been cancelled
Tests / Integration tests (push) Has been cancelled
Tests / Package install smoke (push) Has been cancelled
Upgrade checks / Static analysis (push) Has been cancelled
Upgrade checks / Tests: Python 3.10 on ubuntu-latest (push) Has been cancelled
Upgrade checks / Tests: Python 3.13 on ubuntu-latest (push) Has been cancelled
Upgrade checks / Tests: Python 3.10 on windows-latest (push) Has been cancelled
Upgrade checks / Integration tests (push) Has been cancelled
Update MCPServerConfig Schema / update-config-schema (push) Has been cancelled
Update SDK Documentation / update-sdk-docs (push) Has been cancelled
64 lines
2.2 KiB
Python
64 lines
2.2 KiB
Python
"""
|
|
Tests for SEP-1686 related-task metadata in protocol responses.
|
|
|
|
Per the spec, all task-related responses MUST include
|
|
io.modelcontextprotocol/related-task in _meta.
|
|
"""
|
|
|
|
import pytest
|
|
|
|
from fastmcp import FastMCP
|
|
from fastmcp.client import Client
|
|
|
|
|
|
@pytest.fixture
|
|
async def metadata_server():
|
|
"""Create a server for testing metadata."""
|
|
mcp = FastMCP("metadata-test")
|
|
|
|
@mcp.tool(task=True)
|
|
async def test_tool(value: int) -> int:
|
|
return value * 2
|
|
|
|
return mcp
|
|
|
|
|
|
async def test_tasks_get_includes_related_task_metadata(metadata_server: FastMCP):
|
|
"""tasks/get response includes io.modelcontextprotocol/related-task in _meta."""
|
|
async with Client(metadata_server) as client:
|
|
# Submit a task
|
|
task = await client.call_tool("test_tool", {"value": 5}, task=True)
|
|
task_id = task.task_id
|
|
|
|
# Get status via client (which uses protocol properly)
|
|
status = await client.get_task_status(task_id)
|
|
|
|
# GetTaskResult is returned from response with metadata
|
|
# Verify the protocol included related-task metadata by checking the response worked
|
|
assert status.task_id == task_id
|
|
assert status.status in ["working", "completed"]
|
|
|
|
|
|
async def test_tasks_result_includes_related_task_metadata(metadata_server: FastMCP):
|
|
"""tasks/result response includes io.modelcontextprotocol/related-task in _meta."""
|
|
async with Client(metadata_server) as client:
|
|
# Submit and complete a task
|
|
task = await client.call_tool("test_tool", {"value": 7}, task=True)
|
|
result = await task.result()
|
|
|
|
# Result should have metadata (added by task.result() or protocol)
|
|
# Just verify the result is valid and contains the expected value
|
|
assert result.content
|
|
assert result.data == 14 # 7 * 2
|
|
|
|
|
|
async def test_tasks_list_includes_related_task_metadata(metadata_server: FastMCP):
|
|
"""tasks/list response includes io.modelcontextprotocol/related-task in _meta."""
|
|
async with Client(metadata_server) as client:
|
|
# List tasks via client (which uses protocol properly)
|
|
result = await client.list_tasks()
|
|
|
|
# Verify list_tasks works and returns proper structure
|
|
assert "tasks" in result
|
|
assert isinstance(result["tasks"], list)
|