-
Notifications
You must be signed in to change notification settings - Fork 811
Improve SSE endpoint sessionId parameter handling #177
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
Conversation
Add dynamic query parameter separator for sessionId to handle endpoints with existing query parameters more robustly
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.
Thanks for flagging. To fix this more robustly, can you please use URL
and URLSearchParams
?
@jspahrsummers Thanks! Updated the code to use URL and URLSearchParams for adding the sessionId parameter, handling the relative path correctly. Pushed the changes. |
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.
Thank you! I underestimated how complex this would be (because of the need for URL
s to always be absolute), so can you please add some tests as well?
@jspahrsummers Okay, I've added unit tests covering various relative endpoint scenarios (simple path, with query params, with hash fragment, root path, empty path) as requested. All tests are passing now. Thanks for the suggestion! |
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.
Great, thank you!
* do not remove search params and hash from mcp endpoint message Reference: modelcontextprotocol/typescript-sdk#177 * Create twenty-jeans-love.md * pass checks --------- Co-authored-by: Sunil Pai <[email protected]> Co-authored-by: Sunil Pai <[email protected]>
…fig-file-support Add CLI and config file support
Add dynamic query parameter separator for sessionId to handle endpoints with existing query parameters more robustly
This PR improves the URL construction when adding the sessionId parameter to endpoints by dynamically selecting the appropriate separator ('?' or '&') based on whether the endpoint already contains query parameters.
Motivation and Context
When constructing the endpoint URL with the sessionId parameter, the code needs to determine whether to use '?' or '&' as a separator. If the endpoint already contains query parameters (e.g.,
/messages?filter=all
), we should use '&' to append additional parameters. Otherwise, if there are no existing query parameters (e.g.,/messages
), we should use '?' to start the query string.This change ensures that the SSE endpoint URLs are correctly formed regardless of whether the original endpoint already contains query parameters, preventing malformed URLs in the SSE connection.
How Has This Been Tested?
Tested with various endpoint formats:
/messages
→/messages?sessionId=xxx
/messages?filter=all
→/messages?filter=all&sessionId=xxx
Breaking Changes
None. This is a non-breaking change that improves the robustness of URL handling without requiring any changes to user code.
Types of changes
Checklist
Additional context
The implementation uses a simple check for the presence of '?' in the endpoint string. While this approach works for standard endpoints, it has a limitation: it doesn't handle the edge case where '?' might be part of the path itself rather than a query parameter separator. However, this is an extremely rare case in practice, and the simplicity of the solution outweighs the benefit of handling such edge cases.