Merge branch 'main' into patch-1
This commit is contained in:
@@ -2,8 +2,12 @@ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|||||||
import {
|
import {
|
||||||
SSEClientTransport,
|
SSEClientTransport,
|
||||||
SseError,
|
SseError,
|
||||||
|
SSEClientTransportOptions,
|
||||||
} from "@modelcontextprotocol/sdk/client/sse.js";
|
} from "@modelcontextprotocol/sdk/client/sse.js";
|
||||||
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
import {
|
||||||
|
StreamableHTTPClientTransport,
|
||||||
|
StreamableHTTPClientTransportOptions,
|
||||||
|
} from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
||||||
import {
|
import {
|
||||||
ClientNotification,
|
ClientNotification,
|
||||||
ClientRequest,
|
ClientRequest,
|
||||||
@@ -279,29 +283,6 @@ export function useConnection({
|
|||||||
setConnectionStatus("error-connecting-to-proxy");
|
setConnectionStatus("error-connecting-to-proxy");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let mcpProxyServerUrl;
|
|
||||||
switch (transportType) {
|
|
||||||
case "stdio":
|
|
||||||
mcpProxyServerUrl = new URL(`${getMCPProxyAddress(config)}/stdio`);
|
|
||||||
mcpProxyServerUrl.searchParams.append("command", command);
|
|
||||||
mcpProxyServerUrl.searchParams.append("args", args);
|
|
||||||
mcpProxyServerUrl.searchParams.append("env", JSON.stringify(env));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "sse":
|
|
||||||
mcpProxyServerUrl = new URL(`${getMCPProxyAddress(config)}/sse`);
|
|
||||||
mcpProxyServerUrl.searchParams.append("url", sseUrl);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "streamable-http":
|
|
||||||
mcpProxyServerUrl = new URL(`${getMCPProxyAddress(config)}/mcp`);
|
|
||||||
mcpProxyServerUrl.searchParams.append("url", sseUrl);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
(mcpProxyServerUrl as URL).searchParams.append(
|
|
||||||
"transportType",
|
|
||||||
transportType,
|
|
||||||
);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Inject auth manually instead of using SSEClientTransport, because we're
|
// Inject auth manually instead of using SSEClientTransport, because we're
|
||||||
@@ -320,7 +301,19 @@ export function useConnection({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create appropriate transport
|
// Create appropriate transport
|
||||||
const transportOptions = {
|
let transportOptions:
|
||||||
|
| StreamableHTTPClientTransportOptions
|
||||||
|
| SSEClientTransportOptions;
|
||||||
|
|
||||||
|
let mcpProxyServerUrl;
|
||||||
|
switch (transportType) {
|
||||||
|
case "stdio":
|
||||||
|
mcpProxyServerUrl = new URL(`${getMCPProxyAddress(config)}/stdio`);
|
||||||
|
mcpProxyServerUrl.searchParams.append("command", command);
|
||||||
|
mcpProxyServerUrl.searchParams.append("args", args);
|
||||||
|
mcpProxyServerUrl.searchParams.append("env", JSON.stringify(env));
|
||||||
|
transportOptions = {
|
||||||
|
authProvider: serverAuthProvider,
|
||||||
eventSourceInit: {
|
eventSourceInit: {
|
||||||
fetch: (
|
fetch: (
|
||||||
url: string | URL | globalThis.Request,
|
url: string | URL | globalThis.Request,
|
||||||
@@ -331,10 +324,59 @@ export function useConnection({
|
|||||||
headers,
|
headers,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "sse":
|
||||||
|
mcpProxyServerUrl = new URL(`${getMCPProxyAddress(config)}/sse`);
|
||||||
|
mcpProxyServerUrl.searchParams.append("url", sseUrl);
|
||||||
|
transportOptions = {
|
||||||
|
authProvider: serverAuthProvider,
|
||||||
|
eventSourceInit: {
|
||||||
|
fetch: (
|
||||||
|
url: string | URL | globalThis.Request,
|
||||||
|
init: RequestInit | undefined,
|
||||||
|
) => fetch(url, { ...init, headers }),
|
||||||
|
},
|
||||||
|
requestInit: {
|
||||||
|
headers,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "streamable-http":
|
||||||
|
mcpProxyServerUrl = new URL(`${getMCPProxyAddress(config)}/mcp`);
|
||||||
|
mcpProxyServerUrl.searchParams.append("url", sseUrl);
|
||||||
|
transportOptions = {
|
||||||
|
authProvider: serverAuthProvider,
|
||||||
|
eventSourceInit: {
|
||||||
|
fetch: (
|
||||||
|
url: string | URL | globalThis.Request,
|
||||||
|
init: RequestInit | undefined,
|
||||||
|
) => fetch(url, { ...init, headers }),
|
||||||
|
},
|
||||||
|
requestInit: {
|
||||||
|
headers,
|
||||||
|
},
|
||||||
|
// TODO these should be configurable...
|
||||||
|
reconnectionOptions: {
|
||||||
|
maxReconnectionDelay: 30000,
|
||||||
|
initialReconnectionDelay: 1000,
|
||||||
|
reconnectionDelayGrowFactor: 1.5,
|
||||||
|
maxRetries: 2,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
(mcpProxyServerUrl as URL).searchParams.append(
|
||||||
|
"transportType",
|
||||||
|
transportType,
|
||||||
|
);
|
||||||
|
|
||||||
const clientTransport =
|
const clientTransport =
|
||||||
transportType === "streamable-http"
|
transportType === "streamable-http"
|
||||||
? new StreamableHTTPClientTransport(mcpProxyServerUrl as URL, {
|
? new StreamableHTTPClientTransport(mcpProxyServerUrl as URL, {
|
||||||
sessionId: undefined,
|
sessionId: undefined,
|
||||||
|
...transportOptions,
|
||||||
})
|
})
|
||||||
: new SSEClientTransport(mcpProxyServerUrl as URL, transportOptions);
|
: new SSEClientTransport(mcpProxyServerUrl as URL, transportOptions);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user