Skip to content

Commit c675fb9

Browse files
merge and remove mocks :)
2 parents 960d76c + 0ab862c commit c675fb9

File tree

2 files changed

+5
-85
lines changed

2 files changed

+5
-85
lines changed

tests/integrations/mcp/streaming_asgi_transport.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ async def __aiter__(self):
7676
yield chunk
7777
except anyio.EndOfStream:
7878
pass
79-
finally:
80-
await self.task
8179

8280
stream = StreamingBodyStream(body_receiver, asyncio.create_task(run_app()))
8381
response = Response(status_code=200, headers=[], stream=stream)

tests/integrations/mcp/test_mcp.py

Lines changed: 5 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -75,47 +75,6 @@ def reset_request_ctx():
7575
pass
7676

7777

78-
# Mock MCP types and structures
79-
class MockURI:
80-
"""Mock URI object for resource testing"""
81-
82-
def __init__(self, uri_string):
83-
self.scheme = uri_string.split("://")[0] if "://" in uri_string else ""
84-
self.path = uri_string.split("://")[1] if "://" in uri_string else uri_string
85-
self._uri_string = uri_string
86-
87-
def __str__(self):
88-
return self._uri_string
89-
90-
91-
class MockRequestContext:
92-
"""Mock MCP request context"""
93-
94-
def __init__(self, request_id=None, session_id=None, transport="stdio"):
95-
self.request_id = request_id
96-
if transport in ("http", "sse"):
97-
self.request = MockHTTPRequest(session_id, transport)
98-
else:
99-
self.request = None
100-
101-
102-
class MockHTTPRequest:
103-
"""Mock HTTP request for SSE/StreamableHTTP transport"""
104-
105-
def __init__(self, session_id=None, transport="http"):
106-
self.headers = {}
107-
self.query_params = {}
108-
109-
if transport == "sse":
110-
# SSE transport uses query parameter
111-
if session_id:
112-
self.query_params["session_id"] = session_id
113-
else:
114-
# StreamableHTTP transport uses header
115-
if session_id:
116-
self.headers["mcp-session-id"] = session_id
117-
118-
11978
class MockTextContent:
12079
"""Mock TextContent object"""
12180

@@ -322,7 +281,7 @@ async def test_tool(tool_name, arguments):
322281
"send_default_pii, include_prompts",
323282
[(True, True), (True, False), (False, True), (False, False)],
324283
)
325-
async def test_tool_handler_async(
284+
async def test_tool_handler_streamable_http(
326285
sentry_init,
327286
capture_events,
328287
send_default_pii,
@@ -462,7 +421,7 @@ def failing_tool(tool_name, arguments):
462421
"send_default_pii, include_prompts",
463422
[(True, True), (True, False), (False, True), (False, False)],
464423
)
465-
async def test_prompt_handler_sync(
424+
async def test_prompt_handler_stdio(
466425
sentry_init, capture_events, send_default_pii, include_prompts, stdio
467426
):
468427
"""Test that synchronous prompt handlers create proper spans"""
@@ -541,7 +500,7 @@ async def test_prompt(name, arguments):
541500
"send_default_pii, include_prompts",
542501
[(True, True), (True, False), (False, True), (False, False)],
543502
)
544-
async def test_prompt_handler_async(
503+
async def test_prompt_handler_streamable_http(
545504
sentry_init,
546505
capture_events,
547506
send_default_pii,
@@ -658,7 +617,7 @@ async def failing_prompt(name, arguments):
658617

659618

660619
@pytest.mark.asyncio
661-
async def test_resource_handler_sync(sentry_init, capture_events, stdio):
620+
async def test_resource_handler_stdio(sentry_init, capture_events, stdio):
662621
"""Test that synchronous resource handlers create proper spans"""
663622
sentry_init(
664623
integrations=[MCPIntegration()],
@@ -710,7 +669,7 @@ async def test_resource(uri):
710669

711670

712671
@pytest.mark.asyncio
713-
async def test_resource_handler_async(
672+
async def test_resource_handler_streamble_http(
714673
sentry_init,
715674
capture_events,
716675
json_rpc,
@@ -1148,43 +1107,6 @@ def test_tool_complex(tool_name, arguments):
11481107
assert span["data"]["mcp.request.argument.number"] == "42"
11491108

11501109

1151-
@pytest.mark.asyncio
1152-
async def test_async_handlers_mixed(sentry_init, capture_events):
1153-
"""Test mixing sync and async handlers in the same transaction"""
1154-
sentry_init(
1155-
integrations=[MCPIntegration()],
1156-
traces_sample_rate=1.0,
1157-
)
1158-
events = capture_events()
1159-
1160-
server = Server("test-server")
1161-
1162-
# Set up mock request context
1163-
mock_ctx = MockRequestContext(request_id="req-mixed", transport="stdio")
1164-
request_ctx.set(mock_ctx)
1165-
1166-
@server.call_tool()
1167-
def sync_tool(tool_name, arguments):
1168-
return {"type": "sync"}
1169-
1170-
@server.call_tool()
1171-
async def async_tool(tool_name, arguments):
1172-
return {"type": "async"}
1173-
1174-
with start_transaction(name="mcp tx"):
1175-
sync_result = sync_tool("sync", {})
1176-
async_result = await async_tool("async", {})
1177-
1178-
assert sync_result["type"] == "sync"
1179-
assert async_result["type"] == "async"
1180-
1181-
(tx,) = events
1182-
assert len(tx["spans"]) == 2
1183-
1184-
# Both should be instrumented correctly
1185-
assert all(span["op"] == OP.MCP_SERVER for span in tx["spans"])
1186-
1187-
11881110
@pytest.mark.asyncio
11891111
async def test_sse_transport_detection(sentry_init, capture_events):
11901112
"""Test that SSE transport is correctly detected via query parameter"""

0 commit comments

Comments
 (0)