> 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/langchain.md).

# LangChain

Use AllMCP tools in LangChain agents via `langchain-mcp-adapters`.

***

## Install

{% code title="install" %}

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

{% endcode %}

***

## Minimal example

{% 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()
    model = ChatAnthropic(model="claude-sonnet-4-6")
    agent = create_react_agent(model, tools)

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

asyncio.run(main())
```

{% endcode %}

{% hint style="info" %}
**Auth header.** Pass your key as `X-API-Key: allmcp_xxx`. If your transport layer strips custom headers, use `Authorization: Bearer allmcp_xxx` instead — both are accepted.
{% endhint %}

***

## Multi-user setup

{% hint style="info" %}
**One agent, many users.** Append `?user_id=` to the endpoint URL so each request acts as that user and uses the providers they've connected.
{% endhint %}

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

```python
async def run_for_user(user_id: str, prompt: str) -> str:
    client = MultiServerMCPClient({
        "allmcp": {
            "url": f"https://go.allmcp.co/mcp/?user_id={user_id}",
            "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": prompt}]})
    return result["messages"][-1].content
```

{% endcode %}

***

## With memory

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

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

client = MultiServerMCPClient({...})
tools = await client.get_tools()
agent = create_react_agent(
    ChatAnthropic(model="claude-sonnet-4-6"),
    tools,
    checkpointer=MemorySaver(),
)

config = {"configurable": {"thread_id": "session-1"}}

# Turn 1
await agent.ainvoke({"messages": [{"role": "user", "content": "Connect Bitrix24"}]}, config)
# Turn 2 — agent remembers the previous turn
result = await agent.ainvoke({"messages": [{"role": "user", "content": "Now list my deals"}]}, config)
```

{% endcode %}

***

## Using OpenAI instead of Anthropic

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

```python
from langchain_openai import ChatOpenAI

model = ChatOpenAI(model="gpt-4o")
agent = create_react_agent(model, tools)
```

{% endcode %}

{% hint style="success" %}
**Any LLM works.** AllMCP tools work with any LangChain-compatible LLM.
{% 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/langchain.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.
