Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
a8372b0
test(mcp): Simulate stdio transport with memory streams
alexander-alderman-webb Jan 16, 2026
87a2e26
test(fastmcp): Simulate stdio transport with memory streams
alexander-alderman-webb Jan 19, 2026
70edb6d
cleaning up
alexander-alderman-webb Jan 27, 2026
c238f84
Merge branch 'webb/test-mcp-stdio' into webb/test-fastmcp-stdio
alexander-alderman-webb Jan 27, 2026
f1362bd
send initialization response
alexander-alderman-webb Jan 27, 2026
34dba91
Merge branch 'webb/test-mcp-stdio' into webb/test-fastmcp-stdio
alexander-alderman-webb Jan 27, 2026
46659c5
cleanup
alexander-alderman-webb Jan 27, 2026
ac8e6e4
gate import in conftest
alexander-alderman-webb Jan 27, 2026
8c9aa86
remove mixed method test
alexander-alderman-webb Jan 30, 2026
6579935
rename tests
alexander-alderman-webb Jan 30, 2026
8aa6363
merge
alexander-alderman-webb Jan 30, 2026
5976135
remove test
alexander-alderman-webb Jan 30, 2026
317c002
Merge branch 'master' into webb/test-mcp-stdio
alexander-alderman-webb Jan 30, 2026
9097b69
merge and remove duplicate asyncio marker
alexander-alderman-webb Jan 30, 2026
ef33e1f
add missing import fallback
alexander-alderman-webb Jan 30, 2026
1bf6876
simplify assertions and use stdio in more tests cases
alexander-alderman-webb Feb 2, 2026
771f60e
forgot conftest
alexander-alderman-webb Feb 2, 2026
ef06a2d
fix no-return assertion
alexander-alderman-webb Feb 2, 2026
94e115d
merge master
alexander-alderman-webb Feb 2, 2026
9399f3a
remove unused helper
alexander-alderman-webb Feb 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 116 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@
from typing import Optional
from collections.abc import Iterator

try:
from anyio import create_memory_object_stream, create_task_group
from mcp.types import (
JSONRPCMessage,
JSONRPCNotification,
JSONRPCRequest,
)
from mcp.shared.message import SessionMessage
except ImportError:
create_memory_object_stream = None
create_task_group = None
JSONRPCMessage = None
JSONRPCNotification = None
JSONRPCRequest = None
SessionMessage = None


SENTRY_EVENT_SCHEMA = "./checkouts/data-schemas/relay/event.schema.json"

Expand Down Expand Up @@ -592,6 +608,106 @@ def suppress_deprecation_warnings():
yield


@pytest.fixture
def get_initialization_payload():
def inner(request_id: str):
return SessionMessage( # type: ignore
message=JSONRPCMessage( # type: ignore
root=JSONRPCRequest( # type: ignore
jsonrpc="2.0",
id=request_id,
method="initialize",
params={
"protocolVersion": "2025-11-25",
"capabilities": {},
"clientInfo": {"name": "test-client", "version": "1.0.0"},
},
)
)
)

return inner


@pytest.fixture
def get_initialized_notification_payload():
def inner():
return SessionMessage( # type: ignore
message=JSONRPCMessage( # type: ignore
root=JSONRPCNotification( # type: ignore
jsonrpc="2.0",
method="notifications/initialized",
)
)
)

return inner


@pytest.fixture
def get_mcp_command_payload():
def inner(method: str, params, request_id: str):
return SessionMessage( # type: ignore
message=JSONRPCMessage( # type: ignore
root=JSONRPCRequest( # type: ignore
jsonrpc="2.0",
id=request_id,
method=method,
params=params,
)
)
)

return inner


@pytest.fixture
def stdio(
get_initialization_payload,
get_initialized_notification_payload,
get_mcp_command_payload,
):
async def inner(server, method: str, params, request_id: str | None = None):
if request_id is None:
request_id = "1"

read_stream_writer, read_stream = create_memory_object_stream(0) # type: ignore
write_stream, write_stream_reader = create_memory_object_stream(0) # type: ignore

result = {}

async def run_server():
await server.run(
read_stream, write_stream, server.create_initialization_options()
)

async def simulate_client(tg, result):
init_request = get_initialization_payload("1")
await read_stream_writer.send(init_request)

await write_stream_reader.receive()

initialized_notification = get_initialized_notification_payload()
await read_stream_writer.send(initialized_notification)

request = get_mcp_command_payload(
method, params=params, request_id=request_id
)
await read_stream_writer.send(request)

result["response"] = await write_stream_reader.receive()

tg.cancel_scope.cancel()

async with create_task_group() as tg: # type: ignore
tg.start_soon(run_server)
tg.start_soon(simulate_client, tg, result)

return result["response"]

return inner


class MockServerRequestHandler(BaseHTTPRequestHandler):
def do_GET(self): # noqa: N802
# Process an HTTP GET request and return a response.
Expand Down
Loading
Loading