Skip to content

fix: preserve custom paths in SSE endpoint URLs #466

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

bhosmer-ant
Copy link
Contributor

Summary

When an SSE client connects with a custom path (e.g., /api/v1/custom/sse), ensure the endpoint URL maintains the same base path structure but with /messages instead of /sse. This fixes issues where custom endpoints were getting collapsed to the root path.

Problem

The SSE client was not preserving custom paths when constructing endpoint URLs. When a client connected to a server at a custom path like /api/v1/custom/sse, the endpoint URL would be constructed without preserving the custom path, resulting in POST requests being sent to /messages instead of /api/v1/custom/messages.

Solution

Modified the endpoint event handler in the SSE client to:

  1. Check if the original connection URL contains a custom path
  2. Extract the base path (removing the /sse suffix)
  3. Apply the base path to the endpoint URL with /messages suffix

Testing

This PR makes the failing tests from #439 pass. The tests verify that:

  • Custom paths are preserved when constructing endpoint URLs
  • Multiple levels of paths are handled correctly
  • Query parameters are handled appropriately

Related Issues

Test Plan

🤖 Generated with Claude Code

When an SSE client connects with a custom path (e.g., /api/v1/custom/sse),
ensure the endpoint URL maintains the same base path structure but with
/messages instead of /sse. This fixes issues where custom endpoints were
getting collapsed to the root path.

Should fix issues reported in modelcontextprotocol/inspector#313 and #296
Tests demonstrating the issue were added in PR #439

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@bhosmer-ant bhosmer-ant requested a review from ihrpr May 8, 2025 17:32
@ihrpr
Copy link
Contributor

ihrpr commented May 9, 2025

should we include those filing tests in this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants