Conversation
|
The prefix-based field extraction fixes the Unicode-line-separator truncation, but I think one SSE whitespace bug remains in the same path. At event dispatch, String eventData = this.eventBuilder.toString();
SseEvent sseEvent =
new SseEvent(currentEventId.get(), currentEventType.get(), eventData.trim());Per SSE parsing, each The current new test avoids this by putting the second significant space on an interior line: so List<SseEvent> events = parse(List.of("data: first ", ""));
assertThat(events.get(0).data()).isEqualTo(" first ");I expect the current PR head still returns Since this PR is already replacing regex/trim-based extraction with the SSE field rule, it seems worth removing the whole-event |
98c9150 to
100e402
Compare
|
You're absolutely right — thank you for catching this. The Fixed along the lines you suggested: dispatching now only removes the single trailing separator that the Everything passes locally (7/7 in |
|
Verified the updated head. The whole-event That addresses my review point. Thanks for turning it around quickly. |
What
SseLineSubscriberextracteddata:,id:andevent:values withMULTILINEregexes. The Java regex engine treats U+2028 (LINE SEPARATOR), U+2029 (PARAGRAPH SEPARATOR) and U+0085 (NEXT LINE) as line terminators, so^data:(.+)$matched only a prefix of any line containing one of those characters — and everything after it was silently discarded. The client then failed to deserialise the truncated JSON and threwMcpTransportException: Error parsing JSON-RPC message.This PR removes the three regexes and extracts field values per the SSE specification: the characters after the colon with a single leading space removed. The line splitter feeding the subscriber (
fromLineSubscriber) only splits on\n,\rand\r\n, so those characters now arrive inside a line and are preserved intact.Why
Fixes #1136. Any tool result, resource content or prompt text containing one of these characters — they are legal unescaped inside a JSON string, and they turn up in real content such as text pasted from word processors, web pages and PDFs — was unreadable by the client.
How it was checked
ResponseSubscribersTestasserts that adata:payload containing each of the three characters is preserved byte-for-byte, that a vertical tab still works, that only a single leading space is stripped per data line, and that multi-linedata:accumulation plusid:/event:values containing those characters are captured intact.mvn -pl mcp-core verifypasses, including the spring-javaformat validation.Notes
trim()was dropped together with the regex, matching the reporter's suggested fix: per the SSE spec only one leading space is stripped, so interior whitespace is no longer mangled. The existing whole-eventtrim()behaviour at dispatch is unchanged.Fixes #1136