Skip to content

feat(mcp): route MCP writes through the suggestion-review layer (AGENT-2)#142

Merged
eliotlim merged 1 commit into
mainfrom
feat/agent-2-mcp-writes-review
Jul 13, 2026
Merged

feat(mcp): route MCP writes through the suggestion-review layer (AGENT-2)#142
eliotlim merged 1 commit into
mainfrom
feat/agent-2-mcp-writes-review

Conversation

@eliotlim

Copy link
Copy Markdown
Owner

What

The @book.dev/mcp server's mutating write tools now persist reviewable suggestions by default (matching the in-app agent packages/server/src/ai/agent.ts), instead of mutating pages/db directly. Board: AGENT-2 (Epic: Agent-first-class).

Write tools re-routed → suggestion kind:

  • append_to_page / append_blocksinsert (applyKind append_blocks)
  • update_blockreplace-text
  • set_kit_valuereplace-text
  • set_db_cellset-cell

Suggestions are created via DataClient.createSuggestion (POST /api/pages/:id/suggestions); a new recordSuggestion helper builds {pageId, authorKind:'ai', authorName:'MCP client', kind, target, before, after, payload{applyKind,summary}} so MCP-authored edits replay through the same accept/apply bridge as agent suggestions. Payload/target mappings mirror agent.ts.

Opt-out (deployment-level, by design)

allowDirectEdits on OpenBookMcpOptions, wired from env OPENBOOK_MCP_ALLOW_DIRECT_EDITS in bin.ts. Deliberately a deployment/config flag, not a tool argument — an untrusted client cannot opt itself out of review.

Design call for security review to bless

The 3 pure-creation tools (create_page, create_artifact_page, create_database_row) stay immediate, NOT suggestions: the review model has no kind for "create" (closed set: replace-text/set-cell/insert/delete/set-theme) and no existing host page to attach a suggestion to. This matches agent.ts's own rule ("creation is non-destructive → applies immediately") and the parity acceptance criterion. Gating creation too would require new suggestion-machinery kinds (out of scope; possible follow-up).

Security posture after this change

By default an external MCP client cannot silently mutate existing page text/blocks/kit inputs/db cells — every such write becomes a queued StoredSuggestion (author "MCP client") requiring human acceptance. It can still create new pages/rows (non-destructive) and read/search. Only a deployment setting OPENBOOK_MCP_ALLOW_DIRECT_EDITS restores direct writes.

Tests

New packages/mcp/scripts/suggestions.test.mts (16 checks: default=suggestion + no mutation + agent-parity payload; flag=direct mutation; creation stays immediate). Updated scripts/e2e.mts (43 checks). Full pnpm verify exit 0 in-worktree (build:libs, typecheck, lint, mcp 16, server e2e 251, mcp e2e 43).

Scope: entirely within packages/mcp.

MCP write tools that MUTATE existing content (append_to_page, append_blocks,
update_block, set_kit_value, set_db_cell) now persist a reviewable
StoredSuggestion by default instead of mutating the page/database directly,
using the same review layer + kind/target/payload mapping as the in-app agent
(packages/server/src/ai/agent.ts). Nothing an MCP client writes lands until a
human accepts it in the review pane.

A trusted deployment restores direct mutation via allowDirectEdits
(OpenBookMcpOptions), wired from the OPENBOOK_MCP_ALLOW_DIRECT_EDITS env flag in
bin.ts — a deployment/config decision, never a tool argument the client can set.

Pure creation tools (create_page, create_artifact_page, create_database_row)
stay immediate: creation is non-destructive and the review model has no target
page / suggestion kind for a not-yet-existing page, matching the agent's rule.

Adds scripts/suggestions.test.mts (default=suggestion + flag=direct) and updates
the e2e catalogue to assert the new reviewable-by-default behavior.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KFk2T9k3p7ghCjdzMfkA5w
@vercel

vercel Bot commented Jul 13, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
app.book.pub Skipped Skipped Jul 13, 2026 3:09am

Request Review

@eliotlim eliotlim merged commit a327b59 into main Jul 13, 2026
10 checks passed
@eliotlim eliotlim deleted the feat/agent-2-mcp-writes-review branch July 13, 2026 03:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant