---
title: How to use MCP servers with the OpenAI Agents SDK
description: Open MCPServerStreamableHttp with a URL and auth headers and pass it in mcp_servers, or use HostedMCPTool for public servers. Filters, approvals and timeouts.
canonical: https://mcp1.com/blog/mcp-servers-openai-agents-sdk
last-updated: 2026-12-03
---

# How to use MCP servers with the OpenAI Agents SDK

Open MCPServerStreamableHttp with a URL and auth headers and pass it in mcp\_servers, or use HostedMCPTool for public servers. Filters, approvals and timeouts.

![](https://avatars.githubusercontent.com/u/1297371?s=96&v=4)Eldad FuxFounder and CEO, Appwrite

 agent.py

async with MCPServerStreamableHttp(
  name="linear", params={url, headers}
) as linear:
  agent = Agent(mcp_servers=[linear])

linearconnected

 agent.py

async with MCPServerStreamableHttp(
  name="linear", params={url, headers}
) as linear:
  agent = Agent(mcp_servers=[linear])

linearconnected

To use a remote MCP server with the OpenAI Agents SDK, open an `MCPServerStreamableHttp` with the server’s URL and auth headers, and pass it to the agent in `mcp_servers`. If the server is public and you’d rather OpenAI make the calls, add it as a `HostedMCPTool` in `tools` instead. Either way, the SDK doesn’t run OAuth for you, so send a token.

## How do I connect a remote MCP server to an OpenAI agent?

Open the server as an async context manager, which connects it and closes it when the block ends, and hand it to the agent. This one reads Linear through its read-only endpoint with a Linear API key:

agent.py

```
import asyncio, os
from agents import Agent, Runner
from agents.mcp import MCPServerStreamableHttp

async def main():
    async with MCPServerStreamableHttp(
        name="linear",
        params={
            "url": "https://mcp.linear.app/mcp/readonly",
            "headers": {"Authorization": f"Bearer {os.environ['LINEAR_API_KEY']}"},
            "timeout": 10,
        },
        cache_tools_list=True,
        max_retry_attempts=3,
    ) as linear:
        agent = Agent(
            name="Triage",
            instructions="Answer questions about the team's Linear issues.",
            mcp_servers=[linear],
        )
        result = await Runner.run(agent, "Summarize the open issues in Checkout by priority")
        print(result.final_output)

asyncio.run(main())
```

The SDK lists the server’s tools at the start of each run. `cache_tools_list=True` skips that call after the first time, which is safe when the server’s tools rarely change; call `invalidate_tools_cache()` when they do. The TypeScript SDK has the same class, `MCPServerStreamableHttp` from `@openai/agents`, passed in `mcpServers`.

## Should I use HostedMCPTool or MCPServerStreamableHttp?

Use the hosted tool for public servers when you want the fewest moving parts, and `MCPServerStreamableHttp` when the server is private or you need control over each call. The hosted tool hands the whole round trip to OpenAI’s Responses API:

agent.py

```
from agents import Agent, HostedMCPTool

agent = Agent(
    name="Docs helper",
    tools=[
        HostedMCPTool(
            tool_config={
                "type": "mcp",
                "server_label": "openai_docs",
                "server_url": "https://developers.openai.com/mcp",
                "require_approval": "never",
            }
        )
    ],
)
```

HostedMCPTool vs MCPServerStreamableHttp

Who calls the server

OpenAI’s Responses API, vs your process.

Reachable servers

Publicly reachable URLs only, vs anything your process can reach, including a private network or localhost.

Models

Responses API models, vs any model the SDK runs.

Approvals

The `require_approval` key, with an optional `on_approval_request` callback, vs `require_approval` on the server.

Tool filters and guardrails

Not applied on your side, vs tool\_filter and the SDK’s tool guardrails.

The rest of this post is about `MCPServerStreamableHttp`. Skip `MCPServerSse` for new work: the MCP project has deprecated the SSE transport.

## How do I limit which MCP tools the agent can use?

Pass a `tool_filter`, and the agent never sees the tools left out. Set `require_approval` on top for the tools that should pause the run until your code approves the call:

agent.py

```
from agents.mcp import MCPServerStreamableHttp, create_static_tool_filter

github = MCPServerStreamableHttp(
    name="github",
    params={"url": "https://api.githubcopilot.com/mcp/", "headers": {...}},
    tool_filter=create_static_tool_filter(
        allowed_tool_names=["get_file_contents", "search_code", "list_pull_requests"],
    ),
    require_approval={"always": {"tool_names": ["create_pull_request"]}},
)
```

`create_static_tool_filter` also takes `blocked_tool_names`, and `tool_filter` accepts a function of the run context and tool for filters that depend on the agent or user. Prefer an allow list for servers that can write. A block list or an approval map matches exact names, so a tool the server adds next month runs without either. See [how to stop agents from running destructive MCP tools](https://mcp1.com/blog/stop-destructive-mcp-tools) for which tools to hold back.

The token is the real limit

A filter decides what the model is offered. What the server will do is set by the credential, so give agents read-only tokens or endpoints where they exist, like Linear’s `/mcp/readonly` above. More in [how to make an MCP server read-only](https://mcp1.com/blog/read-only-mcp-server).

## Why do my MCP tool calls time out?

Because the MCP client session times out after 5 seconds by default, and a search across a large workspace can take longer. Raise `client_session_timeout_seconds` on the server, or set it to `None` to turn it off. `params["timeout"]` is the HTTP request timeout, a separate setting. For flaky servers, `max_retry_attempts` retries listing and calling tools with backoff.

## What changes with several MCP servers?

- Connecting. `MCPServerManager` opens a list of servers in one `async with`, and you pass `manager.active_servers` to the agent. By default it drops servers that fail to connect, so the run goes ahead with fewer tools. Check `failed_servers` and fail loudly in production.
- Names. Two servers can both have a `search` tool. Set `mcp_config={"include_server_in_tool_names": True}` on the agent to put the server name in each tool name. More in [MCP tool name collisions](https://mcp1.com/blog/mcp-tool-name-collisions).
- Context. Every tool definition is sent with each model call. Filter hard, or see [too many MCP tools](https://mcp1.com/blog/too-many-mcp-tools).
- Secrets. Each server needs its own token in your environment, its own scoping and its own revocation.

## One URL and one key for every server

MCP1 puts your servers behind one gateway, so the agent holds one MCP1 API key, scoped to that gateway and optionally to some of its servers, with an expiry:

agent.py

```
MCPServerStreamableHttp(
    name="mcp1",
    params={
        "url": "https://mcp1.com/mcp/<workspace>/<gateway>",
        "headers": {"Authorization": f"Bearer {os.environ['MCP1_API_KEY']}"},
    },
    client_session_timeout_seconds=30,
)
```

A small gateway lists its servers’ tools directly, as `linear__list_issues` and so on, already namespaced. A larger one lists MCP1’s own tools, and the agent finds the rest with `mcp1__search_tools` and runs them with `mcp1__call_tool`, which keeps tool definitions small however many servers sit behind it. The key acts as the person who made it, so their groups, read-only grants and tool rules apply, and every call is recorded in the audit log. Revoking the key stops the agent at once. For the same setup in Anthropic’s SDK, see [MCP servers with the Claude Agent SDK](https://mcp1.com/blog/mcp-servers-claude-agent-sdk). The [docs](https://mcp1.com/docs#keys) cover keys, and the Individual plan is free to [start with](https://mcp1.com/signup).

## Common questions

### Does the OpenAI Agents SDK support MCP OAuth?

It doesn’t run a browser sign-in for you. Pass a token in the server’s headers, or an httpx auth object in params\["auth"\] if you manage the OAuth flow in your app.

### Can HostedMCPTool reach a server on localhost?

No. OpenAI’s Responses API makes the calls, so the server must be publicly reachable. Use MCPServerStreamableHttp for private or local servers.

### Can I use stdio MCP servers with the Agents SDK?

Yes, with MCPServerStdio and a command and args. The SDK starts the process and closes it when the async with block ends.

### Does the TypeScript Agents SDK support MCP?

Yes. @openai/agents exports MCPServerStreamableHttp and hostedMcpTool, with the same split between servers your code calls and servers OpenAI calls.

Give your team one URL

Create a workspace, install your servers and share a gateway with a group. Free for individuals.

[Start with MCP1](https://mcp1.com/signup)[Read the docs](https://mcp1.com/docs)

## More from the blog

[ \~/.codex/config.toml[mcp_servers.notion] url = "https://mcp.notion.com/mcp"codex mcp login notionSigned inHow to connect Notion MCP to CodexRun codex mcp add notion --url https://mcp.notion.com/mcp, then codex mcp login notion. Approvals, a token for CI, team config and fixes.![](https://avatars.githubusercontent.com/u/1297371?s=96&v=4)Eldad FuxFounder and CEO, Appwrite](https://mcp1.com/blog/notion-mcp-codex)[ Where PHI goes in one tool callMCP serverBAA, endpoint in scopeModel providerBAA, product namedGatewayBAA, audit logLogsEncrypted, retention setMCP and HIPAA: what to check before agents touch PHIEvery party that handles PHI in an MCP tool call needs a BAA, and model providers’ BAAs don’t cover MCP servers. What to check, limit and log.![](https://avatars.githubusercontent.com/u/1297371?s=96&v=4)Eldad FuxFounder and CEO, Appwrite](https://mcp1.com/blog/mcp-hipaa)

---

This is the markdown copy of https://mcp1.com/blog/mcp-servers-openai-agents-sdk. Site index for agents: https://mcp1.com/llms.txt
