Skip to content

feat(mcp): expose and document checksum-guarded edit_note #1552

Description

@phernandez

Summary

Expose Core's existing optimistic-concurrency capability through the MCP edit_note tool and document the contract.

This is separate from #1536, which is a Basic Memory Cloud bug: Cloud already exposes expected_checksum but currently ignores a stale supplied value on ordinary notes. Core's MCP tool does not currently accept a checksum argument at all.

Current state

  • Core MCP edit_note exposes edit-operation controls such as expected_replacements, but no revision checksum precondition.
  • Core's NoteContentMutationService.edit_note(..., base_checksum=...) already supports an optional accepted-content checksum and rejects stale values through the canonical accepted-note mutation transaction.
  • The Core v2 PUT route exposes this as the x-bm-cloud-note-base-checksum header.
  • The ordinary Core MCP edit path does not carry the precondition into that service.

expected_replacements is not a substitute: it verifies the number of textual matches, not that the note revision is the one the caller read.

Proposed MCP contract

Add an optional expected_checksum argument to Core edit_note:

  • omitted: preserve current blind-edit behavior against the latest accepted note;
  • supplied and current: apply the edit;
  • supplied and stale: return a recognizable conflict and do not mutate the note;
  • the checksum refers to the accepted canonical Markdown revision (db_checksum), not the materialized file checksum or a derived search projection.

The precondition must reach the existing transactional base_checksum enforcement. Do not implement it as only a read-before-write comparison, and do not add locks, retries, or a second concurrency mechanism.

Read contract

Ensure callers can obtain the correct checksum from the corresponding machine-readable Core read result. Use consistent naming or document the mapping clearly if the read response uses db_checksum while the edit input uses expected_checksum.

Documentation

Document:

  • read → conditionally edit workflow;
  • omitted versus supplied behavior;
  • conflict response and required caller action;
  • distinction from expected_replacements;
  • distinction between accepted-content, file, and projection checksums;
  • clients should re-read and deliberately rebase after conflict, not blindly retry a potentially destructive edit.

Update the MCP tool reference and generated schema/man-page coverage as appropriate.

Acceptance criteria

  • Core MCP edit_note accepts optional expected_checksum.
  • Fresh checksum succeeds.
  • Stale checksum returns conflict and leaves content unchanged.
  • Omitted checksum preserves existing behavior.
  • A real integration test proves read A → write B → stale conditional edit A fails → B remains unchanged.
  • Tool schema and user-facing documentation describe the contract accurately.
  • SQLite and PostgreSQL paths are covered where the accepted-note mutation behavior differs.

Out of scope

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions