Skip to content

fix: ctx_patch batch ops rejected with -32602 (schema over-constrains top-level path) (#1005)#1007

Closed
andig wants to merge 2 commits into
yvgude:mainfrom
andig:fix/ctx-patch-batch-schema-1005
Closed

fix: ctx_patch batch ops rejected with -32602 (schema over-constrains top-level path) (#1005)#1007
andig wants to merge 2 commits into
yvgude:mainfrom
andig:fix/ctx-patch-batch-schema-1005

Conversation

@andig

@andig andig commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Problem

Fixes #1005. ctx_patch rejected valid batch calls with MCP error -32602: path is required. The tool documents Batch: ops:[{op, path, ...}], but:

  1. the schema declared required: ["path"], and
  2. the handler called require_resolved_path(…, "path") unconditionally,

so a correct batch was refused before it ever reached execution. On top of that, the implementation only applied ops to one shared params.path — the advertised cross-file batch never actually worked.

Fix

  • Schema: drop path from required. Top-level path is optional when ops is present.
  • Handler: plan_groups groups batch ops by each op's own path (falling back to the top-level path), resolves + write-gates each file, and applies them per file through the shared apply_one — extracted from the old inline handler body and reused by the single-op path too. A batch may now legitimately span files.
  • Existing single-file batch atomicity (bottom-up, all-or-nothing per file) is unchanged; cross-file batches are atomic per file.

Also softens ctx_read's mode docs, which overclaimed "REQUIRED" though the param is optional and defaults to auto (issue item 2).

Scope

Issue item 3 — modeling action-conditional requirements across ctx_execute / ctx_search with JSONSchema oneOf/if-then — is intentionally left as a follow-up rather than speculatively rewriting every tool schema in this PR.

Tests

4 new pure grouping tests (cross-file order, top-level fallback, missing-path rejection, empty-ops). Full existing ctx_patch suite (86 tests incl. batch atomicity, syntax gate, BOM/CRLF, backups) passes.

🤖 Generated with Claude Code

andig and others added 2 commits July 18, 2026 10:43
…path (yvgude#1005)

ctx_patch rejected valid batch calls with `-32602: path is required`. The
schema declared `required: ["path"]` and the handler called
require_resolved_path unconditionally, so a documented batch
(`ops:[{op, path, ...}]`) was refused before execution. The impl also only
ever applied ops to one shared `params.path`, so the advertised cross-file
batch never actually worked.

Fixes:
- Schema: drop `path` from `required`; top-level `path` is optional when `ops`
  is present.
- Handler: `plan_groups` groups batch ops by each op's own `path` (falling
  back to the top-level `path`), resolves+write-gates each file, and applies
  them per file via the shared `apply_one` (extracted from the old inline
  body, reused by the single-op path too). A batch may now span files.

Also softens ctx_read's `mode` docs, which overclaimed "REQUIRED" though the
param is optional and defaults to auto (yvgude#1005 item 2).

Item 3 (modeling action-conditional requirements across ctx_execute /
ctx_search with oneOf/if-then) is left as a follow-up.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The verbose `ops` schema description pushed ctx_patch to 389 tok, over the
370-tok per-tool core budget (core_tool_surface_stays_within_budget). Move the
per-op-path note into the main description and drop the redundant `ops`
description — ctx_patch is back to 355 tok. Regenerate the schema-derived
reference docs (docs/reference/generated/mcp-tools.md).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@yvgude

yvgude commented Jul 18, 2026

Copy link
Copy Markdown
Owner

Superseded by and integrated into #1013, including per-op cross-file batch planning, schema correction, token-budget protection, and additional regression coverage. The original commit/authorship remains preserved in the integrated history. Thank you.

@yvgude yvgude closed this Jul 18, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ctx_patch: batch ops rejected with "-32602: path is required" (schema over-constrains top-level path)

2 participants