Skip to content

Commit 5d5b7ab

Browse files
committed
Minor fixes
1 parent bba7f97 commit 5d5b7ab

2 files changed

Lines changed: 16 additions & 15 deletions

File tree

integrations/mcp/src/haystack_integrations/tools/mcp/mcp_tool.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@
2626
from mcp import ClientSession, StdioServerParameters, types
2727
from mcp.client.sse import sse_client
2828
from mcp.client.stdio import stdio_client
29-
from mcp.client.streamable_http import streamablehttp_client
29+
30+
try:
31+
from mcp.client.streamable_http import streamablehttp_client
32+
except ImportError:
33+
streamablehttp_client = None
3034

3135
logger = logging.getLogger(__name__)
3236

@@ -452,6 +456,13 @@ async def connect(self) -> list[Tool]:
452456
:returns: List of available tools on the server
453457
:raises MCPConnectionError: If connection to the server fails
454458
"""
459+
if streamablehttp_client is None:
460+
message = (
461+
"Streamable HTTP client is not available. "
462+
"This may require a newer version of the mcp package that includes mcp.client.streamable_http"
463+
)
464+
raise MCPConnectionError(message=message, operation="streamable_http_connect")
465+
455466
headers = {"Authorization": f"Bearer {self.token}"} if self.token else None
456467
streamablehttp_transport = await self.exit_stack.enter_async_context(
457468
streamablehttp_client(url=self.url, headers=headers, timeout=timedelta(seconds=self.timeout))

integrations/mcp/tests/test_mcp_server_info.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -233,23 +233,12 @@ def test_sse_server_info_with_token_secret_cannot_serialize(self):
233233
)
234234

235235
# Token-based secrets cannot be serialized
236-
with pytest.raises(ValueError, match="Cannot serialize token-based secret"):
236+
with pytest.raises(ValueError, match="token"):
237237
server_info.to_dict()
238238

239-
def test_streamable_http_server_info_with_token_secret_cannot_serialize(self):
240-
"""Test that StreamableHttpServerInfo with Secret.from_token cannot be serialized."""
241-
server_info = StreamableHttpServerInfo(
242-
url="https://localhost:8000/streamable",
243-
token=Secret.from_token("secret_token_value"),
244-
)
245-
246-
# Token-based secrets cannot be serialized
247-
with pytest.raises(ValueError, match="Cannot serialize token-based secret"):
248-
server_info.to_dict()
249-
250-
def test_secret_deserialization_handles_any_secret_type(self):
239+
def test_secret_deserialization_handles_any_secret_type(self, monkeypatch):
251240
"""Test that our deserialization can handle any Secret type, not just env_vars."""
252-
# Simulate a serialized Secret with just "type" field (like a hypothetical future Secret type)
241+
monkeypatch.setenv("TEST_VAR", "test_var_value")
253242
fake_secret_dict = {"type": "env_var", "env_vars": ["TEST_VAR"], "strict": True} # Valid Secret type
254243

255244
server_info_dict = {
@@ -263,6 +252,7 @@ def test_secret_deserialization_handles_any_secret_type(self):
263252
# This should work - our condition only checks for "type" field
264253
deserialized = SSEServerInfo.from_dict(server_info_dict)
265254
assert isinstance(deserialized.token, Secret)
255+
assert deserialized.token.resolve_value() == "test_var_value"
266256
assert deserialized.url == "https://localhost:8000/sse"
267257

268258
def test_non_secret_dict_with_type_field_not_deserialized(self):

0 commit comments

Comments
 (0)