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
Copy file name to clipboardExpand all lines: docs/user-guide/concepts/tools/mcp-tools.md
+28-11Lines changed: 28 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,11 @@ The [Model Context Protocol (MCP)](https://modelcontextprotocol.io) is an open p
4
4
5
5
MCP enables communication between agents and MCP servers that provide additional tools. Strands includes built-in support for connecting to MCP servers and using their tools.
6
6
7
+
When working with MCP tools in Strands, all agent operations must be performed within the MCP client's context manager (using a with statement).
8
+
This requirement ensures that the MCP session remains active and connected while the agent is using the tools.
9
+
If you attempt to use an agent or its MCP tools outside of this context, you'll encounter errors because the MCP session will have closed.
10
+
11
+
7
12
## MCP Server Connection Options
8
13
9
14
Strands provides several ways to connect to MCP servers:
AgentTools relying on an MCP connection must always be used within a context manager. When you create or use an agent outside a with statement, operations will fail because the MCP session is automatically closed once you exit the context manager block. The MCP connection must remain active throughout the agent's operations to maintain access to the tools and services it provides.
252
+
253
+
Correct usage:
254
+
```python
255
+
with mcp_client:
256
+
agent = Agent(tools=mcp_client.list_tools_sync())
257
+
response = agent("Your prompt") # Works
258
+
```
244
259
245
-
1.**Connection Failures**:
246
-
- Ensure the MCP server is running and accessible
247
-
- Check network connectivity and firewall settings
248
-
- Verify the URL or command is correct
260
+
Incorrect usage:
261
+
```python
262
+
with mcp_client:
263
+
agent = Agent(tools=mcp_client.list_tools_sync())
264
+
response = agent("Your prompt") # Will fail with MCPClientInitializationError
265
+
```
266
+
### **Connection Failures**
267
+
Connection failures occur when there are problems establishing a connection with the MCP server. To resolve these issues, first ensure that the MCP server is running and accessible from your network environment. You should also verify your network connectivity and check if any firewall settings are blocking the connection. Additionally, make sure that the URL or command you're using to connect to the server is correct and properly formatted.
249
268
250
-
2.**Tool Discovery Issues**:
251
-
- Ensure the MCP server properly implements the `list_tools` method
252
-
- Check that tools are correctly registered with the server
269
+
### **Tool Discovery Issues**
270
+
When encountering tool discovery problems, first confirm that the MCP server has properly implemented the list_tools method as this is essential for tool discovery to function. It's also important to verify that all tools have been correctly registered with the server.
253
271
254
-
3.**Tool Execution Errors**:
255
-
- Verify that tool arguments match the expected schema
256
-
- Check server logs for detailed error information
272
+
### **Tool Execution Errors**
273
+
Tool execution errors can arise during the actual operation of MCP tools. To resolve these errors, verify that all tool arguments being passed match the expected schema for that particular tool. When errors occur, consulting the server logs can provide detailed information about what went wrong during the execution process.
0 commit comments