Skip to content

openai_agents: add require_approval to stateless_mcp_server() and stateful_mcp_server() - #220

Merged
campoy merged 2 commits into
mainfrom
fix/openai-agents-python-mcp-require-approval-ignored
Oct 28, 2026
Merged

campoy merged 2 commits into
mainfrom
fix/openai-agents-python-mcp-require-approval-ignored

Conversation

@campoy

@campoy campoy commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

What was changed

stateless_mcp_server() and stateful_mcp_server() take a new require_approval option and pass it to the Workflow-side reference, so the agent pauses before the server's tools run, as it does natively and with temporal_mcp_server(require_approval=...).

  • The option takes the same values as MCPServerStdio(require_approval=...). A callable policy runs in the Workflow and must be deterministic; the docstrings say so.
  • The README's paragraph on the deprecated MCP APIs says to pass require_approval there, and that a policy on the factory's server is not used.

API change: one new keyword argument on each deprecated helper, defaulting to None. Existing code is unchanged. A require_approval set on the factory's server is still ignored, as with temporal_mcp_server(); callers move it to the new option.

Replay and rollback: a reference built without the option is the same as before (MCPServer.__init__(require_approval=None) is the default), so no gate is needed. Code that passes the new option cannot run on an earlier release, which lacks the argument; that is a code dependency, not a replay difference.

Why?

See #219. The agent reads the approval policy from the server it holds, which in a Workflow is the plugin's reference, and the deprecated helpers gave the reference no policy. The policy on the factory's server is never read, so an MCP tool meant to wait for approval runs at once with no error or warning. temporal_mcp_server() already covers this, but stateful_mcp_server() is still the only route with a persistent MCP session, and the deprecated helpers are the only ones that run with MCP Python SDK v1.

Checklist

  1. Closes [Bug] openai_agents: stateless_mcp_server() and stateful_mcp_server() can't require tool approval #219

  2. How was this tested:

    • The existing test_mcp_server in tests/test_openai.py gains stateful-approval and stateless-approval cases: the Workflow must return the interruption for Say-Hello and the server's call_tool must not run. The two test Workflows take the policy as a new argument, so test_mcp_server_factory_argument and test_stateful_mcp_server_no_worker pass None for it. On main all eight MCP Workflow tests fail with TypeError: ... got an unexpected keyword argument 'require_approval'; with the change all eight pass.
    • Locally, the full suite passes (384 tests: main's 382 and the two new cases), and ruff check --select I, ruff format --check, pyright, mypy, basedpyright and pydocstyle pass. These ran with uv 0.13.1, outside the plugin's required-version, so not through make. CI covers make lint and make test.
    • [Bug] openai_agents: stateless_mcp_server() and stateful_mcp_server() can't require tool approval #219's reproduction exits 1 on 1.1.0 and on main at c664a34. With the change it exits 0: both helpers pause before wire runs, like the native run and temporal_mcp_server().
    • Replay, with a Worker with no Workflow cache, on stateless and stateful runs (finished) and a stateless run waiting on a signal after its agent turn:
      • histories recorded on main replay on main and with the change (3 of 3 each);
      • histories recorded with the change but without the option replay on main (3 of 3); with the option (stateless and stateful) they replay with the change, and on main fail with the missing-argument TypeError, not a nondeterminism error;
      • the waiting run started on main finishes with the change, and the one started with the change finishes on main, with no failed Workflow Task;
      • a control that renames the MCP server, so its Activity names change, fails with [TMPRL1100] on all 8 histories.
  3. Any docs updates needed?
    The README's paragraph on the deprecated MCP APIs is updated here.

Not covered:

  • A require_approval or tool_meta_resolver set on the factory's server is still silently ignored, on these helpers and on temporal_mcp_server(). The plugin already rejects a callable tool_filter there. Rejecting these too would make the mistake visible, but it would fail runs that complete today, so it is left for a separate change.
  • A tool_meta_resolver already works when assigned to the returned reference's public attribute, so it gets no new option here.
  • temporalio 1.34.x still bundles the old helpers as temporalio.contrib.openai_agents. No backport here.

Open questions:

  • Is a new option on deprecated helpers acceptable, given that the stateful helper has no replacement with a persistent session?
  • Should a policy or resolver on the factory's server be rejected, like a callable tool_filter?

Draft while these questions are open.

…teful_mcp_server()

The deprecated MCP helpers had no way to require tool approval. The
agent reads the approval policy from the server it holds, which in a
workflow is the plugin's reference, and a policy set on the factory's
server is never read. temporal_mcp_server() already takes
require_approval; the stateful helper is still the only route with a
persistent MCP session, and the deprecated helpers are the only ones
that run with MCP Python SDK v1.

Pass the new option to the workflow-side reference. Callers that omit
it are unchanged.
@campoy
campoy marked this pull request as ready for review October 28, 2026 21:48
@campoy
campoy requested a review from a team as a code owner October 28, 2026 21:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] openai_agents: stateless_mcp_server() and stateful_mcp_server() can't require tool approval

2 participants