-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
Type of issue
issue / bug
Language
Python
Description
I'm learning to use the MCP agent, and when I run the code from the demo in the user manual, I encounter an error:
python`
from langchain_mcp_adapters.client import MultiServerMCPClient
from langchain.agents import create_agent
client = MultiServerMCPClient(
{
"math": {
"transport": "stdio", # Local subprocess communication
"command": "python",
# Absolute path to your math_server.py file
"args": ["/path/to/math_server.py"],
},
"weather": {
"transport": "http", # HTTP-based remote server
# Ensure you start your weather server on port 8000
"url": "http://localhost:8000/mcp",
}
}
)
tools = await client.get_tools()
agent = create_agent(
"claude-sonnet-4-5-20250929",
tools
)
math_response = await agent.ainvoke(
{"messages": [{"role": "user", "content": "what's (3 + 5) x 12?"}]}
)
weather_response = await agent.ainvoke(
{"messages": [{"role": "user", "content": "what is the weather in nyc?"}]}
)
Error message during program execution:
tools = await client.get_tools()
^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: 'await' outside function
`