{"id":"F5lSGJCU","creatorId":"anonymous","title":"Issue #8054: dynamic MCP toolset re-discovery inside call_tool durable steps under DBOSDurability","createdAt":1788468524573,"updatedAt":1788468524573,"latestVersionNum":1,"versions":[{"versionNum":1,"version":null,"branchName":null,"branchSha":null,"runRelease":true,"runBranch":false,"sdkDeps":{"pip":["DBOS uses a sqlite system database; no Postgres required","deps: pydantic-ai-slim[mcp,dbos], dbos, mcp (SDK); no provider keys needed (FunctionModel)","run the snippet; Phase A prints dynamic counts (expect tools_list=5, tools_call=2), Phase B prints static contrast (tools_list=3, tools_call=2)"]},"snippets":[{"id":"server","name":"Instrumented in-process HTTP MCP server","code":"from mcp import types\nfrom mcp.server.fastmcp import FastMCP\n\nCOUNTS = {'initialize': 0, 'tools_list': 0, 'tools_call': 0}\n\nmcp = FastMCP('repro-mcp')\n\n@mcp.tool()\ndef echo(text: str) -> str:\n    \"\"\"Echo text back.\"\"\"\n    return text\n\n# Count MCP wire operations by wrapping the lowlevel request handlers.\nlow = mcp._mcp_server\nfor req_type, key in {\n    types.ListToolsRequest: 'tools_list',\n    types.CallToolRequest: 'tools_call',\n}.items():\n    def make(orig, k):\n        async def wrapped(context):\n            COUNTS[k] += 1\n            return await orig(context)\n        return wrapped\n    low.request_handlers[req_type] = make(low.request_handlers[req_type], key)\n\napp = mcp.streamable_http_app()\n# serve with uvicorn in a background thread (uvicorn.Config(app, ...).run)","primaryOutput":null,"comparisonOutput":null},{"id":"agent","name":"DBOSDurability agent: dynamic per-user MCP pattern vs static contrast","code":"import threading, tempfile, asyncio\nimport uvicorn\nfrom dbos import DBOS, SetWorkflowID\nfrom pydantic_ai import Agent\nfrom pydantic_ai.mcp import MCPToolset\nfrom pydantic_ai.toolsets import DynamicToolset\nfrom pydantic_ai.durable_exec.dbos import DBOSDurability\nfrom pydantic_ai.models.function import FunctionModel\nfrom pydantic_ai.messages import ModelResponse, ToolCallPart, TextPart\n\nURL = 'http://127.0.0.1:8971/mcp'  # instrumented server from snippet 1\n\ndef make_model():\n    script = iter([\n        ModelResponse([ToolCallPart('echo', {'text': 'first'})]),\n        ModelResponse([ToolCallPart('echo', {'text': 'second'})]),\n        ModelResponse([TextPart('all done')]),\n    ])\n    return FunctionModel(lambda messages, info: next(script, ModelResponse([TextPart('end')])))\n\ntmp = tempfile.mkdtemp()\nDBOS(config={'name': 'repro8054', 'system_database_url': f'sqlite:///{tmp}/dbos.sqlite3', 'run_admin_server': False})\nDBOS.launch()\n\n# Phase A - the reported per-user MCP pattern: DynamicToolset -> MCPToolset\nagent_dyn = Agent(\n    make_model(), name='repro_dyn',\n    toolsets=[DynamicToolset(lambda ctx: MCPToolset(URL), id='acme-mcp', per_run_step=False)],\n    capabilities=[DBOSDurability()],\n)\nwith SetWorkflowID('repro-dyn-1'):\n    asyncio.run(agent_dyn.run('call the echo tool twice, then finish', deps=None))\nprint('Phase A (dynamic) MCP counts:', COUNTS)  # observed: tools_list=5, tools_call=2\n\n# Phase B - contrast: same MCPToolset attached statically\nfor k in COUNTS: COUNTS[k] = 0\nagent_static = Agent(make_model(), name='repro_static', toolsets=[MCPToolset(URL, id='mcp-static')], capabilities=[DBOSDurability()])\nwith SetWorkflowID('repro-static-1'):\n    asyncio.run(agent_static.run('call the echo tool twice, then finish', deps=None))\nprint('Phase B (static) MCP counts:', COUNTS)  # observed: tools_list=3, tools_call=2\nDBOS.destroy()","primaryOutput":null,"comparisonOutput":null}],"createdAt":1788468524573}]}