mcp-use 1.9.1-canary.1 → 1.10.0-canary.3
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-QREDNTLS.js → chunk-F5MMLHUR.js} +1 -1
- package/dist/{chunk-33U4IA4N.js → chunk-L6P6GBCW.js} +84 -3
- package/dist/{chunk-ZQUCGISK.js → chunk-LTA4LQTH.js} +6 -4
- package/dist/{chunk-D22NUQTL.js → chunk-QBTQXCAI.js} +185 -1
- package/dist/{chunk-MUZ5WYE3.js → chunk-VPHP7ERH.js} +18 -9
- package/dist/{chunk-U5BX3ISQ.js → chunk-YMJL66MY.js} +10 -6
- package/dist/index.cjs +220 -20
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -12
- package/dist/src/agents/index.cjs +10 -6
- package/dist/src/agents/index.js +3 -3
- package/dist/src/agents/mcp_agent.d.ts.map +1 -1
- package/dist/src/browser.cjs +200 -10
- package/dist/src/browser.js +7 -7
- package/dist/src/client/prompts.js +2 -2
- package/dist/src/connectors/base.d.ts +2 -2
- package/dist/src/connectors/base.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 +207 -12
- package/dist/src/react/index.js +4 -4
- package/dist/src/react/useMcp.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 +268 -125
- package/dist/src/server/index.d.ts +2 -2
- package/dist/src/server/index.d.ts.map +1 -1
- package/dist/src/server/index.js +188 -126
- package/dist/src/server/mcp-server.d.ts +21 -10
- 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/index.d.ts +5 -4
- package/dist/src/server/prompts/index.d.ts.map +1 -1
- package/dist/src/server/resources/index.d.ts +43 -24
- package/dist/src/server/resources/index.d.ts.map +1 -1
- package/dist/src/server/sessions/session-manager.d.ts +11 -5
- package/dist/src/server/sessions/session-manager.d.ts.map +1 -1
- package/dist/src/server/tools/tool-execution-helpers.d.ts +31 -8
- 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 +2 -1
- package/dist/src/server/types/prompt.d.ts.map +1 -1
- package/dist/src/server/types/resource.d.ts +54 -9
- package/dist/src/server/types/resource.d.ts.map +1 -1
- package/dist/src/server/types/tool-context.d.ts +115 -0
- package/dist/src/server/types/tool-context.d.ts.map +1 -1
- package/dist/src/server/types/tool.d.ts +1 -1
- package/dist/src/server/types/tool.d.ts.map +1 -1
- package/dist/src/server/types/widget.d.ts +2 -1
- package/dist/src/server/types/widget.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 +11 -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 +337 -2
- package/dist/src/session.d.ts.map +1 -1
- package/dist/{tool-execution-helpers-BQJTPWPN.js → tool-execution-helpers-2LGVSS7L.js} +1 -1
- package/package.json +3 -3
|
@@ -403,9 +403,10 @@ function createElicitMethod(elicitInput) {
|
|
|
403
403
|
data: validatedData
|
|
404
404
|
};
|
|
405
405
|
} catch (error2) {
|
|
406
|
+
const err = error2;
|
|
406
407
|
throw new ElicitationValidationError(
|
|
407
|
-
`Elicitation data validation failed: ${
|
|
408
|
-
|
|
408
|
+
`Elicitation data validation failed: ${err.message}`,
|
|
409
|
+
err
|
|
409
410
|
);
|
|
410
411
|
}
|
|
411
412
|
}
|
|
@@ -456,7 +457,67 @@ function createLogMethod(sendNotification2, minLogLevel) {
|
|
|
456
457
|
});
|
|
457
458
|
};
|
|
458
459
|
}
|
|
459
|
-
function
|
|
460
|
+
function createClientCapabilityChecker(clientCapabilities) {
|
|
461
|
+
const caps = clientCapabilities || {};
|
|
462
|
+
return {
|
|
463
|
+
can(capability) {
|
|
464
|
+
return capability in caps;
|
|
465
|
+
},
|
|
466
|
+
capabilities() {
|
|
467
|
+
return { ...caps };
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
function createSendNotificationMethod(sessionId, sessions) {
|
|
472
|
+
if (!sessionId || !sessions) {
|
|
473
|
+
return void 0;
|
|
474
|
+
}
|
|
475
|
+
return async (method, params) => {
|
|
476
|
+
const session = sessions.get(sessionId);
|
|
477
|
+
if (!session?.sendNotification) {
|
|
478
|
+
console.warn(
|
|
479
|
+
`[MCP] Cannot send notification to session ${sessionId} - no sendNotification function`
|
|
480
|
+
);
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
try {
|
|
484
|
+
await session.sendNotification({
|
|
485
|
+
method,
|
|
486
|
+
params: params || {}
|
|
487
|
+
});
|
|
488
|
+
} catch (error2) {
|
|
489
|
+
console.error(
|
|
490
|
+
`[MCP] Error sending notification to session ${sessionId}:`,
|
|
491
|
+
error2
|
|
492
|
+
);
|
|
493
|
+
}
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
function createSendNotificationToSessionMethod(sessions) {
|
|
497
|
+
if (!sessions) {
|
|
498
|
+
return void 0;
|
|
499
|
+
}
|
|
500
|
+
return async (sessionId, method, params) => {
|
|
501
|
+
const session = sessions.get(sessionId);
|
|
502
|
+
if (!session?.sendNotification) {
|
|
503
|
+
return false;
|
|
504
|
+
}
|
|
505
|
+
try {
|
|
506
|
+
await session.sendNotification({
|
|
507
|
+
method,
|
|
508
|
+
params: params || {}
|
|
509
|
+
});
|
|
510
|
+
return true;
|
|
511
|
+
} catch (error2) {
|
|
512
|
+
console.error(
|
|
513
|
+
`[MCP] Error sending notification to session ${sessionId}:`,
|
|
514
|
+
error2
|
|
515
|
+
);
|
|
516
|
+
return false;
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
function createEnhancedContext(baseContext, createMessage, elicitInput, progressToken, sendNotification2, minLogLevel, clientCapabilities, sessionId, sessions) {
|
|
460
521
|
const enhancedContext = baseContext ? Object.create(baseContext) : {};
|
|
461
522
|
enhancedContext.sample = createSampleMethod(
|
|
462
523
|
createMessage,
|
|
@@ -469,6 +530,23 @@ function createEnhancedContext(baseContext, createMessage, elicitInput, progress
|
|
|
469
530
|
sendNotification2
|
|
470
531
|
);
|
|
471
532
|
enhancedContext.log = createLogMethod(sendNotification2, minLogLevel);
|
|
533
|
+
enhancedContext.client = createClientCapabilityChecker(clientCapabilities);
|
|
534
|
+
if (sessionId) {
|
|
535
|
+
enhancedContext.session = {
|
|
536
|
+
sessionId
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
const sendNotificationMethod = createSendNotificationMethod(
|
|
540
|
+
sessionId,
|
|
541
|
+
sessions
|
|
542
|
+
);
|
|
543
|
+
if (sendNotificationMethod) {
|
|
544
|
+
enhancedContext.sendNotification = sendNotificationMethod;
|
|
545
|
+
}
|
|
546
|
+
const sendNotificationToSessionMethod = createSendNotificationToSessionMethod(sessions);
|
|
547
|
+
if (sendNotificationToSessionMethod) {
|
|
548
|
+
enhancedContext.sendNotificationToSession = sendNotificationToSessionMethod;
|
|
549
|
+
}
|
|
472
550
|
return enhancedContext;
|
|
473
551
|
}
|
|
474
552
|
var import_zod_json_schema_compat, LOG_LEVELS, VALID_LOG_LEVELS;
|
|
@@ -508,6 +586,9 @@ var init_tool_execution_helpers = __esm({
|
|
|
508
586
|
__name(isValidLogLevel, "isValidLogLevel");
|
|
509
587
|
__name(shouldLogMessage, "shouldLogMessage");
|
|
510
588
|
__name(createLogMethod, "createLogMethod");
|
|
589
|
+
__name(createClientCapabilityChecker, "createClientCapabilityChecker");
|
|
590
|
+
__name(createSendNotificationMethod, "createSendNotificationMethod");
|
|
591
|
+
__name(createSendNotificationToSessionMethod, "createSendNotificationToSessionMethod");
|
|
511
592
|
__name(createEnhancedContext, "createEnhancedContext");
|
|
512
593
|
}
|
|
513
594
|
});
|
|
@@ -705,6 +786,7 @@ var init_conversion2 = __esm({
|
|
|
705
786
|
// src/server/index.ts
|
|
706
787
|
var server_exports = {};
|
|
707
788
|
__export(server_exports, {
|
|
789
|
+
MCPServer: () => MCPServer,
|
|
708
790
|
adaptConnectMiddleware: () => adaptConnectMiddleware,
|
|
709
791
|
adaptMiddleware: () => adaptMiddleware,
|
|
710
792
|
array: () => array,
|
|
@@ -2317,25 +2399,25 @@ function setupWidgetRoutes(app, serverConfig) {
|
|
|
2317
2399
|
__name(setupWidgetRoutes, "setupWidgetRoutes");
|
|
2318
2400
|
|
|
2319
2401
|
// src/server/widgets/ui-resource-registration.ts
|
|
2320
|
-
function uiResourceRegistration(definition) {
|
|
2402
|
+
function uiResourceRegistration(server, definition) {
|
|
2321
2403
|
const displayName = definition.title || definition.name;
|
|
2322
2404
|
let resourceUri;
|
|
2323
2405
|
let mimeType;
|
|
2324
2406
|
switch (definition.type) {
|
|
2325
2407
|
case "externalUrl":
|
|
2326
|
-
resourceUri = generateWidgetUri(definition.widget,
|
|
2408
|
+
resourceUri = generateWidgetUri(definition.widget, server.buildId);
|
|
2327
2409
|
mimeType = "text/uri-list";
|
|
2328
2410
|
break;
|
|
2329
2411
|
case "rawHtml":
|
|
2330
|
-
resourceUri = generateWidgetUri(definition.name,
|
|
2412
|
+
resourceUri = generateWidgetUri(definition.name, server.buildId);
|
|
2331
2413
|
mimeType = "text/html";
|
|
2332
2414
|
break;
|
|
2333
2415
|
case "remoteDom":
|
|
2334
|
-
resourceUri = generateWidgetUri(definition.name,
|
|
2416
|
+
resourceUri = generateWidgetUri(definition.name, server.buildId);
|
|
2335
2417
|
mimeType = "application/vnd.mcp-ui.remote-dom+javascript";
|
|
2336
2418
|
break;
|
|
2337
2419
|
case "appsSdk":
|
|
2338
|
-
resourceUri = generateWidgetUri(definition.name,
|
|
2420
|
+
resourceUri = generateWidgetUri(definition.name, server.buildId, ".html");
|
|
2339
2421
|
mimeType = "text/html+skybridge";
|
|
2340
2422
|
break;
|
|
2341
2423
|
default:
|
|
@@ -2344,12 +2426,12 @@ function uiResourceRegistration(definition) {
|
|
|
2344
2426
|
);
|
|
2345
2427
|
}
|
|
2346
2428
|
const serverConfig = {
|
|
2347
|
-
serverHost:
|
|
2348
|
-
serverPort:
|
|
2349
|
-
serverBaseUrl:
|
|
2350
|
-
buildId:
|
|
2429
|
+
serverHost: server.serverHost,
|
|
2430
|
+
serverPort: server.serverPort || 3e3,
|
|
2431
|
+
serverBaseUrl: server.serverBaseUrl,
|
|
2432
|
+
buildId: server.buildId
|
|
2351
2433
|
};
|
|
2352
|
-
|
|
2434
|
+
server.resource({
|
|
2353
2435
|
name: definition.name,
|
|
2354
2436
|
uri: resourceUri,
|
|
2355
2437
|
title: definition.title,
|
|
@@ -2371,9 +2453,9 @@ function uiResourceRegistration(definition) {
|
|
|
2371
2453
|
}, "readCallback")
|
|
2372
2454
|
});
|
|
2373
2455
|
if (definition.type === "appsSdk") {
|
|
2374
|
-
const buildIdPart =
|
|
2456
|
+
const buildIdPart = server.buildId ? `-${server.buildId}` : "";
|
|
2375
2457
|
const uriTemplate = `ui://widget/${definition.name}${buildIdPart}-{id}.html`;
|
|
2376
|
-
|
|
2458
|
+
server.resourceTemplate({
|
|
2377
2459
|
name: `${definition.name}-dynamic`,
|
|
2378
2460
|
resourceTemplate: {
|
|
2379
2461
|
uriTemplate,
|
|
@@ -2413,13 +2495,15 @@ function uiResourceRegistration(definition) {
|
|
|
2413
2495
|
}
|
|
2414
2496
|
}
|
|
2415
2497
|
}
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2498
|
+
server.tool(
|
|
2499
|
+
{
|
|
2500
|
+
name: definition.name,
|
|
2501
|
+
title: definition.title,
|
|
2502
|
+
description: definition.description,
|
|
2503
|
+
inputs: convertPropsToInputs(definition.props),
|
|
2504
|
+
_meta: Object.keys(toolMetadata).length > 0 ? toolMetadata : void 0
|
|
2505
|
+
},
|
|
2506
|
+
async (params) => {
|
|
2423
2507
|
const uiResource = await createWidgetUIResource(
|
|
2424
2508
|
definition,
|
|
2425
2509
|
params,
|
|
@@ -2429,7 +2513,7 @@ function uiResourceRegistration(definition) {
|
|
|
2429
2513
|
const randomId = Math.random().toString(36).substring(2, 15);
|
|
2430
2514
|
const uniqueUri = generateWidgetUri(
|
|
2431
2515
|
definition.name,
|
|
2432
|
-
|
|
2516
|
+
server.buildId,
|
|
2433
2517
|
".html",
|
|
2434
2518
|
randomId
|
|
2435
2519
|
);
|
|
@@ -2459,9 +2543,9 @@ function uiResourceRegistration(definition) {
|
|
|
2459
2543
|
uiResource
|
|
2460
2544
|
]
|
|
2461
2545
|
};
|
|
2462
|
-
}
|
|
2463
|
-
|
|
2464
|
-
return
|
|
2546
|
+
}
|
|
2547
|
+
);
|
|
2548
|
+
return server;
|
|
2465
2549
|
}
|
|
2466
2550
|
__name(uiResourceRegistration, "uiResourceRegistration");
|
|
2467
2551
|
|
|
@@ -2599,7 +2683,7 @@ function toolRegistration(toolDefinition, callback) {
|
|
|
2599
2683
|
const initialRequestContext = getRequestContext();
|
|
2600
2684
|
const extraProgressToken = extra?._meta?.progressToken;
|
|
2601
2685
|
const extraSendNotification = extra?.sendNotification;
|
|
2602
|
-
const { requestContext, progressToken, sendNotification: sendNotification2 } = findSessionContext(
|
|
2686
|
+
const { requestContext, session, progressToken, sendNotification: sendNotification2 } = findSessionContext(
|
|
2603
2687
|
this.sessions,
|
|
2604
2688
|
initialRequestContext,
|
|
2605
2689
|
extraProgressToken,
|
|
@@ -2610,7 +2694,9 @@ function toolRegistration(toolDefinition, callback) {
|
|
|
2610
2694
|
this.createMessage.bind(this),
|
|
2611
2695
|
this.server.server.elicitInput.bind(this.server.server),
|
|
2612
2696
|
progressToken,
|
|
2613
|
-
sendNotification2
|
|
2697
|
+
sendNotification2,
|
|
2698
|
+
session?.logLevel,
|
|
2699
|
+
session?.clientCapabilities
|
|
2614
2700
|
);
|
|
2615
2701
|
const executeCallback = /* @__PURE__ */ __name(async () => {
|
|
2616
2702
|
if (actualCallback.length >= 2) {
|
|
@@ -2839,24 +2925,25 @@ function registerResourceTemplate(resourceTemplateDefinition, callback) {
|
|
|
2839
2925
|
`Resource template '${resourceTemplateDefinition.name}' must have either a readCallback property or a callback parameter`
|
|
2840
2926
|
);
|
|
2841
2927
|
}
|
|
2842
|
-
const
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2928
|
+
const isFlatStructure = "uriTemplate" in resourceTemplateDefinition;
|
|
2929
|
+
const uriTemplate = isFlatStructure ? resourceTemplateDefinition.uriTemplate : resourceTemplateDefinition.resourceTemplate.uriTemplate;
|
|
2930
|
+
const mimeType = isFlatStructure ? resourceTemplateDefinition.mimeType : resourceTemplateDefinition.resourceTemplate.mimeType;
|
|
2931
|
+
const templateDescription = isFlatStructure ? void 0 : resourceTemplateDefinition.resourceTemplate.description;
|
|
2932
|
+
const template = new import_mcp.ResourceTemplate(uriTemplate, {
|
|
2933
|
+
list: void 0,
|
|
2934
|
+
// Optional: callback to list all matching resources
|
|
2935
|
+
complete: void 0
|
|
2936
|
+
// Optional: callback for auto-completion
|
|
2937
|
+
});
|
|
2851
2938
|
const metadata = {};
|
|
2852
2939
|
if (resourceTemplateDefinition.title) {
|
|
2853
2940
|
metadata.title = resourceTemplateDefinition.title;
|
|
2854
2941
|
}
|
|
2855
|
-
if (resourceTemplateDefinition.description ||
|
|
2856
|
-
metadata.description = resourceTemplateDefinition.description ||
|
|
2942
|
+
if (resourceTemplateDefinition.description || templateDescription) {
|
|
2943
|
+
metadata.description = resourceTemplateDefinition.description || templateDescription;
|
|
2857
2944
|
}
|
|
2858
|
-
if (
|
|
2859
|
-
metadata.mimeType =
|
|
2945
|
+
if (mimeType) {
|
|
2946
|
+
metadata.mimeType = mimeType;
|
|
2860
2947
|
}
|
|
2861
2948
|
if (resourceTemplateDefinition.annotations) {
|
|
2862
2949
|
metadata.annotations = resourceTemplateDefinition.annotations;
|
|
@@ -2866,10 +2953,7 @@ function registerResourceTemplate(resourceTemplateDefinition, callback) {
|
|
|
2866
2953
|
template,
|
|
2867
2954
|
metadata,
|
|
2868
2955
|
async (uri) => {
|
|
2869
|
-
const params = this.parseTemplateUri(
|
|
2870
|
-
resourceTemplateDefinition.resourceTemplate.uriTemplate,
|
|
2871
|
-
uri.toString()
|
|
2872
|
-
);
|
|
2956
|
+
const params = this.parseTemplateUri(uriTemplate, uri.toString());
|
|
2873
2957
|
const { getRequestContext: getRequestContext2, runWithContext: runWithContext2 } = await Promise.resolve().then(() => (init_context_storage(), context_storage_exports));
|
|
2874
2958
|
const { findSessionContext: findSessionContext2 } = await Promise.resolve().then(() => (init_tool_execution_helpers(), tool_execution_helpers_exports));
|
|
2875
2959
|
const initialRequestContext = getRequestContext2();
|
|
@@ -2884,8 +2968,12 @@ function registerResourceTemplate(resourceTemplateDefinition, callback) {
|
|
|
2884
2968
|
const executeCallback = /* @__PURE__ */ __name(async () => {
|
|
2885
2969
|
if (actualCallback.length >= 3) {
|
|
2886
2970
|
return await actualCallback(uri, params, enhancedContext);
|
|
2971
|
+
} else if (actualCallback.length === 2) {
|
|
2972
|
+
return await actualCallback(uri, params);
|
|
2973
|
+
} else if (actualCallback.length === 1) {
|
|
2974
|
+
return await actualCallback(uri);
|
|
2887
2975
|
}
|
|
2888
|
-
return await actualCallback(
|
|
2976
|
+
return await actualCallback();
|
|
2889
2977
|
}, "executeCallback");
|
|
2890
2978
|
const result = requestContext ? await runWithContext2(requestContext, executeCallback) : await executeCallback();
|
|
2891
2979
|
if ("contents" in result && Array.isArray(result.contents)) {
|
|
@@ -3266,6 +3354,17 @@ async function mountMcp(app, mcpServerInstance, sessions, config, isProductionMo
|
|
|
3266
3354
|
context: c,
|
|
3267
3355
|
honoContext: c
|
|
3268
3356
|
});
|
|
3357
|
+
server.server.oninitialized = () => {
|
|
3358
|
+
const clientCapabilities = server.server.getClientCapabilities();
|
|
3359
|
+
if (clientCapabilities && sessions.has(sid)) {
|
|
3360
|
+
const session = sessions.get(sid);
|
|
3361
|
+
session.clientCapabilities = clientCapabilities;
|
|
3362
|
+
console.log(
|
|
3363
|
+
`[MCP] Captured client capabilities for session ${sid}:`,
|
|
3364
|
+
Object.keys(clientCapabilities)
|
|
3365
|
+
);
|
|
3366
|
+
}
|
|
3367
|
+
};
|
|
3269
3368
|
}, "onsessioninitialized"),
|
|
3270
3369
|
onsessionclosed: /* @__PURE__ */ __name((sid) => {
|
|
3271
3370
|
console.log(`[MCP] Session closed: ${sid}`);
|
|
@@ -3509,12 +3608,13 @@ function createBearerAuthMiddleware(provider, baseUrl) {
|
|
|
3509
3608
|
const result = await provider.verifyToken(token);
|
|
3510
3609
|
const payload = result.payload;
|
|
3511
3610
|
const user = provider.getUserInfo(payload);
|
|
3611
|
+
const scope = payload.scope;
|
|
3512
3612
|
const authInfo = {
|
|
3513
3613
|
user,
|
|
3514
3614
|
payload,
|
|
3515
3615
|
accessToken: token,
|
|
3516
3616
|
// Extract scopes from scope claim (OAuth standard)
|
|
3517
|
-
scopes:
|
|
3617
|
+
scopes: scope ? scope.split(" ") : [],
|
|
3518
3618
|
// Extract permissions (Auth0 style, or custom)
|
|
3519
3619
|
permissions: payload.permissions || []
|
|
3520
3620
|
};
|
|
@@ -3562,9 +3662,9 @@ async function setupOAuthForServer(app, oauthProvider, baseUrl, state) {
|
|
|
3562
3662
|
__name(setupOAuthForServer, "setupOAuthForServer");
|
|
3563
3663
|
|
|
3564
3664
|
// src/server/mcp-server.ts
|
|
3565
|
-
var
|
|
3665
|
+
var MCPServer = class {
|
|
3566
3666
|
static {
|
|
3567
|
-
__name(this, "
|
|
3667
|
+
__name(this, "MCPServer");
|
|
3568
3668
|
}
|
|
3569
3669
|
/**
|
|
3570
3670
|
* Native MCP server instance from @modelcontextprotocol/sdk
|
|
@@ -3631,7 +3731,7 @@ var McpServer = class {
|
|
|
3631
3731
|
* access to Hono methods while preserving MCP server functionality.
|
|
3632
3732
|
*
|
|
3633
3733
|
* @param config - Server configuration including name, version, and description
|
|
3634
|
-
* @returns A proxied
|
|
3734
|
+
* @returns A proxied MCPServer instance that supports both MCP and Hono methods
|
|
3635
3735
|
*/
|
|
3636
3736
|
constructor(config) {
|
|
3637
3737
|
this.config = config;
|
|
@@ -3669,37 +3769,56 @@ var McpServer = class {
|
|
|
3669
3769
|
const self = this;
|
|
3670
3770
|
this.tool = ((toolDefinition, callback) => {
|
|
3671
3771
|
const actualCallback = callback || toolDefinition.cb;
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
|
|
3772
|
+
if (actualCallback) {
|
|
3773
|
+
self.registrationRecipes.tools.set(toolDefinition.name, {
|
|
3774
|
+
config: toolDefinition,
|
|
3775
|
+
handler: actualCallback
|
|
3776
|
+
});
|
|
3777
|
+
}
|
|
3676
3778
|
return originalTool.call(self, toolDefinition, callback);
|
|
3677
3779
|
});
|
|
3678
|
-
this.prompt =
|
|
3780
|
+
this.prompt = ((promptDefinition, callback) => {
|
|
3679
3781
|
const actualCallback = callback || promptDefinition.cb;
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3782
|
+
if (actualCallback) {
|
|
3783
|
+
self.registrationRecipes.prompts.set(promptDefinition.name, {
|
|
3784
|
+
config: promptDefinition,
|
|
3785
|
+
handler: actualCallback
|
|
3786
|
+
});
|
|
3787
|
+
}
|
|
3788
|
+
return originalPrompt.call(
|
|
3789
|
+
self,
|
|
3790
|
+
promptDefinition,
|
|
3791
|
+
callback
|
|
3792
|
+
);
|
|
3793
|
+
});
|
|
3794
|
+
this.resource = ((resourceDefinition, callback) => {
|
|
3687
3795
|
const actualCallback = callback || resourceDefinition.readCallback;
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3796
|
+
if (actualCallback) {
|
|
3797
|
+
const resourceKey = `${resourceDefinition.name}:${resourceDefinition.uri}`;
|
|
3798
|
+
self.registrationRecipes.resources.set(resourceKey, {
|
|
3799
|
+
config: resourceDefinition,
|
|
3800
|
+
handler: actualCallback
|
|
3801
|
+
});
|
|
3802
|
+
}
|
|
3693
3803
|
return originalResource.call(self, resourceDefinition, callback);
|
|
3694
|
-
};
|
|
3695
|
-
this.resourceTemplate =
|
|
3804
|
+
});
|
|
3805
|
+
this.resourceTemplate = ((templateDefinition, callback) => {
|
|
3696
3806
|
const actualCallback = callback || templateDefinition.readCallback;
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3807
|
+
if (actualCallback) {
|
|
3808
|
+
self.registrationRecipes.resourceTemplates.set(
|
|
3809
|
+
templateDefinition.name,
|
|
3810
|
+
{
|
|
3811
|
+
config: templateDefinition,
|
|
3812
|
+
handler: actualCallback
|
|
3813
|
+
}
|
|
3814
|
+
);
|
|
3815
|
+
}
|
|
3816
|
+
return originalResourceTemplate.call(
|
|
3817
|
+
self,
|
|
3818
|
+
templateDefinition,
|
|
3819
|
+
callback
|
|
3820
|
+
);
|
|
3821
|
+
});
|
|
3703
3822
|
}
|
|
3704
3823
|
/**
|
|
3705
3824
|
* Create a new server instance for a session following official SDK pattern.
|
|
@@ -3737,6 +3856,15 @@ var McpServer = class {
|
|
|
3737
3856
|
extraProgressToken,
|
|
3738
3857
|
extraSendNotification
|
|
3739
3858
|
);
|
|
3859
|
+
let sessionId;
|
|
3860
|
+
if (session) {
|
|
3861
|
+
for (const [id, s] of this.sessions.entries()) {
|
|
3862
|
+
if (s === session) {
|
|
3863
|
+
sessionId = id;
|
|
3864
|
+
break;
|
|
3865
|
+
}
|
|
3866
|
+
}
|
|
3867
|
+
}
|
|
3740
3868
|
const createMessageWithLogging = /* @__PURE__ */ __name(async (params2, options) => {
|
|
3741
3869
|
console.log("[createMessage] About to call server.createMessage");
|
|
3742
3870
|
console.log("[createMessage] Has server:", !!newServer);
|
|
@@ -3748,11 +3876,12 @@ var McpServer = class {
|
|
|
3748
3876
|
console.log("[createMessage] Got result successfully");
|
|
3749
3877
|
return result;
|
|
3750
3878
|
} catch (err) {
|
|
3879
|
+
const error2 = err;
|
|
3751
3880
|
console.error(
|
|
3752
3881
|
"[createMessage] Error:",
|
|
3753
|
-
|
|
3882
|
+
error2.message,
|
|
3754
3883
|
"Code:",
|
|
3755
|
-
|
|
3884
|
+
error2.code
|
|
3756
3885
|
);
|
|
3757
3886
|
throw err;
|
|
3758
3887
|
}
|
|
@@ -3763,7 +3892,10 @@ var McpServer = class {
|
|
|
3763
3892
|
newServer.server.elicitInput.bind(newServer.server),
|
|
3764
3893
|
progressToken,
|
|
3765
3894
|
sendNotification2,
|
|
3766
|
-
session?.logLevel
|
|
3895
|
+
session?.logLevel,
|
|
3896
|
+
session?.clientCapabilities,
|
|
3897
|
+
sessionId,
|
|
3898
|
+
this.sessions
|
|
3767
3899
|
);
|
|
3768
3900
|
const executeCallback = /* @__PURE__ */ __name(async () => {
|
|
3769
3901
|
if (actualCallback.length >= 2) {
|
|
@@ -3798,8 +3930,8 @@ var McpServer = class {
|
|
|
3798
3930
|
} else {
|
|
3799
3931
|
argsSchema = void 0;
|
|
3800
3932
|
}
|
|
3801
|
-
const wrappedHandler = /* @__PURE__ */ __name(async (params) => {
|
|
3802
|
-
const result = await handler(params);
|
|
3933
|
+
const wrappedHandler = /* @__PURE__ */ __name(async (params, extra) => {
|
|
3934
|
+
const result = await handler(params, extra);
|
|
3803
3935
|
if ("messages" in result && Array.isArray(result.messages)) {
|
|
3804
3936
|
return result;
|
|
3805
3937
|
}
|
|
@@ -3818,8 +3950,8 @@ var McpServer = class {
|
|
|
3818
3950
|
}
|
|
3819
3951
|
for (const [_key, recipe] of this.registrationRecipes.resources) {
|
|
3820
3952
|
const { config, handler } = recipe;
|
|
3821
|
-
const wrappedHandler = /* @__PURE__ */ __name(async () => {
|
|
3822
|
-
const result = await handler();
|
|
3953
|
+
const wrappedHandler = /* @__PURE__ */ __name(async (extra) => {
|
|
3954
|
+
const result = await handler(extra);
|
|
3823
3955
|
if ("contents" in result && Array.isArray(result.contents)) {
|
|
3824
3956
|
return result;
|
|
3825
3957
|
}
|
|
@@ -3839,22 +3971,23 @@ var McpServer = class {
|
|
|
3839
3971
|
}
|
|
3840
3972
|
for (const [_name, recipe] of this.registrationRecipes.resourceTemplates) {
|
|
3841
3973
|
const { config, handler } = recipe;
|
|
3842
|
-
const
|
|
3843
|
-
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
|
|
3974
|
+
const isFlatStructure = "uriTemplate" in config;
|
|
3975
|
+
const uriTemplate = isFlatStructure ? config.uriTemplate : config.resourceTemplate.uriTemplate;
|
|
3976
|
+
const mimeType = isFlatStructure ? config.mimeType : config.resourceTemplate.mimeType;
|
|
3977
|
+
const templateDescription = isFlatStructure ? void 0 : config.resourceTemplate.description;
|
|
3978
|
+
const template = new import_mcp2.ResourceTemplate(uriTemplate, {
|
|
3979
|
+
list: void 0,
|
|
3980
|
+
complete: void 0
|
|
3981
|
+
});
|
|
3849
3982
|
const metadata = {};
|
|
3850
3983
|
if (config.title) {
|
|
3851
3984
|
metadata.title = config.title;
|
|
3852
3985
|
}
|
|
3853
|
-
if (config.description ||
|
|
3854
|
-
metadata.description = config.description ||
|
|
3986
|
+
if (config.description || templateDescription) {
|
|
3987
|
+
metadata.description = config.description || templateDescription;
|
|
3855
3988
|
}
|
|
3856
|
-
if (
|
|
3857
|
-
metadata.mimeType =
|
|
3989
|
+
if (mimeType) {
|
|
3990
|
+
metadata.mimeType = mimeType;
|
|
3858
3991
|
}
|
|
3859
3992
|
if (config.annotations) {
|
|
3860
3993
|
metadata.annotations = config.annotations;
|
|
@@ -3863,23 +3996,23 @@ var McpServer = class {
|
|
|
3863
3996
|
config.name,
|
|
3864
3997
|
template,
|
|
3865
3998
|
metadata,
|
|
3866
|
-
async (uri) => {
|
|
3867
|
-
const params = this.parseTemplateUri(
|
|
3868
|
-
|
|
3869
|
-
uri.toString()
|
|
3870
|
-
);
|
|
3871
|
-
const result = await handler(uri, params);
|
|
3999
|
+
async (uri, extra) => {
|
|
4000
|
+
const params = this.parseTemplateUri(uriTemplate, uri.toString());
|
|
4001
|
+
const result = await handler(uri, params, extra);
|
|
3872
4002
|
if ("contents" in result && Array.isArray(result.contents)) {
|
|
3873
4003
|
return result;
|
|
3874
4004
|
}
|
|
3875
4005
|
const { convertToolResultToResourceResult: convertToolResultToResourceResult2 } = await Promise.resolve().then(() => (init_conversion(), conversion_exports));
|
|
3876
|
-
return convertToolResultToResourceResult2(
|
|
4006
|
+
return convertToolResultToResourceResult2(
|
|
4007
|
+
uri.toString(),
|
|
4008
|
+
result
|
|
4009
|
+
);
|
|
3877
4010
|
}
|
|
3878
4011
|
);
|
|
3879
4012
|
}
|
|
3880
4013
|
newServer.server.setRequestHandler(
|
|
3881
4014
|
import_zod2.z.object({ method: import_zod2.z.literal("logging/setLevel") }).passthrough(),
|
|
3882
|
-
async (request) => {
|
|
4015
|
+
(async (request, extra) => {
|
|
3883
4016
|
const level = request.params?.level;
|
|
3884
4017
|
if (!level) {
|
|
3885
4018
|
throw new import_types2.McpError(
|
|
@@ -3918,7 +4051,7 @@ var McpServer = class {
|
|
|
3918
4051
|
"[MCP] Could not find session for logging/setLevel request"
|
|
3919
4052
|
);
|
|
3920
4053
|
throw new import_types2.McpError(import_types2.ErrorCode.InternalError, "Could not find session");
|
|
3921
|
-
}
|
|
4054
|
+
})
|
|
3922
4055
|
);
|
|
3923
4056
|
this.subscriptionManager.registerHandlers(newServer, this.sessions);
|
|
3924
4057
|
return newServer;
|
|
@@ -3968,7 +4101,9 @@ var McpServer = class {
|
|
|
3968
4101
|
async notifyResourceUpdated(uri) {
|
|
3969
4102
|
return this.subscriptionManager.notifyResourceUpdated(uri, this.sessions);
|
|
3970
4103
|
}
|
|
3971
|
-
uiResource =
|
|
4104
|
+
uiResource = /* @__PURE__ */ __name((definition) => {
|
|
4105
|
+
return uiResourceRegistration(this, definition);
|
|
4106
|
+
}, "uiResource");
|
|
3972
4107
|
/**
|
|
3973
4108
|
* Mount MCP server endpoints at /mcp and /sse
|
|
3974
4109
|
*
|
|
@@ -3993,7 +4128,7 @@ var McpServer = class {
|
|
|
3993
4128
|
const result = await mountMcp(
|
|
3994
4129
|
this.app,
|
|
3995
4130
|
this,
|
|
3996
|
-
// Pass the
|
|
4131
|
+
// Pass the MCPServer instance so mountMcp can call getServerForSession()
|
|
3997
4132
|
this.sessions,
|
|
3998
4133
|
this.config,
|
|
3999
4134
|
isProductionMode()
|
|
@@ -4056,7 +4191,7 @@ var McpServer = class {
|
|
|
4056
4191
|
this.serverHost,
|
|
4057
4192
|
this.serverPort
|
|
4058
4193
|
);
|
|
4059
|
-
if (this.oauthConfig && !this.oauthSetupState.complete) {
|
|
4194
|
+
if (this.oauthConfig && !this.oauthSetupState.complete && this.oauthProvider) {
|
|
4060
4195
|
await setupOAuthForServer(
|
|
4061
4196
|
this.app,
|
|
4062
4197
|
this.oauthProvider,
|
|
@@ -4093,7 +4228,7 @@ var McpServer = class {
|
|
|
4093
4228
|
* @example
|
|
4094
4229
|
* ```typescript
|
|
4095
4230
|
* // For Supabase Edge Functions (handles path rewriting automatically)
|
|
4096
|
-
* const server =
|
|
4231
|
+
* const server = new MCPServer({ name: 'my-server', version: '1.0.0' });
|
|
4097
4232
|
* server.tool({ ... });
|
|
4098
4233
|
* const handler = await server.getHandler({ provider: 'supabase' });
|
|
4099
4234
|
* Deno.serve(handler);
|
|
@@ -4102,14 +4237,14 @@ var McpServer = class {
|
|
|
4102
4237
|
* @example
|
|
4103
4238
|
* ```typescript
|
|
4104
4239
|
* // For Cloudflare Workers
|
|
4105
|
-
* const server =
|
|
4240
|
+
* const server = new MCPServer({ name: 'my-server', version: '1.0.0' });
|
|
4106
4241
|
* server.tool({ ... });
|
|
4107
4242
|
* const handler = await server.getHandler();
|
|
4108
4243
|
* export default { fetch: handler };
|
|
4109
4244
|
* ```
|
|
4110
4245
|
*/
|
|
4111
4246
|
async getHandler(options) {
|
|
4112
|
-
if (this.oauthConfig && !this.oauthSetupState.complete) {
|
|
4247
|
+
if (this.oauthConfig && !this.oauthSetupState.complete && this.oauthProvider) {
|
|
4113
4248
|
await setupOAuthForServer(
|
|
4114
4249
|
this.app,
|
|
4115
4250
|
this.oauthProvider,
|
|
@@ -4180,7 +4315,7 @@ var McpServer = class {
|
|
|
4180
4315
|
}
|
|
4181
4316
|
};
|
|
4182
4317
|
function createMCPServer(name, config = {}) {
|
|
4183
|
-
const instance = new
|
|
4318
|
+
const instance = new MCPServer({
|
|
4184
4319
|
name,
|
|
4185
4320
|
version: config.version || "1.0.0",
|
|
4186
4321
|
description: config.description,
|
|
@@ -4262,12 +4397,13 @@ var SupabaseOAuthProvider = class {
|
|
|
4262
4397
|
}
|
|
4263
4398
|
}
|
|
4264
4399
|
getUserInfo(payload) {
|
|
4400
|
+
const userMetadata = payload.user_metadata;
|
|
4265
4401
|
return {
|
|
4266
4402
|
userId: payload.sub || payload.user_id,
|
|
4267
4403
|
email: payload.email,
|
|
4268
|
-
name:
|
|
4269
|
-
username:
|
|
4270
|
-
picture:
|
|
4404
|
+
name: userMetadata?.name || userMetadata?.full_name,
|
|
4405
|
+
username: userMetadata?.username,
|
|
4406
|
+
picture: userMetadata?.avatar_url,
|
|
4271
4407
|
roles: payload.role ? [payload.role] : [],
|
|
4272
4408
|
permissions: payload.aal ? [`aal:${payload.aal}`] : [],
|
|
4273
4409
|
// Include Supabase-specific claims
|
|
@@ -4340,6 +4476,7 @@ var Auth0OAuthProvider = class {
|
|
|
4340
4476
|
}
|
|
4341
4477
|
}
|
|
4342
4478
|
getUserInfo(payload) {
|
|
4479
|
+
const scope = payload.scope;
|
|
4343
4480
|
return {
|
|
4344
4481
|
userId: payload.sub,
|
|
4345
4482
|
email: payload.email,
|
|
@@ -4352,7 +4489,7 @@ var Auth0OAuthProvider = class {
|
|
|
4352
4489
|
// Auth0 can include roles (if configured)
|
|
4353
4490
|
roles: payload.roles || payload["https://your-app.com/roles"] || [],
|
|
4354
4491
|
// Include scope as well
|
|
4355
|
-
scopes:
|
|
4492
|
+
scopes: scope ? scope.split(" ") : [],
|
|
4356
4493
|
// Additional Auth0-specific claims
|
|
4357
4494
|
email_verified: payload.email_verified,
|
|
4358
4495
|
updated_at: payload.updated_at
|
|
@@ -4424,8 +4561,10 @@ var KeycloakOAuthProvider = class {
|
|
|
4424
4561
|
}
|
|
4425
4562
|
}
|
|
4426
4563
|
getUserInfo(payload) {
|
|
4427
|
-
const
|
|
4428
|
-
const
|
|
4564
|
+
const realmAccess = payload.realm_access;
|
|
4565
|
+
const realmRoles = realmAccess?.roles || [];
|
|
4566
|
+
const resourceAccess = payload.resource_access;
|
|
4567
|
+
const clientRoles = this.config.clientId && (resourceAccess?.[this.config.clientId]?.roles || []) || [];
|
|
4429
4568
|
const allRoles = [...realmRoles, ...clientRoles];
|
|
4430
4569
|
const permissions = [];
|
|
4431
4570
|
if (payload.resource_access) {
|
|
@@ -4439,6 +4578,7 @@ var KeycloakOAuthProvider = class {
|
|
|
4439
4578
|
}
|
|
4440
4579
|
);
|
|
4441
4580
|
}
|
|
4581
|
+
const scope = payload.scope;
|
|
4442
4582
|
return {
|
|
4443
4583
|
userId: payload.sub,
|
|
4444
4584
|
email: payload.email,
|
|
@@ -4449,7 +4589,7 @@ var KeycloakOAuthProvider = class {
|
|
|
4449
4589
|
roles: allRoles,
|
|
4450
4590
|
permissions,
|
|
4451
4591
|
// Include scope as well
|
|
4452
|
-
scopes:
|
|
4592
|
+
scopes: scope ? scope.split(" ") : [],
|
|
4453
4593
|
// Keycloak-specific claims
|
|
4454
4594
|
email_verified: payload.email_verified,
|
|
4455
4595
|
given_name: payload.given_name,
|
|
@@ -4578,7 +4718,7 @@ var CustomOAuthProvider = class {
|
|
|
4578
4718
|
async verifyToken(token) {
|
|
4579
4719
|
try {
|
|
4580
4720
|
const result = await this.config.verifyToken(token);
|
|
4581
|
-
return
|
|
4721
|
+
return result;
|
|
4582
4722
|
} catch (error2) {
|
|
4583
4723
|
throw new Error(`Custom OAuth verification failed: ${error2}`);
|
|
4584
4724
|
}
|
|
@@ -4587,16 +4727,19 @@ var CustomOAuthProvider = class {
|
|
|
4587
4727
|
if (this.config.getUserInfo) {
|
|
4588
4728
|
return this.config.getUserInfo(payload);
|
|
4589
4729
|
}
|
|
4730
|
+
const scope = payload.scope;
|
|
4731
|
+
const roles = payload.roles;
|
|
4732
|
+
const permissions = payload.permissions;
|
|
4590
4733
|
return {
|
|
4591
4734
|
userId: payload.sub || payload.user_id || payload.id,
|
|
4592
|
-
email: payload.email,
|
|
4593
|
-
name: payload.name,
|
|
4594
|
-
username: payload.username || payload.preferred_username,
|
|
4595
|
-
nickname: payload.nickname,
|
|
4596
|
-
picture: payload.picture || payload.avatar_url,
|
|
4597
|
-
roles:
|
|
4598
|
-
permissions:
|
|
4599
|
-
scopes:
|
|
4735
|
+
email: payload.email ? payload.email : void 0,
|
|
4736
|
+
name: payload.name ? payload.name : void 0,
|
|
4737
|
+
username: payload.username || payload.preferred_username ? payload.username || payload.preferred_username : void 0,
|
|
4738
|
+
nickname: payload.nickname ? payload.nickname : void 0,
|
|
4739
|
+
picture: payload.picture || payload.avatar_url ? payload.picture || payload.avatar_url : void 0,
|
|
4740
|
+
roles: Array.isArray(roles) ? roles : [],
|
|
4741
|
+
permissions: Array.isArray(permissions) ? permissions : [],
|
|
4742
|
+
scopes: scope ? scope.split(" ") : []
|
|
4600
4743
|
};
|
|
4601
4744
|
}
|
|
4602
4745
|
getIssuer() {
|