Skip to main content
Glama

patch_array_item

Atomically patch one item of a structured array field by a portable non-null scalar key, instead of read-modify-full-array-write.

Instructions

Atomically patch one item of a structured array field by a portable non-null scalar key, instead of read-modify-full-array-write. Requires the active schema to declare that array with merge_array_by_key and the same key_field; missing/mismatched policy fails closed. Loads current state and writes inside one transaction, so concurrent patches to DIFFERENT keys both survive. Pass expected_item_version to detect a same-key race or expected_item_absent for race-safe creation; a conflict returns the current item instead of overwriting.

Input Schema

NameRequiredDescriptionDefault
itemYesFields to set on the item identified by `key_value`. Merged onto the existing item (shallow) when the key already exists; `key_field` is always set to `key_value` on the written item regardless of what `item` contains.
fieldYesName of the array field to patch.
user_idNo
entity_idYes
key_fieldYesName of the field on each array item that identifies it. Must match the field's declared `merge_array_by_key` `key_field` for the write to be reflected in the snapshot's reducer output.
key_valueYesPortable non-null JSON scalar identifying the row. Numbers must be finite safe integers. The reducer preserves older rows with non-scalar or unsafe-number keys as unkeyed legacy rows, but new patches cannot create them.
entity_typeYes
idempotency_keyYes
expected_item_absentNoWhen true, create only if no item with `key_value` exists. Concurrent creators for the same key produce one success and one `409 ERR_ARRAY_ITEM_CONFLICT` with the committed item.
expected_item_versionNoContent-hash version of the item as last observed by the caller (returned as `item_version` by a prior patch, or computable client-side as SHA-256 over UTF-8 stable serialization: object keys sort lexicographically, arrays preserve order, and scalar values use JSON spellings). When supplied and stale, the patch is refused with `409 ERR_ARRAY_ITEM_CONFLICT` and nothing is written. Omit to always last-write-win on this one row (still scoped — never touches other keys).

Schema Changelog

Changes observed during successful MCP inspections.

  1. Addedv0.25.0

TDQS

A4.5/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full behavioral burden and does so: atomic transaction semantics, that concurrent patches to DIFFERENT keys both survive, that conflicts return the current item rather than overwriting, and that a stale version is refused with 409 and nothing written. This is exactly the concurrency and failure-mode disclosure an agent needs before calling a mutating tool; only auth/permission requirements are absent.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Four sentences, front-loaded with the core action and the read-modify-write alternative, then preconditions, then concurrency, then conflict handling. Dense but every clause adds operative information; no filler or restatement of the name.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 10-parameter mutating tool with no output schema and no annotations, the description covers preconditions, transaction scope, and conflict behavior well. It could go further on the success-response shape (item_version) and on the undocumented idempotency_key, but nothing essential for correct invocation is missing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 60%, and the description meaningfully supplements it by explaining the conditional role of expected_item_version (race detection) and expected_item_absent (race-safe creation), plus the 'portable non-null scalar' contract for key_value. The notable gap is idempotency_key, a required parameter documented in neither the schema nor the description, which matters for an atomic write tool.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource ('patch one item of a structured array field') and immediately contrasts it with the inferior alternative ('instead of read-modify-full-array-write'). The keying mechanism ('by a portable non-null scalar key') further pins down exactly which operation this is, so an agent can distinguish it from generic write tools like store or correct without opening the schema.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives a clear precondition ('requires the active schema to declare that array with merge_array_by_key and the same key_field; missing/mismatched policy fails closed') and spells out when to pass expected_item_version versus expected_item_absent. It lacks explicit exclusion guidance relative to sibling write tools (store, correct, correct_transaction), but the invocation context is well covered.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.