> ## 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.

# OpenAI Agents SDK

> Give an OpenAI Agents SDK agent a Qubrics mailbox through an MCP server.

Use this page to attach Qubrics to an [OpenAI Agents SDK](https://openai.github.io/openai-agents-python/) agent. Servers passed to `mcp_servers` expose their tools to the agent automatically, so you do not write tool wrappers.

> [!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.
* `openai-agents` installed.
* 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 openai-agents
pip install --upgrade sendmux-mcp
```

## Connect over local stdio

The SDK manages the subprocess for you and passes your key through its environment.

```python triage.py theme={null}
import asyncio
import os

from agents import Agent, Runner
from agents.mcp import MCPServerStdio


async def main() -> None:
    async with MCPServerStdio(
        name="Qubrics mailbox",
        params={
            "command": "sendmux-mcp-mailbox",
            "env": {"QUBRICS_API_KEY": os.environ["QUBRICS_MAILBOX_API_KEY"]},
        },
        cache_tools_list=True,
    ) as server:
        agent = Agent(
            name="Inbox agent",
            instructions=(
                "You triage the mailbox you have been granted. "
                "Search before you read, and quote the message you acted on."
            ),
            mcp_servers=[server],
        )

        result = await Runner.run(agent, "What arrived overnight that needs a reply?")
        print(result.final_output)


asyncio.run(main())
```

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

```python theme={null}
params={
    "command": "sendmux-mcp",
    "env": {
        "QUBRICS_MCP_SURFACES": "mailbox,sending",
        "QUBRICS_MAILBOX_API_KEY": os.environ["QUBRICS_MAILBOX_API_KEY"],
        "QUBRICS_SENDING_API_KEY": os.environ["QUBRICS_SENDING_API_KEY"],
    },
}
```

## Connect over private HTTP

Use this when the agent 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 server:

```python theme={null}
import os

from agents.mcp import MCPServerStreamableHttp

server = MCPServerStreamableHttp(
    name="Qubrics mailbox",
    params={
        "url": "http://127.0.0.1:8765/mcp",
        "headers": {"Authorization": f"Bearer {os.environ['QUBRICS_MCP_HTTP_BEARER_TOKEN']}"},
        "timeout": 10,
    },
    cache_tools_list=True,
    max_retry_attempts=3,
)
```

## Require approval before an agent sends

The SDK can hold a tool for approval before it runs. Pair this with the Qubrics sending gate when a human should see the message first.

```python theme={null}
server = MCPServerStdio(
    name="Qubrics",
    params={"command": "sendmux-mcp-mailbox", "env": {"QUBRICS_API_KEY": mailbox_key}},
    tool_filter=["qubrics_mailbox_list_messages", "qubrics_mailbox_search_message_snippets", "qubrics_mailbox_get_message"],
    require_approval="never",
)
```

> [!NOTE]
>
> `tool_filter` narrows what the model can see at all. Use it to build a
> read-only triage agent, then add the sending tools only to the agent that is
> meant to reply.

## Give each user their own mailbox

Mailbox-scoped keys are the isolation boundary. Open a server per tenant so the agent working one tenant structurally cannot read another tenant's mail.

```python theme={null}
def server_for(mailbox_key: str) -> MCPServerStdio:
    return MCPServerStdio(
        name="Qubrics mailbox",
        params={
            "command": "sendmux-mcp-mailbox",
            "env": {"QUBRICS_API_KEY": mailbox_key},
        },
        cache_tools_list=True,
    )
```

## 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] The agent sees no tools
>
> Confirm the surfaces the server started with. `sendmux-mcp` requires
> `QUBRICS_MCP_SURFACES`; the single-surface entry points do not. Check
> `tool_filter` as well, since it hides everything it does not name.

> [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 calls time out
>
> Raise `client_session_timeout_seconds`, and set `max_retry_attempts` so
> transient list and call failures retry with backoff.

> [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] [Agent access](https://sendmux.ai/docs/ai-integrations/agent-access.md)
>
> Register an agent and complete owner approval.

> [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.