Skip to content
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
48 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
2766b40
test(mcp): Use TestClient for Streamable HTTP
alexander-alderman-webb Jan 28, 2026
d3afb38
test(fastmcp): Use TestClient for Streamable HTTP
alexander-alderman-webb Jan 28, 2026
270636d
clean up merge
alexander-alderman-webb Jan 28, 2026
960d76c
test(mcp): Use AsyncClient for SSE
alexander-alderman-webb Jan 30, 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
30e9ec3
rename tests
alexander-alderman-webb Jan 30, 2026
aaf69c3
Merge branch 'webb/test-fastmcp-stdio' into webb/test-mcp-streamable-…
alexander-alderman-webb Jan 30, 2026
0ab862c
merge
alexander-alderman-webb Jan 30, 2026
c675fb9
merge and remove mocks :)
alexander-alderman-webb Jan 30, 2026
1380f56
remove mocks
alexander-alderman-webb Jan 30, 2026
0e37050
Merge branch 'webb/test-mcp-streamable-http' into webb/test-fastmcp-s…
alexander-alderman-webb Jan 30, 2026
8749ad3
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
7703379
Merge branch 'webb/test-fastmcp-stdio' into webb/test-mcp-streamable-…
alexander-alderman-webb Jan 30, 2026
1133d9e
merge and remove duplicate import
alexander-alderman-webb Jan 30, 2026
0bd14e3
address comments
alexander-alderman-webb Jan 30, 2026
ef33e1f
add missing import fallback
alexander-alderman-webb Jan 30, 2026
4715afa
Merge branch 'webb/test-fastmcp-stdio' into webb/test-mcp-streamable-…
alexander-alderman-webb Jan 30, 2026
2df9629
Merge branch 'webb/test-mcp-streamable-http' into webb/test-fastmcp-s…
alexander-alderman-webb Jan 30, 2026
7db7680
Merge branch 'webb/test-fastmcp-streamable-http' into webb/test-mcp-sse
alexander-alderman-webb Jan 30, 2026
d6c2fa5
simplify streaming transport
alexander-alderman-webb Jan 30, 2026
0f47f06
remove unused import
alexander-alderman-webb Jan 30, 2026
1bf6876
simplify assertions and use stdio in more tests cases
alexander-alderman-webb Feb 2, 2026
fd2cc42
Merge branch 'webb/test-fastmcp-stdio' into webb/test-mcp-streamable-…
alexander-alderman-webb Feb 2, 2026
771f60e
forgot conftest
alexander-alderman-webb Feb 2, 2026
8f57fcd
Merge branch 'webb/test-fastmcp-stdio' into webb/test-mcp-streamable-…
alexander-alderman-webb Feb 2, 2026
cc4a19d
merge and simplify assertions
alexander-alderman-webb Feb 2, 2026
ef06a2d
fix no-return assertion
alexander-alderman-webb Feb 2, 2026
955d525
Merge branch 'webb/test-fastmcp-stdio' into webb/test-mcp-streamable-…
alexander-alderman-webb Feb 2, 2026
6b81f86
Merge branch 'webb/test-mcp-streamable-http' into webb/test-fastmcp-s…
alexander-alderman-webb Feb 2, 2026
a16e638
Merge branch 'webb/test-fastmcp-streamable-http' into webb/test-mcp-sse
alexander-alderman-webb Feb 2, 2026
5c0bde6
merge master
alexander-alderman-webb Feb 2, 2026
52e5c41
import order
alexander-alderman-webb Feb 2, 2026
8da7325
import order
alexander-alderman-webb Feb 2, 2026
711b542
import order
alexander-alderman-webb Feb 2, 2026
bad10f8
remove unused mocks
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
195 changes: 195 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
from werkzeug.wrappers import Request, Response
import jsonschema

try:
from starlette.testclient import TestClient
# Catch RuntimeError to prevent the following exception in aws_lambda tests.
# RuntimeError: The starlette.testclient module requires the httpx package to be installed.
except (ImportError, RuntimeError):
TestClient = None

try:
import gevent
Expand Down Expand Up @@ -48,6 +54,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 +614,179 @@ 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):
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


@pytest.fixture()
def json_rpc():
def inner(app, method: str, params, request_id: str):
if request_id is None:
request_id = "1" # arbitrary

with TestClient(app) as client: # type: ignore
init_response = client.post(
"/mcp/",
headers={
"Accept": "application/json, text/event-stream",
"Content-Type": "application/json",
},
json={
"jsonrpc": "2.0",
"method": "initialize",
"params": {
"clientInfo": {"name": "test-client", "version": "1.0"},
"protocolVersion": "2025-11-25",
"capabilities": {},
},
"id": request_id,
},
)

session_id = init_response.headers["mcp-session-id"]

# Notification response is mandatory.
# https://modelcontextprotocol.io/specification/2025-11-25/basic/lifecycle
client.post(
"/mcp/",
headers={
"Accept": "application/json, text/event-stream",
"Content-Type": "application/json",
"mcp-session-id": session_id,
},
json={
"jsonrpc": "2.0",
"method": "notifications/initialized",
"params": {},
},
)

response = client.post(
"/mcp/",
headers={
"Accept": "application/json, text/event-stream",
"Content-Type": "application/json",
"mcp-session-id": session_id,
},
json={
"jsonrpc": "2.0",
"method": method,
"params": params,
"id": request_id,
},
)

return session_id, response

return inner


@pytest.fixture()
def select_mcp_transactions():
def inner(events):
return [
event
for event in events
if event["type"] == "transaction"
and event["contexts"]["trace"]["op"] == "mcp.server"
]

return inner


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