Repository navigation
Breaking: mcp: report an MCP factory that returns the wrong type - #441
Merged
Merged
Conversation
campoy
force-pushed
the
fix/mcp-factory-type-check
branch
from
November 6, 2026 23:15
b252717 to
595cb48
Compare
campoy
marked this pull request as ready for review
November 9, 2026 16:50
temporalio-mcp 0.3.0 only waits for the python/mcp check. The OpenAI Agents check doesn't depend on it and ships with that plugin's own release.
brianstrauch
approved these changes
Nov 9, 2026
campoy
added a commit
that referenced
this pull request
Nov 15, 2026
… wrong type (#451) ## What was changed An OpenAI Agents `mcp_servers` factory that returns the wrong type currently fails its MCP Activity with an opaque `AttributeError`, which the default retry policy retries without limit. This change reports the server name and the returned type: ``` MCP server factory 'hello' returned builtins.object, not agents.mcp.MCPServer ``` The error has type `MCPServerFactoryTypeError` and is non-retryable, matching the adapter's other factory configuration checks. The Activity stops at once so the caller can handle the failure. The check runs before the adapter uses the returned object. The existing factory test checks the message, error type and non-retryable flag. ## Why? Part of #320. OpenAI Agents has its own adapter for `MCPServer` factories, so the `mcp.Client` check in #441 does not cover it. This change works with `temporalio-mcp` 0.2.0. ## Is it breaking? (Breaking) Objects that implement the methods the adapter calls without inheriting from `MCPServer` previously worked. They now fail the Activity. Return an `MCPServer` or a subclass before upgrading. Other wrong types already failed, but their `AttributeError` was retryable. They now fail without retries. This also applies to the next attempt of an in-flight Activity, so fix these factories before upgrading. Deploying a corrected Worker will not automatically resume an Activity that has already failed. The check runs in the Activity; no Workflow code changes. ## Checklist 1. Closes: no issue. Part of #320. 2. How was this tested: - `make test PYTEST_ARGS='-n 0 tests/test_mcp_v2.py tests/test_installed_matches_source.py -q'`: 31 passed. - `make lint`: ruff, formatting, pyright, mypy, basedpyright and pydocstyle passed. - `git diff --check` passed. 3. Any docs updates needed? No. The error names the server and the required type.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was changed
What happens when an
MCPPluginfactory returns something that isn't anmcp.Client? Today the Activity fails with anAttributeErrorabout a private class. It doesn't name the server or the factory, and the default retry policy retries it forever. With this PR, the Activity fails with an error that says what went wrong:The OpenAI Agents half of this change now lives in its own PR, #451, so
temporalio-mcp0.3.0 only waits for this one._mcp_client_backend_factoryin_client.pychecksisinstance(client, Client)before using the client.object().The error is retryable, like the Strands check from #190. After a bad deploy, runs wait for a fixed Worker instead of failing. And the check runs before anything opens, so a wrong factory no longer starts a stdio server first.
Why?
How does a factory return the wrong type? It might return a stdio transport without the
Client(...)wrapper. Or it might return a StrandsMCPClientleft over from before #190, which is what a review on #190 found. Python doesn't stop it unless you run a type checker.Is it breaking? (Breaking)
Only for look-alikes. A look-alike is an object with every method the adapter calls that isn't an
mcp.Client, such as a wrapper or a test double. It worked before, and now it fails every MCP Activity with this retryable error. Before upgrading, return the real client or a subclass. Any other wrong type already failed, with anAttributeError. The README shows factories that return the real type, and no plugin in this repository passes its own client type through this factory.Replay isn't affected: the check runs in the Activity, and no Workflow code changes.
What else did we consider?
typing.Protocol. This keeps look-alikes working. But a@runtime_checkableProtocol only checks that the names exist: a synclist_tools(self)passes, and since Python 3.12 a proxy that forwards through__getattr__fails. Checking signatures too would mean our owninspect.signaturechecks on the tenmcp.Clientmembers the adapter uses, kept in step with every SDK release.AttributeErrorwhere it happens. This is compatible. But it also relabels realAttributeErrors from inside a correct client as "wrong type", and it reports the problem only after the object was entered.factory_argumentthat only a Workflow supplies.What if someone needs look-alikes later? We can loosen this without breaking anyone: keep
isinstance(x, Client), and also accept objects that match aruntime_checkableProtocol of the members the adapter calls. Everything this check accepts still passes; only the message for rejected objects changes. The other order, a Protocol first andisinstancelater, would break people, so this is the safe first step.What's not covered?
temporalio-mcprelease with this check, which Require temporalio-mcp 0.4 in OpenAI Agents and Strands #435 does.temporalio-mcp, and they don't check what those return either. [Feature Request] google_genai, google_adk: run MCP through temporalio-mcp #440 is about moving them ontopython/mcp.Checklist
Closes [Bug] mcp: an MCP factory that does not return mcp.Client fails with an unclear error that retries forever #320.
How was this tested:
mainit exits 1 withAttributeError: '_AsyncGeneratorContextManager' object has no attribute 'protocol_version'. With the change it exits 0 with the retryable error above.main's code and passes with the change.main, the wholepython/mcpsuite passes (113 tests), and ruff, pyright, basedpyright, mypy and pydocstyle are clean.