Orchestrating AI Tools with LangGraph and MCP Server

This tutorial shows how to install LangGraph and MCP Server, define math and weather tool nodes, connect them via a MultiServerMCPClient, and build a ReAct agent that demonstrates tool‑calling workflows, including handling missing functions and HTTP‑based services.

Network Intelligence Research Center (NIRC)
Network Intelligence Research Center (NIRC)
Network Intelligence Research Center (NIRC)
Orchestrating AI Tools with LangGraph and MCP Server

Setup

pip install langchain-mcp-adapters
pip install langgraph "langchain[openai]"

MCP Server definitions

Two MCP servers are created according to the Model Context Protocol (MCP) specification.

StdIO‑based math server provides two tools: add(a, b) (returns the sum of two numbers) and multiply(a, b) (returns the product). The server runs as a subprocess of the LangGraph agent and communicates via a stdio pipe. The division tool divide(a, b) is intentionally omitted.

HTTP weather server provides a single tool get_weather(city) that returns the weather for the specified city. The server is exposed as a RESTful API and is invoked over HTTP.

Agent client

The client creates a MultiServerMCPClient() instance, which connects to both the math server (stdio) and the weather server (HTTP). Calling await client.get_tools() returns a list of the three discovered tool specifications. These tools are bound to a LangGraph ReAct agent via create_react_agent(), enabling the agent to invoke the tools during reasoning.

Interaction examples

Math expression : Query "(3 + 5) x 12" . The agent first calls add(3, 5) → 8, then calls multiply(8, 12) → 96. The final answer is 96.

Division request : Query "what's the result divided by 6?" . Because the divide tool is missing, the agent mistakenly reuses the add tool with arguments 96 and -90, producing 6. The author notes that adding a divide tool would correct this behavior.

Weather query : Query "what is the weather in Beijing?" . The agent invokes the HTTP get_weather("Beijing") tool, receives the weather data, and stores the full dialogue context.

LangGraph core concepts

Node : A Python function that receives the current dialogue state and returns an updated state. Nodes encapsulate single responsibilities such as prompting the LLM, invoking a tool, or performing logical checks.

Edge : Connects nodes and defines execution order. Edges support conditional branching, loops, and termination, allowing the graph to model complex agent workflows.

References

GitHub repository: https://github.com/langchain-ai/langchain-mcp-adapters

Test article: https://zhuanlan.zhihu.com/p/1893223123081482311

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PythonLangChainLangGraphMCP ServerReAct agentAI tool orchestration
Network Intelligence Research Center (NIRC)
Written by

Network Intelligence Research Center (NIRC)

NIRC is based on the National Key Laboratory of Network and Switching Technology at Beijing University of Posts and Telecommunications. It has built a technology matrix across four AI domains—intelligent cloud networking, natural language processing, computer vision, and machine learning systems—dedicated to solving real‑world problems, creating top‑tier systems, publishing high‑impact papers, and contributing significantly to the rapid advancement of China's network technology.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.