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
MCP Tools Not Working with create_react_agent? Here's the Fix
I spent hours debugging why my MCP tools weren't being called by create_react_agent, even though they showed up in the agent's tool list. Turns out there's a crucial step that's not obvious from the documentation.
The Problem
When you connect to an MCP server and load tools like this:
fromlangchain_mcp_adapters.clientimportMultiServerMCPClientfromlanggraph.prebuiltimportcreate_react_agent# Connect to MCP serverclient=MultiServerMCPClient({
"mcp_server": {
"url": "http://127.0.0.1:8001/mcp",
"transport": "streamable_http"
}
})
# Get tools and create agentmcp_tools=awaitclient.get_tools()
agent=create_react_agent(
model=llm,
tools=mcp_tools,
)
The agent can see the tools but never actually calls them. The reasoning traces show the LLM thinking about using tools, but no tool calls happen.
The Solution
You need to explicitly bind the tools to your LLM before passing it to create_react_agent:
asyncdefget_response(self, question: str):
client=MultiServerMCPClient({
"mcp_server": {
"url": "http://127.0.0.1:8001/mcp",
"transport": "streamable_http"
}
})
try:
# Get MCP toolsmcp_tools=awaitclient.get_tools()
# THIS IS THE KEY STEP - bind tools to LLMllm_with_tools=self.llm.bind_tools(mcp_tools)
# Now create agent with bound LLM AND toolsagent=create_react_agent(
model=llm_with_tools, # Use the bound LLMtools=mcp_tools, # Still pass tools to agent
)
# Use agent normallyresult=awaitagent.ainvoke({"messages": [HumanMessage(content=question)]})
returnresult["messages"][-1].contentexceptExceptionase:
returnf"Error: {str(e)}"
Why This Happens
The create_react_agent function expects the LLM to already be tool-aware. When you pass MCP tools to the tools parameter, it makes them available to the agent's execution context, but the underlying LLM still needs to be explicitly told about these tools via bind_tools().
Complete Working Example
Here's a full working example with proper MCP tool integration:
fromlanggraph.prebuiltimportcreate_react_agentfromlangchain_mcp_adapters.clientimportMultiServerMCPClientfromlangchain.schemaimportHumanMessage, SystemMessageimportasyncioclassMCPAgent:
def__init__(self, llm):
self.llm=llmasyncdefget_response(self, question: str):
client=MultiServerMCPClient({
"math_server": {
"url": "http://127.0.0.1:8001/mcp",
"transport": "streamable_http"
}
})
# Get MCP toolsmcp_tools=awaitclient.get_tools()
print(f"Loaded {len(mcp_tools)} MCP tools: {[t.namefortinmcp_tools]}")
# Critical: bind tools to LLMllm_with_tools=self.llm.bind_tools(mcp_tools)
# Create agent with bound LLM and toolsagent=create_react_agent(
model=llm_with_tools,
tools=mcp_tools,
)
messages= [
SystemMessage(content="You are a helpful assistant. Use the available tools when needed."),
HumanMessage(content=question)
]
result=awaitagent.ainvoke({"messages": messages})
returnresult["messages"][-1].content# Usageasyncdefmain():
fromlangchain_openaiimportChatOpenAI# or your preferred LLMllm=ChatOpenAI(model="gpt-4")
agent=MCPAgent(llm)
response=awaitagent.get_response("What's 2+2?")
print(response)
if__name__=="__main__":
asyncio.run(main())
Key Takeaways
Always call llm.bind_tools(mcp_tools) before creating the agent
Pass both the bound LLM and the tools to create_react_agent
The tools parameter makes them available to the execution context
The bound LLM makes the model aware it can call these tools
This solved my tool execution issues completely. Hope it helps others avoid the same debugging session!
Tested with langchain-mcp-adapters and langgraph latest versions as of September 2025.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
MCP Tools Not Working with create_react_agent? Here's the Fix
I spent hours debugging why my MCP tools weren't being called by
create_react_agent
, even though they showed up in the agent's tool list. Turns out there's a crucial step that's not obvious from the documentation.The Problem
When you connect to an MCP server and load tools like this:
The agent can see the tools but never actually calls them. The reasoning traces show the LLM thinking about using tools, but no tool calls happen.
The Solution
You need to explicitly bind the tools to your LLM before passing it to
create_react_agent
:Why This Happens
The
create_react_agent
function expects the LLM to already be tool-aware. When you pass MCP tools to thetools
parameter, it makes them available to the agent's execution context, but the underlying LLM still needs to be explicitly told about these tools viabind_tools()
.Complete Working Example
Here's a full working example with proper MCP tool integration:
Key Takeaways
llm.bind_tools(mcp_tools)
before creating the agentcreate_react_agent
This solved my tool execution issues completely. Hope it helps others avoid the same debugging session!
Tested with
langchain-mcp-adapters
andlanggraph
latest versions as of September 2025.Beta Was this translation helpful? Give feedback.
All reactions