Repository navigation
fix(mcp): a bare 'null' JSON-RPC line must not crash the server #2511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -144,6 +144,11 @@ export async function runMcpServer(): Promise<void> { | |||||
| // Unparseable line → cannot attribute an id; drop it (no id to reply to). | ||||||
| return; | ||||||
| } | ||||||
| // A JSON-RPC request must be a non-null object. `JSON.parse('null')` and bare | ||||||
| // primitives are valid JSON but carry no id to attribute — drop them like an | ||||||
| // unparseable line. Without this, `dispatch(null)` (and the catch below) throw | ||||||
| // on `null.id`, and the uncaught error crashes the server on a `null` line. | ||||||
| if (req === null || typeof req !== 'object') return; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While
Suggested change
|
||||||
| try { | ||||||
| dispatch(req); | ||||||
| } catch (e) { | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add an empty array
[]to the list of raw malformed lines to verify that the server also safely drops arrays without crashing or processing them.