> For the complete documentation index, see [llms.txt](https://docs.allmcp.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.allmcp.co/documentation/agent-frameworks/langgraph.md).

# LangGraph

Use AllMCP tools inside LangGraph workflows — stateful, multi-step agent graphs.

<a href="/pages/uBaUeZYQpupBMd5c1BY0" class="button secondary" data-icon="arrows-split-up-and-left">All frameworks</a> <a href="/pages/QJVxDLqxIz5KMCH5afbE" class="button secondary" data-icon="table-cells">Browse providers</a>

***

## Install

{% code title="install" %}

```bash
pip install langchain-mcp-adapters langchain-anthropic langgraph
```

{% endcode %}

***

## Minimal example (ReAct agent)

{% code title="agent.py" overflow="wrap" %}

```python
import asyncio
from langchain_mcp_adapters.client import MultiServerMCPClient
from langchain_anthropic import ChatAnthropic
from langgraph.prebuilt import create_react_agent

async def main():
    client = MultiServerMCPClient({
        "allmcp": {
            "url": "https://go.allmcp.co/mcp/",
            "transport": "streamable_http",
            "headers": {"X-API-Key": "YOUR_API_KEY"},
        }
    })
    tools = await client.get_tools()

    agent = create_react_agent(
        ChatAnthropic(model="claude-sonnet-4-6"),
        tools,
    )

    result = await agent.ainvoke({
        "messages": [{"role": "user", "content": "List my top 5 deals in Bitrix24"}]
    })
    print(result["messages"][-1].content)

asyncio.run(main())
```

{% endcode %}

{% hint style="info" %}
**LangGraph connects through the adapter.** `MultiServerMCPClient` from `langchain-mcp-adapters` loads every AllMCP tool over `streamable_http`, so any provider you've connected becomes a tool the agent can call.
{% endhint %}

***

## Custom graph with AllMCP tools

Build a graph that uses AllMCP tools as one node in a larger workflow:

{% code title="crm\_graph.py" overflow="wrap" %}

```python
import asyncio
from typing import TypedDict, Annotated
from langchain_mcp_adapters.client import MultiServerMCPClient
from langchain_anthropic import ChatAnthropic
from langchain_core.messages import HumanMessage, BaseMessage
from langgraph.graph import StateGraph, END
from langgraph.prebuilt import ToolNode
import operator


class AgentState(TypedDict):
    messages: Annotated[list[BaseMessage], operator.add]


async def build_crm_graph():
    client = MultiServerMCPClient({
        "allmcp": {
            "url": "https://go.allmcp.co/mcp/",
            "transport": "streamable_http",
            "headers": {"X-API-Key": "YOUR_API_KEY"},
        }
    })
    tools = await client.get_tools()
    model = ChatAnthropic(model="claude-sonnet-4-6").bind_tools(tools)

    def call_model(state: AgentState):
        response = model.invoke(state["messages"])
        return {"messages": [response]}

    def should_continue(state: AgentState):
        last = state["messages"][-1]
        if hasattr(last, "tool_calls") and last.tool_calls:
            return "tools"
        return END

    graph = StateGraph(AgentState)
    graph.add_node("agent", call_model)
    graph.add_node("tools", ToolNode(tools))
    graph.set_entry_point("agent")
    graph.add_conditional_edges("agent", should_continue)
    graph.add_edge("tools", "agent")

    app = graph.compile()

    result = await app.ainvoke({
        "messages": [HumanMessage(content="Summarize my open Bitrix24 deals")]
    })
    return result["messages"][-1].content
```

{% endcode %}

***

## Persistent state across sessions

{% code title="persistent\_state.py" overflow="wrap" %}

```python
from langgraph.checkpoint.memory import MemorySaver

app = graph.compile(checkpointer=MemorySaver())

config = {"configurable": {"thread_id": "user-123-session"}}
await app.ainvoke({"messages": [HumanMessage(content="Connect Bitrix24")]}, config)
await app.ainvoke({"messages": [HumanMessage(content="List my contacts")]}, config)
```

{% endcode %}

{% hint style="success" %}
**Checkpointers keep conversation state.** A `MemorySaver` plus a `thread_id` lets the graph resume the same session across invocations, so a "Connect Bitrix24" turn and a later "List my contacts" turn share context.
{% endhint %}

***

## Multi-user setup

{% code title="multi\_user.py" overflow="wrap" %}

```python
def make_client_config(user_id: str) -> dict:
    return {
        "allmcp": {
            "url": f"https://go.allmcp.co/mcp/?user_id={user_id}",
            "transport": "streamable_http",
            "headers": {"X-API-Key": "YOUR_API_KEY"},
        }
    }
```

{% endcode %}

{% hint style="info" %}
**One key, many users.** Append `?user_id={user_id}` to the endpoint to scope each request to a specific user's connected credentials while reusing the same `X-API-Key`.
{% endhint %}

***

## See also

{% content-ref url="/pages/uBaUeZYQpupBMd5c1BY0" %}
[Overview](/documentation/agent-frameworks/frameworks.md)
{% endcontent-ref %}

{% content-ref url="/pages/QJVxDLqxIz5KMCH5afbE" %}
[All Providers](/documentation/providers/providers.md)
{% endcontent-ref %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.allmcp.co/documentation/agent-frameworks/langgraph.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
