Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MCPTool #8987

Closed
wants to merge 5 commits into from
Closed

Add MCPTool #8987

wants to merge 5 commits into from

Conversation

vblagoje
Copy link
Member

@vblagoje vblagoje commented Mar 6, 2025

Why:

Adds MCPTool (Model Context Protocol), enabling tools to connect and interact with MCP servers via HTTP and stdio transports.

What:

  • Added a new module mcp_tool that includes classes to handle the MCP client implementation for HTTP and stdio transports.
  • Updated __init__.py to export MCP-related classes for external use.
  • Incorporated MCP dependency into pyproject.toml.

How can it be used:

MCP tools can be created and invoked through HTTP or stdio server configurations:

from haystack.tools import MCPTool, HttpMCPServerInfo

server_info = HttpMCPServerInfo(base_url="http://localhost:8000")
tool = MCPTool(name="add", server_info=server_info)
result = tool.invoke(a=5, b=3)

# Using stdio
from haystack.tools import MCPTool, StdioMCPServerInfo

server_info = StdioMCPServerInfo(command="python", args=["server.py"])
tool = MCPTool(name="get_current_time", server_info=server_info)
result = tool.invoke(timezone="America/New_York")

How did you test it:

Implemented unit tests using pytest and unittest.mock to simulate MCP server behaviors. Additionally, integration tests were conducted with actual server instances to validate interactions across network protocols.

Notes for the reviewer:

Focus on the implementation details of the MCPTool class in mcp_tool.py, and ensure tests effectively mock server responses and include proper cleanup routines. Check integration with the new MCP server dependencies in pyproject.toml.

@LastRemote
Copy link
Contributor

Hello @vblagoje , thanks for this PR. This feels so much smoother than configuring Claude Desktop. One stupid question though, does StdioMCPServerInfo respect the conda or venv runtime environment to run local MCP server?

@vblagoje
Copy link
Member Author

Hey @LastRemote this PR is being replaced with deepset-ai/haystack-core-integrations#1487 as we want to iterate improvements there faster independent of haystack. As soon as everything stabilizes I believe we'll eventually integrate it back into haystack as core feature that it is.

@vblagoje
Copy link
Member Author

Superseded by deepset-ai/haystack-core-integrations#1487 Closing

@vblagoje vblagoje closed this Mar 10, 2025
@vblagoje
Copy link
Member Author

Forgot to mention that mcp requires python 3.10 and that was also one of the reasons. Haystack still supports 3.9.

@vblagoje vblagoje deleted the mcp_tool_pr branch March 10, 2025 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants