-
Notifications
You must be signed in to change notification settings - Fork 2k
[mcp] replace SSE event parser with logic from official go-sdk #62713
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
|
||
| // empty reports whether the Event is empty. | ||
| func (e event) empty() bool { | ||
| return e.name == "" && e.id == "" && len(e.data) == 0 && e.retry == "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So close to return e == event{}, yet so far. (No action required.)
| // https://github.com/modelcontextprotocol/go-sdk/blob/a225d4dc7ded92f5492651a1bc60499b3be27044/mcp/event.go#L44 | ||
| var b bytes.Buffer | ||
| if e.name != "" { | ||
| fmt.Fprintf(&b, "event: %s\n", e.name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separate write calls would be better. The types are all string or []byte, so there's not even need for strconv and the likes.
b.WriteString("event : ")
b.WriteString(e.name)
b.WriteRune('\n')OK to push back if you'd rather keep it like the original.
| ) | ||
|
|
||
| // event is an event is a server-sent event. | ||
| // Copied from official go-sdk with minor modification (make all fields private): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any chance we could move all the copied code in its owns files, separate from stuff we've written ourselves?
fixes #62334
changelog: fix an issuse
MCP Session Listenevents may spam audit log with service errormalformed line in SSE stream: ""there is a bug in the current SSE event reader. this change replace it with the latest code from the official go-sdk:
https://github.com/modelcontextprotocol/go-sdk/blob/main/mcp/event.go
(unfortunately we cannot call the function directly atm)
besides copying some tests from the SDK, all existing tests also passed. and manually tested that the bug no longer happens.