How an agent uses tools and MCP

Recorded runs of a LangChain agent with two local Python tools and two MCP servers. Pick a question and step through it: each LLM call, each tool call, and the messages the agent keeps in its state.

Flow

tool calls results 🙋 Question 🧠 Model model node · LLM call ✅ Answer 🔧 Tools tools node · runs calls Local Python tools MCP · weather MCP · handbook
LLM call Local tool, same process MCP tool, separate process over stdio

Agent state: messages

Steps

How this maps to LangChain
  • create_agent() builds a LangGraph graph with two nodes. The model node sends the messages so far, plus a schema for every tool, to the LLM.
  • If the LLM replies with tool calls, the graph goes to the tools node. It runs every call, adds each result as a ToolMessage, and goes back to the model. When the LLM replies without tool calls, the graph ends.
  • The LLM never runs a tool itself. It only asks for one by name, with arguments. Your code runs it and sends the result back.
  • MCP tools come from MultiServerMCPClient.get_tools(), which asks each MCP server for its tools and wraps them as ordinary LangChain tools. The LLM can't tell them apart from local ones. The difference is where they run: calling one sends a JSON-RPC tools/call request to another process.
  • Each LLM call resends the whole message list, so the context grows with every tool round trip. You can watch that in the state panel.
About this page