Integration with hosted MCP (Model Context Protocol) servers using OpenAI agents in Temporal workflows.
Adapted from OpenAI Agents SDK hosted_mcp examples
Before running these examples, be sure to review the prerequisites and background on the integration.
First, start the worker (supports all MCP workflows):
uv run openai_agents/hosted_mcp/run_worker.pyThen run individual examples in separate terminals:
Connect to a hosted MCP server without approval requirements (trusted servers):
uv run openai_agents/hosted_mcp/run_simple_mcp_workflow.pyConnect to a hosted MCP server with approval workflow for tool execution:
uv run openai_agents/hosted_mcp/run_approval_mcp_workflow.pyBoth examples default to using the GitMCP server (https://gitmcp.io/openai/codex) which provides repository analysis capabilities. The workflows can be easily modified to use different MCP servers by changing the server_url parameter.
The approval example demonstrates the callback structure for tool approvals in a Temporal context. In this implementation:
- The approval callback automatically approves requests for demonstration purposes
- In production environments, approvals would typically be handled by communicating with a human user. Because the approval executes in the Temporal workflow, you can use signals or updates to communicate approval status.