Skip to content

fix(cli): return JSON-RPC errors instead of crashing on malformed input - #366

Merged
TMHSDigital merged 1 commit into
TMHSDigital:mainfrom
arpitgoswami:main
Dec 4, 2026
Merged

TMHSDigital merged 1 commit into
TMHSDigital:mainfrom
arpitgoswami:main

Conversation

@arpitgoswami

Copy link
Copy Markdown
Contributor

What

Fixes #341 - MCP server now returns JSON-RPC errors instead of crashing on malformed input.

Changes

  • Strict flag parsing: Uses (Node's parseArgs in strict mode) so mistyped flags (e.g. ) fail with exit code 2 and a usage message instead of being silently ignored.

  • Non-object message rejection: The line handler now validates that the parsed JSON is a plain object. Scalars (, ), arrays (JSON-RPC batch), and other non-objects get a reply and the server keeps running.

  • Internal error handling: is wrapped in try/catch. Any exception (e.g. a throwing tool call) produces a reply instead of crashing the server process.

  • Limit clamping: parameter is clamped to the documented 1..100 range.

  • Testability: Line processing extracted to for easier testing.

Testing

All existing tests pass (

test
node site/checks.test.mjs && node site/lib/lib.test.mjs

checks.test ok: 277 assertions across 34 checks
lib.test ok: 1882 assertions in 79 sections,

check
npm run lint && npm test && npm run validate && npm run check-added && npm run build

lint
node site/lint.mjs

lint ok: 73 scripts parse, no unused imports

test
node site/checks.test.mjs && node site/lib/lib.test.mjs

checks.test ok: 277 assertions across 34 checks
lib.test ok: 1882 assertions in 79 sections

validate
node site/validate.mjs

validate ok: 467 entries, 467 ids, 9 stacks, no broken links
coverage:
2d 72
3d 80
animation 18
audio 43
characters 31
environment 20
fonts 25
shaders-vfx 18
tools 140
video 20
license_spdx 346/467 (74.1%)
publisher 384/467 (82.2%)
55 of 284 tags (19%) are used by one entry: 10x10, 12x12, 8-directional, alicevision, amiga, anim-graph, architecture, asset-browser, atmosphere, auto-rig, autotile, bake-out, canvas-item, clothing, color-clash, cooking, cozy, crouch-slide, exr, farming, fingers, flowmaps, foley, game-sfx, gameplay-programming, gta-format, importer, kinect, kufi, latent-actions, lidar-derived, low-vision, milky-way, multilingual, multithreading, mvs, naskh, netherlands, nintendo-64, pan-cjk, pets, power-tools, rpg-maker, save-system, sentinel, skybox, soft-body, spatial, splitter, steamworks, substance, threejs, ui-strings, vi-like, vintage

check-added
node site/check-added.mjs

check-added ok: 467 entries, no added date later than its first commit

build
node site/build.mjs

Built 467 entries → site/dist (399 active, 423 commercial-ok, 21 per-file)
Prerendered 464 entry rows into index.html; wrote 467 entry pages, 9 stack pages, 10 category pages, 6 alternatives pages, 15 guide pages, sitemap.xml, robots.txt, 404.html, freshness/index.html
389 of 1649 output files changed; 2.8s). Manual verification:

# null input -> -32600
printf 'null\n' | node site/cli/mcp.mjs

# scalar -> -32600
printf '5\n' | node site/cli/mcp.mjs

# batch array -> -32600
printf '[{"jsonrpc":"2.0","method":"ping","id":1}]\n' | node site/cli/mcp.mjs

# valid ping -> works
printf '{"jsonrpc":"2.0","method":"ping","id":1}\n' | node site/cli/mcp.mjs

# mistyped flag -> exit 2 with usage
node site/cli/mcp.mjs --dat

# limit clamping
# limit=200 clamped to 100

All CI checks pass (

check
npm run lint && npm test && npm run validate && npm run check-added && npm run build

lint
node site/lint.mjs

lint ok: 73 scripts parse, no unused imports

test
node site/checks.test.mjs && node site/lib/lib.test.mjs

checks.test ok: 277 assertions across 34 checks
lib.test ok: 1882 assertions in 79 sections

validate
node site/validate.mjs

validate ok: 467 entries, 467 ids, 9 stacks, no broken links
coverage:
2d 72
3d 80
animation 18
audio 43
characters 31
environment 20
fonts 25
shaders-vfx 18
tools 140
video 20
license_spdx 346/467 (74.1%)
publisher 384/467 (82.2%)
55 of 284 tags (19%) are used by one entry: 10x10, 12x12, 8-directional, alicevision, amiga, anim-graph, architecture, asset-browser, atmosphere, auto-rig, autotile, bake-out, canvas-item, clothing, color-clash, cooking, cozy, crouch-slide, exr, farming, fingers, flowmaps, foley, game-sfx, gameplay-programming, gta-format, importer, kinect, kufi, latent-actions, lidar-derived, low-vision, milky-way, multilingual, multithreading, mvs, naskh, netherlands, nintendo-64, pan-cjk, pets, power-tools, rpg-maker, save-system, sentinel, skybox, soft-body, spatial, splitter, steamworks, substance, threejs, ui-strings, vi-like, vintage

check-added
node site/check-added.mjs

check-added ok: 467 entries, no added date later than its first commit

build
node site/build.mjs

Built 467 entries → site/dist (399 active, 423 commercial-ok, 21 per-file)
Prerendered 464 entry rows into index.html; wrote 467 entry pages, 9 stack pages, 10 category pages, 6 alternatives pages, 15 guide pages, sitemap.xml, robots.txt, 404.html, freshness/index.html
389 of 1649 output files changed; 2.8s).

AI note

This patch was written with AI assistance; every check listed above was run in the environment where the patch was built.

Fixes #341

- Use cliArgs for strict flag parsing (mistyped flags now fail with usage)
- Reject non-object JSON-RPC messages with -32600 (scalar, null, array)
- Wrap handle() in try/catch to return -32603 on internal errors
- Clamp search_assets limit to documented 1..100 range
- Extract line handling to processLine() for testability

Fixes TMHSDigital#341
@TMHSDigital
TMHSDigital merged commit b4a3ece into TMHSDigital:main Dec 4, 2026
2 checks passed
TMHSDigital added a commit that referenced this pull request Dec 4, 2026
Resolves the overlap with #366 in site/cli/mcp.mjs and applies the review
changes for both:

- mcp.mjs main(argv) parses the argv it is given in strict mode, so
  `fgda mcp --data x` works and a mistyped flag stops with the usage line.
- The line handler is the exported replyTo(), with tests for bad JSON,
  non-object messages, a throwing tool call and the 1 to 100 limit (#341).
- The run guard in fgda.mjs and mcp.mjs compares real paths, so the CLI
  runs through the symlink npm makes for a package bin. Without this the
  npx command these docs give did nothing on Linux and macOS (#334).
- Restores the indentation of one line touched in #363.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@TMHSDigital

Copy link
Copy Markdown
Owner

Merged in 84c9d56, thanks. Three changes on our side while landing it with #364: the line handler is now the exported replyTo(), with tests for bad JSON, non-object messages, a throwing tool call and the limit clamp; main() parses the argv it is given, so it also works when started as fgda mcp; and a bad flag exits 2 with the usage line.

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.

MCP server exits on a malformed message or a throwing tool call

2 participants