Invalid JSON and malformed parameters return InvalidParams
Why it matters
Malformed JSON is a normal input condition in production — network truncation, client bugs, and injection attempts all produce broken payloads. A server that crashes on JSON.parse() failure (CWE-1286: improper validation of syntactic correctness) takes down all tools with no error sent to the client. OWASP A03 (Injection) is the active risk when valid JSON with adversarial parameter values reaches a handler that doesn't validate types or required fields. CWE-20 (improper input validation) covers both: the server must reject bad input before it reaches business logic.
Severity rationale
High because malformed input can crash the server process (denying all tools) or reach handlers that execute with unvalidated, attacker-controlled values.
Remediation
The MCP SDK handles JSON parse errors at the transport layer. For custom implementations, wrap JSON.parse explicitly and validate parameters before handler dispatch.
// src/transport/handler.ts
function processMessage(raw: string) {
let message
try {
message = JSON.parse(raw)
} catch {
// id is unknown when JSON is invalid — use null
return { jsonrpc: '2.0', id: null, error: { code: -32700, message: 'Parse error: invalid JSON' } }
}
if (message.method === 'tools/call' && !message.params?.name) {
return {
jsonrpc: '2.0', id: message.id,
error: { code: -32602, message: 'Invalid params: missing required field "name"' }
}
}
// ... dispatch
}
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the MCP Server Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- cwe · CWE-20 — Improper Input Validation
- cwe · CWE-1286 — Improper Validation of Syntactic Correctness of Input
- owasp:2021 · A03
- external · jsonrpc-2.0-parse-error — JSON-RPC 2.0 Specification — Parse error (-32700) and Invalid params (-32602)
Taxons
History
- 2026-04-18·v1.0.0·Initial import from mcp-server·automated