Skip to content

[integrations] update_thought MCP with if_unchanged_since#228

Open
txcfi-scott wants to merge 1 commit intoNateBJones-Projects:mainfrom
txcfi-scott:contrib/txcfi-scott/update-thought-mcp
Open

[integrations] update_thought MCP with if_unchanged_since#228
txcfi-scott wants to merge 1 commit intoNateBJones-Projects:mainfrom
txcfi-scott:contrib/txcfi-scott/update-thought-mcp

Conversation

@txcfi-scott
Copy link
Copy Markdown

What it does

Adds a standalone MCP Edge Function that exposes a single new tool: update_thought(id, content?, metadata_patch?, if_unchanged_since?).

The core server/index.ts is curated and does not expose an update path. This integration adds one without touching the core server — it deploys as its own Supabase Edge Function and is registered as a separate custom connector alongside the main Open Brain connector.

Why it matters

Once more than one agent writes to the same Open Brain (Claude Desktop + Codex + a background worker, or a shared brain across teammates), last-write-wins silently drops concurrent edits. Optimistic concurrency is the cheapest fix:

  1. Caller reads a thought, notes its updated_at (T0).
  2. Caller issues update_thought with if_unchanged_since = T0.
  3. If the stored updated_at is still <= T0, the update proceeds. If another writer has advanced it past T0, the server rejects with STALE_READ and the caller can re-fetch and retry.

Omitting if_unchanged_since keeps the old last-write-wins behaviour — fully backward compatible.

What it requires

  • Working Open Brain setup (the thoughts table + the update_updated_at trigger from the getting-started guide).
  • Supabase CLI for deployment.
  • OpenRouter API key — only exercised when callers pass content (re-embedding path).

Tested

Deployed against a live Supabase Open Brain instance. Verified:

  • metadata_patch-only updates succeed without an OpenRouter key.
  • content updates regenerate the embedding and the row's updated_at advances.
  • Two concurrent writers, the second passing if_unchanged_since from its pre-mutation read, receive a clear STALE_READ error once the first writer has committed.

Files touched

Only integrations/update-thought-mcp/ — stays within the contribution scope check.

Attribution

Adapted from a multi-participant capture design used across live Claude / ChatGPT / Codex sessions. Released here as a standalone integration so any Open Brain user can opt in without modifying the core server.

Adds a standalone MCP Edge Function that exposes a single update_thought
tool. Supports shallow metadata merges, content replacement with
re-embedding, and optional if_unchanged_since optimistic concurrency for
multi-writer setups.

Deploys as its own Supabase Edge Function and registers as a separate
custom connector — the core server/index.ts is untouched.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added the integration Contribution: MCP extension or capture source label Apr 23, 2026
@github-actions
Copy link
Copy Markdown

Hey @txcfi-scott — welcome to Open Brain Source! 👋

Thanks for submitting your first PR. The automated review will run shortly and check things like metadata, folder structure, and README completeness. If anything needs fixing, the review comment will tell you exactly what.

Once the automated checks pass, a human admin will review for quality and clarity. Expect a response within a few days.

If you have questions, check out CONTRIBUTING.md or open an issue.

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

Labels

integration Contribution: MCP extension or capture source

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant