[GH-ISSUE #2016] [langchain]: I encountered an error when running the code according to the MCP documentation. #255

Closed
opened 2026-02-17 17:19:30 -05:00 by yindo · 0 comments
Owner

Originally created by @sunstarlixp on GitHub (Dec 24, 2025).
Original GitHub issue: https://github.com/langchain-ai/docs/issues/2016

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
`

Originally created by @sunstarlixp on GitHub (Dec 24, 2025). Original GitHub issue: https://github.com/langchain-ai/docs/issues/2016 ### 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 `
yindo added the langchainexternal labels 2026-02-17 17:19:30 -05:00
yindo closed this issue 2026-02-17 17:19:30 -05:00
yindo changed title from [langchain]: I encountered an error when running the code according to the MCP documentation. to [GH-ISSUE #2016] [langchain]: I encountered an error when running the code according to the MCP documentation. 2026-06-05 17:25:54 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/docs#255