Skip to content

Commit 64e4e6a

Browse files
authored
chore: Update mcp-haystack integration README.md (#1835)
* Update mcp integration README * Small correction
1 parent d8446b5 commit 64e4e6a

1 file changed

Lines changed: 70 additions & 11 deletions

File tree

integrations/mcp/README.md

Lines changed: 70 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,36 @@ pip install mcp-haystack
1010

1111
## Usage
1212

13+
### Using Individual Tools (MCPTool)
14+
1315
```python
1416
from haystack_integrations.tools.mcp import MCPTool, SSEServerInfo
1517

1618
# Create an MCP tool that connects to an HTTP server
17-
server_info = SSEServerInfo(base_url="http://localhost:8000")
19+
server_info = SSEServerInfo(url="http://localhost:8000/sse")
1820
tool = MCPTool(name="my_tool", server_info=server_info)
1921

2022
# Use the tool
2123
result = tool.invoke(param1="value1", param2="value2")
2224
```
2325

26+
### Using Tool Collections (MCPToolset)
27+
28+
```python
29+
from haystack_integrations.tools.mcp import MCPToolset, StdioServerInfo
30+
31+
# Create a toolset that automatically discovers all available tools
32+
server_info = StdioServerInfo(command="uvx", args=["mcp-server-time"])
33+
toolset = MCPToolset(server_info)
34+
35+
# Use tools from the toolset
36+
for tool in toolset:
37+
print(f"Available tool: {tool.name} - {tool.description}")
38+
39+
# Or filter to specific tools
40+
filtered_toolset = MCPToolset(server_info, tool_names=["get_current_time"])
41+
```
42+
2443
# Examples
2544

2645
Check out the examples directory to see practical demonstrations of how to integrate the MCPTool into Haystack's tooling architecture. These examples will help you get started quickly with your own agentic applications.
@@ -31,14 +50,14 @@ In some examples below, we use the `StdioServerInfo` class which relies on `uvx`
3150

3251
## Example 1: MCP Server with SSE Transport
3352

34-
This example demonstrates how to create a simple calculator server using MCP and connect to it using the MCPTool with SSE transport.
53+
This example demonstrates how to create a simple calculator server using MCP and connect to it using MCPTool with SSE transport.
3554

3655
### Step 1: Run the MCP Server
3756

3857
First, run the server that exposes calculator functionality (addition and subtraction) via MCP:
3958

4059
```bash
41-
python examples/mcp_sse_server.py
60+
python examples/mcp_server.py --transport sse
4261
```
4362

4463
This creates a FastMCP server with two tools:
@@ -47,31 +66,53 @@ This creates a FastMCP server with two tools:
4766

4867
The server runs on http://localhost:8000 by default.
4968

50-
### Step 2: Connect with the MCP Client
69+
### Step 2: Connect with Individual Tools (MCPTool)
5170

52-
In a separate terminal, run the client that connects to the calculator server:
71+
In a separate terminal, run the client that connects to the calculator server using individual MCPTool instances:
5372

5473
```bash
55-
python examples/mcp_sse_client.py
74+
python examples/mcp_client.py --transport sse
5675
```
5776

5877
The client creates MCPTool instances that connect to the server, inspect the tool specifications, and invoke the calculator functions remotely.
5978

79+
### Step 3: Connect with Tool Collections (MCPToolset)
80+
81+
Alternatively, use MCPToolset to automatically discover and use all available tools:
82+
83+
```bash
84+
python examples/mcp_sse_toolset.py
85+
```
86+
87+
This demonstrates how MCPToolset can automatically discover all tools from the server and create a collection of tools for easy access.
88+
6089
## Example 2: MCP with StdIO Transport
6190

62-
This example shows how to use MCPTool with stdio transport to execute a local program directly:
91+
This example shows how to use MCP tools with stdio transport to execute a local program directly.
92+
93+
### Using Individual Tools (MCPTool)
6394

6495
```bash
6596
python examples/mcp_stdio_client.py
6697
```
6798

6899
The example creates an MCPTool that uses stdio transport with `StdioServerInfo`, which automatically uses `uvx` behind the scenes to run the `mcp-server-time` tool without requiring manual installation. It queries the current time in different timezones (New York and Los Angeles) by invoking the tool with different parameters.
69100

70-
This demonstrates how MCPTool can work with local programs without running a separate server process, using standard input/output for communication.
101+
### Using Tool Collections (MCPToolset)
102+
103+
```bash
104+
python examples/mcp_stdio_toolset.py
105+
```
106+
107+
This example demonstrates how MCPToolset can automatically discover all available tools from a stdio-based MCP server and create a collection for easy access.
108+
109+
Both approaches demonstrate how MCP tools can work with local programs without running a separate server process, using standard input/output for communication.
71110

72-
## Example 3: MCPTool in a Haystack Pipeline
111+
## Example 3: MCP Tools in Haystack Pipelines
73112

74-
This example showcases how to integrate MCPTool into a Haystack pipeline along with an LLM:
113+
These examples showcase how to integrate MCP tools into Haystack pipelines along with LLMs.
114+
115+
### Using Individual Tools (MCPTool)
75116

76117
```bash
77118
python examples/time_pipeline.py
@@ -83,7 +124,25 @@ This example creates a pipeline that:
83124
3. Invokes the time tool with the appropriate parameters (using `uvx` behind the scenes)
84125
4. Sends the tool's response back to the LLM to generate a final answer
85126

86-
This demonstrates how MCPTool can be seamlessly integrated into Haystack's agentic architecture, allowing LLMs to use external tools via the Model Context Protocol.
127+
### Using Tool Collections (MCPToolset)
128+
129+
```bash
130+
python examples/time_pipeline_toolset.py
131+
```
132+
133+
This example demonstrates the same functionality but uses MCPToolset instead of individual MCPTool instances. The toolset automatically discovers all available tools from the MCP server and makes them available to the LLM.
134+
135+
Both examples demonstrate how MCP tools can be seamlessly integrated into Haystack's agentic architecture, allowing LLMs to use external tools via the Model Context Protocol.
136+
137+
## Example 4: Advanced MCPToolset Features
138+
139+
### Tool Filtering
140+
141+
```bash
142+
python examples/mcp_filtered_tools.py
143+
```
144+
145+
This example demonstrates how to use MCPToolset with tool filtering, allowing you to selectively include only specific tools from an MCP server. This is useful when you want to limit which tools are available to your application or LLM.
87146

88147
## License
89148

0 commit comments

Comments
 (0)