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

Merged
merged 2 commits into from
May 12, 2025

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

@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

bhosmer-ant and others added 2 commits May 12, 2025 11:09
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 <[email protected]>
@bhosmer-ant bhosmer-ant force-pushed the fix/sse-custom-endpoint-paths branch from 39629e2 to 2f522bf Compare May 12, 2025 15:28
@bhosmer-ant
Copy link
Contributor Author

bhosmer-ant commented May 12, 2025

@ihrpr brought the tests over - note, dropped the change to package-lock.json

Copy link
Contributor

@ihrpr ihrpr left a comment

Choose a reason for hiding this comment

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

LGTM

@ihrpr ihrpr merged commit 68a0ca3 into main May 12, 2025
5 checks passed
@ihrpr ihrpr deleted the fix/sse-custom-endpoint-paths branch May 12, 2025 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants