Skip to content

feat(server): add option to customize basePath #45

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

Merged
merged 2 commits into from
Mar 10, 2025

Conversation

zoedsoupe
Copy link
Contributor

@zoedsoupe zoedsoupe commented Mar 7, 2025

Close #44

Summary by CodeRabbit

  • New Features
    • Added a configurable option to set a base path for server endpoints, ensuring improved URL formatting. This enhances routing clarity and overall flexibility in handling server-sent events.
    • Introduced a new test case to validate server behavior with the custom base path, including checks for correct responses and error handling.

Copy link
Contributor

coderabbitai bot commented Mar 7, 2025

Walkthrough

The changes introduce a new configuration option for the SSEServer to set a basePath, enhancing its URL handling capabilities. A new method, WithBasePath, is added to validate and set the basePath, and a new field basePath is included in the SSEServer struct. The ServeHTTP method is modified to construct full paths for the SSE and message endpoints using the basePath, employing exact path matching instead of a switch statement.

Changes

File Summary
server/sse.go Added the WithBasePath method and a basePath field to SSEServer. Modified ServeHTTP to construct full paths using basePath and implement exact path matching.
server/sse_test.go Updated TestSSEServer to include the new WithBasePath parameter. Added checks for the updated baseURL and basePath, and introduced a new test case to validate the SSE server's behavior with the custom base path.

Possibly related PRs

  • Expose SSE server as HttpHandler #29: Enhancements to the SSEServer with a new basePath configuration and modifications to ServeHTTP, related to the initial implementation of the ServeHTTP method without the basePath functionality.
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.

@zoedsoupe zoedsoupe changed the title feat: add option to customize basePath feat(server): add option to customize basePath Mar 7, 2025
@ezynda3 ezynda3 self-assigned this Mar 10, 2025
@ezynda3
Copy link
Contributor

ezynda3 commented Mar 10, 2025

@zoedsoupe This is great! Thanks for the contribution. Would you be able to add one or two simple tests just to show this works as intended? Cheers!

@zoedsoupe
Copy link
Contributor Author

@ezynda3 done! is that ok?

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_test.go (1)

418-470: LGTM - Comprehensive test case for custom basePath functionality

This test case is well-structured and thoroughly tests the custom basePath functionality:

  1. Verifies 404 for requests without the basePath
  2. Confirms successful responses with the basePath
  3. Includes proper resource cleanup

One small suggestion for line 439: consider using path.Join or similar to avoid potential issues with slash concatenation, though the current implementation works as expected with the tested values.

- sseURL := fmt.Sprintf("%s/sse", ts.URL+sseServer.basePath)
+ sseURL := fmt.Sprintf("%s%s/sse", ts.URL, sseServer.basePath)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 48d2867 and 5be191e.

📒 Files selected for processing (2)
  • server/sse.go (5 hunks)
  • server/sse_test.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • server/sse.go
🧰 Additional context used
🪛 golangci-lint (1.62.2)
server/sse_test.go

27-27: SA5011: possible nil pointer dereference

(staticcheck)


24-24: SA5011(related information): this check suggests that the pointer can be nil

(staticcheck)


30-30: SA5011: possible nil pointer dereference

(staticcheck)

🔇 Additional comments (3)
server/sse_test.go (3)

19-22: LGTM - Correctly implemented basePath option

The addition of WithBasePath("/mcp") option aligns with the PR's objective to allow customization of the basePath.


30-35: LGTM - Proper baseURL verification

The test now correctly checks that the baseURL is composed of both the base URL and the basePath.

🧰 Tools
🪛 golangci-lint (1.62.2)

30-30: SA5011: possible nil pointer dereference

(staticcheck)


36-41: LGTM - Good test coverage for the new field

The new assertion properly verifies that the basePath field is correctly set to "/mcp".

@ezynda3 ezynda3 merged commit 468b381 into mark3labs:main Mar 10, 2025
2 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Mar 21, 2025
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.

How can I plug it into an existing net/http server?
2 participants