Connect a Remote MCP Server to an OpenAI Agent
from agents.mcp import MCPServerStreamableHttp
server = MCPServerStreamableHttp(
name="Production MCP",
params={
"url":"https://mcp.example.com/mcp",
"headers":{"Authorization":"Bearer ..."},
"timeout":10,
},
cache_tools_list=True,
max_retry_attempts=2,
)Use HTTPS and scoped credentials
Do not put access tokens in URLs. Use authorization headers and least-privilege server permissions.
Bound retries
Listing tools can usually be retried safely. Mutation tool calls require more care; use idempotency and explicit semantics before enabling automatic retries.