Skip to content

Commit d13d0ef

Browse files
committed
mcp: simplify the initialize check and reword comments from review
1 parent fda1087 commit d13d0ef

1 file changed

Lines changed: 7 additions & 15 deletions

File tree

  • src/environmentd/src/http

‎src/environmentd/src/http/mcp.rs‎

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,8 @@ pub(crate) struct McpRequest {
378378
method: McpMethod,
379379
}
380380

381-
/// Reads a present `id` as `Some`, `null` included. JSON-RPC makes only a
382-
/// missing `id` a notification, and `Option` alone would read `null` as `None`.
381+
/// Wraps a `null` id in `Some`, so it stays a request. A missing `id` is `None`
382+
/// through `#[serde(default)]` on the field, and only that is a notification.
383383
fn present_id<'de, D>(deserializer: D) -> Result<Option<serde_json::Value>, D::Error>
384384
where
385385
D: serde::Deserializer<'de>,
@@ -1176,18 +1176,10 @@ fn answer_parse_failure(
11761176
McpRequestError::InvalidParams(message),
11771177
),
11781178
(true, Err(err)) => (StatusCode::BAD_REQUEST, err),
1179-
// Of the methods whose params can fail to parse, 2026-07-28
1180-
// keeps these two and drops `initialize`.
1181-
(true, Ok(()))
1182-
if !raw
1183-
.method()
1184-
.is_some_and(|name| matches!(name, "tools/list" | "tools/call")) =>
1185-
{
1186-
(
1187-
StatusCode::NOT_FOUND,
1188-
McpRequestError::MethodNotFound("unknown method".to_string()),
1189-
)
1190-
}
1179+
(true, Ok(())) if raw.method() == Some("initialize") => (
1180+
StatusCode::NOT_FOUND,
1181+
McpRequestError::MethodNotFound("unknown method".to_string()),
1182+
),
11911183
(true, Ok(())) => (StatusCode::OK, McpRequestError::InvalidParams(message)),
11921184
}
11931185
}
@@ -1293,7 +1285,7 @@ async fn handle_mcp_method(
12931285
.await
12941286
}
12951287
// Dual-era clients probe with `server/discover` and fall back to
1296-
// `initialize` when 2025-11-25 answers it with -32601.
1288+
// `initialize` when 2025-11-25 answers it with a not found error.
12971289
McpMethod::ServerDiscover(_) if protocol.is_modern() => {
12981290
debug!(endpoint = %endpoint_type, "Processing server/discover");
12991291
handle_discover(

0 commit comments

Comments
 (0)