MCP item writes

How the Marfa MCP tools save an item's edges, which way an edge named by a reverse name runs, and when a change to an item is refused.

marfa_create, marfa_update and marfa_bulk_save are three of the tools an instance serves over MCP. Each write is an API call made with the client's credential. The rules are in the contract's MCP chapter, under Saving edges with items and Changing an item.

Edges saved with an item

marfa_create and each marfa_bulk_save entry take edges, an object that gives each name a list of item IDs. marfa_update takes add_edges and remove_edges, where each entry holds an edge_type and a to_id. A name is an edge type's ID or its reverse name:

NameThe edge runs
An edge type's ID, such as parent-ofFrom the item written to each item named
Its reverse name, such as child-ofFrom each item named to the item written

So one marfa_create call saves a task under its parent:

{
  "type": "core.task",
  "properties": { "title": "Book the van" },
  "edges": { "child-of": ["01a2394e-d555-71ba-bffb-a280969fb025"] }
}
  • A reverse name needs what the same edge needs by its ID: write on the from item's type, and write on the edge type's ID in the credential's edge map. Every rule of the edge type holds, with the refusal Create an edge gives.
  • An item named by a reverse name that the credential can't read is refused item_not_found, as an ID that no item holds is.
  • A refused edge saves nothing of its item.
  • Only these tools read a reverse name. Create an item, Update an item and Upsert items in bulk take an edge type's ID, and answer a reverse name edge_type_not_found.

marfa_overview lists each edge type's reverse_name, and the Catalog gives those of the edge types Marfa ships.

Edges in a bulk save

WhenWhat marfa_bulk_save does
An entry's edge is refused, and atomic is falseReports the entry errored with the refusal's code, and saves the others
An entry's edge is refused, and atomic is true or left outSaves nothing, and answers bulk_atomic_rollback with the entry's place in details.index
mode is upsert, and an entry that lands on a saved item names an edge type's IDReplaces the item's edges of that type with edges to the items listed, as Upsert items in bulk does
An entry that lands on a saved item names a reverse nameAdds the edges that don't stand yet, and removes none, even for an empty list
mode is create_only, and the entry is skippedWrites none of the entry's edges

An entry that changes nothing on its saved item, and whose reverse-name edges all stand, is skipped with the reason unchanged. An entry that only adds edges by a reverse name announces edge.created for each, and no item.updated for its item (Events).

Changing an item

marfa_update takes the version the agent read, and with a state, and only then, from: the state it read the item in. Unlike Update an item, it never merges a stale change: if the item changed since, nothing is written. version_conflict holds the item as it is now in current, and names in conflicting_fields each field of the call that changed since. An item no longer in from answers state_conflict, with both states in details, so a restore from the bin needs from: trashed. If the item changes partway through, failed_step names the refused step and applied those written.

  • An item in the bin takes no edge. marfa_update adds and removes none there, and answers item_not_found. Restore the item first.
  • Edges are added before any is removed. Moving a task to another parent takes two calls: one that removes its child-of edge, then one that adds the other. In one call, the second parent is refused edge_constraint_violation.
  • An edge step is named as the call sent it, so failed_step and applied show a reverse name where the call used one.

On this page