Connect MCP to the OpenAI Agents SDK
The OpenAI Agents SDK supports multiple MCP integration styles. Use hosted MCP when the Responses API should call a publicly reachable server on your behalf; use Streamable HTTP when your application manages the connection; use stdio for a local subprocess.
Streamable HTTP example
from agents import Agent, Runner
from agents.mcp import MCPServerStreamableHttp
async with MCPServerStreamableHttp(
name="Internal MCP",
params={"url":"https://mcp.example.com/mcp"},
cache_tools_list=True,
) as server:
agent = Agent(
name="Assistant",
instructions="Use approved tools when needed.",
mcp_servers=[server],
)
result = await Runner.run(agent, "Find order A-100")Choose the integration boundary deliberately
Hosted MCP reduces local round-trip orchestration. Locally managed MCP gives your code direct control over headers, filtering, metadata, and connection lifecycle.