@@ -124,7 +124,7 @@ def test_call_tool_sync_status(mock_transport, mock_session, is_error, expected_
124124 with MCPClient (mock_transport ["transport_callable" ]) as client :
125125 result = client .call_tool_sync (tool_use_id = "test-123" , name = "test_tool" , arguments = {"param" : "value" })
126126
127- mock_session .call_tool .assert_called_once_with ("test_tool" , {"param" : "value" }, None )
127+ mock_session .call_tool .assert_called_once_with ("test_tool" , {"param" : "value" }, None , meta = None )
128128
129129 assert result ["status" ] == expected_status
130130 assert result ["toolUseId" ] == "test-123"
@@ -153,7 +153,7 @@ def test_call_tool_sync_with_structured_content(mock_transport, mock_session):
153153 with MCPClient (mock_transport ["transport_callable" ]) as client :
154154 result = client .call_tool_sync (tool_use_id = "test-123" , name = "test_tool" , arguments = {"param" : "value" })
155155
156- mock_session .call_tool .assert_called_once_with ("test_tool" , {"param" : "value" }, None )
156+ mock_session .call_tool .assert_called_once_with ("test_tool" , {"param" : "value" }, None , meta = None )
157157
158158 assert result ["status" ] == "success"
159159 assert result ["toolUseId" ] == "test-123"
@@ -180,6 +180,51 @@ def test_call_tool_sync_exception(mock_transport, mock_session):
180180 assert "Test exception" in result ["content" ][0 ]["text" ]
181181
182182
183+ def test_call_tool_sync_forwards_meta (mock_transport , mock_session ):
184+ """Test that call_tool_sync forwards meta to ClientSession.call_tool."""
185+ mock_content = MCPTextContent (type = "text" , text = "Test message" )
186+ mock_session .call_tool .return_value = MCPCallToolResult (isError = False , content = [mock_content ])
187+ meta = {"com.example/request_id" : "abc-123" }
188+
189+ with MCPClient (mock_transport ["transport_callable" ]) as client :
190+ result = client .call_tool_sync (
191+ tool_use_id = "test-123" , name = "test_tool" , arguments = {"param" : "value" }, meta = meta
192+ )
193+
194+ mock_session .call_tool .assert_called_once_with ("test_tool" , {"param" : "value" }, None , meta = meta )
195+ assert result ["status" ] == "success"
196+
197+
198+ @pytest .mark .asyncio
199+ async def test_call_tool_async_forwards_meta (mock_transport , mock_session ):
200+ """Test that call_tool_async forwards meta to ClientSession.call_tool."""
201+ mock_content = MCPTextContent (type = "text" , text = "Test message" )
202+ mock_result = MCPCallToolResult (isError = False , content = [mock_content ])
203+ mock_session .call_tool .return_value = mock_result
204+ meta = {"com.example/request_id" : "abc-123" }
205+
206+ with MCPClient (mock_transport ["transport_callable" ]) as client :
207+ with (
208+ patch ("asyncio.run_coroutine_threadsafe" ) as mock_run_coroutine_threadsafe ,
209+ patch ("asyncio.wrap_future" ) as mock_wrap_future ,
210+ ):
211+ mock_future = MagicMock ()
212+ mock_run_coroutine_threadsafe .return_value = mock_future
213+
214+ async def mock_awaitable ():
215+ return mock_result
216+
217+ mock_wrap_future .return_value = mock_awaitable ()
218+
219+ result = await client .call_tool_async (
220+ tool_use_id = "test-123" , name = "test_tool" , arguments = {"param" : "value" }, meta = meta
221+ )
222+
223+ mock_run_coroutine_threadsafe .assert_called_once ()
224+
225+ assert result ["status" ] == "success"
226+
227+
183228@pytest .mark .asyncio
184229@pytest .mark .parametrize ("is_error,expected_status" , [(False , "success" ), (True , "error" )])
185230async def test_call_tool_async_status (mock_transport , mock_session , is_error , expected_status ):
@@ -584,7 +629,7 @@ def test_call_tool_sync_embedded_nested_text(mock_transport, mock_session):
584629 with MCPClient (mock_transport ["transport_callable" ]) as client :
585630 result = client .call_tool_sync (tool_use_id = "er-text" , name = "get_file_contents" , arguments = {})
586631
587- mock_session .call_tool .assert_called_once_with ("get_file_contents" , {}, None )
632+ mock_session .call_tool .assert_called_once_with ("get_file_contents" , {}, None , meta = None )
588633 assert result ["status" ] == "success"
589634 assert len (result ["content" ]) == 1
590635 assert result ["content" ][0 ]["text" ] == "inner text"
@@ -609,7 +654,7 @@ def test_call_tool_sync_embedded_nested_base64_textual_mime(mock_transport, mock
609654 with MCPClient (mock_transport ["transport_callable" ]) as client :
610655 result = client .call_tool_sync (tool_use_id = "er-blob" , name = "get_file_contents" , arguments = {})
611656
612- mock_session .call_tool .assert_called_once_with ("get_file_contents" , {}, None )
657+ mock_session .call_tool .assert_called_once_with ("get_file_contents" , {}, None , meta = None )
613658 assert result ["status" ] == "success"
614659 assert len (result ["content" ]) == 1
615660 assert result ["content" ][0 ]["text" ] == '{"k":"v"}'
@@ -635,7 +680,7 @@ def test_call_tool_sync_embedded_image_blob(mock_transport, mock_session):
635680 with MCPClient (mock_transport ["transport_callable" ]) as client :
636681 result = client .call_tool_sync (tool_use_id = "er-image" , name = "get_file_contents" , arguments = {})
637682
638- mock_session .call_tool .assert_called_once_with ("get_file_contents" , {}, None )
683+ mock_session .call_tool .assert_called_once_with ("get_file_contents" , {}, None , meta = None )
639684 assert result ["status" ] == "success"
640685 assert len (result ["content" ]) == 1
641686 assert "image" in result ["content" ][0 ]
@@ -660,7 +705,7 @@ def test_call_tool_sync_embedded_non_textual_blob_dropped(mock_transport, mock_s
660705 with MCPClient (mock_transport ["transport_callable" ]) as client :
661706 result = client .call_tool_sync (tool_use_id = "er-binary" , name = "get_file_contents" , arguments = {})
662707
663- mock_session .call_tool .assert_called_once_with ("get_file_contents" , {}, None )
708+ mock_session .call_tool .assert_called_once_with ("get_file_contents" , {}, None , meta = None )
664709 assert result ["status" ] == "success"
665710 assert len (result ["content" ]) == 0 # Content should be dropped
666711
@@ -683,7 +728,7 @@ def test_call_tool_sync_embedded_multiple_textual_mimes(mock_transport, mock_ses
683728 with MCPClient (mock_transport ["transport_callable" ]) as client :
684729 result = client .call_tool_sync (tool_use_id = "er-yaml" , name = "get_file_contents" , arguments = {})
685730
686- mock_session .call_tool .assert_called_once_with ("get_file_contents" , {}, None )
731+ mock_session .call_tool .assert_called_once_with ("get_file_contents" , {}, None , meta = None )
687732 assert result ["status" ] == "success"
688733 assert len (result ["content" ]) == 1
689734 assert "key: value" in result ["content" ][0 ]["text" ]
@@ -710,7 +755,7 @@ def __init__(self):
710755 with MCPClient (mock_transport ["transport_callable" ]) as client :
711756 result = client .call_tool_sync (tool_use_id = "er-unknown" , name = "get_file_contents" , arguments = {})
712757
713- mock_session .call_tool .assert_called_once_with ("get_file_contents" , {}, None )
758+ mock_session .call_tool .assert_called_once_with ("get_file_contents" , {}, None , meta = None )
714759 assert result ["status" ] == "success"
715760 assert len (result ["content" ]) == 0 # Unknown resource type should be dropped
716761
@@ -762,7 +807,7 @@ def test_call_tool_sync_with_meta_and_structured_content(mock_transport, mock_se
762807 with MCPClient (mock_transport ["transport_callable" ]) as client :
763808 result = client .call_tool_sync (tool_use_id = "test-123" , name = "test_tool" , arguments = {"param" : "value" })
764809
765- mock_session .call_tool .assert_called_once_with ("test_tool" , {"param" : "value" }, None )
810+ mock_session .call_tool .assert_called_once_with ("test_tool" , {"param" : "value" }, None , meta = None )
766811
767812 assert result ["status" ] == "success"
768813 assert result ["toolUseId" ] == "test-123"
0 commit comments