> ## Documentation Index
> Fetch the complete documentation index at: https://sendmux.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# LangGraph

> Load Qubrics mailbox and sending tools into a LangGraph agent through the LangChain MCP adapters.

Use this page to load Qubrics tools into a [LangGraph](https://langchain-ai.github.io/langgraph/) agent. The [LangChain MCP adapters](https://github.com/langchain-ai/langchain-mcp-adapters) convert MCP tools into LangChain tools, so anything that accepts a tool list will accept them.

> [!WARNING]
>
> Replace placeholder keys and tokens before running any snippet. Do not commit
> `smx_root_`, `smx_mbx_`, or private HTTP bearer tokens to version control.

## Requirements

* Python 3.10 or newer.
* A Qubrics key for the surface you are calling. Mailbox work needs an `smx_mbx_` key or a scoped `smx_agent_` token.

## Install

> [!WARNING]
>
> Before upgrading an existing installation, keep its working package environment,
> dependency state, and MCP client and tool configuration. Version 2.0.0 removes
> local `file_path` and roots inputs from MCP attachment tools. Before switching
> existing agents, follow the [upgrade and rollback guidance](https://github.com/qubrics/qubrics-sdk/blob/main/packages/python/mcp/README.md#200-upgrade).

```bash theme={null}
pip install langchain-mcp-adapters langgraph
pip install --upgrade sendmux-mcp
```

## Connect over local stdio

The adapter launches the server and passes your key through the subprocess environment. Values written as `${VAR}` are expanded from the current environment, so the key never appears in source.

```python client.py theme={null}
from langchain_mcp_adapters.client import MultiServerMCPClient

client = MultiServerMCPClient(
    {
        "sendmux": {
            "transport": "stdio",
            "command": "sendmux-mcp-mailbox",
            "args": [],
            "env": {"QUBRICS_API_KEY": "${QUBRICS_MAILBOX_API_KEY}"},
        }
    }
)
```

Run more than one surface by switching to the `sendmux-mcp` entry point and naming the surfaces:

```python theme={null}
"sendmux": {
    "transport": "stdio",
    "command": "sendmux-mcp",
    "args": [],
    "env": {
        "QUBRICS_MCP_SURFACES": "mailbox,sending",
        "QUBRICS_MAILBOX_API_KEY": "${QUBRICS_MAILBOX_API_KEY}",
        "QUBRICS_SENDING_API_KEY": "${QUBRICS_SENDING_API_KEY}",
    },
}
```

## Connect over private HTTP

Use this when your graph runs somewhere it cannot spawn a process. Start the server yourself:

```bash theme={null}
QUBRICS_API_KEY=smx_mbx_... \
QUBRICS_MCP_HTTP_BEARER_TOKEN=local-mcp-token \
sendmux-mcp-mailbox --transport http --host 127.0.0.1 --port 8765
```

Then connect with the streamable HTTP transport and send the bearer token:

```python client.py theme={null}
from langchain_mcp_adapters.client import MultiServerMCPClient

client = MultiServerMCPClient(
    {
        "sendmux": {
            "transport": "streamable_http",
            "url": "http://127.0.0.1:8765/mcp",
            "headers": {"Authorization": "Bearer local-mcp-token"},
        }
    }
)
```

## Build the agent

`get_tools()` returns LangChain tools you can hand to a prebuilt agent or bind to a model inside your own graph.

```python agent.py theme={null}
import asyncio

from langchain.agents import create_agent

from client import client


async def main() -> None:
    tools = await client.get_tools()

    agent = create_agent(
        "openai:gpt-4.1",
        tools,
        prompt=(
            "You triage the mailbox you have been granted. "
            "Search before you read, and quote the message you acted on."
        ),
    )

    result = await agent.ainvoke(
        {"messages": "What arrived overnight that needs a reply?"}
    )
    print(result["messages"][-1].content)


asyncio.run(main())
```

> [!NOTE]
>
> Set `tool_name_prefix=True` on `MultiServerMCPClient` when you connect Qubrics
> alongside other MCP servers. It prefixes tool names with the server name and
> prevents collisions.

## Give each user their own mailbox

Mailbox-scoped keys are the isolation boundary. Build a client per tenant rather than sharing one across the graph, so the agent working one tenant structurally cannot read another tenant's mail.

```python theme={null}
def client_for(mailbox_key: str) -> MultiServerMCPClient:
    return MultiServerMCPClient(
        {
            "sendmux": {
                "transport": "stdio",
                "command": "sendmux-mcp-mailbox",
                "args": [],
                "env": {"QUBRICS_API_KEY": mailbox_key},
            }
        }
    )
```

## Sending stays gated

A durable `smx_agent_` token includes `mailbox.read` and `email.receive`, not `email.send`. After a named human owner accepts the invite and approves sending, exchange the durable token for a one-hour Sending-resource token and pass that as `QUBRICS_SENDING_API_KEY`.

## Troubleshooting

> [accordion] get\_tools returns an empty list
>
> Confirm the surfaces the server started with. `sendmux-mcp` requires
> `QUBRICS_MCP_SURFACES`; the single-surface entry points do not.

> [accordion] The subprocess exits immediately
>
> Check the key prefix. Mailbox accepts `smx_mbx_` or a scoped `smx_agent_`,
> Sending accepts a send-capable `smx_mbx_` or an owner-approved
> Sending-resource `smx_agent_`, and Management requires `smx_root_`.

> [accordion] Tool errors stop the graph
>
> Set `handle_tool_errors=True` on `MultiServerMCPClient` to return errors as
> tool messages the model can react to instead of raising.

> [accordion] You granted more than one mailbox
>
> Start the workflow with `qubrics_mailbox_list_granted_mailboxes` and pass the
> returned `mailbox_id` to tools that act on one mailbox.

## Next steps

> [card] [Agent frameworks](https://sendmux.ai/docs/ai-integrations/frameworks)
>
> Compare connections across frameworks.

> [card] [MCP](https://sendmux.ai/docs/ai-integrations/mcp)
>
> Review environment variables and tool discovery.

> [card] [Mailbox API guides](https://sendmux.ai/docs/developer-tools/mailbox-api/search-and-batch.md)
>
> Use search and batch operations efficiently.

> [card] [Python SDK](https://sendmux.ai/docs/developer-tools/sdks/python.md)
>
> Call Qubrics directly when you want full endpoint coverage.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.