Repository navigation
Fix/mcp menu locale awareness - #939
Conversation
🦋 Changeset detectedLatest commit: c28b865 The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
|
recheck |
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/blocks
@emdash-cms/cloudflare
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
afd1d40 to
3881454
Compare
|
/review |
There was a problem hiding this comment.
Fix is correct and well-scoped. The locale-scoped existence check stays inside the transaction (preserves the concurrency-safety property of the original code), inserted items now get tagged with the menu's locale instead of falling back to the column DEFAULT (defaultLocale), and the new translationOf -> locale refine on the MCP boundary is a nice safety net. Tests cover the targeted behavior — per-locale menu_set_items, item locale tagging, locale-scoped NOT_FOUND, locale-scoped update/delete, and the translationOf requirement. Two small follow-up notes inline; neither is a blocker.
|
Review posted. Summary:
|
There was a problem hiding this comment.
Pull request overview
This PR makes MCP menu tooling locale-aware on multi-locale installs so menu write operations can target the intended (name, locale) menu row (and improve NOT_FOUND messaging accordingly), closing a gap where MCP writes could affect the wrong locale variant.
Changes:
- Extend MCP menu write tools (
menu_create,menu_update,menu_delete,menu_set_items) to acceptlocale; extendmenu_createto accepttranslationOfand requirelocalewhentranslationOfis set. - Update
handleMenuSetItems()to optionally scope menu lookup bylocaleand to write new menu items with the menu’s locale. - Add/expand unit + integration tests and update MCP reference docs to reflect the locale-aware menu surface.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/core/src/api/handlers/menus.ts | Add locale-scoped lookup and locale-tagging for handleMenuSetItems(), plus improved locale-scoped NOT_FOUND messages. |
| packages/core/src/mcp/server.ts | Expose locale on menu write tools and translationOf on menu_create, including validation when translating. |
| packages/core/tests/unit/menus/menus.test.ts | Add regression coverage for locale-scoped handleMenuSetItems() behavior and NOT_FOUND messaging. |
| packages/core/tests/integration/mcp/menu.test.ts | Add integration coverage ensuring MCP menu writes target the correct locale variant. |
| docs/src/content/docs/reference/mcp-server.mdx | Document the locale-aware menu tool parameters for MCP. |
| .changeset/mcp-menu-locale-awareness.md | Changeset describing the locale-awareness patch for MCP menu tools. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Addresses Copilot review feedback on emdash-cms#939. handleMenuUpdate, handleMenuDelete, and handleMenuSetItems now return the new AMBIGUOUS_LOCALE error code (HTTP 400) when a name resolves to multiple locale variants and the caller did not pass `locale`. The error message lists the available locales so callers can recover. Previously the lookup silently picked an arbitrary translation, which could rewrite or delete the wrong locale's menu on multi-locale installs. Single-locale installs and callers that already pass `locale` are unaffected. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Two extensions to the AMBIGUOUS_LOCALE work in 061577f: 1. Apply the same fail-loud rule to the four item-level handlers (handleMenuItemCreate / Update / Delete / Reorder) so REST callers to /api/menus/[name]/items get the same protection as MCP callers. All seven name-based menu lookups now refuse ambiguous resolution and list the available locales in the error message. 2. Move the `translationOf` -> `locale` requirement from the MCP Zod .refine() into handleMenuCreate itself, returning VALIDATION_ERROR. The MCP boundary previously was the only enforcement point, leaving REST/SDK callers free to clone into the default locale by accident. Addresses ask-bonk review note emdash-cms#3 on PR emdash-cms#939 and closes the gap noted in the prior review of the AMBIGUOUS_LOCALE follow-up. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
ready for re-review |
|
/review |
There was a problem hiding this comment.
Solid follow-up to the earlier review notes. The fix correctly closes the silent-cross-locale-write bug, the AMBIGUOUS_LOCALE expansion to all seven name-keyed lookups is the right call (fail-loud beats arbitrary tie-break), and lifting the translationOf -> locale guard from the MCP boundary into handleMenuCreate is exactly what was asked for. Tests cover the targeted behavior plus transaction rollback, which is the bit most likely to regress quietly.
Three small notes inline, none blocking. The PR is good to merge as-is.
| deleted and the new list is inserted in the order provided. Use this rather | ||
| than per-item add/remove operations so the resulting order and parent links are | ||
| unambiguous. On multi-locale installs, pass `locale` so only the intended | ||
| translation is rewritten. |
There was a problem hiding this comment.
Not blocking, doc gap: the menu write tools (menu_update, menu_delete, menu_set_items, plus the per-item ones) now return a structured AMBIGUOUS_LOCALE (HTTP 400) when called without locale on a multi-locale install. That's an observable behavior change for MCP callers — worth one sentence here so users don't have to discover it the hard way. Something like:
On multi-locale installs, omitting
localewhen the same menu name exists in more than one locale returnsAMBIGUOUS_LOCALE(the message lists the available locales). Passlocaleto disambiguate.
| if (matches.length === 0) { | ||
| return { | ||
| success: false, | ||
| error: { code: "NOT_FOUND", message: "Menu not found" }, |
There was a problem hiding this comment.
Nit, pre-existing on main but the PR is rewriting the surrounding lines: the item-level handlers (handleMenuItemCreate/Update/Delete/Reorder) still say "Menu not found" here without interpolating menuName or the options.locale, while handleMenuUpdate/Delete/SetItems now produce the more debuggable "Menu '<name>' not found in locale '<locale>'". The AMBIGUOUS_LOCALE messages on the item handlers do include the name (via the shared helper), so the inconsistency is only on the NOT_FOUND branch. Cheap cleanup if you want to do it while you're here:
| error: { code: "NOT_FOUND", message: "Menu not found" }, | |
| if (matches.length === 0) { | |
| return { | |
| success: false, | |
| error: { | |
| code: "NOT_FOUND", | |
| message: `Menu '${menuName}' not found${ | |
| options.locale ? ` in locale '${options.locale}'` : "" | |
| }`, | |
| }, | |
| }; | |
| } |
Or leave for a follow-up — flagging because the diff is already touching every one of these blocks.
| if (error === ambiguousSentinel && ambiguousLocales) { | ||
| return ambiguousMenuLocaleError(menuName, ambiguousLocales); | ||
| } | ||
| throw error; |
There was a problem hiding this comment.
Defensive nit, not blocking: if (error === ambiguousSentinel && ambiguousLocales) is technically correct because the sentinel is only thrown after ambiguousLocales is assigned, but if anyone ever moves the assignment or the throw, the truthy check will silently swallow the ambiguous case and re-throw as the outer 500. Two cheap options: (a) split into two ifs with an else throw so a future refactor can't reorder them into a no-op, or (b) just check error === ambiguousSentinel and assert(ambiguousLocales !== null) after the throw is caught — the invariant is real and should fail loud if it's ever broken.
Not a real bug today; calling out as a future-proofing thing.
|
Review posted successfully. Summary of what I posted:
|
|
Thanks! |
What does this PR do?
Makes the MCP menu write tools locale-aware on multi-locale installs.
Upstream already models menus as per-locale records:
(name, locale)is theunique key, and the same menu name can exist in multiple locales within one
translation group. The handler layer already partly reflects that:
handleMenuCreate()acceptslocaleandtranslationOf,handleMenuUpdate()acceptslocale, andhandleMenuDelete()acceptslocale.The gap is the MCP write surface:
menu_create,menu_update,menu_delete, andmenu_set_itemsdid notexpose
localemenu_createdid not exposetranslationOfhandleMenuSetItems()still selected menus bynameonlyOn a multi-locale install, that meant an MCP caller trying to update
maininfr-frcould silently modify a different locale’s menu instead.This PR fixes that by:
handleMenuSetItems()to accept and honorlocalelocaleon all MCP menu write toolstranslationOfonmenu_createlocalewhentranslationOfis provided onmenu_createmenu_set_itemsrows withlocale: menu.localeNOT_FOUNDmessages on menu writesType of change
Checklist
pnpm typecheckpassespnpm lintpassespnpm testpasses (or targeted tests for my change)pnpm formathas been runmessages.pochanges except in translation PRs — a workflow extractscatalogs on merge to
main.AI-generated code disclosure
Screenshots / test output
Targeted validation run locally: