Repository navigation
Roll back the tool stamp when a tool registration is rejected - #5798
Conversation
This comment has been minimized.
This comment has been minimized.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
BrickerP
left a comment
There was a problem hiding this comment.
The tools rollback looks right: stamp → add_tool → restore/del on any exception, with a _MISSING sentinel so a pre-existing __fastmcp__ is preserved. The four tests cover the rejection case that actually bites (sync body + tasks=True).
Comment / follow-up: the same stamp-before-register pattern is still present in the sibling decorators without a rollback:
decorators/prompts.py(target.__fastmcp__ = metadatathenself.add_prompt(fn))decorators/resources.py(target.__fastmcp__ = metadatathenself.add_resource(fn))
Those paths do not hit the sync+tasks ValueError, but add_prompt / add_resource can still raise (duplicate key, validation, etc.) and would leave a discarded stamp on the caller’s function — the same class of bug this PR fixes for tools. Worth mirroring the try/except + _MISSING helper (or extracting a shared stamp_then_register) in a follow-up so the three decorators stay consistent.
BrickerP
left a comment
There was a problem hiding this comment.
Formal decision on head d84a689f1f6c (prior note was COMMENT-only).
Verified
decorate_and_registercaptures prior__fastmcp__with_MISSING, stamps, thentry: self.add_tool(fn)/except: restore-or-del; raise— a rejected sync+tasks=Trueregistration no longer leakstask=Trueonto the caller's function.- Pre-existing stamp restored by identity; successful async registration keeps the stamp; follow-on
FastMCP("no_tasks").add_tool(sync_tool)getstask_config.mode == "forbidden". - Four new tests in
test_decorator.pymatch the failure mode in #5797.
Approve. (Sibling prompt/resource decorators still stamp-then-register without rollback — follow-up as noted earlier, not blocking this tools fix.)
decorate_and_register writes ToolMeta onto the function before add_tool validates it, and add_tool is where a sync body on a task-enabled server is rejected. A rejected registration therefore left task=True behind, so the function could not be registered on any other server afterwards -- including one with no task support at all, which re-raised the same ValueError. Restore the metadata the function carried before the call (including "none") when add_tool raises, so a failed registration has no side effect.
d84a689 to
b02d664
Compare
There was a problem hiding this comment.
Automated review by the FastMCP triage reviewer bot.
The rollback fixes the rejected-registration leak at its source while preserving successful stamps and prior metadata identity. I found no blocking defect in the current patch; successful-registration portability and sibling decorators remain outside this fix.
Checks
The decorator tests produce three expected failures on the base and all 26 pass on this revision; 112 neighboring tests pass. Independent restoration and duplicate-rejection probes also pass.
zzstoatzz
left a comment
There was a problem hiding this comment.
Independent adversarial review passed for this exact revision. Metadata rollback across functions, bound methods and classmethods; 336 independent tests passed. Applicable local static checks and the combined recovery tests passed. This is code approval; current CI, contribution gate and repository merge requirements remain separate prerequisites.
* Revert "fix: preserve referenced schema definitions (#5588)" This reverts commit 5f1d152. * Revert "fix(server): rebuild tool argument errors instead of echoing pydantic's (#6107)" This reverts commit 8fba5f7. * Revert "Advertise the MCP Apps extension only when the server serves an app (#5062)" This reverts commit b89222b. * Revert "fix(tasks): retain results after tool removal (#5507)" This reverts commit 711575a. * Revert "fix(client): Prevent stale ClientGroup refreshes from replacing newer routes (#5543)" This reverts commit 365d5d2. * Revert "fix(prompts): honor field aliases when rendering prompts (#5836)" This reverts commit a450fd8. * Revert "Stop FastMCP callable caches from retaining dropped tools (#6147)" This reverts commit 713f247. * Revert "feat(auth): Add KeystoneTokenVerifier (#6264)" This reverts commit c33f3de. * Revert "fix(json-schema): keep x-unsupported-pattern when a format is set (#5731)" This reverts commit dc9849d. * Revert "Roll back the tool stamp when a tool registration is rejected (#5798)" This reverts commit d6566c5. * Revert "fix(server): validate cursors when pagination is disabled (#6045)" This reverts commit 4917bee. * Revert "Keep constraints on scalar schema references (#6041)" This reverts commit e5176c9.
* fix: keep additionalProperties on object schemas without a type (#6127) Fixes #6124. Co-authored-by: Alperen Keleş <19610315+alpaylan@users.noreply.github.com> (cherry picked from commit 2a8f333) * Fix hydration of mutually recursive schema types (#6394) Fixes #6135. Supersedes #6137. Co-authored-by: wozhenbang2004 <113896798+wozhenbang2004@users.noreply.github.com> Co-authored-by: Alperen Keleş <19610315+alpaylan@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 0d7bb12) * Isolate filesystem component construction failures (#6210) Fixes #6209. (cherry picked from commit f911b58) * fix(config): apply tool transforms before tag filters on single servers (#6214) Fixes #6196. Co-authored-by: arjunprabhulal <11761445+arjunprabhulal@users.noreply.github.com> (cherry picked from commit 02c121c) * fix(tools): isolate mutable defaults in transformed tool calls (#6184) Fixes #6183. (cherry picked from commit b25a1c5) * fix(openapi): make resource templates for non-identifier path parameters readable (#6187) Fixes #6150. Co-authored-by: alpaylan <19610315+alpaylan@users.noreply.github.com> (cherry picked from commit 63f5718) * Keep constraints on scalar schema references (#6041) Fixes #6042. (cherry picked from commit e5176c9) * Document that a custom httpx_client_factory owns its timeout (#5923) Fixes #5922. (cherry picked from commit c9f64de) * Stop PingMiddleware erroring when the client has no back-channel (#5901) Fixes #5900. (cherry picked from commit 044a519) * Store sessionless client log levels on the connection (#5899) Fixes #5898. (cherry picked from commit c6e0c4d) * Register templated MCPMixin resources as resource templates (#5895) Fixes #5894. (cherry picked from commit 0c9f5f7) * Send the whole body when a body $ref with siblings cannot be flattened (#5893) Fixes #5892. (cherry picked from commit cad6074) * Pass the transport to the fastmcp-remote proxy so it forwards server-initiated requests (#5885) Fixes #5884. (cherry picked from commit 285dd4c) * fix(cli): forward path, stateless and log-level to SDK MCPServer servers (#5870) Fixes #5869. (cherry picked from commit 6dcec21) * fix(client): preserve a caller-provided OAuth httpx client factory when verify is set (#5849) Fixes #5848. (cherry picked from commit b7c6568) * fix(prompts): resolve postponed annotations when rendering (#5803) Fixes #5801. Co-authored-by: BlueX888 <140241684+BlueX888@users.noreply.github.com> (cherry picked from commit 3bf92a6) * Roll back the tool stamp when a tool registration is rejected (#5798) Fixes #5797. (cherry picked from commit d6566c5) * fix(openapi): hydrate data for wrapped non-object responses with validate_output=False (#5784) Fixes #5781. Co-authored-by: BlueX888 <140241684+BlueX888@users.noreply.github.com> (cherry picked from commit 6451faa) * Carry prompt argument titles through PromptArgument and proxies (#5749) Fixes #5748. (cherry picked from commit 288485c) * Relay the client's sampling result unchanged through proxies (#5747) Fixes #5746. (cherry picked from commit 19c349f) * fix(json-schema): keep x-unsupported-pattern when a format is set (#5731) Fixes #5729. (cherry picked from commit dc9849d) * fix(tasks): let async-generator tools run as background tasks (#5730) Fixes #5728. (cherry picked from commit c66e181) * Honor Code Mode search limits after BM25 ranking (#5715) Fixes #5712. Co-authored-by: BlueX888 <140241684+BlueX888@users.noreply.github.com> (cherry picked from commit ee71391) * Keep the client timeout from capping the HTTP read timeout (#5690) Fixes #5675. (cherry picked from commit bf95d12) * fix(auth): avoid rereading failed authorization forms (#5570) Fixes #5569. Co-authored-by: JordanAfolabiLaw <252951842+JordanAfolabiLaw@users.noreply.github.com> (cherry picked from commit e9f0443) * Fix unbounded Apps dev log retention (#5549) Fixes #5548. (cherry picked from commit 0a9a482) * Bound error-stat cardinality in ErrorHandlingMiddleware (#5537) Fixes #5536. (cherry picked from commit 089ff09) * fix(auth): preserve GitHub sessions across transient verification failures (#4881) Fixes #4854. Co-authored-by: benjohngf <7750978+benjohngf@users.noreply.github.com> (cherry picked from commit 3c6fbf7) * Expect the extended read timeout in the factory timeout test (#6395) Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit d8c4edf) * fix(auth): keep revocation ownership separate from user identity (#6404) Fixes #5800. Builds on #5807. Co-authored-by: BlueX888 <140241684+BlueX888@users.noreply.github.com> Co-authored-by: Luck <232011771+67-luck@users.noreply.github.com> (cherry picked from commit cdec3a9) * Authenticate and pin the schema download in the OpenAPI performance test (#6177) Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit a66dd71) * Resolve deferred defaults by alias and keep unverified GitHub scopes out of the cache Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit e064736) * Revert "Roll back the tool stamp when a tool registration is rejected (#5798)" This reverts commit 36a1264. * Revert "Keep constraints on scalar schema references (#6041)" This reverts commit 1ffb3e6. * Revert "fix(json-schema): keep x-unsupported-pattern when a format is set (#5731)" This reverts commit 9da9835. --------- Co-authored-by: zgy <101915083+bfs2021@users.noreply.github.com> Co-authored-by: Alperen Keleş <19610315+alpaylan@users.noreply.github.com> Co-authored-by: wozhenbang2004 <113896798+wozhenbang2004@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: ppy <285454460@qq.com> Co-authored-by: ayush <ayushkumarsaha32@gmail.com> Co-authored-by: arjunprabhulal <11761445+arjunprabhulal@users.noreply.github.com> Co-authored-by: Priyanshu Gupta <priyanshug26005@gmail.com> Co-authored-by: Shayan Ali <shayan.ali8799@gmail.com> Co-authored-by: Asem ahmed <94972604+asasemahmed@users.noreply.github.com> Co-authored-by: 哈基米 <140241684+BlueX888@users.noreply.github.com> Co-authored-by: Luck <2115759892@qq.com> Co-authored-by: Winoren <158550716+Winoren@users.noreply.github.com> Co-authored-by: nosmile99 <147114285+nosmile99@users.noreply.github.com> Co-authored-by: Aarnav Noble <98567595+AarnavNoble@users.noreply.github.com> Co-authored-by: 一片一片 <3037678834@qq.com> Co-authored-by: Junpei Zhang <1259636180@qq.com> Co-authored-by: JordanAfolabiLaw <252951842+JordanAfolabiLaw@users.noreply.github.com> Co-authored-by: mika <spacexstarship01@outlook.com> Co-authored-by: sui-ni2 <loxri127@gmail.com> Co-authored-by: benjohngf <7750978+benjohngf@users.noreply.github.com> Co-authored-by: Luck <232011771+67-luck@users.noreply.github.com>
A rejected tool registration could leave metadata on the callable, causing later registration on another server to inherit settings from the failed attempt. Restore the exact previous metadata when registration fails, including removing the stamp when none existed. Successful registrations keep their metadata.
For example, after
mcp.tool(sync_fn, task=True)rejects a synchronous function,other.add_tool(sync_fn)can register it normally. Existing metadata is preserved by identity when a failed registration temporarily replaces it.Fixes #5797.