How to add MCP tools to Langgraph Graph Definition #4846
Unanswered
magallardo
asked this question in
Q&A
Replies: 1 comment 1 reply
-
I too need help on this - where I'm having trouble is injecting tools into the agent (since the I am not sure if including it inside an |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am defining a Graph and I am trying to add a node with tools coming from an MCP Server. Is there any example of how to do this?
I have tried several things but the issue is that the MultiServerMCPClient getTools is async.
I have tried the following as indicated in the docs but it does not work because the getTools is async and it is expected to be called within an async function.
Any recommendation on how to modify the graph below to include MCP tools?
==========================
from pydantic import BaseModel
from langgraph.graph import StateGraph
from langgraph.prebuilt import ToolNode
def something():
pass
client = MultiServerMCPClient(
{
"math": {
"command": "python",
# Replace with absolute path to your math_server.py file
"args": ["/path/to/math_server.py"],
"transport": "stdio",
},
"weather": {
# Ensure your start your weather server on port 8000
"url": "http://localhost:8000/mcp",
"transport": "streamable_http",
}
}
)
tools = await client.get_tools()
workflow = StateGraph(BaseModel)
workflow.add_node("node_1", something)
workflow.add_node("node_2", something)
workflow.add_node("tools", ToolNode(tools))
...
...
graph = workflow.compile()
graph.name = "My Agent"
==============
Thanks in advance,
Marcelo
Beta Was this translation helpful? Give feedback.
All reactions