Skip to content

[openai-agents-python] breaking: refuse an MCP factory that isn't callable - #593

Merged
campoy merged 1 commit into
mainfrom
fix/openai-agents-python-mcp-factory-callable
Nov 16, 2026
Merged

campoy merged 1 commit into
mainfrom
fix/openai-agents-python-mcp-factory-callable

Conversation

@campoy

@campoy campoy commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

What was changed

OpenAIAgentsPlugin(mcp_servers=...) now checks that each factory is callable when the plugin is built. If it isn't, it raises TypeError, so the Worker doesn't start:

MCP server factory 'filesystem' is agents.mcp.server.MCPServerStreamableHttp, not callable

Today a server passed in place of its factory gets past Worker start. Then every MCP Activity for that server fails with TypeError: 'MCPServerStreamableHttp' object is not callable, which the default retry policy retries forever.

There's a second, smaller fix. When an async factory returns a coroutine, the Activity already fails with MCPServerFactoryTypeError (#451), but Python also warns that the coroutine was never awaited. The coroutine is now closed first.

Both checks live in this plugin's _mcp_server_backend_factory, like MCPPlugin's in #539, not in the _FactoryInvoker this plugin imports from temporalio-mcp.

Why?

The other MCP plugins refuse a factory that isn't a function when the Worker is built: #529, #531, #534, #535, #536 and #555, plus temporalio-mcp and Strands Python with #539 and #377. #531 also closes a returned coroutine, after its review asked for it. This brings OpenAI Agents Python in line.

Is it breaking? (Breaking)

A Worker with a factory that isn't callable used to start, even though every MCP Activity for that server failed and retried. Now it doesn't start, even when no workflow uses that server. Fix the factory before upgrading. No Workflow code or Activity names change.

The deprecated mcp_server_providers route doesn't change. Its providers don't check what the factory returns at all, and I left them alone because they're deprecated.

Checklist

  1. Closes: no issue. Follow-up to Breaking: report an OpenAI Agents MCP server factory that returns the wrong type #451.

  2. How was this tested:

    • The existing test in test_mcp_v2.py now also runs with an async factory, and first passes the returned value in place of the factory. Without the startup check it fails with DID NOT RAISE TypeError, and without the close() with CORO_CREATED. It passes with both.
    • make test on Python 3.12: 644 passed, 2 skipped.
    • make lint passed.
    • git diff --check passed.
  3. Any docs updates needed? The README's MCP section now describes both factory errors.

…in is built

OpenAIAgentsPlugin(mcp_servers=...) now raises TypeError for a factory that
isn't callable, such as a server passed in its place, so the Worker doesn't
start. When an async factory returns a coroutine, the coroutine is closed
before the Activity fails, so Python doesn't warn that it was never
awaited. temporalio-mcp (#539) and Strands (#377) do the same.
@campoy
campoy requested a review from a team as a code owner November 16, 2026 19:00
@campoy
campoy merged commit 075066c into main Nov 16, 2026
16 checks passed
@campoy
campoy deleted the fix/openai-agents-python-mcp-factory-callable branch November 16, 2026 22:48
campoy added a commit that referenced this pull request Nov 16, 2026
…ry that isn't callable (#599)

## What was changed

The deprecated `StatefulMCPServerProvider` now checks that its factory
is callable when you create it. If it isn't, it raises `TypeError`, so
the Worker doesn't start:

```
MCP server factory 'files' is agents.mcp.server.MCPServerStreamableHttp, not callable
```

Today a server passed in place of its factory gets past Worker start.
Then the session Activity fails when it calls the factory, every time a
workflow opens that session.

This is the same check and message #593 added for
`OpenAIAgentsPlugin(mcp_servers=...)`. The deprecated
`StatelessMCPServerProvider` already raises a `TypeError` when you
create it, through `inspect.signature`, so it doesn't change.

## Why?

The GA plan for OpenAI Agents Python asked whether the stateful provider
should refuse a factory that isn't callable, as #555 does for
TypeScript. Adding it after 2.0 would need a 3.0.

## Is it breaking? (Breaking)

A Worker with a stateful provider whose factory isn't callable used to
start, even though every session for that server failed. Now it doesn't
start, even when no workflow uses that server. Fix the factory before
upgrading. No Workflow code or Activity names change.

## Checklist

1. Closes: no issue. Follow-up to #593.

2. How was this tested:
- The existing test in `test_mcp_v2.py` that passes a value in place of
the factory now builds the stateful provider too. It fails with `DID NOT
RAISE TypeError` without the change and passes with it.
   - `make test` on Python 3.12: 619 passed, 2 skipped.
   - `make lint` passed.
   - `git diff --check` passed.

3. Any docs updates needed? The README's paragraph on the deprecated
providers now says both raise `TypeError` for a factory that isn't
callable.
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.

2 participants