fix: writeNoSqlDatabaseContent 对嵌套对象更新缺乏明确的行为说明,导致模型误用 $set 覆盖整个嵌套对象#692
fix: writeNoSqlDatabaseContent 对嵌套对象更新缺乏明确的行为说明,导致模型误用 $set 覆盖整个嵌套对象#692
Conversation
…set 覆盖整个嵌套对象 (issue_mojxks03_yvtgc5)
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dcb0dd8904
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| .optional() | ||
| .describe( | ||
| "更新内容(对象或字符串,推荐对象)(update 操作必填)。按 MongoDB 更新语义传入 MgoUpdate:部分更新请使用 `$set`、`$inc`、`$unset`、`$push` 等操作符,例如使用 `$set` 更新 `status`;不要直接传“字段到值的普通对象”,否则可能替换整条文档。更新嵌套字段时必须使用点号路径,例如通过 `$set` 更新 `address.city`;不要把整个 `address` 对象作为 `$set` 的值传入,否则会替换整个 `address` 对象。", | ||
| "更新内容(对象或字符串,推荐对象)(update 操作必填)。按 MongoDB 更新语义传入 MgoUpdate:部分更新请使用 `$set`、`$inc`、`$unset`、`$push` 等操作符,例如使用 `$set` 更新 `status`。**⚠️ 嵌套字段更新必须使用点号路径**:`$set: {\"address.city\": \"shenzhen\"}` 只更新 `address.city`,保留其他字段;`$set: {address: {city: \"shenzhen\"}}` 会替换整个 address 对象,删除其他字段。当用户说「把 X 更新为 {Y: Z}」时,应理解为「更新 X.Y 为 Z」,使用点号路径而非替换整个对象。", |
There was a problem hiding this comment.
Preserve explicit full-object replacement intent
The new instruction in writeNoSqlDatabaseContent overgeneralizes nested updates by saying 把 X 更新为 {Y: Z} should be interpreted as 更新 X.Y 为 Z, which forces dot-notation even when a user explicitly intends to replace the whole nested object (for example, intentionally dropping sibling keys like province). In those cases the tool guidance now steers the model toward partial updates and can silently keep stale fields, producing incorrect persisted data relative to the user’s request.
Useful? React with 👍 / 👎.
Attribution post-PR evaluation
Cases
|
Attribution issue
Automation summary
writeNoSqlDatabaseContentMCP tool documentation mentioned that nested field updates should use dot notation (e.g.,address.city), but it did not provide a concrete example showing the WRONG vs CORRECT approach. When the user's prompt was ambiguous ("把 shipping 更新为 {"city":"guangzhou"}"), the model interpreted it as replacing the entireshippingobject rather than just updating thecityfield withinshipping. The documentation lacked explicit guidance on how to interpret such ambiguous user requests.writeNoSqlDatabaseContenttool description inmcp/src/tools/databaseNoSQL.tsto:$set: {\"shipping.city\": \"guangzhou\"},错误的做法是$set: {shipping: {city: \"guangzhou\"}}(会删除 province 字段)"updateparameter description: "当用户说「把 X 更新为 {Y: Z}」时,应理解为「更新 X.Y 为 Z」,使用点号路径而非替换整个对象"**⚠️ 嵌套对象局部更新必须使用点号路径**) to highlight the importance of this behaviorChanged files
mcp/src/tools/databaseNoSQL.ts