Guard against id-less `MCPToolset` on the `DBOSAgent` wrapper path
- Closes #5885
Problem
On the DBOSAgent wrapper path, an id-less [MCPToolset][pydantic_ai.mcp.MCPToolset] has wrapped.id is None, which makes two of them collide on:
- The per-run tool-defs cache key —
DBOSMCPToolsetBase.get_toolskeys the cache byself.id or ''(introduced in #5883), so a second id-less toolset silently returns the first's tool definitions and never lists its own. - DBOS step names —
DBOSMCPToolsetBase.__init__derives its step-name prefix as{agent}__mcp_server(emptyid_suffix), so two id-less toolsets register identically-named@DBOS.steps (.get_tools/.get_instructions/.call_tool), which DBOS can't distinguish in the workflow journal — breaking recovery.
Both stem from the same root cause named in the issue: unlike Temporal, DBOS doesn't require ids on MCP leaf toolsets. Temporal's temporalize_toolset raises UserError for any leaf with id is None; the DBOS wrapper's dbosify_toolset had no such guard. Thanks to @DouweM for documenting the sibling step-name symptom.
Fix
Mirror Temporal: raise UserError in the dbosify_toolset closure (durable_exec/dbos/_agent.py) for an id-less MCPToolset. One guard closes both symptoms — an id-less MCP toolset can no longer reach DBOSMCPToolset.__init__, so neither the cache key nor the step name can collide. _mcp.py is intentionally untouched (the guard sits upstream of it).
Scope is deliberately narrow:
- DBOS wraps only
MCPToolsetat construction, so the guard covers only that type — not all leaf toolsets the way Temporal does.FunctionToolsetruns inline (an id-less one stays allowed, by design), and runtimemcp/dynamictoolsets are already rejected by_reject_unsupported_runtime_toolsets. - Not Prefect. #6334 lumps Prefect in, but Prefect names tasks by tool name (
Call MCP Tool: {name}) with no id-keyed cache — the mechanism here is DBOS-specific. - #4977 (
DBOSDurabilitycapability) is unmerged, and already handles this at bind time on that path. The scope here is theDBOSAgentwrapper path onmain.
⚠️ Design decision for a sanity pass
The guard raises for any id-less MCPToolset (Temporal-consistent), not only when 2+ id-less toolsets would actually collide.
The trade-off: a single id-less MCP toolset currently works (it gets the generic name, no collision). Raising for it is a minor backward-compatibility change — those users now need to add an id= (e.g. MCPToolset(url, id='...')).
I went with matching Temporal for engine consistency and because the fix is trivial for users, but this single-toolset back-compat point is your call — happy to switch to collision-only if you'd prefer to preserve it.
Checklist
- Any AI generated code has been reviewed line-by-line by the human PR author, who stands by it.
- No breaking changes in accordance with the version policy. Intentional minor back-compat change: a single id-less
MCPToolsetnow raises, matching Temporal (which requires anidon leaf toolsets). Pending @DouweM's decision on the raise-for-any-id-less vs. only-on-collision fork flagged above. - PR title is fit for the release changelog.