@@ -239,84 +239,62 @@ def test_mcp_client_without_structured_content():
239239
240240
241241def test_call_tool_sync_with_meta ():
242- """Test that call_tool_sync works correctly when meta is provided ."""
242+ """Test that call_tool_sync forwards meta to the MCP server ."""
243243 stdio_mcp_client = MCPClient (
244244 lambda : stdio_client (StdioServerParameters (command = "python" , args = ["tests_integ/mcp/echo_server.py" ]))
245245 )
246246
247247 with stdio_mcp_client :
248248 result = stdio_mcp_client .call_tool_sync (
249249 tool_use_id = "test-meta-sync" ,
250- name = "echo " ,
251- arguments = {"to_echo" : "META_TEST" },
250+ name = "echo_meta " ,
251+ arguments = {},
252252 meta = {"com.example/request_id" : "abc-123" },
253253 )
254254
255255 assert result ["status" ] == "success"
256- assert result ["content" ] == [{"text" : "META_TEST" }]
256+ received_meta = json .loads (result ["content" ][0 ]["text" ])
257+ assert received_meta ["com.example/request_id" ] == "abc-123"
257258
258259
259260@pytest .mark .asyncio
260261async def test_call_tool_async_with_meta ():
261- """Test that call_tool_async works correctly when meta is provided ."""
262+ """Test that call_tool_async forwards meta to the MCP server ."""
262263 stdio_mcp_client = MCPClient (
263264 lambda : stdio_client (StdioServerParameters (command = "python" , args = ["tests_integ/mcp/echo_server.py" ]))
264265 )
265266
266267 with stdio_mcp_client :
267268 result = await stdio_mcp_client .call_tool_async (
268269 tool_use_id = "test-meta-async" ,
269- name = "echo " ,
270- arguments = {"to_echo" : "META_ASYNC_TEST" },
270+ name = "echo_meta " ,
271+ arguments = {},
271272 meta = {"com.example/request_id" : "def-456" },
272273 )
273274
274275 assert result ["status" ] == "success"
275- assert result ["content" ] == [{"text" : "META_ASYNC_TEST" }]
276+ received_meta = json .loads (result ["content" ][0 ]["text" ])
277+ assert received_meta ["com.example/request_id" ] == "def-456"
276278
277279
278280def test_instrumentation_preserves_meta_on_tool_call ():
279- """Test that OTel instrumentation correctly sets _meta on outgoing tool call requests."""
280- captured_params = []
281-
282- def spy_send_request (wrapped , instance , args , kwargs ):
283- if args :
284- request = args [0 ]
285- method = getattr (getattr (request , "root" , None ), "method" , None )
286- if method == "tools/call" and hasattr (request .root , "params" ):
287- params = request .root .params
288- if hasattr (params , "model_dump" ):
289- captured_params .append (params .model_dump (by_alias = True ))
290- elif isinstance (params , dict ):
291- captured_params .append (params .copy ())
292- return wrapped (* args , ** kwargs )
293-
281+ """Test that OTel instrumentation sets _meta that reaches the MCP server."""
294282 stdio_mcp_client = MCPClient (
295283 lambda : stdio_client (StdioServerParameters (command = "python" , args = ["tests_integ/mcp/echo_server.py" ]))
296284 )
297285
298286 with stdio_mcp_client :
299- from mcp .shared .session import BaseSession
300- from wrapt import wrap_function_wrapper
301-
302- original_send = BaseSession .send_request
303- wrap_function_wrapper ("mcp.shared.session" , "BaseSession.send_request" , spy_send_request )
304-
305- try :
306- result = stdio_mcp_client .call_tool_sync (
307- tool_use_id = "test-instrumentation" ,
308- name = "echo" ,
309- arguments = {"to_echo" : "INSTRUMENTATION_TEST" },
310- )
311-
312- assert result ["status" ] == "success"
313- assert len (captured_params ) > 0
287+ result = stdio_mcp_client .call_tool_sync (
288+ tool_use_id = "test-instrumentation" ,
289+ name = "echo_meta" ,
290+ arguments = {},
291+ )
314292
315- params = captured_params [ - 1 ]
316- assert "_meta" in params
317- assert isinstance ( params [ " _meta" ], dict )
318- finally :
319- BaseSession . send_request = original_send
293+ assert result [ "status" ] == "success"
294+ received_meta = json . loads ( result [ "content" ][ 0 ][ "text" ])
295+ # OTel instrumentation should have injected _meta with tracing context
296+ assert received_meta is not None
297+ assert isinstance ( received_meta , dict )
320298
321299
322300@pytest .mark .skipif (
0 commit comments