Skip to content

Commit cdab12a

Browse files
authored
Merge pull request #339 from cliffhall/fix-streamable-endpoint
Fix support for streamable-http connections
2 parents 2e4a522 + 966f95b commit cdab12a

File tree

5 files changed

+216
-34
lines changed

5 files changed

+216
-34
lines changed

client/jest.config.cjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
preset: "ts-jest",
3-
testEnvironment: "jsdom",
3+
testEnvironment: "jest-fixed-jsdom",
44
moduleNameMapper: {
55
"^@/(.*)$": "<rootDir>/src/$1",
66
"\\.css$": "<rootDir>/src/__mocks__/styleMock.js",

client/src/lib/hooks/useConnection.ts

+36-11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
SSEClientTransport,
44
SseError,
55
} from "@modelcontextprotocol/sdk/client/sse.js";
6+
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
67
import {
78
ClientNotification,
89
ClientRequest,
@@ -278,15 +279,29 @@ export function useConnection({
278279
setConnectionStatus("error-connecting-to-proxy");
279280
return;
280281
}
281-
const mcpProxyServerUrl = new URL(`${getMCPProxyAddress(config)}/sse`);
282-
mcpProxyServerUrl.searchParams.append("transportType", transportType);
283-
if (transportType === "stdio") {
284-
mcpProxyServerUrl.searchParams.append("command", command);
285-
mcpProxyServerUrl.searchParams.append("args", args);
286-
mcpProxyServerUrl.searchParams.append("env", JSON.stringify(env));
287-
} else {
288-
mcpProxyServerUrl.searchParams.append("url", sseUrl);
282+
let mcpProxyServerUrl;
283+
switch (transportType) {
284+
case "stdio":
285+
mcpProxyServerUrl = new URL(`${getMCPProxyAddress(config)}/stdio`);
286+
mcpProxyServerUrl.searchParams.append("command", command);
287+
mcpProxyServerUrl.searchParams.append("args", args);
288+
mcpProxyServerUrl.searchParams.append("env", JSON.stringify(env));
289+
break;
290+
291+
case "sse":
292+
mcpProxyServerUrl = new URL(`${getMCPProxyAddress(config)}/sse`);
293+
mcpProxyServerUrl.searchParams.append("url", sseUrl);
294+
break;
295+
296+
case "streamable-http":
297+
mcpProxyServerUrl = new URL(`${getMCPProxyAddress(config)}/mcp`);
298+
mcpProxyServerUrl.searchParams.append("url", sseUrl);
299+
break;
289300
}
301+
(mcpProxyServerUrl as URL).searchParams.append(
302+
"transportType",
303+
transportType,
304+
);
290305

291306
try {
292307
// Inject auth manually instead of using SSEClientTransport, because we're
@@ -304,14 +319,24 @@ export function useConnection({
304319
headers[authHeaderName] = `Bearer ${token}`;
305320
}
306321

307-
const clientTransport = new SSEClientTransport(mcpProxyServerUrl, {
322+
// Create appropriate transport
323+
const transportOptions = {
308324
eventSourceInit: {
309-
fetch: (url, init) => fetch(url, { ...init, headers }),
325+
fetch: (
326+
url: string | URL | globalThis.Request,
327+
init: RequestInit | undefined,
328+
) => fetch(url, { ...init, headers }),
310329
},
311330
requestInit: {
312331
headers,
313332
},
314-
});
333+
};
334+
const clientTransport =
335+
transportType === "streamable-http"
336+
? new StreamableHTTPClientTransport(mcpProxyServerUrl as URL, {
337+
sessionId: undefined,
338+
})
339+
: new SSEClientTransport(mcpProxyServerUrl as URL, transportOptions);
315340

316341
if (onNotification) {
317342
[

package-lock.json

+21-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"@modelcontextprotocol/inspector-cli": "^0.10.2",
4242
"@modelcontextprotocol/inspector-client": "^0.10.2",
4343
"@modelcontextprotocol/inspector-server": "^0.10.2",
44-
"@modelcontextprotocol/sdk": "^1.10.0",
44+
"@modelcontextprotocol/sdk": "^1.10.2",
4545
"concurrently": "^9.0.1",
4646
"shell-quote": "^1.8.2",
4747
"spawn-rx": "^5.1.2",
@@ -52,6 +52,7 @@
5252
"@types/jest": "^29.5.14",
5353
"@types/node": "^22.7.5",
5454
"@types/shell-quote": "^1.7.5",
55+
"jest-fixed-jsdom": "^0.0.9",
5556
"prettier": "3.3.3",
5657
"typescript": "^5.4.2"
5758
}

0 commit comments

Comments
 (0)