You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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`
31
50
32
51
## Example 1: MCP Server with SSE Transport
33
52
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.
35
54
36
55
### Step 1: Run the MCP Server
37
56
38
57
First, run the server that exposes calculator functionality (addition and subtraction) via MCP:
39
58
40
59
```bash
41
-
python examples/mcp_sse_server.py
60
+
python examples/mcp_server.py --transport sse
42
61
```
43
62
44
63
This creates a FastMCP server with two tools:
@@ -47,31 +66,53 @@ This creates a FastMCP server with two tools:
47
66
48
67
The server runs on http://localhost:8000 by default.
49
68
50
-
### Step 2: Connect with the MCP Client
69
+
### Step 2: Connect with Individual Tools (MCPTool)
51
70
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:
53
72
54
73
```bash
55
-
python examples/mcp_sse_client.py
74
+
python examples/mcp_client.py --transport sse
56
75
```
57
76
58
77
The client creates MCPTool instances that connect to the server, inspect the tool specifications, and invoke the calculator functions remotely.
59
78
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
+
60
89
## Example 2: MCP with StdIO Transport
61
90
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)
63
94
64
95
```bash
65
96
python examples/mcp_stdio_client.py
66
97
```
67
98
68
99
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.
69
100
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.
71
110
72
-
## Example 3: MCPTool in a Haystack Pipeline
111
+
## Example 3: MCP Tools in Haystack Pipelines
73
112
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)
75
116
76
117
```bash
77
118
python examples/time_pipeline.py
@@ -83,7 +124,25 @@ This example creates a pipeline that:
83
124
3. Invokes the time tool with the appropriate parameters (using `uvx` behind the scenes)
84
125
4. Sends the tool's response back to the LLM to generate a final answer
85
126
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.
0 commit comments