fix(server): return stdio parse errors

Closed
HE
1mo ago
+34962-15

Summary

  • make the stdio server return JSON-RPC error frames when incoming lines fail JSON-RPC parsing/validation
  • recover a simple request id from the raw line when possible so id-bearing malformed requests do not stay pending
  • keep later valid stdio messages flowing after an invalid line

Fixes #2751.

To verify

  • uv run pytest tests/server/test_stdio.py -q
  • uv run ruff check src/mcp/server/stdio.py tests/server/test_stdio.py
  • uv run pyright src/mcp/server/stdio.py tests/server/test_stdio.py
  • git diff --check