Skip to content

Commit 6be4c60

Browse files
authored
Merge pull request #504 from modelcontextprotocol/basil/fix_path_preservation
fix sse endpoint path preservation
2 parents 1fd6265 + 00cb920 commit 6be4c60

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

src/client/sse.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ describe("SSEClientTransport", () => {
8787
await transport.send(message);
8888

8989
// Verify the POST request maintains the custom path
90-
expect(lastServerRequest.url).toBe("/custom/path/messages");
90+
expect(lastServerRequest.url).toBe("/custom/path/sse");
9191
});
9292

9393
it("handles multiple levels of custom paths", async () => {
@@ -107,7 +107,7 @@ describe("SSEClientTransport", () => {
107107
await transport.send(message);
108108

109109
// Verify the POST request maintains the full custom path
110-
expect(lastServerRequest.url).toBe("/api/v1/custom/deep/path/messages");
110+
expect(lastServerRequest.url).toBe("/api/v1/custom/deep/path/sse");
111111
});
112112

113113
it("maintains custom path for SSE connection", async () => {
@@ -130,7 +130,7 @@ describe("SSEClientTransport", () => {
130130
};
131131

132132
await transport.send(message);
133-
expect(lastServerRequest.url).toBe("/custom/path/messages");
133+
expect(lastServerRequest.url).toBe("/custom/path/sse");
134134
});
135135

136136
it("establishes SSE connection and receives endpoint", async () => {

src/client/sse.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,7 @@ export class SSEClientTransport implements Transport {
147147
this._endpoint = new URL(messageEvent.data, this._url);
148148

149149
// 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-
}
150+
this._endpoint.pathname = this._url.pathname;
157151

158152
if (this._endpoint.origin !== this._url.origin) {
159153
throw new Error(

0 commit comments

Comments
 (0)