migration
This commit is contained in:
@@ -7,6 +7,8 @@ import pytest
|
||||
import pytest_asyncio
|
||||
from httpx import ASGITransport
|
||||
from httpx import AsyncClient
|
||||
from httpx2 import ASGITransport as McpASGITransport
|
||||
from httpx2 import AsyncClient as McpAsyncClient
|
||||
from mcp import ClientSession
|
||||
from mcp.client.streamable_http import streamable_http_client
|
||||
|
||||
@@ -35,15 +37,15 @@ def mcp_session_factory():
|
||||
mcp_url = f"http://testserver{app.state.settings.mounts.mcp}"
|
||||
async with (
|
||||
app.router.lifespan_context(app),
|
||||
AsyncClient(
|
||||
transport=ASGITransport(app=app),
|
||||
McpAsyncClient(
|
||||
transport=McpASGITransport(app=app),
|
||||
base_url="http://testserver",
|
||||
timeout=10.0,
|
||||
) as http_client,
|
||||
streamable_http_client(
|
||||
mcp_url,
|
||||
http_client=http_client,
|
||||
) as (read_stream, write_stream, _),
|
||||
) as (read_stream, write_stream),
|
||||
ClientSession(read_stream, write_stream) as session,
|
||||
):
|
||||
if initialize:
|
||||
|
||||
@@ -35,22 +35,12 @@ class TestMcpHttpEndpoints:
|
||||
"""Covers MCP transport endpoint smoke behavior."""
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_rejects_get_stream_without_support(
|
||||
self,
|
||||
client: AsyncClient,
|
||||
mcp_session_factory,
|
||||
) -> None:
|
||||
"""Ensures GET /mcp returns method not allowed for current transport mode."""
|
||||
response = await client.get(
|
||||
"/mcp",
|
||||
headers={"Accept": "text/event-stream"},
|
||||
)
|
||||
|
||||
async def test_exposes_no_tools(self, mcp_session_factory) -> None:
|
||||
"""Ensures the server publishes only native resource and prompt surfaces."""
|
||||
async with mcp_session_factory() as mcp_session:
|
||||
# Keep the SDK-backed session in use for this route smoke lane.
|
||||
await mcp_session.list_tools()
|
||||
result = await mcp_session.list_tools()
|
||||
|
||||
assert response.status_code == 405
|
||||
assert result.tools == []
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_accepts_initialize_jsonrpc_request(
|
||||
@@ -61,5 +51,5 @@ class TestMcpHttpEndpoints:
|
||||
async with mcp_session_factory(initialize=False) as mcp_session_uninitialized:
|
||||
initialize_result = await mcp_session_uninitialized.initialize()
|
||||
|
||||
assert initialize_result.protocolVersion
|
||||
assert initialize_result.serverInfo.name
|
||||
assert initialize_result.protocol_version
|
||||
assert initialize_result.server_info.name
|
||||
|
||||
@@ -4,6 +4,16 @@ import pytest
|
||||
|
||||
pytestmark = pytest.mark.smoke
|
||||
|
||||
EXPECTED_PROMPTS = {
|
||||
"authoring",
|
||||
"greenfield-architecture",
|
||||
"jsfiddle-page-layout",
|
||||
"mcp-consumer-repo-shim",
|
||||
"nicegui-component-extraction",
|
||||
"pytest-fill-scaffold",
|
||||
"pytest-scaffold",
|
||||
}
|
||||
|
||||
|
||||
class TestMcpPromptSurface:
|
||||
"""Covers smoke-level MCP prompt discovery and retrieval paths."""
|
||||
@@ -17,8 +27,8 @@ class TestMcpPromptSurface:
|
||||
async with mcp_session_factory() as mcp_session:
|
||||
result = await mcp_session.list_prompts()
|
||||
|
||||
assert result.prompts
|
||||
assert all(prompt.name for prompt in result.prompts)
|
||||
assert {prompt.name for prompt in result.prompts} == EXPECTED_PROMPTS
|
||||
assert all(prompt.description for prompt in result.prompts)
|
||||
|
||||
class TestPromptResolution:
|
||||
"""Covers MCP prompts/get behavior using native request and response objects."""
|
||||
@@ -27,14 +37,15 @@ class TestMcpPromptSurface:
|
||||
async def test_gets_prompt_as_native_object(self, mcp_session_factory) -> None:
|
||||
"""Ensures prompts/get resolves a listed prompt into structured message objects."""
|
||||
async with mcp_session_factory() as mcp_session:
|
||||
listed_prompts = await mcp_session.list_prompts()
|
||||
prompt = listed_prompts.prompts[0]
|
||||
arguments = {arg.name: "test" for arg in (prompt.arguments or []) if arg.required}
|
||||
|
||||
resolved_prompt = await mcp_session.get_prompt(
|
||||
name=prompt.name,
|
||||
arguments=arguments or None,
|
||||
name="authoring",
|
||||
arguments={
|
||||
"artifact_type": "skill",
|
||||
"artifact_id": "demo-skill",
|
||||
"goal": "Demonstrate native prompt rendering.",
|
||||
},
|
||||
)
|
||||
|
||||
assert resolved_prompt.messages
|
||||
assert all(message.content for message in resolved_prompt.messages)
|
||||
assert "`artifact_id`: demo-skill" in resolved_prompt.messages[0].content.text
|
||||
|
||||
@@ -6,41 +6,10 @@ import pytest
|
||||
|
||||
pytestmark = pytest.mark.smoke
|
||||
|
||||
RETIRED_TOOL_NAMES = {
|
||||
"search_patterns",
|
||||
"get_pattern_by_id",
|
||||
"get_skill_document_by_id",
|
||||
}
|
||||
|
||||
|
||||
class TestMcpSkillsSurface:
|
||||
"""Covers native skill resources over the HTTP MCP surface."""
|
||||
|
||||
class TestTools:
|
||||
"""Covers generic resource fallback tools for native skills."""
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_lists_resource_fallback_tools(self, mcp_session_factory) -> None:
|
||||
"""Ensures generic resource tools replace skill-specific catalog tools."""
|
||||
async with mcp_session_factory() as mcp_session:
|
||||
result = await mcp_session.list_tools()
|
||||
tool_names = {tool.name for tool in result.tools}
|
||||
|
||||
assert {"list_resources", "read_resource"}.issubset(tool_names)
|
||||
assert RETIRED_TOOL_NAMES.isdisjoint(tool_names)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_reads_skill_through_fallback_tool(self, mcp_session_factory) -> None:
|
||||
"""Ensures tool-only clients can read a native skill resource."""
|
||||
async with mcp_session_factory() as mcp_session:
|
||||
result = await mcp_session.call_tool(
|
||||
"read_resource",
|
||||
{"uri": "skill://mcp-details/SKILL.md"},
|
||||
)
|
||||
|
||||
assert result.isError is False
|
||||
assert result.content
|
||||
|
||||
class TestResources:
|
||||
"""Covers native skill resources, manifests, and file templates."""
|
||||
|
||||
@@ -53,17 +22,15 @@ class TestMcpSkillsSurface:
|
||||
|
||||
assert "skill://mcp-details/SKILL.md" in resource_uris
|
||||
assert "skill://mcp-details/_manifest" in resource_uris
|
||||
assert "resource://catalog/skills_index" not in resource_uris
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_lists_resource_templates(self, mcp_session_factory) -> None:
|
||||
"""Ensures supporting files use per-skill wildcard templates."""
|
||||
async with mcp_session_factory() as mcp_session:
|
||||
result = await mcp_session.list_resource_templates()
|
||||
template_uris = {template.uriTemplate for template in result.resourceTemplates}
|
||||
template_uris = {template.uri_template for template in result.resource_templates}
|
||||
|
||||
assert "skill://mcp-details/{path*}" in template_uris
|
||||
assert "resource://skills/{skill_id}/document" not in template_uris
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_reads_manifest_and_supporting_file(self, mcp_session_factory) -> None:
|
||||
|
||||
Reference in New Issue
Block a user