python - server-1 | @asynccontextmanager server-1 | NameError: name 'asynccontextmanager' is not defined - Stack

I am trying to use MCP adapters for Langgraphbut I am running into an error:server-1 | Traceback (mo

I am trying to use MCP adapters for Langgraph but I am running into an error:

server-1 | Traceback (most recent call last):
server-1 | File "/app/server.py", line 43, in <module>
server-1 | @asynccontextmanager
server-1 | NameError: name 'asynccontextmanager' is not defined
server-1 exited with code 1 

when I place the following reference code for using the mcp adapters

# graph.py
from contextlib import asynccontextmanager
from langchain_mcp_adapters.client import MultiServerMCPClient
from langgraph.prebuilt import create_react_agent
from langchain_anthropic import ChatAnthropic

model = ChatAnthropic(model="claude-3-5-sonnet-latest")

@asynccontextmanager
async def make_graph():
  async with MultiServerMCPClient(
    {
        "math": {
            "command": "python",
            # Make sure to update to the full absolute path to your math_server.py file
            "args": ["/path/to/math_server.py"],
            "transport": "stdio",
        },
        "weather": {
            # make sure you start your weather server on port 8000
            "url": "http://localhost:8000/sse",
            "transport": "sse",
        }
    }
 ) as client:
    agent = create_react_agent(model, client.get_tools())
    yield agent. 

langchain-ai/langchain-mcp-adapters 

Does anyone know why I am getting this error:

NameError: name 'asynccontextmanager' is not defined

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744301301a4567515.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信