Skip to content

Commit 617b1c7

Browse files
committed
Fix more tests
1 parent a99270e commit 617b1c7

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

integrations/mcp/tests/mcp_memory_transport.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from mcp.server import Server
66
from mcp.shared.memory import create_connected_server_and_client_session
77

8-
from haystack_integrations.tools.mcp import MCPClient, MCPServerInfo
8+
from haystack_integrations.tools.mcp import MCPClient, MCPInvocationError, MCPServerInfo
99

1010

1111
class InMemoryClient(MCPClient):
@@ -44,7 +44,12 @@ async def call_tool(self, tool_name: str, tool_args: dict[str, Any]) -> Any:
4444
async with create_connected_server_and_client_session(self.server) as session:
4545
await session.initialize()
4646
response = await session.call_tool(tool_name, tool_args)
47-
return self._validate_response(tool_name, response)
47+
if response.isError:
48+
raise MCPInvocationError(
49+
message=f"Tool '{tool_name}' returned an error: {response.content!s}",
50+
tool_name=tool_name,
51+
)
52+
return response.model_dump_json()
4853

4954

5055
@dataclass

integrations/mcp/tests/test_mcp_tool.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ def test_mcp_tool_invoke(self, mcp_add_tool, mcp_echo_tool):
6666
"""Test invoking MCPTools connected to in-memory servers."""
6767
# Test add tool invocation
6868
add_result = mcp_add_tool.invoke(a=25, b=17)
69-
assert not add_result.isError
70-
assert len(add_result.content) == 1
71-
assert add_result.content[0].text == "42" # 25 + 17
69+
import json
70+
71+
add_result = json.loads(add_result)
72+
assert add_result["content"][0]["text"] == "42"
7273

7374
# Test echo tool invocation
7475
echo_result = mcp_echo_tool.invoke(text="Hello MCP!")
75-
assert not echo_result.isError
76-
assert len(echo_result.content) == 1
77-
assert echo_result.content[0].text == "Hello MCP!"
76+
echo_result = json.loads(echo_result)
77+
assert echo_result["content"][0]["text"] == "Hello MCP!"
7878

7979
def test_mcp_tool_error_handling(self, mcp_error_tool):
8080
"""Test error handling with the in-memory server."""

0 commit comments

Comments
 (0)