Skip to content
Blog

Connecting MCP Tools to LangGraph Agents

Integrate Model Context Protocol (MCP) tool servers dynamically into stateful LangGraph agent workflows using langchain-mcp adapters.

Published on September 11, 2026

AI Assistant

LangGraph excels at orchestrating complex, stateful multi-agent workflows. The Model Context Protocol (MCP) provides a standardized way to expose tools and resources across external processes. Combining LangGraph’s graph-based state machines with MCP’s protocol-level tool interoperability allows developers to build modular, highly extensible AI agents.

In this guide, we walk through connecting external MCP servers directly into LangGraph state graphs.

Integration Architecture

Instead of hardcoding tool logic inside LangGraph node functions, the agent dynamically connects to an MCP server at runtime. The server advertises its schema via the MCP protocol, and LangGraph converts these definitions into executable LangChain tool objects.

[LangGraph Agent Node] <--> [langchain-mcp Client] <--(MCP Protocol)---> [External MCP Server]
                                                                                |-- Tool A
                                                                                |-- Tool B

Step-by-Step Implementation with langchain-mcp-adapters

1. Install Dependencies

pip install langgraph langchain-mcp-adapters langchain-google-genai

2. Loading MCP Tools into LangGraph

import asyncio
from langchain_mcp_adapters.tools import load_mcp_tools
from langchain_google_genai import ChatGoogleGenerativeAI
from langgraph.prebuilt import create_react_agent
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client

async def run_mcp_langgraph_agent():
    # Define parameters to start or connect to an MCP server process
    server_params = StdioServerParameters(
        command="python",
        args=["-m", "my_mcp_server"], # Local or remote MCP server script
        env=None
    )

    # Establish MCP Stdio client connection
    async with stdio_client(server_params) as (read, write):
        async with ClientSession(read, write) as session:
            await session.initialize()

            # Dynamically discover and convert MCP tools to LangChain compatible tools
            mcp_tools = await load_mcp_tools(session)

            # Initialize LLM model
            model = ChatGoogleGenerativeAI(model="gemini-1.5-pro", temperature=0)

            # Create standard prebuilt ReAct agent in LangGraph with converted MCP tools
            agent_executor = create_react_agent(model, mcp_tools)

            # Execute agent query
            query = "Search the database for active enterprise subscriptions."
            response = await agent_executor.ainvoke({"messages": [("user", query)]})

            for message in response["messages"]:
                print(f"[{message.type}]: {message.content}")

if __name__ == "__main__":
    asyncio.run(run_mcp_langgraph_agent())

Advantages of Using MCP with LangGraph

  • Decoupled Tool Deployment: MCP tools run in isolated processes or containerized environments, preventing tool dependencies from bloating agent runtimes.
  • Dynamic Tool Discovery: Agents automatically discover newly added or updated tools on the MCP server without requiring codebase redeployment.
  • Cross-Language Support: Your LangGraph agent (written in Python) can seamlessly invoke tools hosted on MCP servers written in TypeScript, Go, or Rust.

For advanced state graph persistence, checkpointing, and human-in-the-loop patterns, visit the official LangGraph Documentation.