Skip to content

Commit 39629e2

Browse files
bhosmer-antClaude
and
Claude
committed
fix: preserve custom paths in SSE endpoint URLs
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]>
1 parent 35fe98a commit 39629e2

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/client/sse.ts

+11
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,18 @@ export class SSEClientTransport implements Transport {
143143
const messageEvent = event as MessageEvent;
144144

145145
try {
146+
// Use the original URL as the base to resolve the received endpoint
146147
this._endpoint = new URL(messageEvent.data, this._url);
148+
149+
// If the original URL had a custom path, preserve it in the endpoint URL
150+
const originalPath = this._url.pathname;
151+
if (originalPath && originalPath !== '/' && originalPath !== '/sse') {
152+
// Extract the base path from the original URL (everything before the /sse suffix)
153+
const basePath = originalPath.replace(/\/sse$/, '');
154+
// The endpoint should use the same base path but with /messages instead of /sse
155+
this._endpoint.pathname = basePath + '/messages';
156+
}
157+
147158
if (this._endpoint.origin !== this._url.origin) {
148159
throw new Error(
149160
`Endpoint origin does not match connection origin: ${this._endpoint.origin}`,

0 commit comments

Comments
 (0)