diff --git a/src/mcp.rs b/src/mcp.rs index 355bbb1..aa1f039 100644 --- a/src/mcp.rs +++ b/src/mcp.rs @@ -105,13 +105,13 @@ impl<'de> Deserialize<'de> for Envelope { fn visit_map>(self, mut map: A) -> Result { let mut object = serde_json::Map::new(); while let Some(key) = map.next_key::()? { - if matches!(key.as_str(), "jsonrpc" | "id" | "result" | "error") - && object.contains_key(&key) + if matches!( + key.as_str(), + "jsonrpc" | "id" | "method" | "params" | "result" | "error" + ) && object.contains_key(&key) { return Err(A::Error::custom("duplicate JSON-RPC envelope field")); } - // Only reserved envelope fields need uniqueness here. - // Tool results remain opaque JSON, without a local schema. object.insert(key, map.next_value::()?); } Ok(Envelope(Value::Object(object))) diff --git a/tests/mcp.rs b/tests/mcp.rs index d6c2669..7d58f93 100644 --- a/tests/mcp.rs +++ b/tests/mcp.rs @@ -989,6 +989,18 @@ async fn bounded_frames_serial_backpressure_and_broken_stdout_release_the_actual -32600, "jsonrpc", ), + ( + b"{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"initialize\",\"method\":\"ping\"}\n".to_vec(), + false, + -32600, + "jsonrpc", + ), + ( + b"{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"initialize\",\"params\":{},\"params\":{}}\n".to_vec(), + false, + -32600, + "jsonrpc", + ), ] { let fixture = Fixture::start().await; let mut bridge = Bridge::start(&fixture.origin, ORG);