Repository navigation
Conversation
…eToolsCache statelessMcpServer() and statefulMcpServer() references now clear the agent SDK's shared tool cache for their server name when invalidateToolsCache() is called, as native MCP servers do, so the next run lists tools again. A stateful reference also has the next listing clear the Worker-side server's own cache. Runs recorded before this change reused the cached tool list, so the new behavior is behind the patch 'openai-agents-mcp-invalidate-tools-cache'.
This was referenced Oct 30, 2026
This branch has not been deployed
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
statelessMcpServer()andstatefulMcpServer()references now callinvalidateServerToolsCache(name)from@openai/agents-coreininvalidateToolsCache(), as native MCP servers do. The agent SDK keeps a shared tool list per server name, and before this change the references never cleared it, so the next run reused the old list.{ invalidateToolsCache: true }. The dedicated Worker then callsinvalidateToolsCache()on the Worker-side server before it lists, so a factory server with its own cache (cacheToolsList: true) lists again too. Other listings keep their empty input.patched('openai-agents-mcp-invalidate-tools-cache'), asked only wheninvalidateToolsCache()is called (and, for a stateless reference, only when it caches).MCP invalidateToolsCache makes the next run list tools againintest-openai-agents.ts, for both references.No public API change.
Why?
See #241. After
invalidateToolsCache(), the next agent run in the same Workflow still got the old tool names and schemas. No list-tools Activity ran, and nothing warned.Replay and rollback
The next run after
invalidateToolsCache()now schedules a list-tools Activity that it skipped before. Without the gate, an open Workflow that invalidated and then ran the agent again would fail replay with[TMPRL1100].patched()only on replay (workflowInfo().unsafe.isReplaying && patched(...)), so new runs keep the old behavior and marked runs keep the new one. Worker Versioning also works.Checklist
Closes [Bug] openai-agents (TypeScript): invalidateToolsCache() on a plugin MCP server keeps the old tool list #241
How was this tested:
mainatc664a34on its one assertion: both references get['old_tool']afterinvalidateToolsCache(). It passes with this change. With only the Worker-side part removed, the stateful reference still gets['old_tool'].make lint(8 existing warnings, none in changed files),make test(208 passed, 207 onmain),make build,check_npm_package.py,smoke.mjs,check_conventions.pyand Prettier on the changed files pass.main, and 0 with this change.invalidateToolsCache(), plus stateless runs held open before and after it:mainhistories replay onmain, on this change and on the gate-keeping rollback build (6 of 6 each).main, the 3 with the marker fail with[TMPRL1100] ... Non-deprecated patch marker encountered, as expected for a gate.mainhistories that invalidated fail with[TMPRL1100] Activity type of scheduled event 'invokeModelActivity' does not match ... '<server>-list-tools'. That is what the gate prevents.mainrun held afterinvalidateToolsCache()keeps the old list on this change; one held before it lists again; on the rollback build, a run that recorded the marker lists again and one that didn't keeps the old list. The carried histories replay on this change and on the rollback build.mainhistories with[TMPRL1100].CI covers the other Node versions and platforms.
Any docs updates needed?
No. The README doesn't describe MCP tool caching; the agent SDK's MCP guide already says to call
invalidateToolsCache().Not covered
Related: #209 and #210 change the same files (
mcp-client.ts,stateful-mcp-client.ts, and #209 the statefullistToolshandler instateful-mcp-provider.ts). Whichever merges second needs a small rebase.