A3: accept a BOM before the first MCP message; plural-free Problems summary

Found by A2 while writing the alpha checklist: Windows PowerShell 5.1
prefixes piped stdin with a BOM, which lutra mcp rejected; the Problems
summary read "1 errors".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-10-31 14:42:14 +01:00
parent 68599fa2ac
commit c3acd9f60a
3 changed files with 10 additions and 2 deletions

View file

@ -53,7 +53,11 @@ pub enum Incoming {
/// The error response line to send back: a parse error for invalid
/// JSON, invalid request for anything that is not a single JSON-RPC 2.0
/// message, invalid params for params that are not an object.
///
/// A leading byte order mark is dropped first: Windows PowerShell 5.1
/// writes one when it pipes text into a native program.
pub fn parse(line: &str) -> Result<Incoming, String> {
let line = line.strip_prefix('\u{feff}').unwrap_or(line);
let value: Value = serde_json::from_str(line)
.map_err(|e| error(&Value::Null, codes::PARSE_ERROR, &e.to_string(), None))?;
let Value::Object(mut object) = value else {
@ -176,6 +180,10 @@ mod tests {
};
assert_eq!(id, json!("a"));
assert_eq!(params["k"], 1);
assert!(matches!(
parse("\u{feff}{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"ping\"}"),
Ok(Incoming::Request { .. })
));
assert_eq!(
parse(r#"{"jsonrpc":"2.0","method":"notifications/initialized"}"#).unwrap(),
Incoming::Notification {