-
Notifications
You must be signed in to change notification settings - Fork 3.2k
feat(plugin-mcp): add localization support to MCP resource operations #14334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds comprehensive localization support to the MCP plugin, enabling multilingual content management through MCP that matches Payload's REST API capabilities.
Key Changes:
- Added
localeandfallbackLocaleparameters to all resource operations (create, update, find, delete) - Implemented 6 new integration tests covering localization scenarios (all passing)
- Updated documentation with localization usage examples and MCP client setup guide
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| test/plugin-mcp/int.spec.ts | Added 6 comprehensive localization tests and updated getApiKey helper to support update/delete permissions |
| test/plugin-mcp/config.ts | Configured localization with en/es/fr locales and enabled update/delete operations for Posts collection |
| test/plugin-mcp/collections/Posts.ts | Marked title and content fields as localized |
| packages/plugin-mcp/src/mcp/tools/schemas.ts | Added locale and fallbackLocale parameters to find, create, update, and delete tool schemas |
| packages/plugin-mcp/src/mcp/tools/resource/update.ts | Implemented locale parameter handling in update operation and added to schema |
| packages/plugin-mcp/src/mcp/tools/resource/find.ts | Implemented locale parameter handling in find operation |
| packages/plugin-mcp/src/mcp/tools/resource/delete.ts | Implemented locale parameter handling in delete operation |
| packages/plugin-mcp/src/mcp/tools/resource/create.ts | Implemented locale parameter handling in create operation with schema restructuring |
| docs/plugins/mcp.mdx | Added comprehensive documentation for MCP client setup and localization features with examples |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
This is a great start @stevenceuppens! I'll dig into more detail today. |
DanRibbens
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like there are test failures need to be addressed https://github.com/payloadcms/payload/actions/runs/18868951904/job/53872817402?pr=14334#step:12:13889
The MCP plugin's resource tools (find, update, delete) were only accepting string IDs, which caused validation errors when using PostgreSQL. PostgreSQL uses numeric IDs by default, while MongoDB uses string-based ObjectIDs. Changes: - Updated ID parameter schemas to accept both string and number types - Added ID-to-string conversion in find, update, and delete tools - Ensured backward compatibility with MongoDB's string IDs This fixes test failures in PR payloadcms#14334 where all 4 localization tests were failing with "Expected string, received number" validation errors in the PostgreSQL integration test suite. All 15 tests now pass in both PostgreSQL and MongoDB. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
PR Update: PostgreSQL & Partial Update FixesTwo commits added to resolve testing issues: PostgreSQL ID Compatibility (
|
1696f9e to
ee08dd4
Compare
The MCP plugin's resource tools (find, update, delete) were only accepting string IDs, which caused validation errors when using PostgreSQL. PostgreSQL uses numeric IDs by default, while MongoDB uses string-based ObjectIDs. Changes: - Updated ID parameter schemas to accept both string and number types - Added ID-to-string conversion in find, update, and delete tools - Ensured backward compatibility with MongoDB's string IDs This fixes test failures in PR payloadcms#14334 where all 4 localization tests were failing with "Expected string, received number" validation errors in the PostgreSQL integration test suite. All 15 tests now pass in both PostgreSQL and MongoDB. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
I've rebased this PR to resolve the merge conflicts. |
|
@kendelljoseph @DanRibbens - can you give my PR another review :) |
|
Bumping this. Would be really nice to have and seems like an easy merge :) |
|
@kendelljoseph @DanRibbens Can you give my PR another review please? 🙂 |
|
@stevenceuppens Hey! I'll look at this right now. Lets get this done today :) |
kendelljoseph
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking and working great! A much needed improvement! There are also improvements in this PR for Postgres users too, so this is all around a great addition!
We just need to have code conflicts resolved.
The comments about docs you can do as a part of resolving as well -- if not, I will make those improvements with a docs only PR.
- Add locale and fallbackLocale parameters to all resource tools (create, update, find, delete) - Add comprehensive integration tests for localization features - Update documentation with localization usage examples and MCP client configuration - Follow Payload REST API localization pattern for consistency
Updated documentation to accurately reflect that HTTP is the currently supported connection method, with REDIS and STDIO under consideration for future releases. Added a dedicated "Connection Methods" section with HTTP configuration example to provide clearer guidance for users. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
The MCP plugin's resource tools (find, update, delete) were only accepting string IDs, which caused validation errors when using PostgreSQL. PostgreSQL uses numeric IDs by default, while MongoDB uses string-based ObjectIDs. Changes: - Updated ID parameter schemas to accept both string and number types - Added ID-to-string conversion in find, update, and delete tools - Ensured backward compatibility with MongoDB's string IDs This fixes test failures in PR payloadcms#14334 where all 4 localization tests were failing with "Expected string, received number" validation errors in the PostgreSQL integration test suite. All 15 tests now pass in both PostgreSQL and MongoDB. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Previously, the MCP update tool required all collection fields to be provided
when updating a document, even for partial updates. This was because the
schema converter preserved the 'required' status of fields from the collection
schema.
Changes:
- Use Zod's `.partial()` method on converted fields to make all fields optional
- This allows updating a single field without providing all required fields
- Maintains backward compatibility with full updates
Fixes issue where users couldn't update a single field (like a title) without
passing in all the document data. This was particularly problematic with
complex nested fields like layout blocks.
Example:
Before: updatePosts({ id: 1, title: "New Title", content: "...", ... }) ❌
After: updatePosts({ id: 1, title: "New Title" }) ✅
All 15 tests pass in both PostgreSQL and MongoDB.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Remove unnecessary String() conversions for IDs in delete, find, and update tools - Payload operations accept both string and number IDs natively - Conversion was confusing and didn't provide PostgreSQL compatibility benefits - Update MCP documentation: - Clarify HTTP-only transport support (remove REDIS/STDIO mentions) - Add detailed VSCode and Cursor MCP client configuration examples - Update localization examples to use proper JSON-RPC 2.0 format - Recommend npx mcp-remote approach for better compatibility Addresses review comments from @JarrodMFlesch and @kendelljoseph 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
…lity - Fix beforeRead hook in Posts collection to handle localized fields - Handle both object (localized) and string (non-localized) field values - Apply MCP hook override to all locale values when field is localized - Update test expectations to match new MCP hook behavior - Replace "Title Override: " prefix with " (MCP Hook Override)" suffix - Hook adds suffix to all localized values when locale="all" - Add products collection to API key in test helper - Fixes "should list tools" test expecting 4 tools 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
ee08dd4 to
d4ad382
Compare
kendelljoseph
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- fix: id number | string for postgres
- feat: CRUD resource tools support locale and fallbackLocale
Looks great, 👍🏿
DanRibbens
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution!
|
🚀 This is included in version v3.65.0 |
What?
Adds full localization support to the MCP plugin's resource operations (create, update, find, delete).
Why?
The MCP plugin did not expose Payload's localization capabilities. Users with multilingual content could not create or manage translations through MCP, limiting the plugin's usefulness for international projects. This brings MCP feature parity with Payload's REST API.
How?
localeandfallbackLocaleparameters to all resource tools (create, update, find, delete)Testing:
pnpm test:int plugin-mcp # All 15 tests passing (9 existing + 6 new localization tests)Example Usage:
Fixes #