Skip to content

fix(mcp): require confirm_overwrite before bla_init rewrites a config - #361

Open
DeryFerd wants to merge 1 commit into
qybaihe:mainfrom
DeryFerd:fix/mcp-init-confirmation
Open

DeryFerd wants to merge 1 commit into
qybaihe:mainfrom
DeryFerd:fix/mcp-init-confirmation

Conversation

@DeryFerd

@DeryFerd DeryFerd commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

bla_init was the one mutating MCP tool that skipped the write-confirmation boundary. Every other destructive tool (bla_harden apply and restore, bla_defend, bla_protect, bla_encrypt_strings, bla_bind_scope) refuses with confirmation_required until the caller retries with confirm_overwrite: true; bla_init wrote or replaced bla.config.json immediately, with no preview and no ask.

What changed

  • The bla_init handler now consults wouldInitBlaConfigWrite(directory, overwrite), a new helper in src/core/config.ts that mirrors initBlaConfig's exact write decision, and returns confirmation_required with the resolved bla.config.json path when the call would actually create or replace that file (src/mcp/server.ts).
  • Only real writes are gated. A fresh project (create) and a config whose seed is unusable (the mandatory seed-repair write) are gated; a no-op call against a config that already carries a usable seed stays confirmation-free, so the tool does not nag on a plain re-read.
  • confirm_overwrite is added to the tool schema, and a confirmed write now returns a writeReceipt shaped like the other mutating tools.
  • tests/mcp-init-write-confirmation.test.ts covers the create-without-gate, clobber-gated, confirm-then-write and no-op paths; tests/mcp-engine-capability-parity.test.ts records the new parameter so the agent-facing surface stays pinned.

Why this matters

A destructive tool should not touch an existing file until the user is asked, and that is the rule the other six tools already follow. bla.config.json is not inert: it carries intensity, seed and the protection opt-ins that every later bla_harden run reads, so a host agent invoking bla_init unprompted could quietly change a project's security posture. The gate was simply missing from this one branch.

Tests

  • npx vitest run tests/mcp-init-write-confirmation.test.ts tests/mcp-inplace-write-confirmation.test.ts tests/blarc-config-validation.test.ts tests/mcp-engine-capability-parity.test.ts passes, 23 tests.
  • npx vitest run tests/setup-mcp-doctor-release.test.ts tests/hardening-cli-mcp-setup.test.ts tests/mcp-arg-length-bounds.test.ts passes, 44 tests with 2 skipped.

Compatibility

The create path is unchanged, so a caller that only ever initialises a fresh project sees the same behaviour. A caller that relied on bla_init clobbering an existing bla.config.json silently now receives confirmation_required first and must repeat the call with confirm_overwrite: true, which is the intended contract.

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