mcp-use 1.5.1-canary.2 → 1.5.1-canary.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.tsbuildinfo +1 -1
- package/dist/{chunk-QRABML5H.js → chunk-SJEHVCPM.js} +7 -3
- package/dist/index.cjs +7 -3
- package/dist/index.js +1 -1
- package/dist/src/react/Image.d.ts.map +1 -1
- package/dist/src/react/index.cjs +7 -3
- package/dist/src/react/index.js +1 -1
- package/dist/src/react/types.d.ts +23 -1
- package/dist/src/react/types.d.ts.map +1 -1
- package/dist/src/react/useMcp.d.ts.map +1 -1
- package/dist/src/react/widget-types.d.ts +1 -0
- package/dist/src/react/widget-types.d.ts.map +1 -1
- package/dist/src/server/index.cjs +204 -18
- package/dist/src/server/index.d.ts +1 -1
- package/dist/src/server/index.d.ts.map +1 -1
- package/dist/src/server/index.js +204 -18
- package/dist/src/server/mcp-server.d.ts +81 -0
- package/dist/src/server/mcp-server.d.ts.map +1 -1
- package/dist/src/server/types/tool.d.ts +26 -2
- package/dist/src/server/types/tool.d.ts.map +1 -1
- package/package.json +3 -3
|
@@ -311,7 +311,7 @@ function useMcp(options) {
|
|
|
311
311
|
sseReadTimeout
|
|
312
312
|
]);
|
|
313
313
|
const callTool = useCallback(
|
|
314
|
-
async (name, args) => {
|
|
314
|
+
async (name, args, options2) => {
|
|
315
315
|
if (stateRef.current !== "ready" || !clientRef.current) {
|
|
316
316
|
throw new Error(
|
|
317
317
|
`MCP client is not ready (current state: ${state}). Cannot call tool "${name}".`
|
|
@@ -324,7 +324,11 @@ function useMcp(options) {
|
|
|
324
324
|
if (!session) {
|
|
325
325
|
throw new Error("No active session found");
|
|
326
326
|
}
|
|
327
|
-
const result = await session.connector.callTool(
|
|
327
|
+
const result = await session.connector.callTool(
|
|
328
|
+
name,
|
|
329
|
+
args || {},
|
|
330
|
+
options2
|
|
331
|
+
);
|
|
328
332
|
addLog("info", `Tool "${name}" call successful:`, result);
|
|
329
333
|
return result;
|
|
330
334
|
} catch (err) {
|
|
@@ -658,7 +662,7 @@ var ErrorBoundary = class extends React.Component {
|
|
|
658
662
|
// src/react/Image.tsx
|
|
659
663
|
import React2 from "react";
|
|
660
664
|
var Image = /* @__PURE__ */ __name(({ src, ...props }) => {
|
|
661
|
-
const publicUrl = typeof window !== "undefined"
|
|
665
|
+
const publicUrl = typeof window !== "undefined" ? window.__mcpPublicAssetsUrl || window.__mcpPublicUrl || "" : "";
|
|
662
666
|
const getFinalSrc = /* @__PURE__ */ __name((source) => {
|
|
663
667
|
if (!source) return source;
|
|
664
668
|
if (source.startsWith("http://") || source.startsWith("https://") || source.startsWith("data:")) {
|
package/dist/index.cjs
CHANGED
|
@@ -7530,7 +7530,7 @@ function useMcp(options) {
|
|
|
7530
7530
|
sseReadTimeout
|
|
7531
7531
|
]);
|
|
7532
7532
|
const callTool = (0, import_react.useCallback)(
|
|
7533
|
-
async (name, args) => {
|
|
7533
|
+
async (name, args, options2) => {
|
|
7534
7534
|
if (stateRef.current !== "ready" || !clientRef.current) {
|
|
7535
7535
|
throw new Error(
|
|
7536
7536
|
`MCP client is not ready (current state: ${state}). Cannot call tool "${name}".`
|
|
@@ -7543,7 +7543,11 @@ function useMcp(options) {
|
|
|
7543
7543
|
if (!session) {
|
|
7544
7544
|
throw new Error("No active session found");
|
|
7545
7545
|
}
|
|
7546
|
-
const result = await session.connector.callTool(
|
|
7546
|
+
const result = await session.connector.callTool(
|
|
7547
|
+
name,
|
|
7548
|
+
args || {},
|
|
7549
|
+
options2
|
|
7550
|
+
);
|
|
7547
7551
|
addLog("info", `Tool "${name}" call successful:`, result);
|
|
7548
7552
|
return result;
|
|
7549
7553
|
} catch (err) {
|
|
@@ -7877,7 +7881,7 @@ var ErrorBoundary = class extends import_react2.default.Component {
|
|
|
7877
7881
|
// src/react/Image.tsx
|
|
7878
7882
|
var import_react3 = __toESM(require("react"), 1);
|
|
7879
7883
|
var Image = /* @__PURE__ */ __name(({ src, ...props }) => {
|
|
7880
|
-
const publicUrl = typeof window !== "undefined"
|
|
7884
|
+
const publicUrl = typeof window !== "undefined" ? window.__mcpPublicAssetsUrl || window.__mcpPublicUrl || "" : "";
|
|
7881
7885
|
const getFinalSrc = /* @__PURE__ */ __name((source) => {
|
|
7882
7886
|
if (!source) return source;
|
|
7883
7887
|
if (source.startsWith("http://") || source.startsWith("https://") || source.startsWith("data:")) {
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Image.d.ts","sourceRoot":"","sources":["../../../src/react/Image.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B;;;;;;;GAOG;AACH,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,EAAE,CAC1B,KAAK,CAAC,iBAAiB,CAAC,UAAU,CAAC,gBAAgB,CAAC,
|
|
1
|
+
{"version":3,"file":"Image.d.ts","sourceRoot":"","sources":["../../../src/react/Image.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B;;;;;;;GAOG;AACH,eAAO,MAAM,KAAK,EAAE,KAAK,CAAC,EAAE,CAC1B,KAAK,CAAC,iBAAiB,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAwCrD,CAAC"}
|
package/dist/src/react/index.cjs
CHANGED
|
@@ -2187,7 +2187,7 @@ function useMcp(options) {
|
|
|
2187
2187
|
sseReadTimeout
|
|
2188
2188
|
]);
|
|
2189
2189
|
const callTool = (0, import_react.useCallback)(
|
|
2190
|
-
async (name, args) => {
|
|
2190
|
+
async (name, args, options2) => {
|
|
2191
2191
|
if (stateRef.current !== "ready" || !clientRef.current) {
|
|
2192
2192
|
throw new Error(
|
|
2193
2193
|
`MCP client is not ready (current state: ${state}). Cannot call tool "${name}".`
|
|
@@ -2200,7 +2200,11 @@ function useMcp(options) {
|
|
|
2200
2200
|
if (!session) {
|
|
2201
2201
|
throw new Error("No active session found");
|
|
2202
2202
|
}
|
|
2203
|
-
const result = await session.connector.callTool(
|
|
2203
|
+
const result = await session.connector.callTool(
|
|
2204
|
+
name,
|
|
2205
|
+
args || {},
|
|
2206
|
+
options2
|
|
2207
|
+
);
|
|
2204
2208
|
addLog("info", `Tool "${name}" call successful:`, result);
|
|
2205
2209
|
return result;
|
|
2206
2210
|
} catch (err) {
|
|
@@ -2663,7 +2667,7 @@ var ErrorBoundary = class extends import_react2.default.Component {
|
|
|
2663
2667
|
// src/react/Image.tsx
|
|
2664
2668
|
var import_react3 = __toESM(require("react"), 1);
|
|
2665
2669
|
var Image = /* @__PURE__ */ __name(({ src, ...props }) => {
|
|
2666
|
-
const publicUrl = typeof window !== "undefined"
|
|
2670
|
+
const publicUrl = typeof window !== "undefined" ? window.__mcpPublicAssetsUrl || window.__mcpPublicUrl || "" : "";
|
|
2667
2671
|
const getFinalSrc = /* @__PURE__ */ __name((source) => {
|
|
2668
2672
|
if (!source) return source;
|
|
2669
2673
|
if (source.startsWith("http://") || source.startsWith("https://") || source.startsWith("data:")) {
|
package/dist/src/react/index.js
CHANGED
|
@@ -97,10 +97,32 @@ export type UseMcpResult = {
|
|
|
97
97
|
* Function to call a tool on the MCP server.
|
|
98
98
|
* @param name The name of the tool to call.
|
|
99
99
|
* @param args Optional arguments for the tool.
|
|
100
|
+
* @param options Optional request options including timeout configuration.
|
|
100
101
|
* @returns A promise that resolves with the tool's result.
|
|
101
102
|
* @throws If the client is not in the 'ready' state or the call fails.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* // Simple tool call
|
|
107
|
+
* const result = await mcp.callTool('my-tool', { arg: 'value' })
|
|
108
|
+
*
|
|
109
|
+
* // Tool call with extended timeout (e.g., for tools that trigger sampling)
|
|
110
|
+
* const result = await mcp.callTool('analyze-sentiment', { text: 'Hello' }, {
|
|
111
|
+
* timeout: 300000, // 5 minutes
|
|
112
|
+
* resetTimeoutOnProgress: true // Reset timeout when progress notifications are received
|
|
113
|
+
* })
|
|
114
|
+
* ```
|
|
102
115
|
*/
|
|
103
|
-
callTool: (name: string, args?: Record<string, unknown
|
|
116
|
+
callTool: (name: string, args?: Record<string, unknown>, options?: {
|
|
117
|
+
/** Timeout in milliseconds for this tool call (default: 60000 / 60 seconds) */
|
|
118
|
+
timeout?: number;
|
|
119
|
+
/** Maximum total timeout in milliseconds, even with progress resets */
|
|
120
|
+
maxTotalTimeout?: number;
|
|
121
|
+
/** Reset the timeout when progress notifications are received (default: false) */
|
|
122
|
+
resetTimeoutOnProgress?: boolean;
|
|
123
|
+
/** AbortSignal to cancel the request */
|
|
124
|
+
signal?: AbortSignal;
|
|
125
|
+
}) => Promise<any>;
|
|
104
126
|
/**
|
|
105
127
|
* Function to list resources from the MCP server.
|
|
106
128
|
* @returns A promise that resolves when resources are refreshed.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/react/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,mBAAmB,EACnB,YAAY,EACZ,MAAM,EACN,QAAQ,EACR,gBAAgB,EAChB,IAAI,EACL,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,MAAM,MAAM,aAAa,GAAG;IAC1B,6CAA6C;IAC7C,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,6HAA6H;IAC7H,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,2EAA2E;IAC3E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,0EAA0E;IAC1E,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iGAAiG;IACjG,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iFAAiF;IACjF,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,uDAAuD;IACvD,YAAY,CAAC,EAAE;QACb,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,OAAO,CAAC,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;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,YAAY,
|
|
1
|
+
{"version":3,"file":"useMcp.d.ts","sourceRoot":"","sources":["../../../src/react/useMcp.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAS9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,YAAY,CAg4B3D"}
|
|
@@ -81,6 +81,7 @@ declare global {
|
|
|
81
81
|
openai?: API<any> & OpenAiGlobals<any, any, any, any>;
|
|
82
82
|
__getFile?: (filename: string) => string;
|
|
83
83
|
__mcpPublicUrl?: string;
|
|
84
|
+
__mcpPublicAssetsUrl?: string;
|
|
84
85
|
}
|
|
85
86
|
interface WindowEventMap {
|
|
86
87
|
[SET_GLOBALS_EVENT_TYPE]: SetGlobalsEvent;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"widget-types.d.ts","sourceRoot":"","sources":["../../../src/react/widget-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEpD,MAAM,MAAM,KAAK,GAAG,OAAO,GAAG,MAAM,CAAC;AAErC,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,QAAQ,GAAG,YAAY,CAAC;AAE1D,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;AAErE,MAAM,MAAM,cAAc,GAAG;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACrB,MAAM,EA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AAE,OAAO,CAAC,KAC1B,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC/B,mDAAmD;IACnD,mBAAmB,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACvD,2BAA2B;IAC3B,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,uCAAuC;IACvC,kBAAkB,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,OAAO,CAAC;QAAE,IAAI,EAAE,WAAW,CAAA;KAAE,CAAC,CAAC;IAE1E,0CAA0C;IAC1C,WAAW,EAAE,OAAO,CAAC;CACtB"}
|
|
@@ -630,6 +630,22 @@ var McpServer = class {
|
|
|
630
630
|
}
|
|
631
631
|
return `http://${this.serverHost}:${this.serverPort}`;
|
|
632
632
|
}
|
|
633
|
+
/**
|
|
634
|
+
* Gets additional CSP URLs from environment variable
|
|
635
|
+
* Supports comma-separated list or single URL
|
|
636
|
+
* @returns Array of URLs to add to CSP resource_domains
|
|
637
|
+
*/
|
|
638
|
+
getCSPUrls() {
|
|
639
|
+
console.log(globalThis.Deno.env.get("CSP_URLS"));
|
|
640
|
+
const cspUrlsEnv = getEnv2("CSP_URLS");
|
|
641
|
+
if (!cspUrlsEnv) {
|
|
642
|
+
console.log("[CSP] No CSP_URLS environment variable found");
|
|
643
|
+
return [];
|
|
644
|
+
}
|
|
645
|
+
const urls = cspUrlsEnv.split(",").map((url) => url.trim()).filter((url) => url.length > 0);
|
|
646
|
+
console.log("[CSP] Parsed CSP URLs:", urls);
|
|
647
|
+
return urls;
|
|
648
|
+
}
|
|
633
649
|
/**
|
|
634
650
|
* Define a static resource that can be accessed by clients
|
|
635
651
|
*
|
|
@@ -801,11 +817,6 @@ var McpServer = class {
|
|
|
801
817
|
*/
|
|
802
818
|
tool(toolDefinition) {
|
|
803
819
|
const inputSchema = this.createParamsSchema(toolDefinition.inputs || []);
|
|
804
|
-
const context = {
|
|
805
|
-
sample: /* @__PURE__ */ __name(async (params, options) => {
|
|
806
|
-
return await this.createMessage(params, options);
|
|
807
|
-
}, "sample")
|
|
808
|
-
};
|
|
809
820
|
this.server.registerTool(
|
|
810
821
|
toolDefinition.name,
|
|
811
822
|
{
|
|
@@ -815,7 +826,98 @@ var McpServer = class {
|
|
|
815
826
|
annotations: toolDefinition.annotations,
|
|
816
827
|
_meta: toolDefinition._meta
|
|
817
828
|
},
|
|
818
|
-
async (params) => {
|
|
829
|
+
async (params, extra) => {
|
|
830
|
+
const progressToken = extra?._meta?.progressToken;
|
|
831
|
+
const context = {
|
|
832
|
+
/**
|
|
833
|
+
* Request sampling from the client's LLM with automatic progress notifications.
|
|
834
|
+
*
|
|
835
|
+
* Progress notifications are sent every 5 seconds (configurable) while waiting
|
|
836
|
+
* for the sampling response. This prevents client-side timeouts when
|
|
837
|
+
* resetTimeoutOnProgress is enabled.
|
|
838
|
+
*
|
|
839
|
+
* @param params - Sampling parameters (messages, model preferences, etc.)
|
|
840
|
+
* @param options - Optional configuration
|
|
841
|
+
* @param options.timeout - Timeout in milliseconds (default: no timeout / Infinity)
|
|
842
|
+
* @param options.progressIntervalMs - Interval between progress notifications (default: 5000ms)
|
|
843
|
+
* @param options.onProgress - Optional callback called each time progress is reported
|
|
844
|
+
* @returns The sampling result from the client's LLM
|
|
845
|
+
*/
|
|
846
|
+
sample: /* @__PURE__ */ __name(async (sampleParams, options) => {
|
|
847
|
+
const {
|
|
848
|
+
timeout,
|
|
849
|
+
progressIntervalMs = 5e3,
|
|
850
|
+
onProgress
|
|
851
|
+
} = options ?? {};
|
|
852
|
+
let progressCount = 0;
|
|
853
|
+
let completed = false;
|
|
854
|
+
let progressInterval = null;
|
|
855
|
+
if (progressToken && extra?.sendNotification) {
|
|
856
|
+
progressInterval = setInterval(async () => {
|
|
857
|
+
if (completed) return;
|
|
858
|
+
progressCount++;
|
|
859
|
+
const progressData = {
|
|
860
|
+
progress: progressCount,
|
|
861
|
+
total: void 0,
|
|
862
|
+
message: `Waiting for LLM response... (${progressCount * Math.round(progressIntervalMs / 1e3)}s elapsed)`
|
|
863
|
+
};
|
|
864
|
+
if (onProgress) {
|
|
865
|
+
try {
|
|
866
|
+
onProgress(progressData);
|
|
867
|
+
} catch {
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
try {
|
|
871
|
+
await extra.sendNotification({
|
|
872
|
+
method: "notifications/progress",
|
|
873
|
+
params: {
|
|
874
|
+
progressToken,
|
|
875
|
+
progress: progressData.progress,
|
|
876
|
+
total: progressData.total,
|
|
877
|
+
message: progressData.message
|
|
878
|
+
}
|
|
879
|
+
});
|
|
880
|
+
} catch {
|
|
881
|
+
}
|
|
882
|
+
}, progressIntervalMs);
|
|
883
|
+
}
|
|
884
|
+
try {
|
|
885
|
+
const samplePromise = this.createMessage(sampleParams);
|
|
886
|
+
if (timeout && timeout !== Infinity) {
|
|
887
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
888
|
+
setTimeout(
|
|
889
|
+
() => reject(
|
|
890
|
+
new Error(`Sampling timed out after ${timeout}ms`)
|
|
891
|
+
),
|
|
892
|
+
timeout
|
|
893
|
+
);
|
|
894
|
+
});
|
|
895
|
+
return await Promise.race([samplePromise, timeoutPromise]);
|
|
896
|
+
}
|
|
897
|
+
return await samplePromise;
|
|
898
|
+
} finally {
|
|
899
|
+
completed = true;
|
|
900
|
+
if (progressInterval) {
|
|
901
|
+
clearInterval(progressInterval);
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
}, "sample"),
|
|
905
|
+
/**
|
|
906
|
+
* Send a progress notification to the client.
|
|
907
|
+
* Only works if the client requested progress updates for this tool call.
|
|
908
|
+
*/
|
|
909
|
+
reportProgress: progressToken && extra?.sendNotification ? async (progress, total, message) => {
|
|
910
|
+
await extra.sendNotification({
|
|
911
|
+
method: "notifications/progress",
|
|
912
|
+
params: {
|
|
913
|
+
progressToken,
|
|
914
|
+
progress,
|
|
915
|
+
total,
|
|
916
|
+
message
|
|
917
|
+
}
|
|
918
|
+
});
|
|
919
|
+
} : void 0
|
|
920
|
+
};
|
|
819
921
|
if (toolDefinition.cb.length >= 2) {
|
|
820
922
|
return await toolDefinition.cb(params, context);
|
|
821
923
|
}
|
|
@@ -1640,6 +1742,7 @@ if (container && Component) {
|
|
|
1640
1742
|
error
|
|
1641
1743
|
);
|
|
1642
1744
|
}
|
|
1745
|
+
const mcp_connect_domain = this.getServerBaseUrl() ? new URL(this.getServerBaseUrl() || "").origin : null;
|
|
1643
1746
|
this.uiResource({
|
|
1644
1747
|
name: widget.name,
|
|
1645
1748
|
title: metadata.title || widget.name,
|
|
@@ -1669,14 +1772,16 @@ if (container && Component) {
|
|
|
1669
1772
|
"openai/widgetCSP": {
|
|
1670
1773
|
connect_domains: [
|
|
1671
1774
|
// always also add the base url of the server
|
|
1672
|
-
...
|
|
1775
|
+
...mcp_connect_domain ? [mcp_connect_domain] : [],
|
|
1673
1776
|
...metadata.appsSdkMetadata?.["openai/widgetCSP"]?.connect_domains || []
|
|
1674
1777
|
],
|
|
1675
1778
|
resource_domains: [
|
|
1676
1779
|
"https://*.oaistatic.com",
|
|
1677
1780
|
"https://*.oaiusercontent.com",
|
|
1678
1781
|
// always also add the base url of the server
|
|
1679
|
-
...
|
|
1782
|
+
...mcp_connect_domain ? [mcp_connect_domain] : [],
|
|
1783
|
+
// add additional CSP URLs from environment variable
|
|
1784
|
+
...this.getCSPUrls(),
|
|
1680
1785
|
...metadata.appsSdkMetadata?.["openai/widgetCSP"]?.resource_domains || []
|
|
1681
1786
|
]
|
|
1682
1787
|
}
|
|
@@ -1854,6 +1959,8 @@ if (container && Component) {
|
|
|
1854
1959
|
"https://*.openai.com",
|
|
1855
1960
|
// always also add the base url of the server
|
|
1856
1961
|
...this.getServerBaseUrl() ? [this.getServerBaseUrl()] : [],
|
|
1962
|
+
// add additional CSP URLs from environment variable
|
|
1963
|
+
...this.getCSPUrls(),
|
|
1857
1964
|
...metadata.appsSdkMetadata?.["openai/widgetCSP"]?.resource_domains || []
|
|
1858
1965
|
]
|
|
1859
1966
|
}
|
|
@@ -1906,14 +2013,7 @@ if (container && Component) {
|
|
|
1906
2013
|
if (this.mcpMounted) return;
|
|
1907
2014
|
const { StreamableHTTPServerTransport } = await import("@modelcontextprotocol/sdk/server/streamableHttp.js");
|
|
1908
2015
|
const idleTimeoutMs = this.config.sessionIdleTimeoutMs ?? 3e5;
|
|
1909
|
-
const
|
|
1910
|
-
if (closeOldSessionId && this.sessions.has(closeOldSessionId)) {
|
|
1911
|
-
try {
|
|
1912
|
-
this.sessions.get(closeOldSessionId).transport.close();
|
|
1913
|
-
} catch (error) {
|
|
1914
|
-
}
|
|
1915
|
-
this.sessions.delete(closeOldSessionId);
|
|
1916
|
-
}
|
|
2016
|
+
const getTransportConfig = /* @__PURE__ */ __name(() => {
|
|
1917
2017
|
const isProduction = this.isProductionMode();
|
|
1918
2018
|
let allowedOrigins = this.config.allowedOrigins;
|
|
1919
2019
|
let enableDnsRebindingProtection = false;
|
|
@@ -1925,6 +2025,17 @@ if (container && Component) {
|
|
|
1925
2025
|
allowedOrigins = void 0;
|
|
1926
2026
|
enableDnsRebindingProtection = false;
|
|
1927
2027
|
}
|
|
2028
|
+
return { allowedOrigins, enableDnsRebindingProtection };
|
|
2029
|
+
}, "getTransportConfig");
|
|
2030
|
+
const createNewTransport = /* @__PURE__ */ __name(async (closeOldSessionId) => {
|
|
2031
|
+
if (closeOldSessionId && this.sessions.has(closeOldSessionId)) {
|
|
2032
|
+
try {
|
|
2033
|
+
this.sessions.get(closeOldSessionId).transport.close();
|
|
2034
|
+
} catch (error) {
|
|
2035
|
+
}
|
|
2036
|
+
this.sessions.delete(closeOldSessionId);
|
|
2037
|
+
}
|
|
2038
|
+
const { allowedOrigins, enableDnsRebindingProtection } = getTransportConfig();
|
|
1928
2039
|
const transport = new StreamableHTTPServerTransport({
|
|
1929
2040
|
sessionIdGenerator: /* @__PURE__ */ __name(() => generateUUID(), "sessionIdGenerator"),
|
|
1930
2041
|
enableJsonResponse: true,
|
|
@@ -1947,6 +2058,81 @@ if (container && Component) {
|
|
|
1947
2058
|
await this.server.connect(transport);
|
|
1948
2059
|
return transport;
|
|
1949
2060
|
}, "createNewTransport");
|
|
2061
|
+
const createAndAutoInitializeTransport = /* @__PURE__ */ __name(async (oldSessionId) => {
|
|
2062
|
+
const { allowedOrigins, enableDnsRebindingProtection } = getTransportConfig();
|
|
2063
|
+
const transport = new StreamableHTTPServerTransport({
|
|
2064
|
+
sessionIdGenerator: /* @__PURE__ */ __name(() => oldSessionId, "sessionIdGenerator"),
|
|
2065
|
+
// Reuse old session ID!
|
|
2066
|
+
enableJsonResponse: true,
|
|
2067
|
+
allowedOrigins,
|
|
2068
|
+
enableDnsRebindingProtection,
|
|
2069
|
+
// We'll manually store the session, so don't rely on onsessioninitialized
|
|
2070
|
+
onsessionclosed: /* @__PURE__ */ __name((id) => {
|
|
2071
|
+
if (id) {
|
|
2072
|
+
this.sessions.delete(id);
|
|
2073
|
+
}
|
|
2074
|
+
}, "onsessionclosed")
|
|
2075
|
+
});
|
|
2076
|
+
await this.server.connect(transport);
|
|
2077
|
+
this.sessions.set(oldSessionId, {
|
|
2078
|
+
transport,
|
|
2079
|
+
lastAccessedAt: Date.now()
|
|
2080
|
+
});
|
|
2081
|
+
const initBody = {
|
|
2082
|
+
jsonrpc: "2.0",
|
|
2083
|
+
method: "initialize",
|
|
2084
|
+
params: {
|
|
2085
|
+
protocolVersion: "2024-11-05",
|
|
2086
|
+
capabilities: {},
|
|
2087
|
+
clientInfo: { name: "mcp-use-auto-reconnect", version: "1.0.0" }
|
|
2088
|
+
},
|
|
2089
|
+
id: "__auto_init__"
|
|
2090
|
+
};
|
|
2091
|
+
const syntheticHeaders = {
|
|
2092
|
+
"content-type": "application/json",
|
|
2093
|
+
accept: "application/json, text/event-stream"
|
|
2094
|
+
// SDK requires both!
|
|
2095
|
+
};
|
|
2096
|
+
const syntheticReq = {
|
|
2097
|
+
method: "POST",
|
|
2098
|
+
headers: syntheticHeaders,
|
|
2099
|
+
header: /* @__PURE__ */ __name((name) => syntheticHeaders[name.toLowerCase()], "header"),
|
|
2100
|
+
body: initBody
|
|
2101
|
+
};
|
|
2102
|
+
const syntheticRes = {
|
|
2103
|
+
statusCode: 200,
|
|
2104
|
+
setHeader: /* @__PURE__ */ __name(() => syntheticRes, "setHeader"),
|
|
2105
|
+
writeHead: /* @__PURE__ */ __name((code) => {
|
|
2106
|
+
syntheticRes.statusCode = code;
|
|
2107
|
+
return syntheticRes;
|
|
2108
|
+
}, "writeHead"),
|
|
2109
|
+
write: /* @__PURE__ */ __name(() => true, "write"),
|
|
2110
|
+
end: /* @__PURE__ */ __name(() => {
|
|
2111
|
+
}, "end"),
|
|
2112
|
+
on: /* @__PURE__ */ __name(() => syntheticRes, "on"),
|
|
2113
|
+
once: /* @__PURE__ */ __name(() => syntheticRes, "once"),
|
|
2114
|
+
removeListener: /* @__PURE__ */ __name(() => syntheticRes, "removeListener")
|
|
2115
|
+
};
|
|
2116
|
+
await new Promise((resolve) => {
|
|
2117
|
+
syntheticRes.end = () => {
|
|
2118
|
+
resolve();
|
|
2119
|
+
};
|
|
2120
|
+
transport.handleRequest(syntheticReq, syntheticRes, initBody);
|
|
2121
|
+
});
|
|
2122
|
+
if (syntheticRes.statusCode !== 200) {
|
|
2123
|
+
console.error(
|
|
2124
|
+
`[MCP] Auto-initialization failed with status ${syntheticRes.statusCode}`
|
|
2125
|
+
);
|
|
2126
|
+
this.sessions.delete(oldSessionId);
|
|
2127
|
+
throw new Error(
|
|
2128
|
+
`Auto-initialization failed: ${syntheticRes.statusCode}`
|
|
2129
|
+
);
|
|
2130
|
+
}
|
|
2131
|
+
console.log(
|
|
2132
|
+
`[MCP] Auto-initialized session ${oldSessionId} for seamless reconnection`
|
|
2133
|
+
);
|
|
2134
|
+
return transport;
|
|
2135
|
+
}, "createAndAutoInitializeTransport");
|
|
1950
2136
|
const getOrCreateTransport = /* @__PURE__ */ __name(async (sessionId, isInit = false) => {
|
|
1951
2137
|
if (isInit) {
|
|
1952
2138
|
return await createNewTransport(sessionId);
|
|
@@ -1960,9 +2146,9 @@ if (container && Component) {
|
|
|
1960
2146
|
const autoCreate = this.config.autoCreateSessionOnInvalidId ?? true;
|
|
1961
2147
|
if (autoCreate) {
|
|
1962
2148
|
console.warn(
|
|
1963
|
-
`[MCP] Session ${sessionId} not found (expired or invalid), auto-creating new session for seamless reconnection`
|
|
2149
|
+
`[MCP] Session ${sessionId} not found (expired or invalid), auto-creating and initializing new session for seamless reconnection`
|
|
1964
2150
|
);
|
|
1965
|
-
return await
|
|
2151
|
+
return await createAndAutoInitializeTransport(sessionId);
|
|
1966
2152
|
} else {
|
|
1967
2153
|
return null;
|
|
1968
2154
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { createMCPServer, type McpServerInstance } from "./mcp-server.js";
|
|
1
|
+
export { createMCPServer, type McpServerInstance, type ToolContext, type SampleOptions, } from "./mcp-server.js";
|
|
2
2
|
export * from "./types/index.js";
|
|
3
3
|
export { buildWidgetUrl, createExternalUrlResource, createRawHtmlResource, createRemoteDomResource, createUIResourceFromDefinition, type UrlConfig, } from "./adapters/mcp-ui-adapter.js";
|
|
4
4
|
export { adaptConnectMiddleware, adaptMiddleware, isExpressMiddleware, } from "./connect-adapter.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,aAAa,GACnB,MAAM,iBAAiB,CAAC;AAEzB,cAAc,kBAAkB,CAAC;AAGjC,OAAO,EACL,cAAc,EACd,yBAAyB,EACzB,qBAAqB,EACrB,uBAAuB,EACvB,8BAA8B,EAC9B,KAAK,SAAS,GACf,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,mBAAmB,GACpB,MAAM,sBAAsB,CAAC;AAE9B,YAAY,EACV,sBAAsB,EACtB,qBAAqB,EACrB,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,4BAA4B,EAC5B,mBAAmB,EACnB,kBAAkB,EAClB,YAAY,EACZ,YAAY,EACZ,cAAc,EAEd,oBAAoB,EACpB,YAAY,EACZ,cAAc,EACd,WAAW,GACZ,MAAM,kBAAkB,CAAC"}
|