Skip to content

fix: preserve custom paths in SSE endpoint URLs - #466

Merged
ihrpr merged 2 commits into
mainfrom
fix/sse-custom-endpoint-paths
May 12, 2025
Merged

fix: preserve custom paths in SSE endpoint URLs#466
ihrpr merged 2 commits into
mainfrom
fix/sse-custom-endpoint-paths

Conversation

@bhosmer-ant

Copy link
Copy Markdown
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 ihrprMay 8, 2025 17:32
@ihrpr

ihrpr commented May 9, 2025

Copy link
Copy Markdown
Contributor

should we include those filing tests in this PR

bhosmer-antand 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 <noreply@anthropic.com>
@bhosmer-ant
bhosmer-antforce-pushed the fix/sse-custom-endpoint-paths branch from 39629e2 to 2f522bfCompareMay 12, 2025 15:28
@bhosmer-ant

bhosmer-ant commented May 12, 2025

Copy link
Copy Markdown
ContributorAuthor

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

@ihrprihrpr left a comment

Copy link
Copy Markdown
Contributor

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 mainMay 12, 2025
@ihrpr
ihrpr deleted the fix/sse-custom-endpoint-paths branch May 12, 2025 16:24
@onlysyz

Copy link
Copy Markdown

@ihrpr do you have a plan for this release?

@chrisdickinson

Copy link
Copy Markdown

As a heads up, this breaks SSE integrations with mcp.run – we were sending the full SSE endpoint down to support the python-sdk and now the endpoint pathname is being rewritten to /messages.

@bhosmer-antbhosmer-ant mentioned this pull request May 16, 2025
8 tasks
@bhosmer-ant

bhosmer-ant commented May 16, 2025

Copy link
Copy Markdown
ContributorAuthor

As a heads up, this breaks SSE integrations with mcp.run – we were sending the full SSE endpoint down to support the python-sdk and now the endpoint pathname is being rewritten to /messages.

@chrisdickinson thanks for catching - #504 should fix, though it couldn't hurt to verify

[edit: not that simple, reverted path preservation and will revisit]

Sign up for freeto 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.

Incorrect URL in sse.js when providing a custom path Routes other than root ("/") for remote MCP servers don't seem to be supported.

5 participants

@bhosmer-ant@ihrpr@onlysyz@chrisdickinson@olaservo