@@ -71,47 +71,6 @@ def reset_request_ctx():
7171 pass
7272
7373
74- # Mock MCP types and structures
75- class MockURI :
76- """Mock URI object for resource testing"""
77-
78- def __init__ (self , uri_string ):
79- self .scheme = uri_string .split ("://" )[0 ] if "://" in uri_string else ""
80- self .path = uri_string .split ("://" )[1 ] if "://" in uri_string else uri_string
81- self ._uri_string = uri_string
82-
83- def __str__ (self ):
84- return self ._uri_string
85-
86-
87- class MockRequestContext :
88- """Mock MCP request context"""
89-
90- def __init__ (self , request_id = None , session_id = None , transport = "stdio" ):
91- self .request_id = request_id
92- if transport in ("http" , "sse" ):
93- self .request = MockHTTPRequest (session_id , transport )
94- else :
95- self .request = None
96-
97-
98- class MockHTTPRequest :
99- """Mock HTTP request for SSE/StreamableHTTP transport"""
100-
101- def __init__ (self , session_id = None , transport = "http" ):
102- self .headers = {}
103- self .query_params = {}
104-
105- if transport == "sse" :
106- # SSE transport uses query parameter
107- if session_id :
108- self .query_params ["session_id" ] = session_id
109- else :
110- # StreamableHTTP transport uses header
111- if session_id :
112- self .headers ["mcp-session-id" ] = session_id
113-
114-
11574class MockTextContent :
11675 """Mock TextContent object"""
11776
@@ -226,7 +185,7 @@ async def test_tool(tool_name, arguments):
226185 "send_default_pii, include_prompts" ,
227186 [(True , True ), (True , False ), (False , True ), (False , False )],
228187)
229- async def test_tool_handler_async (
188+ async def test_tool_handler_streamable_http (
230189 sentry_init ,
231190 capture_events ,
232191 send_default_pii ,
@@ -366,7 +325,7 @@ def failing_tool(tool_name, arguments):
366325 "send_default_pii, include_prompts" ,
367326 [(True , True ), (True , False ), (False , True ), (False , False )],
368327)
369- async def test_prompt_handler_sync (
328+ async def test_prompt_handler_stdio (
370329 sentry_init , capture_events , send_default_pii , include_prompts , stdio
371330):
372331 """Test that synchronous prompt handlers create proper spans"""
@@ -445,7 +404,7 @@ async def test_prompt(name, arguments):
445404 "send_default_pii, include_prompts" ,
446405 [(True , True ), (True , False ), (False , True ), (False , False )],
447406)
448- async def test_prompt_handler_async (
407+ async def test_prompt_handler_streamable_http (
449408 sentry_init ,
450409 capture_events ,
451410 send_default_pii ,
@@ -562,7 +521,7 @@ async def failing_prompt(name, arguments):
562521
563522
564523@pytest .mark .asyncio
565- async def test_resource_handler_sync (sentry_init , capture_events , stdio ):
524+ async def test_resource_handler_stdio (sentry_init , capture_events , stdio ):
566525 """Test that synchronous resource handlers create proper spans"""
567526 sentry_init (
568527 integrations = [MCPIntegration ()],
@@ -614,7 +573,7 @@ async def test_resource(uri):
614573
615574
616575@pytest .mark .asyncio
617- async def test_resource_handler_async (
576+ async def test_resource_handler_streamble_http (
618577 sentry_init ,
619578 capture_events ,
620579 json_rpc ,
@@ -1052,43 +1011,6 @@ def test_tool_complex(tool_name, arguments):
10521011 assert span ["data" ]["mcp.request.argument.number" ] == "42"
10531012
10541013
1055- @pytest .mark .asyncio
1056- async def test_async_handlers_mixed (sentry_init , capture_events ):
1057- """Test mixing sync and async handlers in the same transaction"""
1058- sentry_init (
1059- integrations = [MCPIntegration ()],
1060- traces_sample_rate = 1.0 ,
1061- )
1062- events = capture_events ()
1063-
1064- server = Server ("test-server" )
1065-
1066- # Set up mock request context
1067- mock_ctx = MockRequestContext (request_id = "req-mixed" , transport = "stdio" )
1068- request_ctx .set (mock_ctx )
1069-
1070- @server .call_tool ()
1071- def sync_tool (tool_name , arguments ):
1072- return {"type" : "sync" }
1073-
1074- @server .call_tool ()
1075- async def async_tool (tool_name , arguments ):
1076- return {"type" : "async" }
1077-
1078- with start_transaction (name = "mcp tx" ):
1079- sync_result = sync_tool ("sync" , {})
1080- async_result = await async_tool ("async" , {})
1081-
1082- assert sync_result ["type" ] == "sync"
1083- assert async_result ["type" ] == "async"
1084-
1085- (tx ,) = events
1086- assert len (tx ["spans" ]) == 2
1087-
1088- # Both should be instrumented correctly
1089- assert all (span ["op" ] == OP .MCP_SERVER for span in tx ["spans" ])
1090-
1091-
10921014@pytest .mark .asyncio
10931015async def test_sse_transport_detection (sentry_init , capture_events , json_rpc_sse ):
10941016 """Test that SSE transport is correctly detected via query parameter"""
0 commit comments