Skip to content

cowork: reject non-object JSON-RPC payloads with -32600 instead of crashing - #40

Draft
Coding-Dev-Tools wants to merge 1 commit into
masterfrom
cowork/improve-click-to-mcp
Draft

cowork: reject non-object JSON-RPC payloads with -32600 instead of crashing#40
Coding-Dev-Tools wants to merge 1 commit into
masterfrom
cowork/improve-click-to-mcp

Conversation

@Coding-Dev-Tools

Copy link
Copy Markdown
Owner

A JSON body that parses but is not an object ([1,2], "x", 5, null) reached msg.get(...) outside the per-request try/except in all three transports:

  • stdio (server.py): AttributeError killed the entire server loop — every subsequent request was lost.
  • HTTP+SSE (http_server.py) and Streamable HTTP (streamable_http.py): unhandled AttributeError → Starlette 500.

Now: stdio replies with JSON-RPC -32600 Invalid Request and keeps serving; both HTTP transports return 400 with the same error. Adds tests/test_invalid_request_payloads.py (7 regression tests, all transports + server-survives check).

Full suite: 210 passed, ruff clean.

…f crashing

A JSON body that parses but is not an object ([1,2], "x", 5, null)
reached msg.get() outside the per-request try/except in all three
transports: the stdio server loop died with AttributeError and both
HTTP transports returned 500. Now stdio replies with a JSON-RPC
-32600 Invalid Request error and keeps serving; HTTP transports
return 400 with the same error. Adds regression tests for all three.
@github-actions

Copy link
Copy Markdown

🤖 Automated Code Review

✅ Ruff Lint — No issues

⚠️ Ruff Format — Formatting needed

unformatted: File would be reformatted
   --> README.md:220:1
    |
219 |
220 +
221 | @click.group()
--------------------------------------------------------------------------------
225 |
226 +
227 | @my_cli.command()
--------------------------------------------------------------------------------
236 |
237 +
238 | if __name__ == "__main__":
--------------------------------------------------------------------------------
276 |
277 +
278 | @click.group()
--------------------------------------------------------------------------------
282 |
283 +
284 | @cli.command()
--------------------------------------------------------------------------------
290 |
291 +
292 | # Run as MCP server
--------------------------------------------------------------------------------
377 |
378 +
379 | @app.command()

✅ Secret Detection — Clean

✅ Large Files — Within limits

📊 Diff Stats — 4 file(s) changed

 click_to_mcp/http_server.py            |   8 +++
 click_to_mcp/server.py                 |  11 ++++
 click_to_mcp/streamable_http.py        |   7 +++
 tests/test_invalid_request_payloads.py | 100 +++++++++++++++++++++++++++++++++
 4 files changed, 126 insertions(+)

Verdict: ⚠️ Warnings — Lint/format issues found. Recommend fixing before merge.

Automated by Coding-Dev-Tools/.github reusable workflow.

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