@strapi/core 5.58.0 → 5.60.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Strapi.d.ts.map +1 -1
- package/dist/Strapi.js +1 -0
- package/dist/Strapi.js.map +1 -1
- package/dist/Strapi.mjs +1 -0
- package/dist/Strapi.mjs.map +1 -1
- package/dist/core-api/routes/index.js +10 -45
- package/dist/core-api/routes/index.js.map +1 -1
- package/dist/core-api/routes/index.mjs +10 -25
- package/dist/core-api/routes/index.mjs.map +1 -1
- package/dist/core-api/routes/response.d.ts +28 -0
- package/dist/core-api/routes/response.d.ts.map +1 -0
- package/dist/core-api/routes/response.js +63 -0
- package/dist/core-api/routes/response.js.map +1 -0
- package/dist/core-api/routes/response.mjs +40 -0
- package/dist/core-api/routes/response.mjs.map +1 -0
- package/dist/ee/entitlements.d.ts.map +1 -1
- package/dist/ee/entitlements.js.map +1 -1
- package/dist/ee/entitlements.mjs.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/loaders/apis.d.ts.map +1 -1
- package/dist/loaders/apis.js.map +1 -1
- package/dist/loaders/apis.mjs.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.js +2 -2
- package/dist/loaders/plugins/get-enabled-plugins.js.map +1 -1
- package/dist/loaders/plugins/get-enabled-plugins.mjs +2 -2
- package/dist/loaders/plugins/get-enabled-plugins.mjs.map +1 -1
- package/dist/middlewares/cors.d.ts.map +1 -1
- package/dist/middlewares/cors.js.map +1 -1
- package/dist/middlewares/cors.mjs.map +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.js +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.js.map +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.mjs +1 -1
- package/dist/migrations/database/5.0.0-discard-drafts.mjs.map +1 -1
- package/dist/migrations/first-published-at.js +1 -1
- package/dist/migrations/first-published-at.js.map +1 -1
- package/dist/migrations/first-published-at.mjs +1 -1
- package/dist/migrations/first-published-at.mjs.map +1 -1
- package/dist/package.json.js +15 -14
- package/dist/package.json.js.map +1 -1
- package/dist/package.json.mjs +15 -14
- package/dist/package.json.mjs.map +1 -1
- package/dist/providers/admin.d.ts.map +1 -1
- package/dist/providers/admin.js +8 -0
- package/dist/providers/admin.js.map +1 -1
- package/dist/providers/admin.mjs +8 -0
- package/dist/providers/admin.mjs.map +1 -1
- package/dist/registries/controllers.d.ts.map +1 -1
- package/dist/registries/controllers.js.map +1 -1
- package/dist/registries/controllers.mjs.map +1 -1
- package/dist/services/config.js +1 -1
- package/dist/services/config.js.map +1 -1
- package/dist/services/config.mjs +2 -2
- package/dist/services/config.mjs.map +1 -1
- package/dist/services/content-source-maps.js +6 -6
- package/dist/services/content-source-maps.js.map +1 -1
- package/dist/services/content-source-maps.mjs +6 -6
- package/dist/services/content-source-maps.mjs.map +1 -1
- package/dist/services/document-service/components.d.ts +27 -12
- package/dist/services/document-service/components.d.ts.map +1 -1
- package/dist/services/document-service/components.js +530 -86
- package/dist/services/document-service/components.js.map +1 -1
- package/dist/services/document-service/components.mjs +532 -89
- package/dist/services/document-service/components.mjs.map +1 -1
- package/dist/services/document-service/events.d.ts.map +1 -1
- package/dist/services/document-service/events.js +11 -2
- package/dist/services/document-service/events.js.map +1 -1
- package/dist/services/document-service/events.mjs +11 -2
- package/dist/services/document-service/events.mjs.map +1 -1
- package/dist/services/document-service/middlewares/middleware-manager.d.ts +1 -1
- package/dist/services/document-service/middlewares/middleware-manager.d.ts.map +1 -1
- package/dist/services/document-service/middlewares/middleware-manager.js +6 -1
- package/dist/services/document-service/middlewares/middleware-manager.js.map +1 -1
- package/dist/services/document-service/middlewares/middleware-manager.mjs +6 -1
- package/dist/services/document-service/middlewares/middleware-manager.mjs.map +1 -1
- package/dist/services/document-service/repository.d.ts.map +1 -1
- package/dist/services/document-service/repository.js +26 -7
- package/dist/services/document-service/repository.js.map +1 -1
- package/dist/services/document-service/repository.mjs +27 -8
- package/dist/services/document-service/repository.mjs.map +1 -1
- package/dist/services/document-service/transform/data.d.ts.map +1 -1
- package/dist/services/document-service/transform/data.js.map +1 -1
- package/dist/services/document-service/transform/data.mjs.map +1 -1
- package/dist/services/document-service/transform/relations/transform/default-locale.d.ts +4 -1
- package/dist/services/document-service/transform/relations/transform/default-locale.d.ts.map +1 -1
- package/dist/services/document-service/transform/relations/transform/default-locale.js +12 -9
- package/dist/services/document-service/transform/relations/transform/default-locale.js.map +1 -1
- package/dist/services/document-service/transform/relations/transform/default-locale.mjs +12 -10
- package/dist/services/document-service/transform/relations/transform/default-locale.mjs.map +1 -1
- package/dist/services/document-service/utils/clone-relations.d.ts +21 -4
- package/dist/services/document-service/utils/clone-relations.d.ts.map +1 -1
- package/dist/services/document-service/utils/clone-relations.js +619 -34
- package/dist/services/document-service/utils/clone-relations.js.map +1 -1
- package/dist/services/document-service/utils/clone-relations.mjs +619 -36
- package/dist/services/document-service/utils/clone-relations.mjs.map +1 -1
- package/dist/services/document-service/utils/unidirectional-relations.d.ts +4 -2
- package/dist/services/document-service/utils/unidirectional-relations.d.ts.map +1 -1
- package/dist/services/document-service/utils/unidirectional-relations.js +1 -10
- package/dist/services/document-service/utils/unidirectional-relations.js.map +1 -1
- package/dist/services/document-service/utils/unidirectional-relations.mjs +1 -10
- package/dist/services/document-service/utils/unidirectional-relations.mjs.map +1 -1
- package/dist/services/entity-validator/index.d.ts.map +1 -1
- package/dist/services/entity-validator/index.js +6 -2
- package/dist/services/entity-validator/index.js.map +1 -1
- package/dist/services/entity-validator/index.mjs +7 -3
- package/dist/services/entity-validator/index.mjs.map +1 -1
- package/dist/services/event-hub.d.ts +1 -0
- package/dist/services/event-hub.d.ts.map +1 -1
- package/dist/services/event-hub.js +30 -5
- package/dist/services/event-hub.js.map +1 -1
- package/dist/services/event-hub.mjs +30 -5
- package/dist/services/event-hub.mjs.map +1 -1
- package/dist/services/mcp/handlers/handlePost.d.ts.map +1 -1
- package/dist/services/mcp/handlers/handlePost.js +4 -2
- package/dist/services/mcp/handlers/handlePost.js.map +1 -1
- package/dist/services/mcp/handlers/handlePost.mjs +4 -2
- package/dist/services/mcp/handlers/handlePost.mjs.map +1 -1
- package/dist/services/mcp/internal/McpServerFactory.d.ts +4 -1
- package/dist/services/mcp/internal/McpServerFactory.d.ts.map +1 -1
- package/dist/services/mcp/internal/McpServerFactory.js +8 -2
- package/dist/services/mcp/internal/McpServerFactory.js.map +1 -1
- package/dist/services/mcp/internal/McpServerFactory.mjs +9 -3
- package/dist/services/mcp/internal/McpServerFactory.mjs.map +1 -1
- package/dist/services/mcp/internal/resolveToolSchemaScope.d.ts +16 -0
- package/dist/services/mcp/internal/resolveToolSchemaScope.d.ts.map +1 -0
- package/dist/services/mcp/internal/resolveToolSchemaScope.js +40 -0
- package/dist/services/mcp/internal/resolveToolSchemaScope.js.map +1 -0
- package/dist/services/mcp/internal/resolveToolSchemaScope.mjs +38 -0
- package/dist/services/mcp/internal/resolveToolSchemaScope.mjs.map +1 -0
- package/dist/services/mcp/tool-registry.d.ts +5 -0
- package/dist/services/mcp/tool-registry.d.ts.map +1 -1
- package/dist/services/mcp/tool-registry.js +30 -1
- package/dist/services/mcp/tool-registry.js.map +1 -1
- package/dist/services/mcp/tool-registry.mjs +30 -1
- package/dist/services/mcp/tool-registry.mjs.map +1 -1
- package/dist/services/webhook-runner.d.ts.map +1 -1
- package/dist/services/webhook-runner.js +23 -3
- package/dist/services/webhook-runner.js.map +1 -1
- package/dist/services/webhook-runner.mjs +23 -3
- package/dist/services/webhook-runner.mjs.map +1 -1
- package/dist/services/webhook-store.d.ts.map +1 -1
- package/dist/services/webhook-store.js +23 -4
- package/dist/services/webhook-store.js.map +1 -1
- package/dist/services/webhook-store.mjs +23 -4
- package/dist/services/webhook-store.mjs.map +1 -1
- package/dist/utils/fetch.d.ts.map +1 -1
- package/dist/utils/fetch.js +44 -8
- package/dist/utils/fetch.js.map +1 -1
- package/dist/utils/fetch.mjs +37 -8
- package/dist/utils/fetch.mjs.map +1 -1
- package/dist/utils/transform-content-types-to-models.js +5 -5
- package/dist/utils/transform-content-types-to-models.js.map +1 -1
- package/dist/utils/transform-content-types-to-models.mjs +5 -5
- package/dist/utils/transform-content-types-to-models.mjs.map +1 -1
- package/package.json +15 -14
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
// Default subscriber to easily add listeners with the on() method
|
|
6
6
|
const defaultSubscriber = async (eventName, ...args)=>{
|
|
7
7
|
if (listeners.has(eventName)) {
|
|
8
|
-
|
|
8
|
+
// Iterate over a copy so that a listener removed during the emit (e.g. a once() listener)
|
|
9
|
+
// does not make the loop skip the next listener
|
|
10
|
+
for (const listener of listeners.get(eventName).slice()){
|
|
9
11
|
await listener(...args);
|
|
10
12
|
}
|
|
11
13
|
}
|
|
@@ -48,13 +50,36 @@
|
|
|
48
50
|
};
|
|
49
51
|
},
|
|
50
52
|
off (eventName, listener) {
|
|
51
|
-
listeners.get(eventName)
|
|
53
|
+
const eventListeners = listeners.get(eventName);
|
|
54
|
+
if (eventListeners === undefined) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const listenerIndex = eventListeners.indexOf(listener);
|
|
58
|
+
// Only remove the listener if it exists
|
|
59
|
+
if (listenerIndex >= 0) {
|
|
60
|
+
eventListeners.splice(listenerIndex, 1);
|
|
61
|
+
}
|
|
52
62
|
},
|
|
53
63
|
once (eventName, listener) {
|
|
54
|
-
|
|
55
|
-
|
|
64
|
+
let fired = false;
|
|
65
|
+
// Remove the registered wrapper, not the original listener which is not in the list
|
|
66
|
+
const wrapper = async (...args)=>{
|
|
67
|
+
// An emit that copied the listener list before the removal can still call the wrapper
|
|
68
|
+
if (fired === true) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
fired = true;
|
|
72
|
+
eventHub.off(eventName, wrapper);
|
|
56
73
|
return listener(...args);
|
|
57
|
-
}
|
|
74
|
+
};
|
|
75
|
+
return eventHub.on(eventName, wrapper);
|
|
76
|
+
},
|
|
77
|
+
hasListeners (eventName) {
|
|
78
|
+
// Subscribers other than the default one receive every event
|
|
79
|
+
const hasCustomSubscriber = subscribers.some((subscriber)=>subscriber !== defaultSubscriber);
|
|
80
|
+
// Listeners are only reached through the default subscriber
|
|
81
|
+
const hasEventListener = subscribers.includes(defaultSubscriber) && (listeners.get(eventName)?.length ?? 0) > 0;
|
|
82
|
+
return hasCustomSubscriber || hasEventListener;
|
|
58
83
|
},
|
|
59
84
|
destroy () {
|
|
60
85
|
this.removeAllListeners();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-hub.mjs","sources":["../../src/services/event-hub.ts"],"sourcesContent":["export type Subscriber = (eventName: string, ...args: any[]) => Promise<void>;\nexport type Listener = (...args: any[]) => Promise<void>;\n\nexport interface EventHub {\n emit(eventName: string, ...args: unknown[]): Promise<void>;\n subscribe(subscriber: Subscriber): () => void;\n unsubscribe(subscriber: Subscriber): void;\n on(eventName: string, listener: Listener): () => void;\n off(eventName: string, listener: Listener): void;\n once(eventName: string, listener: Listener): () => void;\n destroy(): EventHub;\n removeListener(eventName: string, listener: Listener): void;\n removeAllListeners(): EventHub;\n removeAllSubscribers(): EventHub;\n addListener(eventName: string, listener: Listener): () => void;\n}\n\n/**\n * The event hub is Strapi's event control center.\n */\nexport default function createEventHub(): EventHub {\n const listeners = new Map();\n\n // Default subscriber to easily add listeners with the on() method\n const defaultSubscriber = async (eventName: string, ...args: unknown[]) => {\n if (listeners.has(eventName)) {\n for (const listener of listeners.get(eventName)) {\n await listener(...args);\n }\n }\n };\n\n // Store of subscribers that will be called when an event is emitted\n const subscribers = [defaultSubscriber];\n\n const eventHub: EventHub = {\n async emit(eventName, ...args) {\n for (const subscriber of subscribers) {\n await subscriber(eventName, ...args);\n }\n },\n\n subscribe(subscriber) {\n subscribers.push(subscriber);\n\n // Return a function to remove the subscriber\n return () => {\n eventHub.unsubscribe(subscriber);\n };\n },\n\n unsubscribe(subscriber) {\n const subscriberIndex = subscribers.indexOf(subscriber);\n\n // Only remove the subscriber if it exists\n if (subscriberIndex >= 0) {\n subscribers.splice(subscriberIndex, 1);\n }\n },\n\n on(eventName, listener) {\n if (!listeners.has(eventName)) {\n listeners.set(eventName, [listener]);\n } else {\n listeners.get(eventName).push(listener);\n }\n\n // Return a function to remove the listener\n return () => {\n eventHub.off(eventName, listener);\n };\n },\n\n off(eventName, listener) {\n listeners.get(eventName)
|
|
1
|
+
{"version":3,"file":"event-hub.mjs","sources":["../../src/services/event-hub.ts"],"sourcesContent":["export type Subscriber = (eventName: string, ...args: any[]) => Promise<void>;\nexport type Listener = (...args: any[]) => Promise<void>;\n\nexport interface EventHub {\n emit(eventName: string, ...args: unknown[]): Promise<void>;\n subscribe(subscriber: Subscriber): () => void;\n unsubscribe(subscriber: Subscriber): void;\n on(eventName: string, listener: Listener): () => void;\n off(eventName: string, listener: Listener): void;\n once(eventName: string, listener: Listener): () => void;\n destroy(): EventHub;\n removeListener(eventName: string, listener: Listener): void;\n removeAllListeners(): EventHub;\n removeAllSubscribers(): EventHub;\n addListener(eventName: string, listener: Listener): () => void;\n hasListeners(eventName: string): boolean;\n}\n\n/**\n * The event hub is Strapi's event control center.\n */\nexport default function createEventHub(): EventHub {\n const listeners = new Map();\n\n // Default subscriber to easily add listeners with the on() method\n const defaultSubscriber = async (eventName: string, ...args: unknown[]) => {\n if (listeners.has(eventName)) {\n // Iterate over a copy so that a listener removed during the emit (e.g. a once() listener)\n // does not make the loop skip the next listener\n for (const listener of listeners.get(eventName).slice()) {\n await listener(...args);\n }\n }\n };\n\n // Store of subscribers that will be called when an event is emitted\n const subscribers = [defaultSubscriber];\n\n const eventHub: EventHub = {\n async emit(eventName, ...args) {\n for (const subscriber of subscribers) {\n await subscriber(eventName, ...args);\n }\n },\n\n subscribe(subscriber) {\n subscribers.push(subscriber);\n\n // Return a function to remove the subscriber\n return () => {\n eventHub.unsubscribe(subscriber);\n };\n },\n\n unsubscribe(subscriber) {\n const subscriberIndex = subscribers.indexOf(subscriber);\n\n // Only remove the subscriber if it exists\n if (subscriberIndex >= 0) {\n subscribers.splice(subscriberIndex, 1);\n }\n },\n\n on(eventName, listener) {\n if (!listeners.has(eventName)) {\n listeners.set(eventName, [listener]);\n } else {\n listeners.get(eventName).push(listener);\n }\n\n // Return a function to remove the listener\n return () => {\n eventHub.off(eventName, listener);\n };\n },\n\n off(eventName, listener) {\n const eventListeners = listeners.get(eventName);\n\n if (eventListeners === undefined) {\n return;\n }\n\n const listenerIndex = eventListeners.indexOf(listener);\n\n // Only remove the listener if it exists\n if (listenerIndex >= 0) {\n eventListeners.splice(listenerIndex, 1);\n }\n },\n\n once(eventName, listener) {\n let fired = false;\n\n // Remove the registered wrapper, not the original listener which is not in the list\n const wrapper: Listener = async (...args) => {\n // An emit that copied the listener list before the removal can still call the wrapper\n if (fired === true) {\n return;\n }\n\n fired = true;\n eventHub.off(eventName, wrapper);\n return listener(...args);\n };\n\n return eventHub.on(eventName, wrapper);\n },\n\n hasListeners(eventName) {\n // Subscribers other than the default one receive every event\n const hasCustomSubscriber = subscribers.some(\n (subscriber) => subscriber !== defaultSubscriber\n );\n // Listeners are only reached through the default subscriber\n const hasEventListener =\n subscribers.includes(defaultSubscriber) && (listeners.get(eventName)?.length ?? 0) > 0;\n\n return hasCustomSubscriber || hasEventListener;\n },\n\n destroy() {\n this.removeAllListeners();\n this.removeAllSubscribers();\n return this;\n },\n\n removeListener(eventName, listener) {\n return eventHub.off(eventName, listener);\n },\n\n removeAllListeners() {\n listeners.clear();\n return this;\n },\n\n removeAllSubscribers() {\n subscribers.length = 0;\n return this;\n },\n\n addListener(eventName, listener) {\n return eventHub.on(eventName, listener);\n },\n };\n\n return eventHub;\n}\n"],"names":["createEventHub","listeners","Map","defaultSubscriber","eventName","args","has","listener","get","slice","subscribers","eventHub","emit","subscriber","subscribe","push","unsubscribe","subscriberIndex","indexOf","splice","on","set","off","eventListeners","undefined","listenerIndex","once","fired","wrapper","hasListeners","hasCustomSubscriber","some","hasEventListener","includes","length","destroy","removeAllListeners","removeAllSubscribers","removeListener","clear","addListener"],"mappings":"AAkBA;;AAEC,IACc,SAASA,cAAAA,GAAAA;AACtB,IAAA,MAAMC,YAAY,IAAIC,GAAAA,EAAAA;;IAGtB,MAAMC,iBAAAA,GAAoB,OAAOC,SAAAA,EAAmB,GAAGC,IAAAA,GAAAA;QACrD,IAAIJ,SAAAA,CAAUK,GAAG,CAACF,SAAAA,CAAAA,EAAY;;;AAG5B,YAAA,KAAK,MAAMG,QAAAA,IAAYN,SAAAA,CAAUO,GAAG,CAACJ,SAAAA,CAAAA,CAAWK,KAAK,EAAA,CAAI;AACvD,gBAAA,MAAMF,QAAAA,CAAAA,GAAYF,IAAAA,CAAAA;AACpB,YAAA;AACF,QAAA;AACF,IAAA,CAAA;;AAGA,IAAA,MAAMK,WAAAA,GAAc;AAACP,QAAAA;AAAkB,KAAA;AAEvC,IAAA,MAAMQ,QAAAA,GAAqB;AACzB,QAAA,MAAMC,IAAAA,CAAAA,CAAKR,SAAS,EAAE,GAAGC,IAAI,EAAA;YAC3B,KAAK,MAAMQ,cAAcH,WAAAA,CAAa;AACpC,gBAAA,MAAMG,WAAWT,SAAAA,EAAAA,GAAcC,IAAAA,CAAAA;AACjC,YAAA;AACF,QAAA,CAAA;AAEAS,QAAAA,SAAAA,CAAAA,CAAUD,UAAU,EAAA;AAClBH,YAAAA,WAAAA,CAAYK,IAAI,CAACF,UAAAA,CAAAA;;YAGjB,OAAO,IAAA;AACLF,gBAAAA,QAAAA,CAASK,WAAW,CAACH,UAAAA,CAAAA;AACvB,YAAA,CAAA;AACF,QAAA,CAAA;AAEAG,QAAAA,WAAAA,CAAAA,CAAYH,UAAU,EAAA;YACpB,MAAMI,eAAAA,GAAkBP,WAAAA,CAAYQ,OAAO,CAACL,UAAAA,CAAAA;;AAG5C,YAAA,IAAII,mBAAmB,CAAA,EAAG;gBACxBP,WAAAA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AAAA,CAAAA;AAChC,QAAA;AACF,KAAA;IAEA,OAAOI,QAAAA;AACT;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlePost.d.ts","sourceRoot":"","sources":["../../../../src/services/mcp/handlers/handlePost.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"handlePost.d.ts","sourceRoot":"","sources":["../../../../src/services/mcp/handlers/handlePost.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAU1C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAEtD,eAAO,MAAM,iBAAiB,GAAI,MAAM,sBAAsB,KAAG,IAAI,CAAC,iBA4ErE,CAAC"}
|
|
@@ -4,6 +4,7 @@ var node = require('@modelcontextprotocol/node');
|
|
|
4
4
|
var metrics = require('../metrics/metrics.js');
|
|
5
5
|
var sendJsonRpcError = require('../utils/sendJsonRpcError.js');
|
|
6
6
|
var withTimeout = require('../utils/withTimeout.js');
|
|
7
|
+
var resolveToolSchemaScope = require('../internal/resolveToolSchemaScope.js');
|
|
7
8
|
|
|
8
9
|
const createPostHandler = (deps)=>{
|
|
9
10
|
const { strapi, authenticationStrategy, config, createServerWithRegistries, capabilityDefinitions } = deps;
|
|
@@ -27,19 +28,20 @@ const createPostHandler = (deps)=>{
|
|
|
27
28
|
// Let audit logs pick up MCP actions and tag their origin.
|
|
28
29
|
ctx.state.user = authResult.user;
|
|
29
30
|
ctx.state.auditSource = 'mcp';
|
|
31
|
+
const requestBody = ctx.request.body ?? null;
|
|
30
32
|
const { mcpServer } = createServerWithRegistries({
|
|
31
33
|
strapi,
|
|
32
34
|
definitions: capabilityDefinitions,
|
|
33
35
|
isDevMode: config.isDevMode(),
|
|
34
36
|
ability: authResult.ability,
|
|
35
|
-
user: authResult.user
|
|
37
|
+
user: authResult.user,
|
|
38
|
+
toolSchemaScope: resolveToolSchemaScope.resolveToolSchemaScope(requestBody)
|
|
36
39
|
});
|
|
37
40
|
const transport = new node.NodeStreamableHTTPServerTransport({
|
|
38
41
|
sessionIdGenerator: undefined
|
|
39
42
|
});
|
|
40
43
|
try {
|
|
41
44
|
await withTimeout.withTimeout(mcpServer.connect(transport), config.connectTimeoutMs, 'mcpServer.connect');
|
|
42
|
-
const requestBody = ctx.request.body ?? null;
|
|
43
45
|
await withTimeout.withTimeout(transport.handleRequest(req, res, requestBody), config.requestTimeoutMs, 'transport.handleRequest');
|
|
44
46
|
} finally{
|
|
45
47
|
await mcpServer.close();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlePost.js","sources":["../../../../src/services/mcp/handlers/handlePost.ts"],"sourcesContent":["import { NodeStreamableHTTPServerTransport } from '@modelcontextprotocol/node';\nimport type { Core } from '@strapi/types';\nimport {\n classifyMcpRequestFailure,\n sendDidNotAuthenticateMcpRequest,\n sendDidNotHandleMcpRequest,\n sendDidUseMcpServer,\n} from '../metrics/metrics';\nimport { sendJsonRpcError } from '../utils/sendJsonRpcError';\nimport { withTimeout } from '../utils/withTimeout';\nimport type { McpHandlerDependencies } from './types';\n\nexport const createPostHandler = (deps: McpHandlerDependencies): Core.MiddlewareHandler => {\n const {\n strapi,\n authenticationStrategy,\n config,\n createServerWithRegistries,\n capabilityDefinitions,\n } = deps;\n\n return async (ctx) => {\n // Opt out of Koa's response phase — the MCP SDK writes directly to ctx.res\n // (via res.writeHead / res.end / SSE streaming). Without this, Koa's respond()\n // would also try to write ctx.body to the socket after the handler returns.\n ctx.respond = false;\n const req = ctx.req;\n const res = ctx.res;\n\n let hadAuthenticatedMcpRequest = false;\n\n try {\n const authResult = await authenticationStrategy.authenticate(ctx);\n if (authResult.authenticated === false) {\n sendDidNotAuthenticateMcpRequest(strapi, authResult.reason);\n sendJsonRpcError(res, 'AUTHENTICATION_REQUIRED');\n return;\n }\n\n hadAuthenticatedMcpRequest = true;\n sendDidUseMcpServer(strapi);\n\n // Let audit logs pick up MCP actions and tag their origin.\n ctx.state.user = authResult.user;\n ctx.state.auditSource = 'mcp';\n\n const { mcpServer } = createServerWithRegistries({\n strapi,\n definitions: capabilityDefinitions,\n isDevMode: config.isDevMode(),\n ability: authResult.ability,\n user: authResult.user,\n });\n\n const transport = new NodeStreamableHTTPServerTransport({\n sessionIdGenerator: undefined,\n });\n\n try {\n await withTimeout(\n mcpServer.connect(transport),\n config.connectTimeoutMs,\n 'mcpServer.connect'\n );\n\n
|
|
1
|
+
{"version":3,"file":"handlePost.js","sources":["../../../../src/services/mcp/handlers/handlePost.ts"],"sourcesContent":["import { NodeStreamableHTTPServerTransport } from '@modelcontextprotocol/node';\nimport type { Core } from '@strapi/types';\nimport {\n classifyMcpRequestFailure,\n sendDidNotAuthenticateMcpRequest,\n sendDidNotHandleMcpRequest,\n sendDidUseMcpServer,\n} from '../metrics/metrics';\nimport { sendJsonRpcError } from '../utils/sendJsonRpcError';\nimport { withTimeout } from '../utils/withTimeout';\nimport { resolveToolSchemaScope } from '../internal/resolveToolSchemaScope';\nimport type { McpHandlerDependencies } from './types';\n\nexport const createPostHandler = (deps: McpHandlerDependencies): Core.MiddlewareHandler => {\n const {\n strapi,\n authenticationStrategy,\n config,\n createServerWithRegistries,\n capabilityDefinitions,\n } = deps;\n\n return async (ctx) => {\n // Opt out of Koa's response phase — the MCP SDK writes directly to ctx.res\n // (via res.writeHead / res.end / SSE streaming). Without this, Koa's respond()\n // would also try to write ctx.body to the socket after the handler returns.\n ctx.respond = false;\n const req = ctx.req;\n const res = ctx.res;\n\n let hadAuthenticatedMcpRequest = false;\n\n try {\n const authResult = await authenticationStrategy.authenticate(ctx);\n if (authResult.authenticated === false) {\n sendDidNotAuthenticateMcpRequest(strapi, authResult.reason);\n sendJsonRpcError(res, 'AUTHENTICATION_REQUIRED');\n return;\n }\n\n hadAuthenticatedMcpRequest = true;\n sendDidUseMcpServer(strapi);\n\n // Let audit logs pick up MCP actions and tag their origin.\n ctx.state.user = authResult.user;\n ctx.state.auditSource = 'mcp';\n\n const requestBody = ctx.request.body ?? null;\n const { mcpServer } = createServerWithRegistries({\n strapi,\n definitions: capabilityDefinitions,\n isDevMode: config.isDevMode(),\n ability: authResult.ability,\n user: authResult.user,\n toolSchemaScope: resolveToolSchemaScope(requestBody),\n });\n\n const transport = new NodeStreamableHTTPServerTransport({\n sessionIdGenerator: undefined,\n });\n\n try {\n await withTimeout(\n mcpServer.connect(transport),\n config.connectTimeoutMs,\n 'mcpServer.connect'\n );\n\n await withTimeout(\n transport.handleRequest(req, res, requestBody),\n config.requestTimeoutMs,\n 'transport.handleRequest'\n );\n } finally {\n await mcpServer.close();\n }\n } catch (error) {\n strapi.log.error('[MCP] Error handling POST request', {\n error: error instanceof Error ? error.message : 'Unknown error',\n stack: error instanceof Error ? error.stack : undefined,\n });\n\n sendJsonRpcError(res, 'INTERNAL_ERROR');\n\n if (hadAuthenticatedMcpRequest) {\n sendDidNotHandleMcpRequest(strapi, classifyMcpRequestFailure(error));\n }\n }\n };\n};\n"],"names":["createPostHandler","deps","strapi","authenticationStrategy","config","createServerWithRegistries","capabilityDefinitions","ctx","respond","req","res","hadAuthenticatedMcpRequest","authResult","authenticate","authenticated","sendDidNotAuthenticateMcpRequest","reason","sendJsonRpcError","sendDidUseMcpServer","state","user","auditSource","requestBody","request","body","mcpServer","definitions","isDevMode","ability","toolSchemaScope","resolveToolSchemaScope","transport","NodeStreamableHTTPServerTransport","sessionIdGenerator","undefined","withTimeout","connect","connectTimeoutMs","handleRequest","requestTimeoutMs","close","error","log","Error","message","stack","sendDidNotHandleMcpRequest","classifyMcpRequestFailure"],"mappings":";;;;;;;;AAaO,MAAMA,oBAAoB,CAACC,IAAAA,GAAAA;IAChC,MAAM,EACJC,MAAM,EACNC,sBAAsB,EACtBC,MAAM,EACNC,0BAA0B,EAC1BC,qBAAqB,EACtB,GAAGL,IAAAA;AAEJ,IAAA,OAAO,OAAOM,GAAA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CAACL,SAAAA,CAAAA,EAClB3B,MAAAA,CAAOiC,gBAAgB,EACvB,mBAAA,CAAA;gBAGF,MAAMF,uBAAAA,CACJJ,UAAUO,aAAa,CAAC7B,KAAKC,GAAAA,EAAKY,WAAAA,CAAAA,EAClClB,MAAAA,CAAOmC,gBAAgB,EACvB,yBAAA,CAAA;YAEJ,CAAA,QAAU;AACR,gBAAA,MAAMd,UAAUe,KAAK,EAAA;AACvB,YAAA;AACF,QAAA,CAAA,CAAE,OAAOC,KAAAA,EAAO;AACdvC,YAAAA,MAAAA,CAAOwC,GAAG,CAACD,KAAK,CAAC,mCAAA,EAAqC;AACpDA,gBAAAA,KAAAA,EAAOA,KAAAA,YAAiBE,KAAAA,GAAQF,KAAAA,CAAMG,OAAO,GAAG,eAAA;AAChDC,gBAAAA,KAAAA,EAAOJ,KAAAA,YAAiBE,KAAAA,GAAQF,KAAAA,CAAMI,KAAK,GAAGX;AAChD,aAAA,CAAA;AAEAjB,YAAAA,iCAAAA,CAAiBP,GAAAA,EAAK,gBAAA,CAAA;AAEtB,YAAA,IAAIC,0BAAAA,EAA4B;AAC9BmC,gBAAAA,kCAAAA,CAA2B5C,QAAQ6C,iCAAAA,CAA0BN,KAAAA,CAAAA,CAAAA;AAC/D,YAAA;AACF,QAAA;AACF,IAAA,CAAA;AACF;;;;"}
|
|
@@ -2,6 +2,7 @@ import { NodeStreamableHTTPServerTransport } from '@modelcontextprotocol/node';
|
|
|
2
2
|
import { sendDidNotAuthenticateMcpRequest, sendDidUseMcpServer, sendDidNotHandleMcpRequest, classifyMcpRequestFailure } from '../metrics/metrics.mjs';
|
|
3
3
|
import { sendJsonRpcError } from '../utils/sendJsonRpcError.mjs';
|
|
4
4
|
import { withTimeout } from '../utils/withTimeout.mjs';
|
|
5
|
+
import { resolveToolSchemaScope } from '../internal/resolveToolSchemaScope.mjs';
|
|
5
6
|
|
|
6
7
|
const createPostHandler = (deps)=>{
|
|
7
8
|
const { strapi, authenticationStrategy, config, createServerWithRegistries, capabilityDefinitions } = deps;
|
|
@@ -25,19 +26,20 @@ const createPostHandler = (deps)=>{
|
|
|
25
26
|
// Let audit logs pick up MCP actions and tag their origin.
|
|
26
27
|
ctx.state.user = authResult.user;
|
|
27
28
|
ctx.state.auditSource = 'mcp';
|
|
29
|
+
const requestBody = ctx.request.body ?? null;
|
|
28
30
|
const { mcpServer } = createServerWithRegistries({
|
|
29
31
|
strapi,
|
|
30
32
|
definitions: capabilityDefinitions,
|
|
31
33
|
isDevMode: config.isDevMode(),
|
|
32
34
|
ability: authResult.ability,
|
|
33
|
-
user: authResult.user
|
|
35
|
+
user: authResult.user,
|
|
36
|
+
toolSchemaScope: resolveToolSchemaScope(requestBody)
|
|
34
37
|
});
|
|
35
38
|
const transport = new NodeStreamableHTTPServerTransport({
|
|
36
39
|
sessionIdGenerator: undefined
|
|
37
40
|
});
|
|
38
41
|
try {
|
|
39
42
|
await withTimeout(mcpServer.connect(transport), config.connectTimeoutMs, 'mcpServer.connect');
|
|
40
|
-
const requestBody = ctx.request.body ?? null;
|
|
41
43
|
await withTimeout(transport.handleRequest(req, res, requestBody), config.requestTimeoutMs, 'transport.handleRequest');
|
|
42
44
|
} finally{
|
|
43
45
|
await mcpServer.close();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlePost.mjs","sources":["../../../../src/services/mcp/handlers/handlePost.ts"],"sourcesContent":["import { NodeStreamableHTTPServerTransport } from '@modelcontextprotocol/node';\nimport type { Core } from '@strapi/types';\nimport {\n classifyMcpRequestFailure,\n sendDidNotAuthenticateMcpRequest,\n sendDidNotHandleMcpRequest,\n sendDidUseMcpServer,\n} from '../metrics/metrics';\nimport { sendJsonRpcError } from '../utils/sendJsonRpcError';\nimport { withTimeout } from '../utils/withTimeout';\nimport type { McpHandlerDependencies } from './types';\n\nexport const createPostHandler = (deps: McpHandlerDependencies): Core.MiddlewareHandler => {\n const {\n strapi,\n authenticationStrategy,\n config,\n createServerWithRegistries,\n capabilityDefinitions,\n } = deps;\n\n return async (ctx) => {\n // Opt out of Koa's response phase — the MCP SDK writes directly to ctx.res\n // (via res.writeHead / res.end / SSE streaming). Without this, Koa's respond()\n // would also try to write ctx.body to the socket after the handler returns.\n ctx.respond = false;\n const req = ctx.req;\n const res = ctx.res;\n\n let hadAuthenticatedMcpRequest = false;\n\n try {\n const authResult = await authenticationStrategy.authenticate(ctx);\n if (authResult.authenticated === false) {\n sendDidNotAuthenticateMcpRequest(strapi, authResult.reason);\n sendJsonRpcError(res, 'AUTHENTICATION_REQUIRED');\n return;\n }\n\n hadAuthenticatedMcpRequest = true;\n sendDidUseMcpServer(strapi);\n\n // Let audit logs pick up MCP actions and tag their origin.\n ctx.state.user = authResult.user;\n ctx.state.auditSource = 'mcp';\n\n const { mcpServer } = createServerWithRegistries({\n strapi,\n definitions: capabilityDefinitions,\n isDevMode: config.isDevMode(),\n ability: authResult.ability,\n user: authResult.user,\n });\n\n const transport = new NodeStreamableHTTPServerTransport({\n sessionIdGenerator: undefined,\n });\n\n try {\n await withTimeout(\n mcpServer.connect(transport),\n config.connectTimeoutMs,\n 'mcpServer.connect'\n );\n\n
|
|
1
|
+
{"version":3,"file":"handlePost.mjs","sources":["../../../../src/services/mcp/handlers/handlePost.ts"],"sourcesContent":["import { NodeStreamableHTTPServerTransport } from '@modelcontextprotocol/node';\nimport type { Core } from '@strapi/types';\nimport {\n classifyMcpRequestFailure,\n sendDidNotAuthenticateMcpRequest,\n sendDidNotHandleMcpRequest,\n sendDidUseMcpServer,\n} from '../metrics/metrics';\nimport { sendJsonRpcError } from '../utils/sendJsonRpcError';\nimport { withTimeout } from '../utils/withTimeout';\nimport { resolveToolSchemaScope } from '../internal/resolveToolSchemaScope';\nimport type { McpHandlerDependencies } from './types';\n\nexport const createPostHandler = (deps: McpHandlerDependencies): Core.MiddlewareHandler => {\n const {\n strapi,\n authenticationStrategy,\n config,\n createServerWithRegistries,\n capabilityDefinitions,\n } = deps;\n\n return async (ctx) => {\n // Opt out of Koa's response phase — the MCP SDK writes directly to ctx.res\n // (via res.writeHead / res.end / SSE streaming). Without this, Koa's respond()\n // would also try to write ctx.body to the socket after the handler returns.\n ctx.respond = false;\n const req = ctx.req;\n const res = ctx.res;\n\n let hadAuthenticatedMcpRequest = false;\n\n try {\n const authResult = await authenticationStrategy.authenticate(ctx);\n if (authResult.authenticated === false) {\n sendDidNotAuthenticateMcpRequest(strapi, authResult.reason);\n sendJsonRpcError(res, 'AUTHENTICATION_REQUIRED');\n return;\n }\n\n hadAuthenticatedMcpRequest = true;\n sendDidUseMcpServer(strapi);\n\n // Let audit logs pick up MCP actions and tag their origin.\n ctx.state.user = authResult.user;\n ctx.state.auditSource = 'mcp';\n\n const requestBody = ctx.request.body ?? null;\n const { mcpServer } = createServerWithRegistries({\n strapi,\n definitions: capabilityDefinitions,\n isDevMode: config.isDevMode(),\n ability: authResult.ability,\n user: authResult.user,\n toolSchemaScope: resolveToolSchemaScope(requestBody),\n });\n\n const transport = new NodeStreamableHTTPServerTransport({\n sessionIdGenerator: undefined,\n });\n\n try {\n await withTimeout(\n mcpServer.connect(transport),\n config.connectTimeoutMs,\n 'mcpServer.connect'\n );\n\n await withTimeout(\n transport.handleRequest(req, res, requestBody),\n config.requestTimeoutMs,\n 'transport.handleRequest'\n );\n } finally {\n await mcpServer.close();\n }\n } catch (error) {\n strapi.log.error('[MCP] Error handling POST request', {\n error: error instanceof Error ? error.message : 'Unknown error',\n stack: error instanceof Error ? error.stack : undefined,\n });\n\n sendJsonRpcError(res, 'INTERNAL_ERROR');\n\n if (hadAuthenticatedMcpRequest) {\n sendDidNotHandleMcpRequest(strapi, classifyMcpRequestFailure(error));\n }\n }\n };\n};\n"],"names":["createPostHandler","deps","strapi","authenticationStrategy","config","createServerWithRegistries","capabilityDefinitions","ctx","respond","req","res","hadAuthenticatedMcpRequest","authResult","authenticate","authenticated","sendDidNotAuthenticateMcpRequest","reason","sendJsonRpcError","sendDidUseMcpServer","state","user","auditSource","requestBody","request","body","mcpServer","definitions","isDevMode","ability","toolSchemaScope","resolveToolSchemaScope","transport","NodeStreamableHTTPServerTransport","sessionIdGenerator","undefined","withTimeout","connect","connectTimeoutMs","handleRequest","requestTimeoutMs","close","error","log","Error","message","stack","sendDidNotHandleMcpRequest","classifyMcpRequestFailure"],"mappings":";;;;;;AAaO,MAAMA,oBAAoB,CAACC,IAAAA,GAAAA;IAChC,MAAM,EACJC,MAAM,EACNC,sBAAsB,EACtBC,MAAM,EACNC,0BAA0B,EAC1BC,qBAAqB,EACtB,GAAGL,IAAAA;AAEJ,IAAA,OAAO,OAAOM,GAAAA,GAAAA;;;;AAIZA,QAAAA,GAAAA,CAAIC,OAAO,GAAG,KAAA;QACd,MAAMC,GAAAA,GAAMF,IAAIE,GAAG;QACnB,MAAMC,GAAAA,GAAMH,IAAIG,GAAG;AAEnB,QAAA,IAAIC,0BAAAA,GAA6B,KAAA;QAEjC,IAAI;AACF,YAAA,MAAMC,UAAAA,GAAa,MAAMT,sBAAAA,CAAuBU,YAAY,CAACN,GAAAA,CAAAA;YAC7D,IAAIK,UAAAA,CAAWE,aAAa,KAAK,KAAA,EAAO;gBACtCC,gCAAAA,CAAiCb,MAAAA,EAAQU,WAAWI,MAAM,CAAA;AAC1DC,gBAAAA,gBAAAA,CAAiBP,GAAAA,EAAK,yBAAA,CAAA;AACtB,gBAAA;AACF,YAAA;YAEAC,0BAAAA,GAA6B,IAAA;YAC7BO,mBAAAA,CAAoBhB,MAAAA,CAAAA;;AAGpBK,YAAAA,GAAAA,CAAIY,KAAK,CAACC,IAAI,GAAGR,WAAWQ,IAAI;YAChCb,GAAAA,CAAIY,KAAK,CAACE,WAAW,GAAG,KAAA;AAExB,YAAA,MAAMC,WAAAA,GAAcf,GAAAA,CAAIgB,OAAO,CAACC,IAAI,IAAI,IAAA;AACxC,YAAA,MAAM,EAAEC,SAAS,EAAE,GAAGpB,0BAAAA,CAA2B;AAC/CH,gBAAAA,MAAAA;gBACAwB,WAAAA,EAAapB,qBAAAA;AAC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-registry';
|
|
|
6
6
|
import type { McpAdminTokenAbility } from '../authentication';
|
|
7
7
|
import { McpCapabilityDefinitionRegistry } from './McpCapabilityDefinitionRegistry';
|
|
8
8
|
import type { McpCapabilityRegistryReadonly } from './McpCapabilityRegistry';
|
|
9
|
+
import type { McpToolSchemaScope } from './resolveToolSchemaScope';
|
|
9
10
|
export type McpCapabilityDefinitions = {
|
|
10
11
|
tools: McpCapabilityDefinitionRegistry<'tool', Modules.MCP.McpToolDefinition>;
|
|
11
12
|
prompts: McpCapabilityDefinitionRegistry<'prompt', Modules.MCP.McpPromptDefinition>;
|
|
@@ -32,6 +33,8 @@ export type CreateMcpServerWithRegistriesParams = {
|
|
|
32
33
|
isDevMode: boolean;
|
|
33
34
|
ability: McpAdminTokenAbility;
|
|
34
35
|
user: Modules.MCP.McpHandlerContext['user'];
|
|
36
|
+
/** Tools whose schemas the request needs. Defaults to `'all'`. */
|
|
37
|
+
toolSchemaScope?: McpToolSchemaScope;
|
|
35
38
|
};
|
|
36
|
-
export declare const createMcpServerWithRegistries: ({ strapi, definitions, isDevMode, ability, user, }: CreateMcpServerWithRegistriesParams) => McpServerWithRegistries;
|
|
39
|
+
export declare const createMcpServerWithRegistries: ({ strapi, definitions, isDevMode, ability, user, toolSchemaScope, }: CreateMcpServerWithRegistriesParams) => McpServerWithRegistries;
|
|
37
40
|
//# sourceMappingURL=McpServerFactory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"McpServerFactory.d.ts","sourceRoot":"","sources":["../../../../src/services/mcp/internal/McpServerFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA2B,MAAM,8BAA8B,CAAC;AAClF,OAAO,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EA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3B,SAAS,EAAE,mBAAmB,CAAC;CAChC,CAAC;AAEF,qEAAqE;AACrE,MAAM,MAAM,qBAAqB,GAAG;IAClC,KAAK,EAAE,6BAA6B,CAAC;IACrC,OAAO,EAAE,6BAA6B,CAAC;IACvC,SAAS,EAAE,6BAA6B,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,qBAAqB,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,mCAAmC,GAAG;IAChD,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC;IACpB,WAAW,EAAE,wBAAwB,CAAC;IACtC,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,oBAAoB,CAAC;IAC9B,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAC5C,kEAAkE;IAClE,eAAe,CAAC,EAAE,kBAAkB,CAAC;CACtC,CAAC;AAEF,eAAO,MAAM,6BAA6B,GAAI,qEAO3C,mCAAmC,KAAG,uBAsExC,CAAC"}
|
|
@@ -6,7 +6,7 @@ var resourceRegistry = require('../resource-registry.js');
|
|
|
6
6
|
var toolRegistry = require('../tool-registry.js');
|
|
7
7
|
var syncMcpSessionCapabilities = require('./syncMcpSessionCapabilities.js');
|
|
8
8
|
|
|
9
|
-
const createMcpServerWithRegistries = ({ strapi, definitions, isDevMode, ability, user })=>{
|
|
9
|
+
const createMcpServerWithRegistries = ({ strapi, definitions, isDevMode, ability, user, toolSchemaScope = 'all' })=>{
|
|
10
10
|
const capabilities = {
|
|
11
11
|
logging: {}
|
|
12
12
|
};
|
|
@@ -32,7 +32,13 @@ const createMcpServerWithRegistries = ({ strapi, definitions, isDevMode, ability
|
|
|
32
32
|
strapi,
|
|
33
33
|
definitions: definitions.tools,
|
|
34
34
|
ability,
|
|
35
|
-
user
|
|
35
|
+
user,
|
|
36
|
+
// A tool the token cannot use stays disabled, so its schemas are never advertised nor used.
|
|
37
|
+
shouldResolveSchemas: (definition)=>(toolSchemaScope === 'all' || toolSchemaScope.has(definition.name)) && syncMcpSessionCapabilities.canUseMcpCapability({
|
|
38
|
+
ability,
|
|
39
|
+
definition,
|
|
40
|
+
isDevMode
|
|
41
|
+
})
|
|
36
42
|
});
|
|
37
43
|
const prompts = new promptRegistry.McpPromptRegistry({
|
|
38
44
|
strapi,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"McpServerFactory.js","sources":["../../../../src/services/mcp/internal/McpServerFactory.ts"],"sourcesContent":["import { McpServer, type ServerCapabilities } from '@modelcontextprotocol/server';\nimport type { Core, Modules } from '@strapi/types';\nimport { McpPromptRegistry } from '../prompt-registry';\nimport { McpResourceRegistry } from '../resource-registry';\nimport { McpToolRegistry } from '../tool-registry';\nimport type { McpAdminTokenAbility } from '../authentication';\nimport { McpCapabilityDefinitionRegistry } from './McpCapabilityDefinitionRegistry';\nimport type { McpCapabilityRegistryReadonly } from './McpCapabilityRegistry';\nimport { syncMcpSessionCapabilities } from './syncMcpSessionCapabilities';\n\nexport type McpCapabilityDefinitions = {\n tools: McpCapabilityDefinitionRegistry<'tool', Modules.MCP.McpToolDefinition>;\n prompts: McpCapabilityDefinitionRegistry<'prompt', Modules.MCP.McpPromptDefinition>;\n resources: McpCapabilityDefinitionRegistry<'resource', Modules.MCP.McpResourceDefinition>;\n};\n\nexport type McpRegistries = {\n tools: McpToolRegistry;\n prompts: McpPromptRegistry;\n resources: McpResourceRegistry;\n};\n\n/** Read-only registry surface exposed on McpServerWithRegistries. */\nexport type McpRegistriesReadonly = {\n tools: McpCapabilityRegistryReadonly;\n prompts: McpCapabilityRegistryReadonly;\n resources: McpCapabilityRegistryReadonly;\n};\n\nexport type McpServerWithRegistries = {\n mcpServer: McpServer;\n registries: McpRegistriesReadonly;\n};\n\nexport type CreateMcpServerWithRegistriesParams = {\n strapi: Core.Strapi;\n definitions: McpCapabilityDefinitions;\n isDevMode: boolean;\n ability: McpAdminTokenAbility;\n user: Modules.MCP.McpHandlerContext['user'];\n};\n\nexport const createMcpServerWithRegistries = ({\n strapi,\n definitions,\n isDevMode,\n ability,\n user,\n}: CreateMcpServerWithRegistriesParams): McpServerWithRegistries => {\n const capabilities: ServerCapabilities = {\n logging: {},\n };\n // Advertise capability categories when definitions exist (server-level), not per-user enabled\n // count. Clients discover the real set via tools/list, prompts/list, resources/list after sync.\n if (definitions.tools.size > 0) {\n capabilities.tools = {};\n }\n if (definitions.prompts.size > 0) {\n capabilities.prompts = {};\n }\n if (definitions.resources.size > 0) {\n capabilities.resources = {};\n }\n\n const mcpServer = new McpServer(\n {\n name: 'strapi-mcp-server',\n version: '1.0.0',\n },\n {\n capabilities,\n }\n );\n\n // Bootstrap registries with current definitions\n const tools = new McpToolRegistry({\n strapi,\n definitions: definitions.tools,\n ability,\n user,\n });\n const prompts = new McpPromptRegistry({\n strapi,\n definitions: definitions.prompts,\n });\n const resources = new McpResourceRegistry({\n strapi,\n definitions: definitions.resources,\n });\n\n // Register capabilities (disabled by default)\n tools.bind(mcpServer);\n prompts.bind(mcpServer);\n resources.bind(mcpServer);\n\n syncMcpSessionCapabilities({\n registries: {\n tools,\n prompts,\n resources,\n },\n definitions,\n ability,\n isDevMode,\n });\n\n return {\n mcpServer,\n registries: {\n tools,\n prompts,\n resources,\n },\n };\n};\n"],"names":["createMcpServerWithRegistries","strapi","definitions","isDevMode","ability","user","capabilities","logging","tools","size","prompts","resources","mcpServer","McpServer","name","version","McpToolRegistry","McpPromptRegistry","McpResourceRegistry","bind","syncMcpSessionCapabilities","registries"],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"McpServerFactory.js","sources":["../../../../src/services/mcp/internal/McpServerFactory.ts"],"sourcesContent":["import { McpServer, type ServerCapabilities } from '@modelcontextprotocol/server';\nimport type { Core, Modules } from '@strapi/types';\nimport { McpPromptRegistry } from '../prompt-registry';\nimport { McpResourceRegistry } from '../resource-registry';\nimport { McpToolRegistry } from '../tool-registry';\nimport type { McpAdminTokenAbility } from '../authentication';\nimport { McpCapabilityDefinitionRegistry } from './McpCapabilityDefinitionRegistry';\nimport type { McpCapabilityRegistryReadonly } from './McpCapabilityRegistry';\nimport { canUseMcpCapability, syncMcpSessionCapabilities } from './syncMcpSessionCapabilities';\nimport type { McpToolSchemaScope } from './resolveToolSchemaScope';\n\nexport type McpCapabilityDefinitions = {\n tools: McpCapabilityDefinitionRegistry<'tool', Modules.MCP.McpToolDefinition>;\n prompts: McpCapabilityDefinitionRegistry<'prompt', Modules.MCP.McpPromptDefinition>;\n resources: McpCapabilityDefinitionRegistry<'resource', Modules.MCP.McpResourceDefinition>;\n};\n\nexport type McpRegistries = {\n tools: McpToolRegistry;\n prompts: McpPromptRegistry;\n resources: McpResourceRegistry;\n};\n\n/** Read-only registry surface exposed on McpServerWithRegistries. */\nexport type McpRegistriesReadonly = {\n tools: McpCapabilityRegistryReadonly;\n prompts: McpCapabilityRegistryReadonly;\n resources: McpCapabilityRegistryReadonly;\n};\n\nexport type McpServerWithRegistries = {\n mcpServer: McpServer;\n registries: McpRegistriesReadonly;\n};\n\nexport type CreateMcpServerWithRegistriesParams = {\n strapi: Core.Strapi;\n definitions: McpCapabilityDefinitions;\n isDevMode: boolean;\n ability: McpAdminTokenAbility;\n user: Modules.MCP.McpHandlerContext['user'];\n /** Tools whose schemas the request needs. Defaults to `'all'`. */\n toolSchemaScope?: McpToolSchemaScope;\n};\n\nexport const createMcpServerWithRegistries = ({\n strapi,\n definitions,\n isDevMode,\n ability,\n user,\n toolSchemaScope = 'all',\n}: CreateMcpServerWithRegistriesParams): McpServerWithRegistries => {\n const capabilities: ServerCapabilities = {\n logging: {},\n };\n // Advertise capability categories when definitions exist (server-level), not per-user enabled\n // count. Clients discover the real set via tools/list, prompts/list, resources/list after sync.\n if (definitions.tools.size > 0) {\n capabilities.tools = {};\n }\n if (definitions.prompts.size > 0) {\n capabilities.prompts = {};\n }\n if (definitions.resources.size > 0) {\n capabilities.resources = {};\n }\n\n const mcpServer = new McpServer(\n {\n name: 'strapi-mcp-server',\n version: '1.0.0',\n },\n {\n capabilities,\n }\n );\n\n // Bootstrap registries with current definitions\n const tools = new McpToolRegistry({\n strapi,\n definitions: definitions.tools,\n ability,\n user,\n // A tool the token cannot use stays disabled, so its schemas are never advertised nor used.\n shouldResolveSchemas: (definition) =>\n (toolSchemaScope === 'all' || toolSchemaScope.has(definition.name)) &&\n canUseMcpCapability({ ability, definition, isDevMode }),\n });\n const prompts = new McpPromptRegistry({\n strapi,\n definitions: definitions.prompts,\n });\n const resources = new McpResourceRegistry({\n strapi,\n definitions: definitions.resources,\n });\n\n // Register capabilities (disabled by default)\n tools.bind(mcpServer);\n prompts.bind(mcpServer);\n resources.bind(mcpServer);\n\n syncMcpSessionCapabilities({\n registries: {\n tools,\n prompts,\n resources,\n },\n definitions,\n ability,\n isDevMode,\n });\n\n return {\n mcpServer,\n registries: {\n tools,\n prompts,\n resources,\n },\n };\n};\n"],"names":["createMcpServerWithRegistries","strapi","definitions","isDevMode","ability","user","toolSchemaScope","capabilities","logging","tools","size","prompts","resources","mcpServer","McpServer","name","version","McpToolRegistry","shouldResolveSchemas","definition","has","canUseMcpCapability","McpPromptRegistry","McpResourceRegistry","bind","syncMcpSessionCapabilities","registries"],"mappings":";;;;;;;;MA6CaA,6BAAAA,GAAgC,CAAC,EAC5CC,MAAM,EACNC,WAAW,EACXC,SAAS,EACTC,OAAO,EACPC,IAAI,EACJC,eAAAA,GAAkB,KAAK,EACa,GAAA;AACpC,IAAA,MAAMC,YAAAA,GAAmC;AACvCC,QAAAA,OAAAA,EAAS;AACX,KAAA;;;AAGA,IAAA,IAAIN,WAAAA,CAAYO,KAAK,CAACC,IAAI,GAAG,CAAA,EAAG;QAC9BH,YAAAA,CAAaE,KAAK,GAAG,EAAC;AACxB,IAAA;AACA,IAAA,IAAIP,WAAAA,CAAYS,OAAO,CAACD,IAAI,GAAG,CAAA,EAAG;QAChCH,YAAAA,CAAaI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AAA,WAAAA;AACAE,QAAAA,OAAAA;AACAD,QAAAA;AACF,KAAA,CAAA;IAEA,OAAO;AACLU,QAAAA,SAAAA;QACAa,UAAAA,EAAY;AACVjB,YAAAA,KAAAA;AACAE,YAAAA,OAAAA;AACAC,YAAAA;AACF;AACF,KAAA;AACF;;;;"}
|
|
@@ -2,9 +2,9 @@ import { McpServer } from '@modelcontextprotocol/server';
|
|
|
2
2
|
import { McpPromptRegistry } from '../prompt-registry.mjs';
|
|
3
3
|
import { McpResourceRegistry } from '../resource-registry.mjs';
|
|
4
4
|
import { McpToolRegistry } from '../tool-registry.mjs';
|
|
5
|
-
import { syncMcpSessionCapabilities } from './syncMcpSessionCapabilities.mjs';
|
|
5
|
+
import { canUseMcpCapability, syncMcpSessionCapabilities } from './syncMcpSessionCapabilities.mjs';
|
|
6
6
|
|
|
7
|
-
const createMcpServerWithRegistries = ({ strapi, definitions, isDevMode, ability, user })=>{
|
|
7
|
+
const createMcpServerWithRegistries = ({ strapi, definitions, isDevMode, ability, user, toolSchemaScope = 'all' })=>{
|
|
8
8
|
const capabilities = {
|
|
9
9
|
logging: {}
|
|
10
10
|
};
|
|
@@ -30,7 +30,13 @@ const createMcpServerWithRegistries = ({ strapi, definitions, isDevMode, ability
|
|
|
30
30
|
strapi,
|
|
31
31
|
definitions: definitions.tools,
|
|
32
32
|
ability,
|
|
33
|
-
user
|
|
33
|
+
user,
|
|
34
|
+
// A tool the token cannot use stays disabled, so its schemas are never advertised nor used.
|
|
35
|
+
shouldResolveSchemas: (definition)=>(toolSchemaScope === 'all' || toolSchemaScope.has(definition.name)) && canUseMcpCapability({
|
|
36
|
+
ability,
|
|
37
|
+
definition,
|
|
38
|
+
isDevMode
|
|
39
|
+
})
|
|
34
40
|
});
|
|
35
41
|
const prompts = new McpPromptRegistry({
|
|
36
42
|
strapi,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"McpServerFactory.mjs","sources":["../../../../src/services/mcp/internal/McpServerFactory.ts"],"sourcesContent":["import { McpServer, type ServerCapabilities } from '@modelcontextprotocol/server';\nimport type { Core, Modules } from '@strapi/types';\nimport { McpPromptRegistry } from '../prompt-registry';\nimport { McpResourceRegistry } from '../resource-registry';\nimport { McpToolRegistry } from '../tool-registry';\nimport type { McpAdminTokenAbility } from '../authentication';\nimport { McpCapabilityDefinitionRegistry } from './McpCapabilityDefinitionRegistry';\nimport type { McpCapabilityRegistryReadonly } from './McpCapabilityRegistry';\nimport { syncMcpSessionCapabilities } from './syncMcpSessionCapabilities';\n\nexport type McpCapabilityDefinitions = {\n tools: McpCapabilityDefinitionRegistry<'tool', Modules.MCP.McpToolDefinition>;\n prompts: McpCapabilityDefinitionRegistry<'prompt', Modules.MCP.McpPromptDefinition>;\n resources: McpCapabilityDefinitionRegistry<'resource', Modules.MCP.McpResourceDefinition>;\n};\n\nexport type McpRegistries = {\n tools: McpToolRegistry;\n prompts: McpPromptRegistry;\n resources: McpResourceRegistry;\n};\n\n/** Read-only registry surface exposed on McpServerWithRegistries. */\nexport type McpRegistriesReadonly = {\n tools: McpCapabilityRegistryReadonly;\n prompts: McpCapabilityRegistryReadonly;\n resources: McpCapabilityRegistryReadonly;\n};\n\nexport type McpServerWithRegistries = {\n mcpServer: McpServer;\n registries: McpRegistriesReadonly;\n};\n\nexport type CreateMcpServerWithRegistriesParams = {\n strapi: Core.Strapi;\n definitions: McpCapabilityDefinitions;\n isDevMode: boolean;\n ability: McpAdminTokenAbility;\n user: Modules.MCP.McpHandlerContext['user'];\n};\n\nexport const createMcpServerWithRegistries = ({\n strapi,\n definitions,\n isDevMode,\n ability,\n user,\n}: CreateMcpServerWithRegistriesParams): McpServerWithRegistries => {\n const capabilities: ServerCapabilities = {\n logging: {},\n };\n // Advertise capability categories when definitions exist (server-level), not per-user enabled\n // count. Clients discover the real set via tools/list, prompts/list, resources/list after sync.\n if (definitions.tools.size > 0) {\n capabilities.tools = {};\n }\n if (definitions.prompts.size > 0) {\n capabilities.prompts = {};\n }\n if (definitions.resources.size > 0) {\n capabilities.resources = {};\n }\n\n const mcpServer = new McpServer(\n {\n name: 'strapi-mcp-server',\n version: '1.0.0',\n },\n {\n capabilities,\n }\n );\n\n // Bootstrap registries with current definitions\n const tools = new McpToolRegistry({\n strapi,\n definitions: definitions.tools,\n ability,\n user,\n });\n const prompts = new McpPromptRegistry({\n strapi,\n definitions: definitions.prompts,\n });\n const resources = new McpResourceRegistry({\n strapi,\n definitions: definitions.resources,\n });\n\n // Register capabilities (disabled by default)\n tools.bind(mcpServer);\n prompts.bind(mcpServer);\n resources.bind(mcpServer);\n\n syncMcpSessionCapabilities({\n registries: {\n tools,\n prompts,\n resources,\n },\n definitions,\n ability,\n isDevMode,\n });\n\n return {\n mcpServer,\n registries: {\n tools,\n prompts,\n resources,\n },\n };\n};\n"],"names":["createMcpServerWithRegistries","strapi","definitions","isDevMode","ability","user","capabilities","logging","tools","size","prompts","resources","mcpServer","McpServer","name","version","McpToolRegistry","McpPromptRegistry","McpResourceRegistry","bind","syncMcpSessionCapabilities","registries"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"McpServerFactory.mjs","sources":["../../../../src/services/mcp/internal/McpServerFactory.ts"],"sourcesContent":["import { McpServer, type ServerCapabilities } from '@modelcontextprotocol/server';\nimport type { Core, Modules } from '@strapi/types';\nimport { McpPromptRegistry } from '../prompt-registry';\nimport { McpResourceRegistry } from '../resource-registry';\nimport { McpToolRegistry } from '../tool-registry';\nimport type { McpAdminTokenAbility } from '../authentication';\nimport { McpCapabilityDefinitionRegistry } from './McpCapabilityDefinitionRegistry';\nimport type { McpCapabilityRegistryReadonly } from './McpCapabilityRegistry';\nimport { canUseMcpCapability, syncMcpSessionCapabilities } from './syncMcpSessionCapabilities';\nimport type { McpToolSchemaScope } from './resolveToolSchemaScope';\n\nexport type McpCapabilityDefinitions = {\n tools: McpCapabilityDefinitionRegistry<'tool', Modules.MCP.McpToolDefinition>;\n prompts: McpCapabilityDefinitionRegistry<'prompt', Modules.MCP.McpPromptDefinition>;\n resources: McpCapabilityDefinitionRegistry<'resource', Modules.MCP.McpResourceDefinition>;\n};\n\nexport type McpRegistries = {\n tools: McpToolRegistry;\n prompts: McpPromptRegistry;\n resources: McpResourceRegistry;\n};\n\n/** Read-only registry surface exposed on McpServerWithRegistries. */\nexport type McpRegistriesReadonly = {\n tools: McpCapabilityRegistryReadonly;\n prompts: McpCapabilityRegistryReadonly;\n resources: McpCapabilityRegistryReadonly;\n};\n\nexport type McpServerWithRegistries = {\n mcpServer: McpServer;\n registries: McpRegistriesReadonly;\n};\n\nexport type CreateMcpServerWithRegistriesParams = {\n strapi: Core.Strapi;\n definitions: McpCapabilityDefinitions;\n isDevMode: boolean;\n ability: McpAdminTokenAbility;\n user: Modules.MCP.McpHandlerContext['user'];\n /** Tools whose schemas the request needs. Defaults to `'all'`. */\n toolSchemaScope?: McpToolSchemaScope;\n};\n\nexport const createMcpServerWithRegistries = ({\n strapi,\n definitions,\n isDevMode,\n ability,\n user,\n toolSchemaScope = 'all',\n}: CreateMcpServerWithRegistriesParams): McpServerWithRegistries => {\n const capabilities: ServerCapabilities = {\n logging: {},\n };\n // Advertise capability categories when definitions exist (server-level), not per-user enabled\n // count. Clients discover the real set via tools/list, prompts/list, resources/list after sync.\n if (definitions.tools.size > 0) {\n capabilities.tools = {};\n }\n if (definitions.prompts.size > 0) {\n capabilities.prompts = {};\n }\n if (definitions.resources.size > 0) {\n capabilities.resources = {};\n }\n\n const mcpServer = new McpServer(\n {\n name: 'strapi-mcp-server',\n version: '1.0.0',\n },\n {\n capabilities,\n }\n );\n\n // Bootstrap registries with current definitions\n const tools = new McpToolRegistry({\n strapi,\n definitions: definitions.tools,\n ability,\n user,\n // A tool the token cannot use stays disabled, so its schemas are never advertised nor used.\n shouldResolveSchemas: (definition) =>\n (toolSchemaScope === 'all' || toolSchemaScope.has(definition.name)) &&\n canUseMcpCapability({ ability, definition, isDevMode }),\n });\n const prompts = new McpPromptRegistry({\n strapi,\n definitions: definitions.prompts,\n });\n const resources = new McpResourceRegistry({\n strapi,\n definitions: definitions.resources,\n });\n\n // Register capabilities (disabled by default)\n tools.bind(mcpServer);\n prompts.bind(mcpServer);\n resources.bind(mcpServer);\n\n syncMcpSessionCapabilities({\n registries: {\n tools,\n prompts,\n resources,\n },\n definitions,\n ability,\n isDevMode,\n });\n\n return {\n mcpServer,\n registries: {\n tools,\n prompts,\n resources,\n },\n };\n};\n"],"names":["createMcpServerWithRegistries","strapi","definitions","isDevMode","ability","user","toolSchemaScope","capabilities","logging","tools","size","prompts","resources","mcpServer","McpServer","name","version","McpToolRegistry","shouldResolveSchemas","definition","has","canUseMcpCapability","McpPromptRegistry","McpResourceRegistry","bind","syncMcpSessionCapabilities","registries"],"mappings":";;;;;;MA6CaA,6BAAAA,GAAgC,CAAC,EAC5CC,MAAM,EACNC,WAAW,EACXC,SAAS,EACTC,OAAO,EACPC,IAAI,EACJC,eAAAA,GAAkB,KAAK,EACa,GAAA;AACpC,IAAA,MAAMC,YAAAA,GAAmC;AACvCC,QAAAA,OAAAA,EAAS;AACX,KAAA;;;AAGA,IAAA,IAAIN,WAAAA,CAAYO,KAAK,CAACC,IAAI,GAAG,CAAA,EAAG;QAC9BH,YAAAA,CAAaE,KAAK,GAAG,EAAC;AACxB,IAAA;AACA,IAAA,IAAIP,WAAAA,CAAYS,OAAO,CAACD,IAAI,GAAG,CAAA,EAAG;QAChCH,YAAAA,CAAaI,OAAO,GAAG,EAAC;AAC1B,IAAA;AACA,IAAA,IAAIT,WAAAA,CAAYU,SAAS,CAACF,IAAI,GAAG,CAAA,EAAG;QAClCH,YAAAA,CAAaK,SAAS,GAAG,EAAC;AAC5B,IAAA;IAEA,MAAMC,SAAAA,GAAY,IAAIC,SAAAA,CACpB;QACEC,IAAAA,EAAM,mBAAA;QACNC,OAAAA,EAAS;KACX,EACA;AACET,QAAAA;AACF,KAAA,CAAA;;IAIF,MAAME,KAAAA,GAAQ,IAAIQ,eAAAA,CAAgB;AAChChB,QAAAA,MAAAA;AACAC,QAAAA,WAAAA,EAAaA,YAAYO,KAAK;AAC9BL,QAAAA,OAAAA;AACAC,QAAAA,IAAAA;;AAEAa,QAAAA,oBAAAA,EAAsB,CAACC,UAAAA,GACrB,CAACb,eAAAA,KAAoB,KAAA,IAASA,eAAAA,CAAgBc,GAAG,CAACD,UAAAA,CAAWJ,IAAI,CAAA,KACjEM,mBAAAA,CAAoB;AAAEjB,gBAAAA,OAAAA;AAASe,gBAAAA,UAAAA;AAAYhB,gBAAAA;AAAU,aAAA;AACzD,KAAA,CAAA;IACA,MAAMQ,OAAAA,GAAU,IAAIW,iBAAAA,CAAkB;AACpCrB,QAAAA,MAAAA;AACAC,QAAAA,WAAAA,EAAaA,YAAYS;AAC3B,KAAA,CAAA;IACA,MAAMC,SAAAA,GAAY,IAAIW,mBAAAA,CAAoB;AACxCtB,QAAAA,MAAAA;AACAC,QAAAA,WAAAA,EAAaA,YAAYU;AAC3B,KAAA,CAAA;;AAGAH,IAAAA,KAAAA,CAAMe,IAAI,CAACX,SAAAA,CAAAA;AACXF,IAAAA,OAAAA,CAAQa,IAAI,CAACX,SAAAA,CAAAA;AACbD,IAAAA,SAAAA,CAAUY,IAAI,CAACX,SAAAA,CAAAA;IAEfY,0BAAAA,CAA2B;QACzBC,UAAAA,EAAY;AACVjB,YAAAA,KAAAA;AACAE,YAAAA,OAAAA;AACAC,YAAAA;AACF,SAAA;AACAV,QAAAA,WAAAA;AACAE,QAAAA,OAAAA;AACAD,QAAAA;AACF,KAAA,CAAA;IAEA,OAAO;AACLU,QAAAA,SAAAA;QACAa,UAAAA,EAAY;AACVjB,YAAAA,KAAAA;AACAE,YAAAA,OAAAA;AACAC,YAAAA;AACF;AACF,KAAA;AACF;;;;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tools whose input/output schemas a request needs.
|
|
3
|
+
*
|
|
4
|
+
* - `'all'`: every tool may be advertised (e.g. `tools/list`).
|
|
5
|
+
* - a set: only these tools may be invoked (`tools/call`); every other tool can skip schema
|
|
6
|
+
* resolution because the request never lists nor calls it.
|
|
7
|
+
*/
|
|
8
|
+
export type McpToolSchemaScope = 'all' | ReadonlySet<string>;
|
|
9
|
+
/**
|
|
10
|
+
* Derives the tool schema scope from a JSON-RPC POST body (a single message or a batch).
|
|
11
|
+
*
|
|
12
|
+
* The server is stateless and rebuilt for every POST, so the body is the full set of work the
|
|
13
|
+
* server will do. Unknown shapes fall back to `'all'` so the SDK keeps producing its own errors.
|
|
14
|
+
*/
|
|
15
|
+
export declare const resolveToolSchemaScope: (body: unknown) => McpToolSchemaScope;
|
|
16
|
+
//# sourceMappingURL=resolveToolSchemaScope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveToolSchemaScope.d.ts","sourceRoot":"","sources":["../../../../src/services/mcp/internal/resolveToolSchemaScope.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,MAAM,kBAAkB,GAAG,KAAK,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;AAK7D;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,GAAI,MAAM,OAAO,KAAG,kBAwBtD,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Tools whose input/output schemas a request needs.
|
|
5
|
+
*
|
|
6
|
+
* - `'all'`: every tool may be advertised (e.g. `tools/list`).
|
|
7
|
+
* - a set: only these tools may be invoked (`tools/call`); every other tool can skip schema
|
|
8
|
+
* resolution because the request never lists nor calls it.
|
|
9
|
+
*/ const isRecord = (value)=>typeof value === 'object' && value !== null && Array.isArray(value) === false;
|
|
10
|
+
/**
|
|
11
|
+
* Derives the tool schema scope from a JSON-RPC POST body (a single message or a batch).
|
|
12
|
+
*
|
|
13
|
+
* The server is stateless and rebuilt for every POST, so the body is the full set of work the
|
|
14
|
+
* server will do. Unknown shapes fall back to `'all'` so the SDK keeps producing its own errors.
|
|
15
|
+
*/ const resolveToolSchemaScope = (body)=>{
|
|
16
|
+
const messages = Array.isArray(body) ? body : [
|
|
17
|
+
body
|
|
18
|
+
];
|
|
19
|
+
const toolNames = new Set();
|
|
20
|
+
for (const message of messages){
|
|
21
|
+
if (isRecord(message) === false) {
|
|
22
|
+
return 'all';
|
|
23
|
+
}
|
|
24
|
+
// Responses and notifications carry no method or a method that never touches tools.
|
|
25
|
+
if (message.method === 'tools/list') {
|
|
26
|
+
return 'all';
|
|
27
|
+
}
|
|
28
|
+
if (message.method === 'tools/call') {
|
|
29
|
+
const params = message.params;
|
|
30
|
+
if (isRecord(params) === false || typeof params.name !== 'string') {
|
|
31
|
+
return 'all';
|
|
32
|
+
}
|
|
33
|
+
toolNames.add(params.name);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return toolNames;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
exports.resolveToolSchemaScope = resolveToolSchemaScope;
|
|
40
|
+
//# sourceMappingURL=resolveToolSchemaScope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveToolSchemaScope.js","sources":["../../../../src/services/mcp/internal/resolveToolSchemaScope.ts"],"sourcesContent":["/**\n * Tools whose input/output schemas a request needs.\n *\n * - `'all'`: every tool may be advertised (e.g. `tools/list`).\n * - a set: only these tools may be invoked (`tools/call`); every other tool can skip schema\n * resolution because the request never lists nor calls it.\n */\nexport type McpToolSchemaScope = 'all' | ReadonlySet<string>;\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && Array.isArray(value) === false;\n\n/**\n * Derives the tool schema scope from a JSON-RPC POST body (a single message or a batch).\n *\n * The server is stateless and rebuilt for every POST, so the body is the full set of work the\n * server will do. Unknown shapes fall back to `'all'` so the SDK keeps producing its own errors.\n */\nexport const resolveToolSchemaScope = (body: unknown): McpToolSchemaScope => {\n const messages = Array.isArray(body) ? body : [body];\n const toolNames = new Set<string>();\n\n for (const message of messages) {\n if (isRecord(message) === false) {\n return 'all';\n }\n\n // Responses and notifications carry no method or a method that never touches tools.\n if (message.method === 'tools/list') {\n return 'all';\n }\n\n if (message.method === 'tools/call') {\n const params = message.params;\n if (isRecord(params) === false || typeof params.name !== 'string') {\n return 'all';\n }\n toolNames.add(params.name);\n }\n }\n\n return toolNames;\n};\n"],"names":["isRecord","value","Array","isArray","resolveToolSchemaScope","body","messages","toolNames","Set","message","method","params","name","add"],"mappings":";;AAAA;;;;;;AAMC,IAGD,MAAMA,QAAAA,GAAW,CAACC,KAAAA,GAChB,OAAOA,KAAAA,KAAU,QAAA,IAAYA,KAAAA,KAAU,IAAA,IAAQC,KAAAA,CAAMC,OAAO,CAACF,KAAAA,CAAAA,KAAW,KAAA;AAE1E;;;;;IAMO,MAAMG,sBAAAA,GAAyB,CAACC,IAAAA,GAAAA;AACrC,IAAA,MAAMC,QAAAA,GAAWJ,KAAAA,CAAMC,OAAO,CAACE,QAAQA,IAAAA,GAAO;AAACA,QAAAA;AAAK,KAAA;AACpD,IAAA,MAAME,YAAY,IAAIC,GAAAA,EAAAA;IAEtB,KAAK,MAAMC,WAAWH,QAAAA,CAAU;QAC9B,IAAIN,QAAAA,CAASS,aAAa,KAAA,EAAO;YAC/B,OAAO,KAAA;AACT,QAAA;;QAGA,IAAIA,OAAAA,CAAQC,MAAM,KAAK,YAAA,EAAc;YACnC,OAAO,KAAA;AACT,QAAA;QAEA,IAAID,OAAAA,CAAQC,MAAM,KAAK,YAAA,EAAc;YACnC,MAAMC,MAAAA,GAASF,QAAQE,MAAM;AAC7B,YAAA,IAAIX,SAASW,MAAAA,CAAAA,KAAY,KAAA,IAAS,OAAOA,MAAAA,CAAOC,IAAI,KAAK,QAAA,EAAU;gBACjE,OAAO,KAAA;AACT,YAAA;YACAL,SAAAA,CAAUM,GAAG,CAACF,MAAAA,CAAOC,IAAI,CAAA;AAC3B,QAAA;AACF,IAAA;IAEA,OAAOL,SAAAA;AACT;;;;"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tools whose input/output schemas a request needs.
|
|
3
|
+
*
|
|
4
|
+
* - `'all'`: every tool may be advertised (e.g. `tools/list`).
|
|
5
|
+
* - a set: only these tools may be invoked (`tools/call`); every other tool can skip schema
|
|
6
|
+
* resolution because the request never lists nor calls it.
|
|
7
|
+
*/ const isRecord = (value)=>typeof value === 'object' && value !== null && Array.isArray(value) === false;
|
|
8
|
+
/**
|
|
9
|
+
* Derives the tool schema scope from a JSON-RPC POST body (a single message or a batch).
|
|
10
|
+
*
|
|
11
|
+
* The server is stateless and rebuilt for every POST, so the body is the full set of work the
|
|
12
|
+
* server will do. Unknown shapes fall back to `'all'` so the SDK keeps producing its own errors.
|
|
13
|
+
*/ const resolveToolSchemaScope = (body)=>{
|
|
14
|
+
const messages = Array.isArray(body) ? body : [
|
|
15
|
+
body
|
|
16
|
+
];
|
|
17
|
+
const toolNames = new Set();
|
|
18
|
+
for (const message of messages){
|
|
19
|
+
if (isRecord(message) === false) {
|
|
20
|
+
return 'all';
|
|
21
|
+
}
|
|
22
|
+
// Responses and notifications carry no method or a method that never touches tools.
|
|
23
|
+
if (message.method === 'tools/list') {
|
|
24
|
+
return 'all';
|
|
25
|
+
}
|
|
26
|
+
if (message.method === 'tools/call') {
|
|
27
|
+
const params = message.params;
|
|
28
|
+
if (isRecord(params) === false || typeof params.name !== 'string') {
|
|
29
|
+
return 'all';
|
|
30
|
+
}
|
|
31
|
+
toolNames.add(params.name);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return toolNames;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export { resolveToolSchemaScope };
|
|
38
|
+
//# sourceMappingURL=resolveToolSchemaScope.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveToolSchemaScope.mjs","sources":["../../../../src/services/mcp/internal/resolveToolSchemaScope.ts"],"sourcesContent":["/**\n * Tools whose input/output schemas a request needs.\n *\n * - `'all'`: every tool may be advertised (e.g. `tools/list`).\n * - a set: only these tools may be invoked (`tools/call`); every other tool can skip schema\n * resolution because the request never lists nor calls it.\n */\nexport type McpToolSchemaScope = 'all' | ReadonlySet<string>;\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && Array.isArray(value) === false;\n\n/**\n * Derives the tool schema scope from a JSON-RPC POST body (a single message or a batch).\n *\n * The server is stateless and rebuilt for every POST, so the body is the full set of work the\n * server will do. Unknown shapes fall back to `'all'` so the SDK keeps producing its own errors.\n */\nexport const resolveToolSchemaScope = (body: unknown): McpToolSchemaScope => {\n const messages = Array.isArray(body) ? body : [body];\n const toolNames = new Set<string>();\n\n for (const message of messages) {\n if (isRecord(message) === false) {\n return 'all';\n }\n\n // Responses and notifications carry no method or a method that never touches tools.\n if (message.method === 'tools/list') {\n return 'all';\n }\n\n if (message.method === 'tools/call') {\n const params = message.params;\n if (isRecord(params) === false || typeof params.name !== 'string') {\n return 'all';\n }\n toolNames.add(params.name);\n }\n }\n\n return toolNames;\n};\n"],"names":["isRecord","value","Array","isArray","resolveToolSchemaScope","body","messages","toolNames","Set","message","method","params","name","add"],"mappings":"AAAA;;;;;;AAMC,IAGD,MAAMA,QAAAA,GAAW,CAACC,KAAAA,GAChB,OAAOA,KAAAA,KAAU,QAAA,IAAYA,KAAAA,KAAU,IAAA,IAAQC,KAAAA,CAAMC,OAAO,CAACF,KAAAA,CAAAA,KAAW,KAAA;AAE1E;;;;;IAMO,MAAMG,sBAAAA,GAAyB,CAACC,IAAAA,GAAAA;AACrC,IAAA,MAAMC,QAAAA,GAAWJ,KAAAA,CAAMC,OAAO,CAACE,QAAQA,IAAAA,GAAO;AAACA,QAAAA;AAAK,KAAA;AACpD,IAAA,MAAME,YAAY,IAAIC,GAAAA,EAAAA;IAEtB,KAAK,MAAMC,WAAWH,QAAAA,CAAU;QAC9B,IAAIN,QAAAA,CAASS,aAAa,KAAA,EAAO;YAC/B,OAAO,KAAA;AACT,QAAA;;QAGA,IAAIA,OAAAA,CAAQC,MAAM,KAAK,YAAA,EAAc;YACnC,OAAO,KAAA;AACT,QAAA;QAEA,IAAID,OAAAA,CAAQC,MAAM,KAAK,YAAA,EAAc;YACnC,MAAMC,MAAAA,GAASF,QAAQE,MAAM;AAC7B,YAAA,IAAIX,SAASW,MAAAA,CAAAA,KAAY,KAAA,IAAS,OAAOA,MAAAA,CAAOC,IAAI,KAAK,QAAA,EAAU;gBACjE,OAAO,KAAA;AACT,YAAA;YACAL,SAAAA,CAAUM,GAAG,CAACF,MAAAA,CAAOC,IAAI,CAAA;AAC3B,QAAA;AACF,IAAA;IAEA,OAAOL,SAAAA;AACT;;;;"}
|
|
@@ -46,6 +46,11 @@ export declare class McpToolRegistry extends McpCapabilityRegistryBase<'tool', M
|
|
|
46
46
|
definitions: McpCapabilityDefinitionRegistry<'tool', Modules.MCP.McpToolDefinition>;
|
|
47
47
|
ability: McpAdminTokenAbility;
|
|
48
48
|
user: Modules.MCP.McpHandlerContext['user'];
|
|
49
|
+
/**
|
|
50
|
+
* Whether the current request needs this tool's schemas. Resolving them is the dominant
|
|
51
|
+
* per-request cost, so tools the request never lists nor calls skip it. Defaults to every tool.
|
|
52
|
+
*/
|
|
53
|
+
shouldResolveSchemas?: (definition: Modules.MCP.McpToolDefinition) => boolean;
|
|
49
54
|
});
|
|
50
55
|
bind(mcpServer: McpServer): void;
|
|
51
56
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-registry.d.ts","sourceRoot":"","sources":["../../../src/services/mcp/tool-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAiB,MAAM,8BAA8B,CAAC;AAC7F,OAAO,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,+BAA+B,EAAE,MAAM,4CAA4C,CAAC;AAC7F,OAAO,EACL,KAAK,qBAA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BAAiB,CAAC,MAAM,CAAC,CAAC;QAC5C;;;WAGG;QACH,oBAAoB,CAAC,EAAE,CAAC,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB,KAAK,OAAO,CAAC;KAC/E;IAQD,IAAI,CAAC,SAAS,EAAE,SAAS;CAiH1B"}
|
|
@@ -51,12 +51,37 @@ function _class_private_field_loose_key(name) {
|
|
|
51
51
|
* strapi.ai.mcp.registerTool(greet);
|
|
52
52
|
* ```
|
|
53
53
|
*/ const makeMcpToolDefinition = (definition)=>definition;
|
|
54
|
-
var _strapi = /*#__PURE__*/ _class_private_field_loose_key("_strapi"), _ability = /*#__PURE__*/ _class_private_field_loose_key("_ability"), _user = /*#__PURE__*/ _class_private_field_loose_key("_user");
|
|
54
|
+
var _strapi = /*#__PURE__*/ _class_private_field_loose_key("_strapi"), _ability = /*#__PURE__*/ _class_private_field_loose_key("_ability"), _user = /*#__PURE__*/ _class_private_field_loose_key("_user"), _shouldResolveSchemas = /*#__PURE__*/ _class_private_field_loose_key("_shouldResolveSchemas");
|
|
55
55
|
class McpToolRegistry extends McpCapabilityRegistry.McpCapabilityRegistryBase {
|
|
56
56
|
bind(mcpServer) {
|
|
57
57
|
const strapi = _class_private_field_loose_base(this, _strapi)[_strapi];
|
|
58
58
|
super.register((definition)=>{
|
|
59
59
|
const { name, title, description, resolveInputSchema, resolveOutputSchema, createHandler } = definition;
|
|
60
|
+
if (_class_private_field_loose_base(this, _shouldResolveSchemas)[_shouldResolveSchemas](definition) === false) {
|
|
61
|
+
// Keep the tool known to the SDK so a call answers `Tool <name> disabled` (no permission)
|
|
62
|
+
// rather than `not found`. The request never lists nor runs it, so no schema is needed.
|
|
63
|
+
const unavailableResult = {
|
|
64
|
+
content: [
|
|
65
|
+
{
|
|
66
|
+
type: 'text',
|
|
67
|
+
text: `Tool "${name}" is not available in this request`
|
|
68
|
+
}
|
|
69
|
+
],
|
|
70
|
+
isError: true
|
|
71
|
+
};
|
|
72
|
+
return createSafeCapabilityRegistration.createSafeCapabilityRegistration({
|
|
73
|
+
strapi,
|
|
74
|
+
capabilityType: 'Tool',
|
|
75
|
+
name,
|
|
76
|
+
createHandler: ()=>async ()=>unavailableResult,
|
|
77
|
+
createFallbackHandler: ()=>async ()=>unavailableResult,
|
|
78
|
+
createErrorResult: ()=>unavailableResult,
|
|
79
|
+
registerWithSdk: (safeHandler)=>mcpServer.registerTool(name, {
|
|
80
|
+
title,
|
|
81
|
+
description
|
|
82
|
+
}, safeHandler)
|
|
83
|
+
});
|
|
84
|
+
}
|
|
60
85
|
// Bind the session ability and token owner into the handler context so handlers can enforce
|
|
61
86
|
// field-level and entity-level permission checks and set creator fields.
|
|
62
87
|
const context = {
|
|
@@ -129,10 +154,14 @@ class McpToolRegistry extends McpCapabilityRegistry.McpCapabilityRegistryBase {
|
|
|
129
154
|
}), Object.defineProperty(this, _user, {
|
|
130
155
|
writable: true,
|
|
131
156
|
value: void 0
|
|
157
|
+
}), Object.defineProperty(this, _shouldResolveSchemas, {
|
|
158
|
+
writable: true,
|
|
159
|
+
value: void 0
|
|
132
160
|
});
|
|
133
161
|
_class_private_field_loose_base(this, _strapi)[_strapi] = ctx.strapi;
|
|
134
162
|
_class_private_field_loose_base(this, _ability)[_ability] = ctx.ability;
|
|
135
163
|
_class_private_field_loose_base(this, _user)[_user] = ctx.user;
|
|
164
|
+
_class_private_field_loose_base(this, _shouldResolveSchemas)[_shouldResolveSchemas] = ctx.shouldResolveSchemas ?? (()=>true);
|
|
136
165
|
}
|
|
137
166
|
}
|
|
138
167
|
|