Skip to content

feat(SSEServer): add WithAppendQueryToMessageEndpoint() #136

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

liut
Copy link

@liut liut commented Apr 12, 2025

Configures the SSE server to append the original request's RawQuery to message endpoint.

The WithAppendQueryToMessageEndpoint configures the SSE server to append the query string of the original request to the message endpoint URL sent to the client during SSE connection initialization. This is useful when it is necessary to retain the query parameters from the initial SSE connection request and pass them on to subsequent message requests, thereby maintaining context, target orientation, and authentication details throughout the communication channel.

For examples:

## handleSSE
GET      "/mcp/sse?token=ohmy-tk-4nz4rc3vmwao"
## handleMessage
POST     "/mcp/message?sessionId=8c82d889-e63d-4b4b-80f9-9acfb96cd2ce&token=ohmy-tk-4nz4rc3vmwao"

Summary by CodeRabbit

  • New Features
    • Improved streaming connection setup: The system now appends query parameters from your initial request to the message endpoint URL. This enhancement helps preserve context and can improve session handling during communications.

Copy link
Contributor

coderabbitai bot commented Apr 12, 2025

Walkthrough

This pull request introduces a new boolean field appendQueryToMessageEndpoint in the SSEServer struct to control whether the original request's query parameters should be appended to the message endpoint URL during SSE connection initialization. It adds the WithAppendQueryToMessageEndpoint function to set this flag and updates the handleSSE method to conditionally append query parameters when the flag is enabled and present in the incoming request.

Changes

File(s) Change Summary
server/sse.go - Added the appendQueryToMessageEndpoint boolean field to the SSEServer struct.
- Introduced the WithAppendQueryToMessageEndpoint function.
- Updated the handleSSE method to append query parameters to the message endpoint URL when the flag is enabled and query parameters are present.

Possibly related PRs

  • fix java mcp message endpoint #75: Modifies SSEServer struct by adding boolean fields controlling message endpoint URL construction, affecting handleSSE logic similarly.

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3b27053 and efe46f7.

📒 Files selected for processing (1)
  • server/sse.go (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • server/sse.go

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
server/sse.go (1)

309-314: Consider a more robust approach for appending query parameters.

While the current implementation works correctly with the existing GetMessageEndpointForClient function (which always includes a sessionId parameter), it could be more robust to handle edge cases:

  1. The code assumes the endpoint already contains parameters and always uses & as a separator
  2. If the request query already contains a sessionId parameter, this would create duplicate parameters

Consider this more robust implementation:

  endpoint := s.GetMessageEndpointForClient(sessionID)
  if s.appendQueryToMessageEndpoint && len(r.URL.RawQuery) > 0 {
-   endpoint += "&" + r.URL.RawQuery
+   // Parse the original query to potentially filter parameters
+   originalQuery, _ := url.ParseQuery(r.URL.RawQuery)
+   
+   // Remove sessionId if present to avoid duplication
+   originalQuery.Del("sessionId")
+   
+   // Only append if there are remaining parameters
+   if len(originalQuery) > 0 {
+     if strings.Contains(endpoint, "?") {
+       endpoint += "&" + originalQuery.Encode()
+     } else {
+       endpoint += "?" + originalQuery.Encode()
+     }
+   }
  }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b8dc82d and 39e1423.

📒 Files selected for processing (1)
  • server/sse.go (4 hunks)
🔇 Additional comments (2)
server/sse.go (2)

116-125: Well-documented function with clear purpose.

The WithAppendQueryToMessageEndpoint function follows the established pattern of option functions and includes comprehensive documentation that clearly explains its purpose and use cases.


69-69: Good structural placement of the new field.

The new appendQueryToMessageEndpoint boolean field is appropriately placed at the end of the struct definition, maintaining backward compatibility and following the established pattern for feature flags in this struct.

@liut liut force-pushed the feature/w549-with-append-query branch 2 times, most recently from 65b2789 to 3b27053 Compare April 17, 2025 08:48
@kangkang66
Copy link

Hi there,

I hope you're doing well. I'm reaching out to kindly request the review and merge of PR #136 as soon as possible. This change is critical for our business operations, and we're currently blocked pending its inclusion in the main branch.

We really appreciate the work you're doing on this project and would be extremely grateful if this PR could be prioritized. Please let me know if there's anything I can do to help expedite the process.

Thanks in advance for your time and support!

Best regards

configures the SSE server to append the original request's RawQuery to message endpoint
@liut liut force-pushed the feature/w549-with-append-query branch from 3b27053 to efe46f7 Compare April 21, 2025 07:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants