mcp-use 1.9.1-canary.0 → 1.10.0-canary.10
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/README.md +9 -6
- package/dist/.tsbuildinfo +1 -1
- package/dist/chunk-6EYDSXO6.js +942 -0
- package/dist/{chunk-D22NUQTL.js → chunk-BFSVTG6G.js} +213 -12
- package/dist/{chunk-KHTTBIRP.js → chunk-BPP5XYP6.js} +156 -5
- package/dist/{chunk-3R5PDYIN.js → chunk-J75I2C26.js} +39 -11
- package/dist/{chunk-5URNFWCQ.js → chunk-LWVK6RXA.js} +8 -3
- package/dist/{chunk-MUZ5WYE3.js → chunk-NBSNYHID.js} +22 -13
- package/dist/{chunk-U5BX3ISQ.js → chunk-NRALSDBH.js} +22 -408
- package/dist/{chunk-ZQUCGISK.js → chunk-PL645KUX.js} +21 -5
- package/dist/{chunk-QREDNTLS.js → chunk-ZMA4JG4C.js} +1 -1
- package/dist/{context-storage-TXQ4DVSS.js → context-storage-NA4MHWOZ.js} +3 -1
- package/dist/index.cjs +854 -122
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +57 -23
- package/dist/src/adapters/langchain_adapter.d.ts +1 -1
- package/dist/src/adapters/langchain_adapter.d.ts.map +1 -1
- package/dist/src/agents/index.cjs +2071 -1620
- package/dist/src/agents/index.js +4 -4
- package/dist/src/agents/mcp_agent.d.ts +5 -0
- package/dist/src/agents/mcp_agent.d.ts.map +1 -1
- package/dist/src/auth/browser-provider.d.ts +2 -2
- package/dist/src/auth/browser-provider.d.ts.map +1 -1
- package/dist/src/auth/callback.d.ts.map +1 -1
- package/dist/src/auth/index.cjs +39 -11
- package/dist/src/auth/index.js +1 -1
- package/dist/src/auth/types.d.ts +1 -1
- package/dist/src/auth/types.d.ts.map +1 -1
- package/dist/src/browser.cjs +3299 -2601
- package/dist/src/browser.d.ts +2 -1
- package/dist/src/browser.d.ts.map +1 -1
- package/dist/src/browser.js +10 -5
- package/dist/src/client/browser.d.ts +5 -0
- package/dist/src/client/browser.d.ts.map +1 -1
- package/dist/src/client/connectors/codeMode.d.ts +1 -1
- package/dist/src/client/connectors/codeMode.d.ts.map +1 -1
- package/dist/src/client/executors/base.d.ts +1 -1
- package/dist/src/client/executors/base.d.ts.map +1 -1
- package/dist/src/client/prompts.cjs +13 -4
- package/dist/src/client/prompts.js +3 -2
- package/dist/src/client.d.ts +7 -1
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/connectors/base.d.ts +56 -6
- package/dist/src/connectors/base.d.ts.map +1 -1
- package/dist/src/connectors/http.d.ts.map +1 -1
- package/dist/src/connectors/stdio.d.ts.map +1 -1
- package/dist/src/connectors/websocket.d.ts +1 -1
- package/dist/src/connectors/websocket.d.ts.map +1 -1
- package/dist/src/oauth-helper.d.ts.map +1 -1
- package/dist/src/react/WidgetControls.d.ts.map +1 -1
- package/dist/src/react/index.cjs +1098 -47
- package/dist/src/react/index.d.ts +1 -1
- package/dist/src/react/index.d.ts.map +1 -1
- package/dist/src/react/index.js +5 -5
- package/dist/src/react/types.d.ts +1 -1
- package/dist/src/react/types.d.ts.map +1 -1
- package/dist/src/react/useMcp.d.ts.map +1 -1
- package/dist/src/server/context-storage.d.ts +8 -1
- package/dist/src/server/context-storage.d.ts.map +1 -1
- package/dist/src/server/endpoints/mount-mcp.d.ts +4 -1
- package/dist/src/server/endpoints/mount-mcp.d.ts.map +1 -1
- package/dist/src/server/index.cjs +2162 -287
- package/dist/src/server/index.d.ts +4 -3
- package/dist/src/server/index.d.ts.map +1 -1
- package/dist/src/server/index.js +870 -261
- package/dist/src/server/mcp-server.d.ts +107 -27
- package/dist/src/server/mcp-server.d.ts.map +1 -1
- package/dist/src/server/oauth/middleware.d.ts.map +1 -1
- package/dist/src/server/oauth/providers/auth0.d.ts +1 -1
- package/dist/src/server/oauth/providers/auth0.d.ts.map +1 -1
- package/dist/src/server/oauth/providers/custom.d.ts +4 -2
- package/dist/src/server/oauth/providers/custom.d.ts.map +1 -1
- package/dist/src/server/oauth/providers/keycloak.d.ts +1 -1
- package/dist/src/server/oauth/providers/keycloak.d.ts.map +1 -1
- package/dist/src/server/oauth/providers/supabase.d.ts +1 -1
- package/dist/src/server/oauth/providers/supabase.d.ts.map +1 -1
- package/dist/src/server/oauth/providers/types.d.ts +9 -5
- package/dist/src/server/oauth/providers/types.d.ts.map +1 -1
- package/dist/src/server/oauth/providers.d.ts +27 -9
- package/dist/src/server/oauth/providers.d.ts.map +1 -1
- package/dist/src/server/oauth/setup.d.ts +5 -4
- package/dist/src/server/oauth/setup.d.ts.map +1 -1
- package/dist/src/server/oauth/utils.d.ts +3 -2
- package/dist/src/server/oauth/utils.d.ts.map +1 -1
- package/dist/src/server/prompts/conversion.d.ts +1 -1
- package/dist/src/server/prompts/conversion.d.ts.map +1 -1
- package/dist/src/server/prompts/index.d.ts +6 -5
- package/dist/src/server/prompts/index.d.ts.map +1 -1
- package/dist/src/server/resources/conversion.d.ts +1 -1
- package/dist/src/server/resources/conversion.d.ts.map +1 -1
- package/dist/src/server/resources/index.d.ts +45 -25
- package/dist/src/server/resources/index.d.ts.map +1 -1
- package/dist/src/server/resources/subscriptions.d.ts +54 -0
- package/dist/src/server/resources/subscriptions.d.ts.map +1 -0
- package/dist/src/server/sessions/session-manager.d.ts +17 -5
- package/dist/src/server/sessions/session-manager.d.ts.map +1 -1
- package/dist/src/server/tools/tool-execution-helpers.d.ts +59 -23
- package/dist/src/server/tools/tool-execution-helpers.d.ts.map +1 -1
- package/dist/src/server/tools/tool-registration.d.ts +21 -7
- package/dist/src/server/tools/tool-registration.d.ts.map +1 -1
- package/dist/src/server/types/common.d.ts +25 -9
- package/dist/src/server/types/common.d.ts.map +1 -1
- package/dist/src/server/types/index.d.ts +3 -3
- package/dist/src/server/types/index.d.ts.map +1 -1
- package/dist/src/server/types/prompt.d.ts +3 -2
- package/dist/src/server/types/prompt.d.ts.map +1 -1
- package/dist/src/server/types/resource.d.ts +60 -10
- package/dist/src/server/types/resource.d.ts.map +1 -1
- package/dist/src/server/types/tool-context.d.ts +132 -1
- package/dist/src/server/types/tool-context.d.ts.map +1 -1
- package/dist/src/server/types/tool.d.ts +43 -2
- package/dist/src/server/types/tool.d.ts.map +1 -1
- package/dist/src/server/types/widget.d.ts +11 -1
- package/dist/src/server/types/widget.d.ts.map +1 -1
- package/dist/src/server/utils/response-helpers.d.ts +65 -33
- package/dist/src/server/utils/response-helpers.d.ts.map +1 -1
- package/dist/src/server/widgets/index.d.ts +3 -3
- package/dist/src/server/widgets/index.d.ts.map +1 -1
- package/dist/src/server/widgets/mount-widgets-dev.d.ts.map +1 -1
- package/dist/src/server/widgets/ui-resource-registration.d.ts +13 -25
- package/dist/src/server/widgets/ui-resource-registration.d.ts.map +1 -1
- package/dist/src/server/widgets/widget-helpers.d.ts +11 -6
- package/dist/src/server/widgets/widget-helpers.d.ts.map +1 -1
- package/dist/src/server/widgets/widget-types.d.ts +3 -3
- package/dist/src/server/widgets/widget-types.d.ts.map +1 -1
- package/dist/src/session.d.ts +372 -2
- package/dist/src/session.d.ts.map +1 -1
- package/dist/src/task_managers/sse.d.ts +2 -2
- package/dist/src/task_managers/sse.d.ts.map +1 -1
- package/dist/src/task_managers/stdio.d.ts +2 -2
- package/dist/src/task_managers/stdio.d.ts.map +1 -1
- package/dist/src/task_managers/streamable_http.d.ts +2 -2
- package/dist/src/task_managers/streamable_http.d.ts.map +1 -1
- package/dist/src/telemetry/events.d.ts +219 -0
- package/dist/src/telemetry/events.d.ts.map +1 -1
- package/dist/src/telemetry/index.d.ts +2 -2
- package/dist/src/telemetry/index.d.ts.map +1 -1
- package/dist/src/telemetry/telemetry.d.ts +56 -1
- package/dist/src/telemetry/telemetry.d.ts.map +1 -1
- package/dist/src/telemetry/utils.d.ts +1 -1
- package/dist/src/telemetry/utils.d.ts.map +1 -1
- package/dist/src/version.d.ts +8 -0
- package/dist/src/version.d.ts.map +1 -0
- package/dist/{tool-execution-helpers-IVUDHXMK.js → tool-execution-helpers-XFVBSRXM.js} +9 -2
- package/dist/tsup.config.d.ts.map +1 -1
- package/package.json +6 -5
- package/dist/chunk-MTHLLDCX.js +0 -97
package/dist/src/server/index.js
CHANGED
|
@@ -2,11 +2,12 @@ import {
|
|
|
2
2
|
getRequestContext,
|
|
3
3
|
hasRequestContext,
|
|
4
4
|
runWithContext
|
|
5
|
-
} from "../../chunk-
|
|
5
|
+
} from "../../chunk-LWVK6RXA.js";
|
|
6
6
|
import {
|
|
7
7
|
createEnhancedContext,
|
|
8
|
-
findSessionContext
|
|
9
|
-
|
|
8
|
+
findSessionContext,
|
|
9
|
+
isValidLogLevel
|
|
10
|
+
} from "../../chunk-BPP5XYP6.js";
|
|
10
11
|
import {
|
|
11
12
|
convertToolResultToResourceResult
|
|
12
13
|
} from "../../chunk-362PI25Z.js";
|
|
@@ -15,13 +16,17 @@ import {
|
|
|
15
16
|
} from "../../chunk-2EYAMIT3.js";
|
|
16
17
|
import "../../chunk-KUEVOU4M.js";
|
|
17
18
|
import {
|
|
19
|
+
Telemetry,
|
|
20
|
+
VERSION,
|
|
18
21
|
fsHelpers,
|
|
19
22
|
generateUUID,
|
|
20
23
|
getCwd,
|
|
21
24
|
getEnv,
|
|
25
|
+
getPackageVersion,
|
|
22
26
|
isDeno,
|
|
23
27
|
pathHelpers
|
|
24
|
-
} from "../../chunk-
|
|
28
|
+
} from "../../chunk-6EYDSXO6.js";
|
|
29
|
+
import "../../chunk-34R6SIER.js";
|
|
25
30
|
import {
|
|
26
31
|
__name
|
|
27
32
|
} from "../../chunk-3GQAWCBQ.js";
|
|
@@ -30,7 +35,12 @@ import {
|
|
|
30
35
|
import {
|
|
31
36
|
McpServer as OfficialMcpServer,
|
|
32
37
|
ResourceTemplate as ResourceTemplate2
|
|
33
|
-
} from "@modelcontextprotocol
|
|
38
|
+
} from "@mcp-use/modelcontextprotocol-sdk/server/mcp.js";
|
|
39
|
+
import {
|
|
40
|
+
McpError,
|
|
41
|
+
ErrorCode
|
|
42
|
+
} from "@mcp-use/modelcontextprotocol-sdk/types.js";
|
|
43
|
+
import { z as z2 } from "zod";
|
|
34
44
|
|
|
35
45
|
// src/server/utils/response-helpers.ts
|
|
36
46
|
function text(content) {
|
|
@@ -63,7 +73,109 @@ function image(data, mimeType = "image/png") {
|
|
|
63
73
|
};
|
|
64
74
|
}
|
|
65
75
|
__name(image, "image");
|
|
66
|
-
function
|
|
76
|
+
function getAudioMimeType(filename) {
|
|
77
|
+
const ext = filename.split(".").pop()?.toLowerCase();
|
|
78
|
+
switch (ext) {
|
|
79
|
+
case "wav":
|
|
80
|
+
return "audio/wav";
|
|
81
|
+
case "mp3":
|
|
82
|
+
return "audio/mpeg";
|
|
83
|
+
case "ogg":
|
|
84
|
+
return "audio/ogg";
|
|
85
|
+
case "m4a":
|
|
86
|
+
return "audio/mp4";
|
|
87
|
+
case "webm":
|
|
88
|
+
return "audio/webm";
|
|
89
|
+
case "flac":
|
|
90
|
+
return "audio/flac";
|
|
91
|
+
case "aac":
|
|
92
|
+
return "audio/aac";
|
|
93
|
+
default:
|
|
94
|
+
return "audio/wav";
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
__name(getAudioMimeType, "getAudioMimeType");
|
|
98
|
+
function arrayBufferToBase64(buffer) {
|
|
99
|
+
if (isDeno) {
|
|
100
|
+
const bytes = new Uint8Array(buffer);
|
|
101
|
+
let binary2 = "";
|
|
102
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
103
|
+
binary2 += String.fromCharCode(bytes[i]);
|
|
104
|
+
}
|
|
105
|
+
return btoa(binary2);
|
|
106
|
+
} else {
|
|
107
|
+
return Buffer.from(buffer).toString("base64");
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
__name(arrayBufferToBase64, "arrayBufferToBase64");
|
|
111
|
+
function audio(dataOrPath, mimeType) {
|
|
112
|
+
const isFilePath = dataOrPath.includes("/") || dataOrPath.includes("\\") || dataOrPath.includes(".");
|
|
113
|
+
if (isFilePath && dataOrPath.length < 1e3) {
|
|
114
|
+
return (async () => {
|
|
115
|
+
const buffer = await fsHelpers.readFile(dataOrPath);
|
|
116
|
+
const base64Data = arrayBufferToBase64(buffer);
|
|
117
|
+
const inferredMimeType = mimeType || getAudioMimeType(dataOrPath);
|
|
118
|
+
return {
|
|
119
|
+
content: [
|
|
120
|
+
{
|
|
121
|
+
type: "audio",
|
|
122
|
+
data: base64Data,
|
|
123
|
+
mimeType: inferredMimeType
|
|
124
|
+
}
|
|
125
|
+
],
|
|
126
|
+
_meta: {
|
|
127
|
+
mimeType: inferredMimeType,
|
|
128
|
+
isAudio: true
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
})();
|
|
132
|
+
}
|
|
133
|
+
const finalMimeType = mimeType || "audio/wav";
|
|
134
|
+
return {
|
|
135
|
+
content: [
|
|
136
|
+
{
|
|
137
|
+
type: "audio",
|
|
138
|
+
data: dataOrPath,
|
|
139
|
+
mimeType: finalMimeType
|
|
140
|
+
}
|
|
141
|
+
],
|
|
142
|
+
_meta: {
|
|
143
|
+
mimeType: finalMimeType,
|
|
144
|
+
isAudio: true
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
__name(audio, "audio");
|
|
149
|
+
function resource(uri, mimeTypeOrContent, text2) {
|
|
150
|
+
if (typeof mimeTypeOrContent === "object" && mimeTypeOrContent !== null && "content" in mimeTypeOrContent) {
|
|
151
|
+
const contentResult = mimeTypeOrContent;
|
|
152
|
+
let extractedText;
|
|
153
|
+
let extractedMimeType;
|
|
154
|
+
if (contentResult._meta && typeof contentResult._meta === "object") {
|
|
155
|
+
const meta = contentResult._meta;
|
|
156
|
+
if (meta.mimeType && typeof meta.mimeType === "string") {
|
|
157
|
+
extractedMimeType = meta.mimeType;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (contentResult.content && contentResult.content.length > 0) {
|
|
161
|
+
const firstContent = contentResult.content[0];
|
|
162
|
+
if (firstContent.type === "text" && "text" in firstContent) {
|
|
163
|
+
extractedText = firstContent.text;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
const resourceContent2 = {
|
|
167
|
+
type: "resource",
|
|
168
|
+
resource: {
|
|
169
|
+
uri,
|
|
170
|
+
...extractedMimeType && { mimeType: extractedMimeType },
|
|
171
|
+
...extractedText && { text: extractedText }
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
return {
|
|
175
|
+
content: [resourceContent2]
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
const mimeType = mimeTypeOrContent;
|
|
67
179
|
const resourceContent = {
|
|
68
180
|
type: "resource",
|
|
69
181
|
resource: {
|
|
@@ -202,37 +314,12 @@ function binary(base64Data, mimeType) {
|
|
|
202
314
|
}
|
|
203
315
|
__name(binary, "binary");
|
|
204
316
|
function widget(config) {
|
|
205
|
-
const {
|
|
206
|
-
name,
|
|
207
|
-
data,
|
|
208
|
-
message,
|
|
209
|
-
invoking,
|
|
210
|
-
invoked,
|
|
211
|
-
widgetAccessible = true,
|
|
212
|
-
resultCanProduceWidget = true,
|
|
213
|
-
buildId
|
|
214
|
-
} = config;
|
|
215
|
-
const randomId = Math.random().toString(36).substring(2, 15);
|
|
216
|
-
const buildIdPart = buildId ? `-${buildId}` : "";
|
|
217
|
-
const uniqueUri = `ui://widget/${name}${buildIdPart}-${randomId}.html`;
|
|
218
|
-
const metadata = {
|
|
219
|
-
"openai/outputTemplate": uniqueUri,
|
|
220
|
-
"openai/widgetAccessible": widgetAccessible,
|
|
221
|
-
"openai/resultCanProduceWidget": resultCanProduceWidget
|
|
222
|
-
};
|
|
223
|
-
if (invoking) {
|
|
224
|
-
metadata["openai/toolInvocation/invoking"] = invoking;
|
|
225
|
-
}
|
|
226
|
-
if (invoked) {
|
|
227
|
-
metadata["openai/toolInvocation/invoked"] = invoked;
|
|
228
|
-
}
|
|
229
|
-
const displayMessage = message || `Displaying ${name}`;
|
|
317
|
+
const { data, message } = config;
|
|
230
318
|
return {
|
|
231
|
-
_meta: metadata,
|
|
232
319
|
content: [
|
|
233
320
|
{
|
|
234
321
|
type: "text",
|
|
235
|
-
text:
|
|
322
|
+
text: message || ""
|
|
236
323
|
}
|
|
237
324
|
],
|
|
238
325
|
// structuredContent will be injected as window.openai.toolOutput by Apps SDK
|
|
@@ -338,7 +425,7 @@ function parseTemplateUri(template, uri) {
|
|
|
338
425
|
const params = {};
|
|
339
426
|
let regexPattern = template.replace(/[.*+?^$()[\]\\|]/g, "\\$&");
|
|
340
427
|
const paramNames = [];
|
|
341
|
-
regexPattern = regexPattern.replace(
|
|
428
|
+
regexPattern = regexPattern.replace(/\{([^}]+)\}/g, (_, paramName) => {
|
|
342
429
|
paramNames.push(paramName);
|
|
343
430
|
return "([^/]+)";
|
|
344
431
|
});
|
|
@@ -901,6 +988,7 @@ function createWidgetRegistration(widgetName, metadata, html2, serverConfig, isD
|
|
|
901
988
|
const props = metadata.inputs || {};
|
|
902
989
|
const description = metadata.description || `Widget: ${widgetName}`;
|
|
903
990
|
const title = metadata.title || widgetName;
|
|
991
|
+
const exposeAsTool = metadata.exposeAsTool !== void 0 ? metadata.exposeAsTool : true;
|
|
904
992
|
const mcp_connect_domain = serverConfig.serverBaseUrl ? new URL(serverConfig.serverBaseUrl || "").origin : null;
|
|
905
993
|
return {
|
|
906
994
|
name: widgetName,
|
|
@@ -916,7 +1004,8 @@ function createWidgetRegistration(widgetName, metadata, html2, serverConfig, isD
|
|
|
916
1004
|
type: "appsSdk",
|
|
917
1005
|
props,
|
|
918
1006
|
html: html2,
|
|
919
|
-
dev: isDev
|
|
1007
|
+
dev: isDev,
|
|
1008
|
+
exposeAsTool
|
|
920
1009
|
},
|
|
921
1010
|
...metadata._meta || {}
|
|
922
1011
|
},
|
|
@@ -1196,10 +1285,42 @@ if (container && Component) {
|
|
|
1196
1285
|
console.log(`[WIDGETS] Watching resources directory: ${resourcesPath}`);
|
|
1197
1286
|
}
|
|
1198
1287
|
};
|
|
1288
|
+
const nodeStubsPlugin = {
|
|
1289
|
+
name: "node-stubs",
|
|
1290
|
+
enforce: "pre",
|
|
1291
|
+
resolveId(id) {
|
|
1292
|
+
if (id === "posthog-node" || id.startsWith("posthog-node/")) {
|
|
1293
|
+
return "\0virtual:posthog-node-stub";
|
|
1294
|
+
}
|
|
1295
|
+
return null;
|
|
1296
|
+
},
|
|
1297
|
+
load(id) {
|
|
1298
|
+
if (id === "\0virtual:posthog-node-stub") {
|
|
1299
|
+
return `
|
|
1300
|
+
export class PostHog {
|
|
1301
|
+
constructor() {}
|
|
1302
|
+
capture() {}
|
|
1303
|
+
identify() {}
|
|
1304
|
+
alias() {}
|
|
1305
|
+
flush() { return Promise.resolve(); }
|
|
1306
|
+
shutdown() { return Promise.resolve(); }
|
|
1307
|
+
}
|
|
1308
|
+
export default PostHog;
|
|
1309
|
+
`;
|
|
1310
|
+
}
|
|
1311
|
+
return null;
|
|
1312
|
+
}
|
|
1313
|
+
};
|
|
1199
1314
|
const viteServer = await createServer({
|
|
1200
1315
|
root: tempDir,
|
|
1201
1316
|
base: baseRoute + "/",
|
|
1202
|
-
plugins: [
|
|
1317
|
+
plugins: [
|
|
1318
|
+
nodeStubsPlugin,
|
|
1319
|
+
ssrCssPlugin,
|
|
1320
|
+
watchResourcesPlugin,
|
|
1321
|
+
tailwindcss(),
|
|
1322
|
+
react()
|
|
1323
|
+
],
|
|
1203
1324
|
resolve: {
|
|
1204
1325
|
alias: {
|
|
1205
1326
|
"@": pathHelpers.join(getCwd(), resourcesDir)
|
|
@@ -1220,12 +1341,15 @@ if (container && Component) {
|
|
|
1220
1341
|
// Explicitly tell Vite to watch files outside root
|
|
1221
1342
|
// This is needed because widget entry files import from resources directory
|
|
1222
1343
|
optimizeDeps: {
|
|
1223
|
-
//
|
|
1224
|
-
|
|
1344
|
+
// Exclude Node.js-only packages from browser bundling
|
|
1345
|
+
// posthog-node is for server-side telemetry and doesn't work in browser
|
|
1346
|
+
exclude: ["posthog-node"]
|
|
1225
1347
|
},
|
|
1226
1348
|
ssr: {
|
|
1227
1349
|
// Force Vite to transform these packages in SSR instead of using external requires
|
|
1228
|
-
noExternal: ["@openai/apps-sdk-ui", "react-router"]
|
|
1350
|
+
noExternal: ["@openai/apps-sdk-ui", "react-router"],
|
|
1351
|
+
// Mark Node.js-only packages as external in SSR mode
|
|
1352
|
+
external: ["posthog-node"]
|
|
1229
1353
|
},
|
|
1230
1354
|
define: {
|
|
1231
1355
|
// Define process.env for SSR context
|
|
@@ -1482,25 +1606,31 @@ function setupWidgetRoutes(app, serverConfig) {
|
|
|
1482
1606
|
__name(setupWidgetRoutes, "setupWidgetRoutes");
|
|
1483
1607
|
|
|
1484
1608
|
// src/server/widgets/ui-resource-registration.ts
|
|
1485
|
-
function uiResourceRegistration(definition) {
|
|
1609
|
+
function uiResourceRegistration(server, definition) {
|
|
1486
1610
|
const displayName = definition.title || definition.name;
|
|
1611
|
+
if (definition.type === "appsSdk" && definition._meta) {
|
|
1612
|
+
server.widgetDefinitions.set(
|
|
1613
|
+
definition.name,
|
|
1614
|
+
definition._meta
|
|
1615
|
+
);
|
|
1616
|
+
}
|
|
1487
1617
|
let resourceUri;
|
|
1488
1618
|
let mimeType;
|
|
1489
1619
|
switch (definition.type) {
|
|
1490
1620
|
case "externalUrl":
|
|
1491
|
-
resourceUri = generateWidgetUri(definition.widget,
|
|
1621
|
+
resourceUri = generateWidgetUri(definition.widget, server.buildId);
|
|
1492
1622
|
mimeType = "text/uri-list";
|
|
1493
1623
|
break;
|
|
1494
1624
|
case "rawHtml":
|
|
1495
|
-
resourceUri = generateWidgetUri(definition.name,
|
|
1625
|
+
resourceUri = generateWidgetUri(definition.name, server.buildId);
|
|
1496
1626
|
mimeType = "text/html";
|
|
1497
1627
|
break;
|
|
1498
1628
|
case "remoteDom":
|
|
1499
|
-
resourceUri = generateWidgetUri(definition.name,
|
|
1629
|
+
resourceUri = generateWidgetUri(definition.name, server.buildId);
|
|
1500
1630
|
mimeType = "application/vnd.mcp-ui.remote-dom+javascript";
|
|
1501
1631
|
break;
|
|
1502
1632
|
case "appsSdk":
|
|
1503
|
-
resourceUri = generateWidgetUri(definition.name,
|
|
1633
|
+
resourceUri = generateWidgetUri(definition.name, server.buildId, ".html");
|
|
1504
1634
|
mimeType = "text/html+skybridge";
|
|
1505
1635
|
break;
|
|
1506
1636
|
default:
|
|
@@ -1509,12 +1639,12 @@ function uiResourceRegistration(definition) {
|
|
|
1509
1639
|
);
|
|
1510
1640
|
}
|
|
1511
1641
|
const serverConfig = {
|
|
1512
|
-
serverHost:
|
|
1513
|
-
serverPort:
|
|
1514
|
-
serverBaseUrl:
|
|
1515
|
-
buildId:
|
|
1642
|
+
serverHost: server.serverHost,
|
|
1643
|
+
serverPort: server.serverPort || 3e3,
|
|
1644
|
+
serverBaseUrl: server.serverBaseUrl,
|
|
1645
|
+
buildId: server.buildId
|
|
1516
1646
|
};
|
|
1517
|
-
|
|
1647
|
+
server.resource({
|
|
1518
1648
|
name: definition.name,
|
|
1519
1649
|
uri: resourceUri,
|
|
1520
1650
|
title: definition.title,
|
|
@@ -1536,9 +1666,9 @@ function uiResourceRegistration(definition) {
|
|
|
1536
1666
|
}, "readCallback")
|
|
1537
1667
|
});
|
|
1538
1668
|
if (definition.type === "appsSdk") {
|
|
1539
|
-
const buildIdPart =
|
|
1669
|
+
const buildIdPart = server.buildId ? `-${server.buildId}` : "";
|
|
1540
1670
|
const uriTemplate = `ui://widget/${definition.name}${buildIdPart}-{id}.html`;
|
|
1541
|
-
|
|
1671
|
+
server.resourceTemplate({
|
|
1542
1672
|
name: `${definition.name}-dynamic`,
|
|
1543
1673
|
resourceTemplate: {
|
|
1544
1674
|
uriTemplate,
|
|
@@ -1563,70 +1693,77 @@ function uiResourceRegistration(definition) {
|
|
|
1563
1693
|
}, "readCallback")
|
|
1564
1694
|
});
|
|
1565
1695
|
}
|
|
1566
|
-
const
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
const
|
|
1570
|
-
|
|
1571
|
-
"openai/
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1696
|
+
const widgetMetadata = definition._meta?.["mcp-use/widget"];
|
|
1697
|
+
const exposeAsTool = definition.exposeAsTool ?? widgetMetadata?.exposeAsTool ?? true;
|
|
1698
|
+
if (exposeAsTool) {
|
|
1699
|
+
const toolMetadata = definition._meta || {};
|
|
1700
|
+
if (definition.type === "appsSdk" && definition.appsSdkMetadata) {
|
|
1701
|
+
toolMetadata["openai/outputTemplate"] = resourceUri;
|
|
1702
|
+
const toolMetadataFields = [
|
|
1703
|
+
"openai/toolInvocation/invoking",
|
|
1704
|
+
"openai/toolInvocation/invoked",
|
|
1705
|
+
"openai/widgetAccessible",
|
|
1706
|
+
"openai/resultCanProduceWidget"
|
|
1707
|
+
];
|
|
1708
|
+
for (const field of toolMetadataFields) {
|
|
1709
|
+
if (definition.appsSdkMetadata[field] !== void 0) {
|
|
1710
|
+
toolMetadata[field] = definition.appsSdkMetadata[field];
|
|
1711
|
+
}
|
|
1578
1712
|
}
|
|
1579
1713
|
}
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
const randomId = Math.random().toString(36).substring(2, 15);
|
|
1595
|
-
const uniqueUri = generateWidgetUri(
|
|
1596
|
-
definition.name,
|
|
1597
|
-
this.buildId,
|
|
1598
|
-
".html",
|
|
1599
|
-
randomId
|
|
1714
|
+
server.tool(
|
|
1715
|
+
{
|
|
1716
|
+
name: definition.name,
|
|
1717
|
+
title: definition.title,
|
|
1718
|
+
description: definition.description,
|
|
1719
|
+
inputs: convertPropsToInputs(definition.props),
|
|
1720
|
+
annotations: definition.toolAnnotations,
|
|
1721
|
+
_meta: Object.keys(toolMetadata).length > 0 ? toolMetadata : void 0
|
|
1722
|
+
},
|
|
1723
|
+
async (params) => {
|
|
1724
|
+
const uiResource = await createWidgetUIResource(
|
|
1725
|
+
definition,
|
|
1726
|
+
params,
|
|
1727
|
+
serverConfig
|
|
1600
1728
|
);
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1729
|
+
if (definition.type === "appsSdk") {
|
|
1730
|
+
const randomId = Math.random().toString(36).substring(2, 15);
|
|
1731
|
+
const uniqueUri = generateWidgetUri(
|
|
1732
|
+
definition.name,
|
|
1733
|
+
server.buildId,
|
|
1734
|
+
".html",
|
|
1735
|
+
randomId
|
|
1736
|
+
);
|
|
1737
|
+
const uniqueToolMetadata = {
|
|
1738
|
+
...toolMetadata,
|
|
1739
|
+
"openai/outputTemplate": uniqueUri
|
|
1740
|
+
};
|
|
1741
|
+
return {
|
|
1742
|
+
_meta: uniqueToolMetadata,
|
|
1743
|
+
content: [
|
|
1744
|
+
{
|
|
1745
|
+
type: "text",
|
|
1746
|
+
text: `Displaying ${displayName}`
|
|
1747
|
+
}
|
|
1748
|
+
],
|
|
1749
|
+
// structuredContent will be injected as window.openai.toolOutput by Apps SDK
|
|
1750
|
+
structuredContent: params
|
|
1751
|
+
};
|
|
1752
|
+
}
|
|
1605
1753
|
return {
|
|
1606
|
-
_meta: uniqueToolMetadata,
|
|
1607
1754
|
content: [
|
|
1608
1755
|
{
|
|
1609
1756
|
type: "text",
|
|
1610
|
-
text: `Displaying ${displayName}
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1757
|
+
text: `Displaying ${displayName}`,
|
|
1758
|
+
description: `Show MCP-UI widget for ${displayName}`
|
|
1759
|
+
},
|
|
1760
|
+
uiResource
|
|
1761
|
+
]
|
|
1615
1762
|
};
|
|
1616
1763
|
}
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
type: "text",
|
|
1621
|
-
text: `Displaying ${displayName}`,
|
|
1622
|
-
description: `Show MCP-UI widget for ${displayName}`
|
|
1623
|
-
},
|
|
1624
|
-
uiResource
|
|
1625
|
-
]
|
|
1626
|
-
};
|
|
1627
|
-
}, "cb")
|
|
1628
|
-
});
|
|
1629
|
-
return this;
|
|
1764
|
+
);
|
|
1765
|
+
}
|
|
1766
|
+
return server;
|
|
1630
1767
|
}
|
|
1631
1768
|
__name(uiResourceRegistration, "uiResourceRegistration");
|
|
1632
1769
|
|
|
@@ -1762,7 +1899,7 @@ function toolRegistration(toolDefinition, callback) {
|
|
|
1762
1899
|
const initialRequestContext = getRequestContext();
|
|
1763
1900
|
const extraProgressToken = extra?._meta?.progressToken;
|
|
1764
1901
|
const extraSendNotification = extra?.sendNotification;
|
|
1765
|
-
const { requestContext, progressToken, sendNotification: sendNotification2 } = findSessionContext(
|
|
1902
|
+
const { requestContext, session, progressToken, sendNotification: sendNotification2 } = findSessionContext(
|
|
1766
1903
|
this.sessions,
|
|
1767
1904
|
initialRequestContext,
|
|
1768
1905
|
extraProgressToken,
|
|
@@ -1773,7 +1910,9 @@ function toolRegistration(toolDefinition, callback) {
|
|
|
1773
1910
|
this.createMessage.bind(this),
|
|
1774
1911
|
this.server.server.elicitInput.bind(this.server.server),
|
|
1775
1912
|
progressToken,
|
|
1776
|
-
sendNotification2
|
|
1913
|
+
sendNotification2,
|
|
1914
|
+
session?.logLevel,
|
|
1915
|
+
session?.clientCapabilities
|
|
1777
1916
|
);
|
|
1778
1917
|
const executeCallback = /* @__PURE__ */ __name(async () => {
|
|
1779
1918
|
if (actualCallback.length >= 2) {
|
|
@@ -1793,7 +1932,155 @@ function toolRegistration(toolDefinition, callback) {
|
|
|
1793
1932
|
__name(toolRegistration, "toolRegistration");
|
|
1794
1933
|
|
|
1795
1934
|
// src/server/resources/index.ts
|
|
1796
|
-
import { ResourceTemplate } from "@modelcontextprotocol
|
|
1935
|
+
import { ResourceTemplate } from "@mcp-use/modelcontextprotocol-sdk/server/mcp.js";
|
|
1936
|
+
|
|
1937
|
+
// src/server/resources/subscriptions.ts
|
|
1938
|
+
import {
|
|
1939
|
+
SubscribeRequestSchema,
|
|
1940
|
+
UnsubscribeRequestSchema
|
|
1941
|
+
} from "@mcp-use/modelcontextprotocol-sdk/types.js";
|
|
1942
|
+
var ResourceSubscriptionManager = class {
|
|
1943
|
+
static {
|
|
1944
|
+
__name(this, "ResourceSubscriptionManager");
|
|
1945
|
+
}
|
|
1946
|
+
/**
|
|
1947
|
+
* Tracks resource subscriptions per session
|
|
1948
|
+
* Map structure: uri -> Set<sessionId>
|
|
1949
|
+
*/
|
|
1950
|
+
subscriptions = /* @__PURE__ */ new Map();
|
|
1951
|
+
/**
|
|
1952
|
+
* Register subscription handlers with an MCP server instance
|
|
1953
|
+
*
|
|
1954
|
+
* @param server - The native MCP server instance
|
|
1955
|
+
* @param sessions - Map of active sessions
|
|
1956
|
+
*/
|
|
1957
|
+
registerHandlers(server, sessions) {
|
|
1958
|
+
server.server.setRequestHandler(
|
|
1959
|
+
SubscribeRequestSchema,
|
|
1960
|
+
async (request) => {
|
|
1961
|
+
const { uri } = request.params;
|
|
1962
|
+
const sessionId = this.getSessionIdFromContext(sessions, server);
|
|
1963
|
+
if (!sessionId) {
|
|
1964
|
+
console.warn(
|
|
1965
|
+
`[MCP] Could not determine session ID for resource subscription to ${uri}`
|
|
1966
|
+
);
|
|
1967
|
+
return {};
|
|
1968
|
+
}
|
|
1969
|
+
if (!this.subscriptions.has(uri)) {
|
|
1970
|
+
this.subscriptions.set(uri, /* @__PURE__ */ new Set());
|
|
1971
|
+
}
|
|
1972
|
+
this.subscriptions.get(uri).add(sessionId);
|
|
1973
|
+
console.log(
|
|
1974
|
+
`[MCP] Session ${sessionId} subscribed to resource: ${uri}`
|
|
1975
|
+
);
|
|
1976
|
+
return {};
|
|
1977
|
+
}
|
|
1978
|
+
);
|
|
1979
|
+
server.server.setRequestHandler(
|
|
1980
|
+
UnsubscribeRequestSchema,
|
|
1981
|
+
async (request) => {
|
|
1982
|
+
const { uri } = request.params;
|
|
1983
|
+
const sessionId = this.getSessionIdFromContext(sessions, server);
|
|
1984
|
+
if (!sessionId) {
|
|
1985
|
+
console.warn(
|
|
1986
|
+
`[MCP] Could not determine session ID for resource unsubscribe from ${uri}`
|
|
1987
|
+
);
|
|
1988
|
+
return {};
|
|
1989
|
+
}
|
|
1990
|
+
const subscribers = this.subscriptions.get(uri);
|
|
1991
|
+
if (subscribers) {
|
|
1992
|
+
subscribers.delete(sessionId);
|
|
1993
|
+
if (subscribers.size === 0) {
|
|
1994
|
+
this.subscriptions.delete(uri);
|
|
1995
|
+
}
|
|
1996
|
+
console.log(
|
|
1997
|
+
`[MCP] Session ${sessionId} unsubscribed from resource: ${uri}`
|
|
1998
|
+
);
|
|
1999
|
+
}
|
|
2000
|
+
return {};
|
|
2001
|
+
}
|
|
2002
|
+
);
|
|
2003
|
+
}
|
|
2004
|
+
/**
|
|
2005
|
+
* Get session ID from request context or sessions map
|
|
2006
|
+
*
|
|
2007
|
+
* @param sessions - Map of active sessions
|
|
2008
|
+
* @param server - The server instance to match against
|
|
2009
|
+
* @returns The session ID, or undefined if not found
|
|
2010
|
+
*/
|
|
2011
|
+
getSessionIdFromContext(sessions, server) {
|
|
2012
|
+
const requestContext = getRequestContext();
|
|
2013
|
+
let sessionId;
|
|
2014
|
+
if (requestContext) {
|
|
2015
|
+
sessionId = requestContext.req.header("mcp-session-id");
|
|
2016
|
+
}
|
|
2017
|
+
if (!sessionId) {
|
|
2018
|
+
for (const [sid, session] of sessions.entries()) {
|
|
2019
|
+
if (session.server === server) {
|
|
2020
|
+
sessionId = sid;
|
|
2021
|
+
break;
|
|
2022
|
+
}
|
|
2023
|
+
}
|
|
2024
|
+
}
|
|
2025
|
+
return sessionId;
|
|
2026
|
+
}
|
|
2027
|
+
/**
|
|
2028
|
+
* Notify subscribed clients that a resource has been updated
|
|
2029
|
+
*
|
|
2030
|
+
* This method sends a `notifications/resources/updated` notification to all
|
|
2031
|
+
* sessions that have subscribed to the specified resource URI.
|
|
2032
|
+
*
|
|
2033
|
+
* @param uri - The URI of the resource that changed
|
|
2034
|
+
* @param sessions - Map of active sessions
|
|
2035
|
+
* @returns Promise that resolves when all notifications have been sent
|
|
2036
|
+
*/
|
|
2037
|
+
async notifyResourceUpdated(uri, sessions) {
|
|
2038
|
+
const subscribers = this.subscriptions.get(uri);
|
|
2039
|
+
if (!subscribers || subscribers.size === 0) {
|
|
2040
|
+
return;
|
|
2041
|
+
}
|
|
2042
|
+
console.log(
|
|
2043
|
+
`[MCP] Notifying ${subscribers.size} subscriber(s) of resource update: ${uri}`
|
|
2044
|
+
);
|
|
2045
|
+
for (const sessionId of subscribers) {
|
|
2046
|
+
const session = sessions.get(sessionId);
|
|
2047
|
+
if (session?.server) {
|
|
2048
|
+
try {
|
|
2049
|
+
await session.server.server.sendResourceUpdated({ uri });
|
|
2050
|
+
console.log(
|
|
2051
|
+
`[MCP] Sent resource update notification to session ${sessionId}`
|
|
2052
|
+
);
|
|
2053
|
+
} catch (error2) {
|
|
2054
|
+
console.error(
|
|
2055
|
+
`[MCP] Failed to send resource update notification to session ${sessionId}:`,
|
|
2056
|
+
error2
|
|
2057
|
+
);
|
|
2058
|
+
}
|
|
2059
|
+
}
|
|
2060
|
+
}
|
|
2061
|
+
}
|
|
2062
|
+
/**
|
|
2063
|
+
* Clean up resource subscriptions for a closed session
|
|
2064
|
+
*
|
|
2065
|
+
* This method is called automatically when a session is closed to remove
|
|
2066
|
+
* all resource subscriptions associated with that session.
|
|
2067
|
+
*
|
|
2068
|
+
* @param sessionId - The session ID to clean up
|
|
2069
|
+
*/
|
|
2070
|
+
cleanupSession(sessionId) {
|
|
2071
|
+
for (const [uri, subscribers] of this.subscriptions) {
|
|
2072
|
+
subscribers.delete(sessionId);
|
|
2073
|
+
if (subscribers.size === 0) {
|
|
2074
|
+
this.subscriptions.delete(uri);
|
|
2075
|
+
}
|
|
2076
|
+
}
|
|
2077
|
+
console.log(
|
|
2078
|
+
`[MCP] Cleaned up resource subscriptions for session ${sessionId}`
|
|
2079
|
+
);
|
|
2080
|
+
}
|
|
2081
|
+
};
|
|
2082
|
+
|
|
2083
|
+
// src/server/resources/index.ts
|
|
1797
2084
|
function registerResource(resourceDefinition, callback) {
|
|
1798
2085
|
const actualCallback = callback || resourceDefinition.readCallback;
|
|
1799
2086
|
if (!actualCallback) {
|
|
@@ -1803,8 +2090,8 @@ function registerResource(resourceDefinition, callback) {
|
|
|
1803
2090
|
}
|
|
1804
2091
|
const explicitMimeType = resourceDefinition.mimeType;
|
|
1805
2092
|
const wrappedCallback = /* @__PURE__ */ __name(async () => {
|
|
1806
|
-
const { getRequestContext: getRequestContext2, runWithContext: runWithContext2 } = await import("../../context-storage-
|
|
1807
|
-
const { findSessionContext: findSessionContext2 } = await import("../../tool-execution-helpers-
|
|
2093
|
+
const { getRequestContext: getRequestContext2, runWithContext: runWithContext2 } = await import("../../context-storage-NA4MHWOZ.js");
|
|
2094
|
+
const { findSessionContext: findSessionContext2 } = await import("../../tool-execution-helpers-XFVBSRXM.js");
|
|
1808
2095
|
const initialRequestContext = getRequestContext2();
|
|
1809
2096
|
const sessions = this.sessions || /* @__PURE__ */ new Map();
|
|
1810
2097
|
const { requestContext } = findSessionContext2(
|
|
@@ -1852,24 +2139,25 @@ function registerResourceTemplate(resourceTemplateDefinition, callback) {
|
|
|
1852
2139
|
`Resource template '${resourceTemplateDefinition.name}' must have either a readCallback property or a callback parameter`
|
|
1853
2140
|
);
|
|
1854
2141
|
}
|
|
1855
|
-
const
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
2142
|
+
const isFlatStructure = "uriTemplate" in resourceTemplateDefinition;
|
|
2143
|
+
const uriTemplate = isFlatStructure ? resourceTemplateDefinition.uriTemplate : resourceTemplateDefinition.resourceTemplate.uriTemplate;
|
|
2144
|
+
const mimeType = isFlatStructure ? resourceTemplateDefinition.mimeType : resourceTemplateDefinition.resourceTemplate.mimeType;
|
|
2145
|
+
const templateDescription = isFlatStructure ? void 0 : resourceTemplateDefinition.resourceTemplate.description;
|
|
2146
|
+
const template = new ResourceTemplate(uriTemplate, {
|
|
2147
|
+
list: void 0,
|
|
2148
|
+
// Optional: callback to list all matching resources
|
|
2149
|
+
complete: void 0
|
|
2150
|
+
// Optional: callback for auto-completion
|
|
2151
|
+
});
|
|
1864
2152
|
const metadata = {};
|
|
1865
2153
|
if (resourceTemplateDefinition.title) {
|
|
1866
2154
|
metadata.title = resourceTemplateDefinition.title;
|
|
1867
2155
|
}
|
|
1868
|
-
if (resourceTemplateDefinition.description ||
|
|
1869
|
-
metadata.description = resourceTemplateDefinition.description ||
|
|
2156
|
+
if (resourceTemplateDefinition.description || templateDescription) {
|
|
2157
|
+
metadata.description = resourceTemplateDefinition.description || templateDescription;
|
|
1870
2158
|
}
|
|
1871
|
-
if (
|
|
1872
|
-
metadata.mimeType =
|
|
2159
|
+
if (mimeType) {
|
|
2160
|
+
metadata.mimeType = mimeType;
|
|
1873
2161
|
}
|
|
1874
2162
|
if (resourceTemplateDefinition.annotations) {
|
|
1875
2163
|
metadata.annotations = resourceTemplateDefinition.annotations;
|
|
@@ -1879,12 +2167,9 @@ function registerResourceTemplate(resourceTemplateDefinition, callback) {
|
|
|
1879
2167
|
template,
|
|
1880
2168
|
metadata,
|
|
1881
2169
|
async (uri) => {
|
|
1882
|
-
const params = this.parseTemplateUri(
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
);
|
|
1886
|
-
const { getRequestContext: getRequestContext2, runWithContext: runWithContext2 } = await import("../../context-storage-TXQ4DVSS.js");
|
|
1887
|
-
const { findSessionContext: findSessionContext2 } = await import("../../tool-execution-helpers-IVUDHXMK.js");
|
|
2170
|
+
const params = this.parseTemplateUri(uriTemplate, uri.toString());
|
|
2171
|
+
const { getRequestContext: getRequestContext2, runWithContext: runWithContext2 } = await import("../../context-storage-NA4MHWOZ.js");
|
|
2172
|
+
const { findSessionContext: findSessionContext2 } = await import("../../tool-execution-helpers-XFVBSRXM.js");
|
|
1888
2173
|
const initialRequestContext = getRequestContext2();
|
|
1889
2174
|
const sessions = this.sessions || /* @__PURE__ */ new Map();
|
|
1890
2175
|
const { requestContext } = findSessionContext2(
|
|
@@ -1897,8 +2182,12 @@ function registerResourceTemplate(resourceTemplateDefinition, callback) {
|
|
|
1897
2182
|
const executeCallback = /* @__PURE__ */ __name(async () => {
|
|
1898
2183
|
if (actualCallback.length >= 3) {
|
|
1899
2184
|
return await actualCallback(uri, params, enhancedContext);
|
|
2185
|
+
} else if (actualCallback.length === 2) {
|
|
2186
|
+
return await actualCallback(uri, params);
|
|
2187
|
+
} else if (actualCallback.length === 1) {
|
|
2188
|
+
return await actualCallback(uri);
|
|
1900
2189
|
}
|
|
1901
|
-
return await actualCallback(
|
|
2190
|
+
return await actualCallback();
|
|
1902
2191
|
}, "executeCallback");
|
|
1903
2192
|
const result = requestContext ? await runWithContext2(requestContext, executeCallback) : await executeCallback();
|
|
1904
2193
|
if ("contents" in result && Array.isArray(result.contents)) {
|
|
@@ -1928,12 +2217,14 @@ function registerPrompt(promptDefinition, callback) {
|
|
|
1928
2217
|
argsSchema = this.convertZodSchemaToParams(
|
|
1929
2218
|
promptDefinition.schema
|
|
1930
2219
|
);
|
|
2220
|
+
} else if (promptDefinition.args && promptDefinition.args.length > 0) {
|
|
2221
|
+
argsSchema = this.createParamsSchema(promptDefinition.args);
|
|
1931
2222
|
} else {
|
|
1932
|
-
argsSchema =
|
|
2223
|
+
argsSchema = void 0;
|
|
1933
2224
|
}
|
|
1934
2225
|
const wrappedCallback = /* @__PURE__ */ __name(async (params, extra) => {
|
|
1935
|
-
const { getRequestContext: getRequestContext2, runWithContext: runWithContext2 } = await import("../../context-storage-
|
|
1936
|
-
const { findSessionContext: findSessionContext2 } = await import("../../tool-execution-helpers-
|
|
2226
|
+
const { getRequestContext: getRequestContext2, runWithContext: runWithContext2 } = await import("../../context-storage-NA4MHWOZ.js");
|
|
2227
|
+
const { findSessionContext: findSessionContext2 } = await import("../../tool-execution-helpers-XFVBSRXM.js");
|
|
1937
2228
|
const initialRequestContext = getRequestContext2();
|
|
1938
2229
|
const sessions = this.sessions || /* @__PURE__ */ new Map();
|
|
1939
2230
|
const { requestContext } = findSessionContext2(
|
|
@@ -2204,7 +2495,7 @@ async function sendNotificationToSession2(sessionId, method, params) {
|
|
|
2204
2495
|
__name(sendNotificationToSession2, "sendNotificationToSession");
|
|
2205
2496
|
|
|
2206
2497
|
// src/server/sessions/session-manager.ts
|
|
2207
|
-
function startIdleCleanup(sessions, idleTimeoutMs) {
|
|
2498
|
+
function startIdleCleanup(sessions, idleTimeoutMs, mcpServerInstance) {
|
|
2208
2499
|
if (idleTimeoutMs <= 0) {
|
|
2209
2500
|
return void 0;
|
|
2210
2501
|
}
|
|
@@ -2222,6 +2513,7 @@ function startIdleCleanup(sessions, idleTimeoutMs) {
|
|
|
2222
2513
|
);
|
|
2223
2514
|
for (const sessionId of expiredSessions) {
|
|
2224
2515
|
sessions.delete(sessionId);
|
|
2516
|
+
mcpServerInstance?.cleanupSessionSubscriptions?.(sessionId);
|
|
2225
2517
|
}
|
|
2226
2518
|
}
|
|
2227
2519
|
}, 6e4);
|
|
@@ -2230,12 +2522,16 @@ __name(startIdleCleanup, "startIdleCleanup");
|
|
|
2230
2522
|
|
|
2231
2523
|
// src/server/endpoints/mount-mcp.ts
|
|
2232
2524
|
async function mountMcp(app, mcpServerInstance, sessions, config, isProductionMode2) {
|
|
2233
|
-
const { FetchStreamableHTTPServerTransport } = await import("@modelcontextprotocol
|
|
2525
|
+
const { FetchStreamableHTTPServerTransport } = await import("@mcp-use/modelcontextprotocol-sdk/experimental/fetch-streamable-http/index.js");
|
|
2234
2526
|
const idleTimeoutMs = config.sessionIdleTimeoutMs ?? 3e5;
|
|
2235
2527
|
const transports = /* @__PURE__ */ new Map();
|
|
2236
2528
|
let idleCleanupInterval;
|
|
2237
2529
|
if (idleTimeoutMs > 0) {
|
|
2238
|
-
idleCleanupInterval = startIdleCleanup(
|
|
2530
|
+
idleCleanupInterval = startIdleCleanup(
|
|
2531
|
+
sessions,
|
|
2532
|
+
idleTimeoutMs,
|
|
2533
|
+
mcpServerInstance
|
|
2534
|
+
);
|
|
2239
2535
|
}
|
|
2240
2536
|
const handleRequest = /* @__PURE__ */ __name(async (c) => {
|
|
2241
2537
|
const sessionId = c.req.header("mcp-session-id");
|
|
@@ -2262,11 +2558,33 @@ async function mountMcp(app, mcpServerInstance, sessions, config, isProductionMo
|
|
|
2262
2558
|
context: c,
|
|
2263
2559
|
honoContext: c
|
|
2264
2560
|
});
|
|
2561
|
+
server.server.oninitialized = () => {
|
|
2562
|
+
const clientCapabilities = server.server.getClientCapabilities();
|
|
2563
|
+
const clientInfo = server.server.getClientInfo?.() || {};
|
|
2564
|
+
const protocolVersion = server.server.getProtocolVersion?.() || "unknown";
|
|
2565
|
+
if (clientCapabilities && sessions.has(sid)) {
|
|
2566
|
+
const session = sessions.get(sid);
|
|
2567
|
+
session.clientCapabilities = clientCapabilities;
|
|
2568
|
+
console.log(
|
|
2569
|
+
`[MCP] Captured client capabilities for session ${sid}:`,
|
|
2570
|
+
Object.keys(clientCapabilities)
|
|
2571
|
+
);
|
|
2572
|
+
}
|
|
2573
|
+
Telemetry.getInstance().trackServerInitialize({
|
|
2574
|
+
protocolVersion: String(protocolVersion),
|
|
2575
|
+
clientInfo: clientInfo || {},
|
|
2576
|
+
clientCapabilities: clientCapabilities || {},
|
|
2577
|
+
sessionId: sid
|
|
2578
|
+
}).catch(
|
|
2579
|
+
(e) => console.debug(`Failed to track server initialize: ${e}`)
|
|
2580
|
+
);
|
|
2581
|
+
};
|
|
2265
2582
|
}, "onsessioninitialized"),
|
|
2266
2583
|
onsessionclosed: /* @__PURE__ */ __name((sid) => {
|
|
2267
2584
|
console.log(`[MCP] Session closed: ${sid}`);
|
|
2268
2585
|
transports.delete(sid);
|
|
2269
2586
|
sessions.delete(sid);
|
|
2587
|
+
mcpServerInstance.cleanupSessionSubscriptions?.(sid);
|
|
2270
2588
|
}, "onsessionclosed")
|
|
2271
2589
|
});
|
|
2272
2590
|
await server.connect(transport);
|
|
@@ -2504,12 +2822,13 @@ function createBearerAuthMiddleware(provider, baseUrl) {
|
|
|
2504
2822
|
const result = await provider.verifyToken(token);
|
|
2505
2823
|
const payload = result.payload;
|
|
2506
2824
|
const user = provider.getUserInfo(payload);
|
|
2825
|
+
const scope = payload.scope;
|
|
2507
2826
|
const authInfo = {
|
|
2508
2827
|
user,
|
|
2509
2828
|
payload,
|
|
2510
2829
|
accessToken: token,
|
|
2511
2830
|
// Extract scopes from scope claim (OAuth standard)
|
|
2512
|
-
scopes:
|
|
2831
|
+
scopes: scope ? scope.split(" ") : [],
|
|
2513
2832
|
// Extract permissions (Auth0 style, or custom)
|
|
2514
2833
|
permissions: payload.permissions || []
|
|
2515
2834
|
};
|
|
@@ -2557,9 +2876,16 @@ async function setupOAuthForServer(app, oauthProvider, baseUrl, state) {
|
|
|
2557
2876
|
__name(setupOAuthForServer, "setupOAuthForServer");
|
|
2558
2877
|
|
|
2559
2878
|
// src/server/mcp-server.ts
|
|
2560
|
-
var
|
|
2879
|
+
var MCPServerClass = class {
|
|
2561
2880
|
static {
|
|
2562
|
-
__name(this, "
|
|
2881
|
+
__name(this, "MCPServerClass");
|
|
2882
|
+
}
|
|
2883
|
+
/**
|
|
2884
|
+
* Get the mcp-use package version.
|
|
2885
|
+
* Works in all environments (Node.js, browser, Cloudflare Workers, Deno, etc.)
|
|
2886
|
+
*/
|
|
2887
|
+
static getPackageVersion() {
|
|
2888
|
+
return getPackageVersion();
|
|
2563
2889
|
}
|
|
2564
2890
|
/**
|
|
2565
2891
|
* Native MCP server instance from @modelcontextprotocol/sdk
|
|
@@ -2583,8 +2909,6 @@ var McpServer = class {
|
|
|
2583
2909
|
buildId;
|
|
2584
2910
|
sessions = /* @__PURE__ */ new Map();
|
|
2585
2911
|
idleCleanupInterval;
|
|
2586
|
-
oauthConfig;
|
|
2587
|
-
// Store OAuth config for lazy initialization
|
|
2588
2912
|
oauthSetupState = {
|
|
2589
2913
|
complete: false,
|
|
2590
2914
|
provider: void 0,
|
|
@@ -2593,15 +2917,37 @@ var McpServer = class {
|
|
|
2593
2917
|
oauthProvider;
|
|
2594
2918
|
oauthMiddleware;
|
|
2595
2919
|
/**
|
|
2596
|
-
* Storage for
|
|
2920
|
+
* Storage for registrations that can be replayed on new server instances
|
|
2597
2921
|
* Following the official SDK pattern where each session gets its own server instance
|
|
2922
|
+
* @internal Exposed for telemetry purposes
|
|
2598
2923
|
*/
|
|
2599
|
-
|
|
2924
|
+
registrations = {
|
|
2600
2925
|
tools: /* @__PURE__ */ new Map(),
|
|
2601
2926
|
prompts: /* @__PURE__ */ new Map(),
|
|
2602
2927
|
resources: /* @__PURE__ */ new Map(),
|
|
2603
2928
|
resourceTemplates: /* @__PURE__ */ new Map()
|
|
2604
2929
|
};
|
|
2930
|
+
/**
|
|
2931
|
+
* Storage for widget definitions, used to inject metadata into tool responses
|
|
2932
|
+
* when using the widget() helper with returnsWidget option
|
|
2933
|
+
*/
|
|
2934
|
+
widgetDefinitions = /* @__PURE__ */ new Map();
|
|
2935
|
+
/**
|
|
2936
|
+
* Resource subscription manager for tracking and notifying resource updates
|
|
2937
|
+
*/
|
|
2938
|
+
subscriptionManager = new ResourceSubscriptionManager();
|
|
2939
|
+
/**
|
|
2940
|
+
* Clean up resource subscriptions for a closed session
|
|
2941
|
+
*
|
|
2942
|
+
* This method is called automatically when a session is closed to remove
|
|
2943
|
+
* all resource subscriptions associated with that session.
|
|
2944
|
+
*
|
|
2945
|
+
* @param sessionId - The session ID to clean up
|
|
2946
|
+
* @internal
|
|
2947
|
+
*/
|
|
2948
|
+
cleanupSessionSubscriptions(sessionId) {
|
|
2949
|
+
this.subscriptionManager.cleanupSession(sessionId);
|
|
2950
|
+
}
|
|
2605
2951
|
/**
|
|
2606
2952
|
* Creates a new MCP server instance with Hono integration
|
|
2607
2953
|
*
|
|
@@ -2610,23 +2956,34 @@ var McpServer = class {
|
|
|
2610
2956
|
* access to Hono methods while preserving MCP server functionality.
|
|
2611
2957
|
*
|
|
2612
2958
|
* @param config - Server configuration including name, version, and description
|
|
2613
|
-
* @returns A proxied
|
|
2959
|
+
* @returns A proxied MCPServer instance that supports both MCP and Hono methods
|
|
2614
2960
|
*/
|
|
2615
2961
|
constructor(config) {
|
|
2616
2962
|
this.config = config;
|
|
2617
2963
|
this.serverHost = config.host || "localhost";
|
|
2618
2964
|
this.serverBaseUrl = config.baseUrl;
|
|
2619
|
-
this.nativeServer = new OfficialMcpServer(
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2965
|
+
this.nativeServer = new OfficialMcpServer(
|
|
2966
|
+
{
|
|
2967
|
+
name: config.name,
|
|
2968
|
+
version: config.version
|
|
2969
|
+
},
|
|
2970
|
+
{
|
|
2971
|
+
capabilities: {
|
|
2972
|
+
logging: {},
|
|
2973
|
+
resources: {
|
|
2974
|
+
subscribe: true,
|
|
2975
|
+
listChanged: true
|
|
2976
|
+
}
|
|
2977
|
+
}
|
|
2978
|
+
}
|
|
2979
|
+
);
|
|
2623
2980
|
this.app = createHonoApp(requestLogger);
|
|
2624
|
-
this.
|
|
2981
|
+
this.oauthProvider = config.oauth;
|
|
2625
2982
|
this.wrapRegistrationMethods();
|
|
2626
2983
|
return createHonoProxy(this, this.app);
|
|
2627
2984
|
}
|
|
2628
2985
|
/**
|
|
2629
|
-
* Wrap registration methods to capture
|
|
2986
|
+
* Wrap registration methods to capture registrations following official SDK pattern.
|
|
2630
2987
|
* Each session will get a fresh server instance with all registrations replayed.
|
|
2631
2988
|
*/
|
|
2632
2989
|
wrapRegistrationMethods() {
|
|
@@ -2636,50 +2993,113 @@ var McpServer = class {
|
|
|
2636
2993
|
const originalResourceTemplate = registerResourceTemplate;
|
|
2637
2994
|
const self = this;
|
|
2638
2995
|
this.tool = ((toolDefinition, callback) => {
|
|
2639
|
-
const
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2996
|
+
const widgetConfig = toolDefinition.widget;
|
|
2997
|
+
const widgetName = widgetConfig?.name;
|
|
2998
|
+
if (widgetConfig && widgetName) {
|
|
2999
|
+
const buildIdPart = self.buildId ? `-${self.buildId}` : "";
|
|
3000
|
+
const outputTemplate = `ui://widget/${widgetName}${buildIdPart}.html`;
|
|
3001
|
+
toolDefinition._meta = {
|
|
3002
|
+
...toolDefinition._meta,
|
|
3003
|
+
"openai/outputTemplate": outputTemplate,
|
|
3004
|
+
"openai/toolInvocation/invoking": widgetConfig.invoking ?? `Loading ${widgetName}...`,
|
|
3005
|
+
"openai/toolInvocation/invoked": widgetConfig.invoked ?? `${widgetName} ready`,
|
|
3006
|
+
"openai/widgetAccessible": widgetConfig.widgetAccessible ?? true,
|
|
3007
|
+
"openai/resultCanProduceWidget": widgetConfig.resultCanProduceWidget ?? true
|
|
3008
|
+
};
|
|
3009
|
+
}
|
|
3010
|
+
let actualCallback = callback || toolDefinition.cb;
|
|
3011
|
+
if (widgetConfig && widgetName && actualCallback) {
|
|
3012
|
+
const originalCallback = actualCallback;
|
|
3013
|
+
actualCallback = /* @__PURE__ */ __name((async (params, ctx) => {
|
|
3014
|
+
const result = await originalCallback(params, ctx);
|
|
3015
|
+
const widgetDef = self.widgetDefinitions.get(widgetName);
|
|
3016
|
+
if (result && typeof result === "object") {
|
|
3017
|
+
const randomId = Math.random().toString(36).substring(2, 15);
|
|
3018
|
+
const buildIdPart = self.buildId ? `-${self.buildId}` : "";
|
|
3019
|
+
const uniqueUri = `ui://widget/${widgetName}${buildIdPart}-${randomId}.html`;
|
|
3020
|
+
const responseMeta = {
|
|
3021
|
+
...widgetDef || {},
|
|
3022
|
+
// Include mcp-use/widget and other widget metadata
|
|
3023
|
+
"openai/outputTemplate": uniqueUri,
|
|
3024
|
+
"openai/toolInvocation/invoking": widgetConfig.invoking ?? `Loading ${widgetName}...`,
|
|
3025
|
+
"openai/toolInvocation/invoked": widgetConfig.invoked ?? `${widgetName} ready`,
|
|
3026
|
+
"openai/widgetAccessible": widgetConfig.widgetAccessible ?? true,
|
|
3027
|
+
"openai/resultCanProduceWidget": widgetConfig.resultCanProduceWidget ?? true
|
|
3028
|
+
};
|
|
3029
|
+
result._meta = responseMeta;
|
|
3030
|
+
if (result.content?.[0]?.type === "text" && !result.content[0].text) {
|
|
3031
|
+
result.content[0].text = `Displaying ${widgetName}`;
|
|
3032
|
+
}
|
|
3033
|
+
}
|
|
3034
|
+
return result;
|
|
3035
|
+
}), "actualCallback");
|
|
3036
|
+
}
|
|
3037
|
+
if (actualCallback) {
|
|
3038
|
+
self.registrations.tools.set(toolDefinition.name, {
|
|
3039
|
+
config: toolDefinition,
|
|
3040
|
+
handler: actualCallback
|
|
3041
|
+
});
|
|
3042
|
+
}
|
|
3043
|
+
return originalTool.call(self, toolDefinition, actualCallback);
|
|
2645
3044
|
});
|
|
2646
|
-
this.prompt =
|
|
3045
|
+
this.prompt = ((promptDefinition, callback) => {
|
|
2647
3046
|
const actualCallback = callback || promptDefinition.cb;
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
3047
|
+
if (actualCallback) {
|
|
3048
|
+
self.registrations.prompts.set(promptDefinition.name, {
|
|
3049
|
+
config: promptDefinition,
|
|
3050
|
+
handler: actualCallback
|
|
3051
|
+
});
|
|
3052
|
+
}
|
|
3053
|
+
return originalPrompt.call(
|
|
3054
|
+
self,
|
|
3055
|
+
promptDefinition,
|
|
3056
|
+
callback
|
|
3057
|
+
);
|
|
3058
|
+
});
|
|
3059
|
+
this.resource = ((resourceDefinition, callback) => {
|
|
2655
3060
|
const actualCallback = callback || resourceDefinition.readCallback;
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
3061
|
+
if (actualCallback) {
|
|
3062
|
+
const resourceKey = `${resourceDefinition.name}:${resourceDefinition.uri}`;
|
|
3063
|
+
self.registrations.resources.set(resourceKey, {
|
|
3064
|
+
config: resourceDefinition,
|
|
3065
|
+
handler: actualCallback
|
|
3066
|
+
});
|
|
3067
|
+
}
|
|
2661
3068
|
return originalResource.call(self, resourceDefinition, callback);
|
|
2662
|
-
};
|
|
2663
|
-
this.resourceTemplate =
|
|
3069
|
+
});
|
|
3070
|
+
this.resourceTemplate = ((templateDefinition, callback) => {
|
|
2664
3071
|
const actualCallback = callback || templateDefinition.readCallback;
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
3072
|
+
if (actualCallback) {
|
|
3073
|
+
self.registrations.resourceTemplates.set(templateDefinition.name, {
|
|
3074
|
+
config: templateDefinition,
|
|
3075
|
+
handler: actualCallback
|
|
3076
|
+
});
|
|
3077
|
+
}
|
|
3078
|
+
return originalResourceTemplate.call(
|
|
3079
|
+
self,
|
|
3080
|
+
templateDefinition,
|
|
3081
|
+
callback
|
|
3082
|
+
);
|
|
3083
|
+
});
|
|
2671
3084
|
}
|
|
2672
3085
|
/**
|
|
2673
3086
|
* Create a new server instance for a session following official SDK pattern.
|
|
2674
3087
|
* This is called for each initialize request to create an isolated server.
|
|
2675
3088
|
*/
|
|
2676
3089
|
getServerForSession() {
|
|
2677
|
-
const newServer = new OfficialMcpServer(
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
3090
|
+
const newServer = new OfficialMcpServer(
|
|
3091
|
+
{
|
|
3092
|
+
name: this.config.name,
|
|
3093
|
+
version: this.config.version
|
|
3094
|
+
},
|
|
3095
|
+
{
|
|
3096
|
+
capabilities: {
|
|
3097
|
+
logging: {}
|
|
3098
|
+
}
|
|
3099
|
+
}
|
|
3100
|
+
);
|
|
3101
|
+
for (const [name, registration] of this.registrations.tools) {
|
|
3102
|
+
const { config, handler: actualCallback } = registration;
|
|
2683
3103
|
let inputSchema;
|
|
2684
3104
|
if (config.schema) {
|
|
2685
3105
|
inputSchema = this.convertZodSchemaToParams(config.schema);
|
|
@@ -2692,12 +3112,21 @@ var McpServer = class {
|
|
|
2692
3112
|
const initialRequestContext = getRequestContext();
|
|
2693
3113
|
const extraProgressToken = extra?._meta?.progressToken;
|
|
2694
3114
|
const extraSendNotification = extra?.sendNotification;
|
|
2695
|
-
const { requestContext, progressToken, sendNotification: sendNotification2 } = findSessionContext(
|
|
3115
|
+
const { requestContext, session, progressToken, sendNotification: sendNotification2 } = findSessionContext(
|
|
2696
3116
|
this.sessions,
|
|
2697
3117
|
initialRequestContext,
|
|
2698
3118
|
extraProgressToken,
|
|
2699
3119
|
extraSendNotification
|
|
2700
3120
|
);
|
|
3121
|
+
let sessionId;
|
|
3122
|
+
if (session) {
|
|
3123
|
+
for (const [id, s] of this.sessions.entries()) {
|
|
3124
|
+
if (s === session) {
|
|
3125
|
+
sessionId = id;
|
|
3126
|
+
break;
|
|
3127
|
+
}
|
|
3128
|
+
}
|
|
3129
|
+
}
|
|
2701
3130
|
const createMessageWithLogging = /* @__PURE__ */ __name(async (params2, options) => {
|
|
2702
3131
|
console.log("[createMessage] About to call server.createMessage");
|
|
2703
3132
|
console.log("[createMessage] Has server:", !!newServer);
|
|
@@ -2709,11 +3138,12 @@ var McpServer = class {
|
|
|
2709
3138
|
console.log("[createMessage] Got result successfully");
|
|
2710
3139
|
return result;
|
|
2711
3140
|
} catch (err) {
|
|
3141
|
+
const error2 = err;
|
|
2712
3142
|
console.error(
|
|
2713
3143
|
"[createMessage] Error:",
|
|
2714
|
-
|
|
3144
|
+
error2.message,
|
|
2715
3145
|
"Code:",
|
|
2716
|
-
|
|
3146
|
+
error2.code
|
|
2717
3147
|
);
|
|
2718
3148
|
throw err;
|
|
2719
3149
|
}
|
|
@@ -2723,7 +3153,11 @@ var McpServer = class {
|
|
|
2723
3153
|
createMessageWithLogging,
|
|
2724
3154
|
newServer.server.elicitInput.bind(newServer.server),
|
|
2725
3155
|
progressToken,
|
|
2726
|
-
sendNotification2
|
|
3156
|
+
sendNotification2,
|
|
3157
|
+
session?.logLevel,
|
|
3158
|
+
session?.clientCapabilities,
|
|
3159
|
+
sessionId,
|
|
3160
|
+
this.sessions
|
|
2727
3161
|
);
|
|
2728
3162
|
const executeCallback = /* @__PURE__ */ __name(async () => {
|
|
2729
3163
|
if (actualCallback.length >= 2) {
|
|
@@ -2731,10 +3165,26 @@ var McpServer = class {
|
|
|
2731
3165
|
}
|
|
2732
3166
|
return await actualCallback(params);
|
|
2733
3167
|
}, "executeCallback");
|
|
2734
|
-
|
|
2735
|
-
|
|
3168
|
+
const startTime = Date.now();
|
|
3169
|
+
let success = true;
|
|
3170
|
+
let errorType = null;
|
|
3171
|
+
try {
|
|
3172
|
+
const result = requestContext ? await runWithContext(requestContext, executeCallback) : await executeCallback();
|
|
3173
|
+
return result;
|
|
3174
|
+
} catch (err) {
|
|
3175
|
+
success = false;
|
|
3176
|
+
errorType = err instanceof Error ? err.name : "unknown_error";
|
|
3177
|
+
throw err;
|
|
3178
|
+
} finally {
|
|
3179
|
+
const executionTimeMs = Date.now() - startTime;
|
|
3180
|
+
Telemetry.getInstance().trackServerToolCall({
|
|
3181
|
+
toolName: name,
|
|
3182
|
+
lengthInputArgument: JSON.stringify(params).length,
|
|
3183
|
+
success,
|
|
3184
|
+
errorType,
|
|
3185
|
+
executionTimeMs
|
|
3186
|
+
}).catch((e) => console.debug(`Failed to track tool call: ${e}`));
|
|
2736
3187
|
}
|
|
2737
|
-
return await executeCallback();
|
|
2738
3188
|
}, "wrappedHandler");
|
|
2739
3189
|
newServer.registerTool(
|
|
2740
3190
|
name,
|
|
@@ -2748,21 +3198,38 @@ var McpServer = class {
|
|
|
2748
3198
|
wrappedHandler
|
|
2749
3199
|
);
|
|
2750
3200
|
}
|
|
2751
|
-
for (const [name,
|
|
2752
|
-
const { config, handler } =
|
|
3201
|
+
for (const [name, registration] of this.registrations.prompts) {
|
|
3202
|
+
const { config, handler } = registration;
|
|
2753
3203
|
let argsSchema;
|
|
2754
3204
|
if (config.schema) {
|
|
2755
3205
|
argsSchema = this.convertZodSchemaToParams(config.schema);
|
|
3206
|
+
} else if (config.args && config.args.length > 0) {
|
|
3207
|
+
argsSchema = this.createParamsSchema(config.args);
|
|
2756
3208
|
} else {
|
|
2757
|
-
argsSchema =
|
|
3209
|
+
argsSchema = void 0;
|
|
2758
3210
|
}
|
|
2759
|
-
const wrappedHandler = /* @__PURE__ */ __name(async (params) => {
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
3211
|
+
const wrappedHandler = /* @__PURE__ */ __name(async (params, extra) => {
|
|
3212
|
+
let success = true;
|
|
3213
|
+
let errorType = null;
|
|
3214
|
+
try {
|
|
3215
|
+
const result = await handler(params, extra);
|
|
3216
|
+
if ("messages" in result && Array.isArray(result.messages)) {
|
|
3217
|
+
return result;
|
|
3218
|
+
}
|
|
3219
|
+
const { convertToolResultToPromptResult: convertToolResultToPromptResult2 } = await import("../../conversion-OTRZZBUU.js");
|
|
3220
|
+
return convertToolResultToPromptResult2(result);
|
|
3221
|
+
} catch (err) {
|
|
3222
|
+
success = false;
|
|
3223
|
+
errorType = err instanceof Error ? err.name : "unknown_error";
|
|
3224
|
+
throw err;
|
|
3225
|
+
} finally {
|
|
3226
|
+
Telemetry.getInstance().trackServerPromptCall({
|
|
3227
|
+
name,
|
|
3228
|
+
description: config.description ?? null,
|
|
3229
|
+
success,
|
|
3230
|
+
errorType
|
|
3231
|
+
}).catch((e) => console.debug(`Failed to track prompt call: ${e}`));
|
|
2763
3232
|
}
|
|
2764
|
-
const { convertToolResultToPromptResult: convertToolResultToPromptResult2 } = await import("../../conversion-OTRZZBUU.js");
|
|
2765
|
-
return convertToolResultToPromptResult2(result);
|
|
2766
3233
|
}, "wrappedHandler");
|
|
2767
3234
|
newServer.registerPrompt(
|
|
2768
3235
|
name,
|
|
@@ -2774,15 +3241,42 @@ var McpServer = class {
|
|
|
2774
3241
|
wrappedHandler
|
|
2775
3242
|
);
|
|
2776
3243
|
}
|
|
2777
|
-
for (const [_key,
|
|
2778
|
-
const { config, handler } =
|
|
2779
|
-
const wrappedHandler = /* @__PURE__ */ __name(async () => {
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
3244
|
+
for (const [_key, registration] of this.registrations.resources) {
|
|
3245
|
+
const { config, handler } = registration;
|
|
3246
|
+
const wrappedHandler = /* @__PURE__ */ __name(async (extra) => {
|
|
3247
|
+
let success = true;
|
|
3248
|
+
let errorType = null;
|
|
3249
|
+
let contents = [];
|
|
3250
|
+
try {
|
|
3251
|
+
const result = await handler(extra);
|
|
3252
|
+
if ("contents" in result && Array.isArray(result.contents)) {
|
|
3253
|
+
contents = result.contents;
|
|
3254
|
+
return result;
|
|
3255
|
+
}
|
|
3256
|
+
const { convertToolResultToResourceResult: convertToolResultToResourceResult2 } = await import("../../conversion-5MA4VY3B.js");
|
|
3257
|
+
const converted = convertToolResultToResourceResult2(
|
|
3258
|
+
config.uri,
|
|
3259
|
+
result
|
|
3260
|
+
);
|
|
3261
|
+
contents = converted.contents || [];
|
|
3262
|
+
return converted;
|
|
3263
|
+
} catch (err) {
|
|
3264
|
+
success = false;
|
|
3265
|
+
errorType = err instanceof Error ? err.name : "unknown_error";
|
|
3266
|
+
throw err;
|
|
3267
|
+
} finally {
|
|
3268
|
+
Telemetry.getInstance().trackServerResourceCall({
|
|
3269
|
+
name: config.name,
|
|
3270
|
+
description: config.description ?? null,
|
|
3271
|
+
contents: contents.map((c) => ({
|
|
3272
|
+
mime_type: c.mimeType ?? null,
|
|
3273
|
+
text: c.text ? `[text: ${c.text.length} chars]` : null,
|
|
3274
|
+
blob: c.blob ? `[blob: ${c.blob.length} bytes]` : null
|
|
3275
|
+
})),
|
|
3276
|
+
success,
|
|
3277
|
+
errorType
|
|
3278
|
+
}).catch((e) => console.debug(`Failed to track resource call: ${e}`));
|
|
2783
3279
|
}
|
|
2784
|
-
const { convertToolResultToResourceResult: convertToolResultToResourceResult2 } = await import("../../conversion-5MA4VY3B.js");
|
|
2785
|
-
return convertToolResultToResourceResult2(config.uri, result);
|
|
2786
3280
|
}, "wrappedHandler");
|
|
2787
3281
|
newServer.registerResource(
|
|
2788
3282
|
config.name,
|
|
@@ -2795,24 +3289,25 @@ var McpServer = class {
|
|
|
2795
3289
|
wrappedHandler
|
|
2796
3290
|
);
|
|
2797
3291
|
}
|
|
2798
|
-
for (const [_name,
|
|
2799
|
-
const { config, handler } =
|
|
2800
|
-
const
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
3292
|
+
for (const [_name, registration] of this.registrations.resourceTemplates) {
|
|
3293
|
+
const { config, handler } = registration;
|
|
3294
|
+
const isFlatStructure = "uriTemplate" in config;
|
|
3295
|
+
const uriTemplate = isFlatStructure ? config.uriTemplate : config.resourceTemplate.uriTemplate;
|
|
3296
|
+
const mimeType = isFlatStructure ? config.mimeType : config.resourceTemplate.mimeType;
|
|
3297
|
+
const templateDescription = isFlatStructure ? void 0 : config.resourceTemplate.description;
|
|
3298
|
+
const template = new ResourceTemplate2(uriTemplate, {
|
|
3299
|
+
list: void 0,
|
|
3300
|
+
complete: void 0
|
|
3301
|
+
});
|
|
2807
3302
|
const metadata = {};
|
|
2808
3303
|
if (config.title) {
|
|
2809
3304
|
metadata.title = config.title;
|
|
2810
3305
|
}
|
|
2811
|
-
if (config.description ||
|
|
2812
|
-
metadata.description = config.description ||
|
|
3306
|
+
if (config.description || templateDescription) {
|
|
3307
|
+
metadata.description = config.description || templateDescription;
|
|
2813
3308
|
}
|
|
2814
|
-
if (
|
|
2815
|
-
metadata.mimeType =
|
|
3309
|
+
if (mimeType) {
|
|
3310
|
+
metadata.mimeType = mimeType;
|
|
2816
3311
|
}
|
|
2817
3312
|
if (config.annotations) {
|
|
2818
3313
|
metadata.annotations = config.annotations;
|
|
@@ -2821,20 +3316,90 @@ var McpServer = class {
|
|
|
2821
3316
|
config.name,
|
|
2822
3317
|
template,
|
|
2823
3318
|
metadata,
|
|
2824
|
-
async (uri) => {
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
3319
|
+
async (uri, extra) => {
|
|
3320
|
+
let success = true;
|
|
3321
|
+
let errorType = null;
|
|
3322
|
+
let contents = [];
|
|
3323
|
+
try {
|
|
3324
|
+
const params = this.parseTemplateUri(uriTemplate, uri.toString());
|
|
3325
|
+
const result = await handler(uri, params, extra);
|
|
3326
|
+
if ("contents" in result && Array.isArray(result.contents)) {
|
|
3327
|
+
contents = result.contents;
|
|
3328
|
+
return result;
|
|
3329
|
+
}
|
|
3330
|
+
const { convertToolResultToResourceResult: convertToolResultToResourceResult2 } = await import("../../conversion-5MA4VY3B.js");
|
|
3331
|
+
const converted = convertToolResultToResourceResult2(
|
|
3332
|
+
uri.toString(),
|
|
3333
|
+
result
|
|
3334
|
+
);
|
|
3335
|
+
contents = converted.contents || [];
|
|
3336
|
+
return converted;
|
|
3337
|
+
} catch (err) {
|
|
3338
|
+
success = false;
|
|
3339
|
+
errorType = err instanceof Error ? err.name : "unknown_error";
|
|
3340
|
+
throw err;
|
|
3341
|
+
} finally {
|
|
3342
|
+
Telemetry.getInstance().trackServerResourceCall({
|
|
3343
|
+
name: config.name,
|
|
3344
|
+
description: config.description ?? null,
|
|
3345
|
+
contents: contents.map((c) => ({
|
|
3346
|
+
mimeType: c.mimeType ?? null,
|
|
3347
|
+
text: c.text ? `[text: ${c.text.length} chars]` : null,
|
|
3348
|
+
blob: c.blob ? `[blob: ${c.blob.length} bytes]` : null
|
|
3349
|
+
})),
|
|
3350
|
+
success,
|
|
3351
|
+
errorType
|
|
3352
|
+
}).catch(
|
|
3353
|
+
(e) => console.debug(`Failed to track resource template call: ${e}`)
|
|
3354
|
+
);
|
|
2832
3355
|
}
|
|
2833
|
-
const { convertToolResultToResourceResult: convertToolResultToResourceResult2 } = await import("../../conversion-5MA4VY3B.js");
|
|
2834
|
-
return convertToolResultToResourceResult2(uri.toString(), result);
|
|
2835
3356
|
}
|
|
2836
3357
|
);
|
|
2837
3358
|
}
|
|
3359
|
+
newServer.server.setRequestHandler(
|
|
3360
|
+
z2.object({ method: z2.literal("logging/setLevel") }).passthrough(),
|
|
3361
|
+
(async (request, extra) => {
|
|
3362
|
+
const level = request.params?.level;
|
|
3363
|
+
if (!level) {
|
|
3364
|
+
throw new McpError(
|
|
3365
|
+
ErrorCode.InvalidParams,
|
|
3366
|
+
"Missing 'level' parameter"
|
|
3367
|
+
);
|
|
3368
|
+
}
|
|
3369
|
+
if (!isValidLogLevel(level)) {
|
|
3370
|
+
throw new McpError(
|
|
3371
|
+
ErrorCode.InvalidParams,
|
|
3372
|
+
`Invalid log level '${level}'. Must be one of: debug, info, notice, warning, error, critical, alert, emergency`
|
|
3373
|
+
);
|
|
3374
|
+
}
|
|
3375
|
+
const requestContext = getRequestContext();
|
|
3376
|
+
if (requestContext) {
|
|
3377
|
+
const sessionId = requestContext.req.header("mcp-session-id");
|
|
3378
|
+
if (sessionId && this.sessions.has(sessionId)) {
|
|
3379
|
+
const session = this.sessions.get(sessionId);
|
|
3380
|
+
session.logLevel = level;
|
|
3381
|
+
console.log(
|
|
3382
|
+
`[MCP] Set log level to '${level}' for session ${sessionId}`
|
|
3383
|
+
);
|
|
3384
|
+
return {};
|
|
3385
|
+
}
|
|
3386
|
+
}
|
|
3387
|
+
for (const [sessionId, session] of this.sessions.entries()) {
|
|
3388
|
+
if (session.server === newServer) {
|
|
3389
|
+
session.logLevel = level;
|
|
3390
|
+
console.log(
|
|
3391
|
+
`[MCP] Set log level to '${level}' for session ${sessionId}`
|
|
3392
|
+
);
|
|
3393
|
+
return {};
|
|
3394
|
+
}
|
|
3395
|
+
}
|
|
3396
|
+
console.warn(
|
|
3397
|
+
"[MCP] Could not find session for logging/setLevel request"
|
|
3398
|
+
);
|
|
3399
|
+
throw new McpError(ErrorCode.InternalError, "Could not find session");
|
|
3400
|
+
})
|
|
3401
|
+
);
|
|
3402
|
+
this.subscriptionManager.registerHandlers(newServer, this.sessions);
|
|
2838
3403
|
return newServer;
|
|
2839
3404
|
}
|
|
2840
3405
|
/**
|
|
@@ -2848,23 +3413,43 @@ var McpServer = class {
|
|
|
2848
3413
|
this.serverPort
|
|
2849
3414
|
);
|
|
2850
3415
|
}
|
|
2851
|
-
// Tool registration helper
|
|
2852
|
-
tool
|
|
3416
|
+
// Tool registration helper - type is set in wrapRegistrationMethods
|
|
3417
|
+
tool;
|
|
2853
3418
|
// Schema conversion helpers (used by tool registration)
|
|
2854
3419
|
convertZodSchemaToParams = convertZodSchemaToParams;
|
|
2855
3420
|
createParamsSchema = createParamsSchema;
|
|
2856
3421
|
// Template URI parsing helper (used by resource templates)
|
|
2857
3422
|
parseTemplateUri = parseTemplateUri;
|
|
2858
|
-
// Resource registration helpers
|
|
2859
|
-
resource
|
|
2860
|
-
resourceTemplate
|
|
2861
|
-
// Prompt registration helper
|
|
2862
|
-
prompt
|
|
3423
|
+
// Resource registration helpers - types are set in wrapRegistrationMethods
|
|
3424
|
+
resource;
|
|
3425
|
+
resourceTemplate;
|
|
3426
|
+
// Prompt registration helper - type is set in wrapRegistrationMethods
|
|
3427
|
+
prompt;
|
|
2863
3428
|
// Notification helpers
|
|
2864
3429
|
getActiveSessions = getActiveSessions;
|
|
2865
3430
|
sendNotification = sendNotification;
|
|
2866
3431
|
sendNotificationToSession = sendNotificationToSession2;
|
|
2867
|
-
|
|
3432
|
+
/**
|
|
3433
|
+
* Notify subscribed clients that a resource has been updated
|
|
3434
|
+
*
|
|
3435
|
+
* This method sends a `notifications/resources/updated` notification to all
|
|
3436
|
+
* sessions that have subscribed to the specified resource URI.
|
|
3437
|
+
*
|
|
3438
|
+
* @param uri - The URI of the resource that changed
|
|
3439
|
+
* @returns Promise that resolves when all notifications have been sent
|
|
3440
|
+
*
|
|
3441
|
+
* @example
|
|
3442
|
+
* ```typescript
|
|
3443
|
+
* // After updating a resource, notify subscribers
|
|
3444
|
+
* await server.notifyResourceUpdated("file:///path/to/resource.txt");
|
|
3445
|
+
* ```
|
|
3446
|
+
*/
|
|
3447
|
+
async notifyResourceUpdated(uri) {
|
|
3448
|
+
return this.subscriptionManager.notifyResourceUpdated(uri, this.sessions);
|
|
3449
|
+
}
|
|
3450
|
+
uiResource = /* @__PURE__ */ __name((definition) => {
|
|
3451
|
+
return uiResourceRegistration(this, definition);
|
|
3452
|
+
}, "uiResource");
|
|
2868
3453
|
/**
|
|
2869
3454
|
* Mount MCP server endpoints at /mcp and /sse
|
|
2870
3455
|
*
|
|
@@ -2889,7 +3474,7 @@ var McpServer = class {
|
|
|
2889
3474
|
const result = await mountMcp(
|
|
2890
3475
|
this.app,
|
|
2891
3476
|
this,
|
|
2892
|
-
// Pass the
|
|
3477
|
+
// Pass the MCPServer instance so mountMcp can call getServerForSession()
|
|
2893
3478
|
this.sessions,
|
|
2894
3479
|
this.config,
|
|
2895
3480
|
isProductionMode()
|
|
@@ -2947,7 +3532,12 @@ var McpServer = class {
|
|
|
2947
3532
|
if (hostEnv) {
|
|
2948
3533
|
this.serverHost = hostEnv;
|
|
2949
3534
|
}
|
|
2950
|
-
|
|
3535
|
+
this.serverBaseUrl = getServerBaseUrl(
|
|
3536
|
+
this.serverBaseUrl,
|
|
3537
|
+
this.serverHost,
|
|
3538
|
+
this.serverPort
|
|
3539
|
+
);
|
|
3540
|
+
if (this.oauthProvider && !this.oauthSetupState.complete) {
|
|
2951
3541
|
await setupOAuthForServer(
|
|
2952
3542
|
this.app,
|
|
2953
3543
|
this.oauthProvider,
|
|
@@ -2962,10 +3552,14 @@ var McpServer = class {
|
|
|
2962
3552
|
await this.mountMcp();
|
|
2963
3553
|
await this.mountInspector();
|
|
2964
3554
|
this.logRegisteredItems();
|
|
3555
|
+
this._trackServerRun("http");
|
|
2965
3556
|
await startServer(this.app, this.serverPort, this.serverHost, {
|
|
2966
3557
|
onDenoRequest: rewriteSupabaseRequest
|
|
2967
3558
|
});
|
|
2968
3559
|
}
|
|
3560
|
+
_trackServerRun(transport) {
|
|
3561
|
+
Telemetry.getInstance().trackServerRunFromServer(this, transport).catch((e) => console.debug(`Failed to track server run: ${e}`));
|
|
3562
|
+
}
|
|
2969
3563
|
/**
|
|
2970
3564
|
* Get the fetch handler for the server after mounting all endpoints
|
|
2971
3565
|
*
|
|
@@ -2984,7 +3578,7 @@ var McpServer = class {
|
|
|
2984
3578
|
* @example
|
|
2985
3579
|
* ```typescript
|
|
2986
3580
|
* // For Supabase Edge Functions (handles path rewriting automatically)
|
|
2987
|
-
* const server =
|
|
3581
|
+
* const server = new MCPServer({ name: 'my-server', version: '1.0.0' });
|
|
2988
3582
|
* server.tool({ ... });
|
|
2989
3583
|
* const handler = await server.getHandler({ provider: 'supabase' });
|
|
2990
3584
|
* Deno.serve(handler);
|
|
@@ -2993,14 +3587,14 @@ var McpServer = class {
|
|
|
2993
3587
|
* @example
|
|
2994
3588
|
* ```typescript
|
|
2995
3589
|
* // For Cloudflare Workers
|
|
2996
|
-
* const server =
|
|
3590
|
+
* const server = new MCPServer({ name: 'my-server', version: '1.0.0' });
|
|
2997
3591
|
* server.tool({ ... });
|
|
2998
3592
|
* const handler = await server.getHandler();
|
|
2999
3593
|
* export default { fetch: handler };
|
|
3000
3594
|
* ```
|
|
3001
3595
|
*/
|
|
3002
3596
|
async getHandler(options) {
|
|
3003
|
-
if (this.
|
|
3597
|
+
if (this.oauthProvider && !this.oauthSetupState.complete) {
|
|
3004
3598
|
await setupOAuthForServer(
|
|
3005
3599
|
this.app,
|
|
3006
3600
|
this.oauthProvider,
|
|
@@ -3019,6 +3613,8 @@ var McpServer = class {
|
|
|
3019
3613
|
console.log("[MCP] Mounting inspector");
|
|
3020
3614
|
await this.mountInspector();
|
|
3021
3615
|
console.log("[MCP] Mounted inspector");
|
|
3616
|
+
const provider = options?.provider || "fetch";
|
|
3617
|
+
this._trackServerRun(provider);
|
|
3022
3618
|
const fetchHandler = this.app.fetch.bind(this.app);
|
|
3023
3619
|
if (options?.provider === "supabase") {
|
|
3024
3620
|
return async (req) => {
|
|
@@ -3070,8 +3666,9 @@ var McpServer = class {
|
|
|
3070
3666
|
}
|
|
3071
3667
|
}
|
|
3072
3668
|
};
|
|
3669
|
+
var MCPServer = MCPServerClass;
|
|
3073
3670
|
function createMCPServer(name, config = {}) {
|
|
3074
|
-
const instance = new
|
|
3671
|
+
const instance = new MCPServerClass({
|
|
3075
3672
|
name,
|
|
3076
3673
|
version: config.version || "1.0.0",
|
|
3077
3674
|
description: config.description,
|
|
@@ -3155,12 +3752,13 @@ var SupabaseOAuthProvider = class {
|
|
|
3155
3752
|
}
|
|
3156
3753
|
}
|
|
3157
3754
|
getUserInfo(payload) {
|
|
3755
|
+
const userMetadata = payload.user_metadata;
|
|
3158
3756
|
return {
|
|
3159
3757
|
userId: payload.sub || payload.user_id,
|
|
3160
3758
|
email: payload.email,
|
|
3161
|
-
name:
|
|
3162
|
-
username:
|
|
3163
|
-
picture:
|
|
3759
|
+
name: userMetadata?.name || userMetadata?.full_name,
|
|
3760
|
+
username: userMetadata?.username,
|
|
3761
|
+
picture: userMetadata?.avatar_url,
|
|
3164
3762
|
roles: payload.role ? [payload.role] : [],
|
|
3165
3763
|
permissions: payload.aal ? [`aal:${payload.aal}`] : [],
|
|
3166
3764
|
// Include Supabase-specific claims
|
|
@@ -3233,6 +3831,7 @@ var Auth0OAuthProvider = class {
|
|
|
3233
3831
|
}
|
|
3234
3832
|
}
|
|
3235
3833
|
getUserInfo(payload) {
|
|
3834
|
+
const scope = payload.scope;
|
|
3236
3835
|
return {
|
|
3237
3836
|
userId: payload.sub,
|
|
3238
3837
|
email: payload.email,
|
|
@@ -3245,7 +3844,7 @@ var Auth0OAuthProvider = class {
|
|
|
3245
3844
|
// Auth0 can include roles (if configured)
|
|
3246
3845
|
roles: payload.roles || payload["https://your-app.com/roles"] || [],
|
|
3247
3846
|
// Include scope as well
|
|
3248
|
-
scopes:
|
|
3847
|
+
scopes: scope ? scope.split(" ") : [],
|
|
3249
3848
|
// Additional Auth0-specific claims
|
|
3250
3849
|
email_verified: payload.email_verified,
|
|
3251
3850
|
updated_at: payload.updated_at
|
|
@@ -3317,8 +3916,10 @@ var KeycloakOAuthProvider = class {
|
|
|
3317
3916
|
}
|
|
3318
3917
|
}
|
|
3319
3918
|
getUserInfo(payload) {
|
|
3320
|
-
const
|
|
3321
|
-
const
|
|
3919
|
+
const realmAccess = payload.realm_access;
|
|
3920
|
+
const realmRoles = realmAccess?.roles || [];
|
|
3921
|
+
const resourceAccess = payload.resource_access;
|
|
3922
|
+
const clientRoles = this.config.clientId && (resourceAccess?.[this.config.clientId]?.roles || []) || [];
|
|
3322
3923
|
const allRoles = [...realmRoles, ...clientRoles];
|
|
3323
3924
|
const permissions = [];
|
|
3324
3925
|
if (payload.resource_access) {
|
|
@@ -3332,6 +3933,7 @@ var KeycloakOAuthProvider = class {
|
|
|
3332
3933
|
}
|
|
3333
3934
|
);
|
|
3334
3935
|
}
|
|
3936
|
+
const scope = payload.scope;
|
|
3335
3937
|
return {
|
|
3336
3938
|
userId: payload.sub,
|
|
3337
3939
|
email: payload.email,
|
|
@@ -3342,7 +3944,7 @@ var KeycloakOAuthProvider = class {
|
|
|
3342
3944
|
roles: allRoles,
|
|
3343
3945
|
permissions,
|
|
3344
3946
|
// Include scope as well
|
|
3345
|
-
scopes:
|
|
3947
|
+
scopes: scope ? scope.split(" ") : [],
|
|
3346
3948
|
// Keycloak-specific claims
|
|
3347
3949
|
email_verified: payload.email_verified,
|
|
3348
3950
|
given_name: payload.given_name,
|
|
@@ -3471,7 +4073,7 @@ var CustomOAuthProvider = class {
|
|
|
3471
4073
|
async verifyToken(token) {
|
|
3472
4074
|
try {
|
|
3473
4075
|
const result = await this.config.verifyToken(token);
|
|
3474
|
-
return
|
|
4076
|
+
return result;
|
|
3475
4077
|
} catch (error2) {
|
|
3476
4078
|
throw new Error(`Custom OAuth verification failed: ${error2}`);
|
|
3477
4079
|
}
|
|
@@ -3480,16 +4082,19 @@ var CustomOAuthProvider = class {
|
|
|
3480
4082
|
if (this.config.getUserInfo) {
|
|
3481
4083
|
return this.config.getUserInfo(payload);
|
|
3482
4084
|
}
|
|
4085
|
+
const scope = payload.scope;
|
|
4086
|
+
const roles = payload.roles;
|
|
4087
|
+
const permissions = payload.permissions;
|
|
3483
4088
|
return {
|
|
3484
4089
|
userId: payload.sub || payload.user_id || payload.id,
|
|
3485
|
-
email: payload.email,
|
|
3486
|
-
name: payload.name,
|
|
3487
|
-
username: payload.username || payload.preferred_username,
|
|
3488
|
-
nickname: payload.nickname,
|
|
3489
|
-
picture: payload.picture || payload.avatar_url,
|
|
3490
|
-
roles:
|
|
3491
|
-
permissions:
|
|
3492
|
-
scopes:
|
|
4090
|
+
email: payload.email ? payload.email : void 0,
|
|
4091
|
+
name: payload.name ? payload.name : void 0,
|
|
4092
|
+
username: payload.username || payload.preferred_username ? payload.username || payload.preferred_username : void 0,
|
|
4093
|
+
nickname: payload.nickname ? payload.nickname : void 0,
|
|
4094
|
+
picture: payload.picture || payload.avatar_url ? payload.picture || payload.avatar_url : void 0,
|
|
4095
|
+
roles: Array.isArray(roles) ? roles : [],
|
|
4096
|
+
permissions: Array.isArray(permissions) ? permissions : [],
|
|
4097
|
+
scopes: scope ? scope.split(" ") : []
|
|
3493
4098
|
};
|
|
3494
4099
|
}
|
|
3495
4100
|
getIssuer() {
|
|
@@ -3674,9 +4279,12 @@ function requireAnyScope(needed) {
|
|
|
3674
4279
|
}
|
|
3675
4280
|
__name(requireAnyScope, "requireAnyScope");
|
|
3676
4281
|
export {
|
|
4282
|
+
MCPServer,
|
|
4283
|
+
VERSION,
|
|
3677
4284
|
adaptConnectMiddleware,
|
|
3678
4285
|
adaptMiddleware,
|
|
3679
4286
|
array,
|
|
4287
|
+
audio,
|
|
3680
4288
|
binary,
|
|
3681
4289
|
buildWidgetUrl,
|
|
3682
4290
|
createExternalUrlResource,
|
|
@@ -3687,6 +4295,7 @@ export {
|
|
|
3687
4295
|
css,
|
|
3688
4296
|
error,
|
|
3689
4297
|
getAuth,
|
|
4298
|
+
getPackageVersion,
|
|
3690
4299
|
getRequestContext,
|
|
3691
4300
|
hasAnyScope,
|
|
3692
4301
|
hasRequestContext,
|