Skip to content

[Routine - VT] fix(mcp): guard files iteration in validate_json_structure against undefined#82

Draft
winterdrive wants to merge 1 commit into
mainfrom
routine/vt-fix-validatejson-undefined-files-260709
Draft

[Routine - VT] fix(mcp): guard files iteration in validate_json_structure against undefined#82
winterdrive wants to merge 1 commit into
mainfrom
routine/vt-fix-validatejson-undefined-files-260709

Conversation

@winterdrive

Copy link
Copy Markdown
Owner

1. Pre-flight Check

Open PRs checked (all Draft, all CLEAN merge status):

This PR touches only mcp-server/src/server.ts, which is not modified by any of the above. No overlap.

2. Changes

validate_json_structure (the MCP tool AI agents are told to call before any direct write to .vscode/virtualTab.json) validates each group's optional files field with:

if (g.files !== undefined && !Array.isArray(g.files)) {
  errors.push(...);
} else {
  for (const f of g.files) { ... }   // BUG: runs even when g.files is undefined
}

Since files is a legitimately optional field (per the tool's own JSON schema), any group without a files key hits the else branch and does for (const f of undefined), throwing TypeError: undefined is not iterable. That exception is swallowed by the handler's outer try/catch and reported back to the AI agent as "JSON parse error: ... is not iterable" — a misleading false negative for perfectly valid, syntactically correct JSON.

Fix: only iterate g.files when it is actually an array (else if (Array.isArray(g.files))), matching the same predicate already used for the invalid-type check.

Confirms this PR does not modify commands, contributed configuration keys, dependencies, or the tab-group serialization/storage format. No package.json/package-lock.json/CHANGELOG.md changes.

3. Safety Verification

Commands run locally, all passed:

  • npx tsc -p ./ — no errors
  • npx tsc -p ./mcp-server — no errors
  • npm run test (tsc -p ./ && jest --runInBand) — 25 suites / 175 tests passed
  • npm run build:mcp (esbuild bundle sanity check) — succeeded
  • Manual repro: extracted the validation logic and ran it against [{ "id": "g1", "name": "Empty Group" }] (no files key) — before the fix this throws; after the fix it returns { "valid": true, "errors": [], "warnings": [] }

No lint or format:check npm scripts exist in this repo, so those steps were skipped per the routine-task instructions.

4. CI / Release Gate Note

This is a daily routine Draft PR. Package version bump and CHANGELOG.md consolidation are intentionally deferred to the weekend release/integration PR. If CI fails solely due to the repository's version-bump release gate, that is expected release-readiness behavior, not a code validation failure.

…defined

Groups without a "files" key (a valid, optional field) hit the else
branch's `for...of g.files`, throwing "undefined is not iterable".
That TypeError was swallowed by the outer catch and reported back to
the AI agent as a misleading "JSON parse error" for otherwise valid
JSON.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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