Skip to content

fix!: answer -32603 when a tools or config file is not a JSON object - #20

Merged
Martin Bens (SpiGAndromeda) merged 1 commit into
mainfrom
fix/read-json-file-object-gate
Sep 13, 2026
Merged

Martin Bens (SpiGAndromeda) merged 1 commit into
mainfrom
fix/read-json-file-object-gate

Conversation

@SpiGAndromeda

@SpiGAndromeda Martin Bens (SpiGAndromeda) commented Sep 13, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #18.

What

read_json_file guaranteed its file held exactly one parseable JSON document but not that the document was an object. A tools or config file holding 5, "x", [1,2], true or false passed the gate; handle_tools_list then ran .tools // [] on it and handle_initialize handed it to --argjson config. The failed index left an empty capture, the --argjson inside create_response rejected it, and that status — create_response being process_request's last command — reached the read loop's response=$(process_request "$line") assignment, where errexit is active. The server exited with no response, in the default shell mode, while the neighboring missing/empty/multi-document/unparseable files all answer -32603.

read_json_file now requires the single document to be a JSON object — one gate covering both handlers and validate_tool_arguments. initialize and tools/list answer -32603 naming the file. A null document, which previously read as an empty configuration by accident, answers -32603 with the rest.

Breaking (Major per AGENTS.md §Compatibility contract)

  • read_json_file returns 1 for a file whose single document is not a JSON object.
  • initialize / tools/list answer -32603 where a null document previously produced the default configuration and an empty tools list.
  • validate_tool_arguments' unreadable-list message changed from "is missing or not parseable JSON." to "is missing or does not hold one JSON object.".

A consumer whose config and tools files each hold one JSON object sees no change.

read_json_file guaranteed its file held exactly one parseable JSON document but not that the document was an object, so a file holding `5`, `"x"`, `[1,2]`, `true` or `false` passed the gate. handle_tools_list then ran `.tools // []` on it and handle_initialize handed it to `--argjson config`. Indexing a non-object errors, the empty capture made the `--argjson` inside create_response reject, and create_response is process_request's last command, so its status reached the read loop's `response=$(process_request "$line")` assignment, where errexit is active. The server exited with no response and never read the request that followed (in the default shell mode, with no `set -o posix` involved), while the neighboring missing, empty, multi-document and unparseable files all answer `-32603`.

read_json_file now requires the single document to be a JSON object, one gate covering both handlers and validate_tool_arguments. initialize and tools/list answer `-32603` naming the file. A `null` document, which previously read as an empty configuration by accident (indexing `null` yields `null` and jq's `//` took the defaults), answers `-32603` with the rest.

BREAKING CHANGE: read_json_file returns 1 for a file whose single document is not a JSON object, initialize and tools/list answer -32603 where a null document previously produced the default configuration and an empty tools list, and validate_tool_arguments' unreadable-list message changed from "is missing or not parseable JSON." to "is missing or does not hold one JSON object.". A consumer whose config and tools files each hold one JSON object sees no change.

Fixes #18.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@SpiGAndromeda
Martin Bens (SpiGAndromeda) merged commit bf093ec into main Sep 13, 2026
3 checks passed
@SpiGAndromeda
Martin Bens (SpiGAndromeda) deleted the fix/read-json-file-object-gate branch September 13, 2026 10:50
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.

a tools or config file holding a non-object document ends the server, in the default shell mode

1 participant