@strapi/core 5.59.0 → 5.61.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/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/package.json.js +17 -21
- package/dist/package.json.js.map +1 -1
- package/dist/package.json.mjs +17 -21
- 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/providers/webhooks.d.ts.map +1 -1
- package/dist/providers/webhooks.js +1 -0
- package/dist/providers/webhooks.js.map +1 -1
- package/dist/providers/webhooks.mjs +1 -0
- package/dist/providers/webhooks.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/document-service/components.d.ts +14 -1
- package/dist/services/document-service/components.d.ts.map +1 -1
- package/dist/services/document-service/components.js +413 -18
- package/dist/services/document-service/components.js.map +1 -1
- package/dist/services/document-service/components.mjs +414 -20
- 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 +8 -2
- package/dist/services/document-service/events.js.map +1 -1
- package/dist/services/document-service/events.mjs +8 -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/entity-validator/index.d.ts.map +1 -1
- package/dist/services/entity-validator/index.js +41 -6
- package/dist/services/entity-validator/index.js.map +1 -1
- package/dist/services/entity-validator/index.mjs +42 -7
- 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 +7 -0
- package/dist/services/event-hub.js.map +1 -1
- package/dist/services/event-hub.mjs +7 -0
- 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 +5 -2
- package/dist/services/mcp/handlers/handlePost.js.map +1 -1
- package/dist/services/mcp/handlers/handlePost.mjs +5 -2
- package/dist/services/mcp/handlers/handlePost.mjs.map +1 -1
- package/dist/services/mcp/internal/McpConfiguration.d.ts +2 -0
- package/dist/services/mcp/internal/McpConfiguration.d.ts.map +1 -1
- package/dist/services/mcp/internal/McpConfiguration.js +17 -0
- package/dist/services/mcp/internal/McpConfiguration.js.map +1 -1
- package/dist/services/mcp/internal/McpConfiguration.mjs +17 -1
- package/dist/services/mcp/internal/McpConfiguration.mjs.map +1 -1
- package/dist/services/mcp/internal/McpServerFactory.d.ts +6 -1
- package/dist/services/mcp/internal/McpServerFactory.d.ts.map +1 -1
- package/dist/services/mcp/internal/McpServerFactory.js +11 -3
- package/dist/services/mcp/internal/McpServerFactory.js.map +1 -1
- package/dist/services/mcp/internal/McpServerFactory.mjs +12 -4
- 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 +5 -6
- package/dist/services/webhook-runner.d.ts.map +1 -1
- package/dist/services/webhook-runner.js +45 -8
- package/dist/services/webhook-runner.js.map +1 -1
- package/dist/services/webhook-runner.mjs +45 -8
- 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 +21 -2
- package/dist/services/webhook-store.js.map +1 -1
- package/dist/services/webhook-store.mjs +21 -2
- package/dist/services/webhook-store.mjs.map +1 -1
- package/package.json +17 -21
|
@@ -8,6 +8,21 @@ var id = 0;
|
|
|
8
8
|
function _class_private_field_loose_key(name) {
|
|
9
9
|
return "__private_" + id++ + "_" + name;
|
|
10
10
|
}
|
|
11
|
+
const DEFAULT_MAX_TOOL_INPUT_ELEMENTS = 10000;
|
|
12
|
+
// The SDK throws on any value that is not a number >= 1, so only a valid value may reach it.
|
|
13
|
+
const resolveMaxToolInputElements = (strapi)=>{
|
|
14
|
+
const raw = strapi.config.get('server.mcp.maxToolInputElements');
|
|
15
|
+
if (raw === undefined) {
|
|
16
|
+
return DEFAULT_MAX_TOOL_INPUT_ELEMENTS;
|
|
17
|
+
}
|
|
18
|
+
// env() returns strings
|
|
19
|
+
const value = typeof raw === 'string' && raw.trim() !== '' ? Number(raw) : raw;
|
|
20
|
+
if (value === Infinity || Number.isInteger(value) && value >= 1) {
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
strapi.log.warn(`[MCP] Invalid server.mcp.maxToolInputElements (${String(raw)}). ` + `Expected an integer >= 1 or Infinity. Using ${DEFAULT_MAX_TOOL_INPUT_ELEMENTS}.`);
|
|
24
|
+
return DEFAULT_MAX_TOOL_INPUT_ELEMENTS;
|
|
25
|
+
};
|
|
11
26
|
var _strapi = /*#__PURE__*/ _class_private_field_loose_key("_strapi");
|
|
12
27
|
class McpConfiguration {
|
|
13
28
|
isEnabled() {
|
|
@@ -25,8 +40,9 @@ class McpConfiguration {
|
|
|
25
40
|
this.path = '/mcp';
|
|
26
41
|
this.connectTimeoutMs = strapi.config.get('server.mcp.connectTimeoutMs', 5 * 1000); // 5 seconds
|
|
27
42
|
this.requestTimeoutMs = strapi.config.get('server.mcp.requestTimeoutMs', 60 * 1000); // 60 seconds
|
|
43
|
+
this.maxToolInputElements = resolveMaxToolInputElements(strapi);
|
|
28
44
|
}
|
|
29
45
|
}
|
|
30
46
|
|
|
31
|
-
export { McpConfiguration };
|
|
47
|
+
export { DEFAULT_MAX_TOOL_INPUT_ELEMENTS, McpConfiguration };
|
|
32
48
|
//# sourceMappingURL=McpConfiguration.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"McpConfiguration.mjs","sources":["../../../../src/services/mcp/internal/McpConfiguration.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\n\nexport class McpConfiguration {\n readonly path: string;\n\n readonly connectTimeoutMs: number;\n\n readonly requestTimeoutMs: number;\n\n #strapi: Core.Strapi;\n\n constructor(strapi: Core.Strapi) {\n this.#strapi = strapi;\n this.path = '/mcp';\n this.connectTimeoutMs = strapi.config.get('server.mcp.connectTimeoutMs', 5 * 1000); // 5 seconds\n this.requestTimeoutMs = strapi.config.get('server.mcp.requestTimeoutMs', 60 * 1000); // 60 seconds\n }\n\n isEnabled(): boolean {\n return this.#strapi.config.get<boolean>('server.mcp.enabled', false) === true;\n }\n\n isDevMode(): boolean {\n return this.#strapi.config.get('autoReload', false);\n }\n}\n"],"names":["
|
|
1
|
+
{"version":3,"file":"McpConfiguration.mjs","sources":["../../../../src/services/mcp/internal/McpConfiguration.ts"],"sourcesContent":["import type { Core } from '@strapi/types';\n\nexport const DEFAULT_MAX_TOOL_INPUT_ELEMENTS = 10_000;\n\n// The SDK throws on any value that is not a number >= 1, so only a valid value may reach it.\nconst resolveMaxToolInputElements = (strapi: Core.Strapi): number => {\n const raw = strapi.config.get<unknown>('server.mcp.maxToolInputElements');\n\n if (raw === undefined) {\n return DEFAULT_MAX_TOOL_INPUT_ELEMENTS;\n }\n\n // env() returns strings\n const value = typeof raw === 'string' && raw.trim() !== '' ? Number(raw) : raw;\n\n if (value === Infinity || (Number.isInteger(value) && (value as number) >= 1)) {\n return value as number;\n }\n\n strapi.log.warn(\n `[MCP] Invalid server.mcp.maxToolInputElements (${String(raw)}). ` +\n `Expected an integer >= 1 or Infinity. Using ${DEFAULT_MAX_TOOL_INPUT_ELEMENTS}.`\n );\n\n return DEFAULT_MAX_TOOL_INPUT_ELEMENTS;\n};\n\nexport class McpConfiguration {\n readonly path: string;\n\n readonly connectTimeoutMs: number;\n\n readonly requestTimeoutMs: number;\n\n readonly maxToolInputElements: number;\n\n #strapi: Core.Strapi;\n\n constructor(strapi: Core.Strapi) {\n this.#strapi = strapi;\n this.path = '/mcp';\n this.connectTimeoutMs = strapi.config.get('server.mcp.connectTimeoutMs', 5 * 1000); // 5 seconds\n this.requestTimeoutMs = strapi.config.get('server.mcp.requestTimeoutMs', 60 * 1000); // 60 seconds\n this.maxToolInputElements = resolveMaxToolInputElements(strapi);\n }\n\n isEnabled(): boolean {\n return this.#strapi.config.get<boolean>('server.mcp.enabled', false) === true;\n }\n\n isDevMode(): boolean {\n return this.#strapi.config.get('autoReload', false);\n }\n}\n"],"names":["DEFAULT_MAX_TOOL_INPUT_ELEMENTS","resolveMaxToolInputElements","strapi","raw","config","get","undefined","value","trim","Number","Infinity","isInteger","log","warn","String","McpConfiguration","isEnabled","isDevMode","path","connectTimeoutMs","requestTimeoutMs","maxToolInputElements"],"mappings":";;;;;;;;;;AAEO,MAAMA,kCAAkC;AAE/C;AACA,MAAMC,8BAA8B,CAACC,MAAAA,GAAAA;AACnC,IAAA,MAAMC,GAAAA,GAAMD,MAAAA,CAAOE,MAAM,CAACC,GAAG,CAAU,iCAAA,CAAA;AAEvC,IAAA,IAAIF,QAAQG,SAAAA,EAAW;QACrB,OAAON,+BAAAA;AACT,IAAA;;IAGA,MAAMO,KAAAA,GAAQ,OAAOJ,GAAAA,KAAQ,QAAA,IAAYA,IAAIK,IAAI,EAAA,KAAO,EAAA,GAAKC,MAAAA,CAAON,GAAAA,CAAAA,GAAOA,GAAAA;IAE3E,IAAII,KAAAA,KAAUG,YAAaD,MAAAA,CAAOE,SAAS,CAACJ,KAAAA,CAAAA,IAAWA,SAAoB,CAAA,EAAI;QAC7E,OAAOA,KAAAA;AACT,IAAA;AAEAL,IAAAA,MAAAA,CAAOU,GAAG,CAACC,IAAI,CACb,CAAC,+CAA+C,EAAEC,MAAAA,CAAOX,GAAAA,CAAAA,CAAK,GAAG,CAAC,GAChE,CAAC,4CAA4C,EAAEH,+BAAAA,CAAgC,CAAC,CAAC,CAAA;IAGrF,OAAOA,+BAAAA;AACT,CAAA;AAWE,IAAA,OAAA,iBAAA,8BAAA,CAAA,SAAA,CAAA;AATK,MAAMe,gBAAAA,CAAAA;IAmBXC,SAAAA,GAAqB;QACnB,OAAO,+BAAA,CAAA,IAAI,EAAC,OAAA,CAAA,CAAA,OAAA,CAAA,CAAQZ,MAAM,CAACC,GAAG,CAAU,oBAAA,EAAsB,KAAA,CAAA,KAAW,IAAA;AAC3E,IAAA;IAEAY,SAAAA,GAAqB;QACnB,OAAO,+BAAA,CAAA,IAAI,EAAC,OAAA,CAAA,CAAA,SAAQb,MAAM,CAACC,GAAG,CAAC,YAAA,EAAc,KAAA,CAAA;AAC/C,IAAA;AAdA,IAAA,WAAA,CAAYH,MAAmB,CAAE;QAFjC,MAAA,CAAA,cAAA,CAAA,IAAA,EAAA,OAAA,EAAA;;mBAAA;;QAGE,+BAAA,CAAA,IAAI,EAAC,OAAA,CAAA,CAAA,OAAA,CAAA,GAAUA,MAAAA;QACf,IAAI,CAACgB,IAAI,GAAG,MAAA;QACZ,IAAI,CAACC,gBAAgB,GAAGjB,MAAAA,CAAOE,MAAM,CAACC,GAAG,CAAC,6BAAA,EAA+B,CAAA,GAAI,IAAA,CAAA,CAAA;QAC7E,IAAI,CAACe,gBAAgB,GAAGlB,MAAAA,CAAOE,MAAM,CAACC,GAAG,CAAC,6BAAA,EAA+B,EAAA,GAAK,IAAA,CAAA,CAAA;QAC9E,IAAI,CAACgB,oBAAoB,GAAGpB,2BAAAA,CAA4BC,MAAAA,CAAAA;AAC1D,IAAA;AASF;;;;"}
|
|
@@ -6,6 +6,7 @@ import { McpToolRegistry } from '../tool-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,10 @@ 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;
|
|
38
|
+
/** Passed to the SDK as `maxToolInputElements`. */
|
|
39
|
+
maxToolInputElements?: number;
|
|
35
40
|
};
|
|
36
|
-
export declare const createMcpServerWithRegistries: ({ strapi, definitions, isDevMode, ability, user, }: CreateMcpServerWithRegistriesParams) => McpServerWithRegistries;
|
|
41
|
+
export declare const createMcpServerWithRegistries: ({ strapi, definitions, isDevMode, ability, user, toolSchemaScope, maxToolInputElements, }: CreateMcpServerWithRegistriesParams) => McpServerWithRegistries;
|
|
37
42
|
//# 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,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,+BAA+B,EAAE,MAAM,mCAAmC,CAAC;
|
|
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,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAA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,CAAC,EAAE,MAAM,CAAC;CAC/B,CAAC;AAEF,eAAO,MAAM,6BAA6B,GAAI,2FAQ3C,mCAAmC,KAAG,uBAuExC,CAAC"}
|
|
@@ -4,9 +4,10 @@ var server = require('@modelcontextprotocol/server');
|
|
|
4
4
|
var promptRegistry = require('../prompt-registry.js');
|
|
5
5
|
var resourceRegistry = require('../resource-registry.js');
|
|
6
6
|
var toolRegistry = require('../tool-registry.js');
|
|
7
|
+
var McpConfiguration = require('./McpConfiguration.js');
|
|
7
8
|
var syncMcpSessionCapabilities = require('./syncMcpSessionCapabilities.js');
|
|
8
9
|
|
|
9
|
-
const createMcpServerWithRegistries = ({ strapi, definitions, isDevMode, ability, user })=>{
|
|
10
|
+
const createMcpServerWithRegistries = ({ strapi, definitions, isDevMode, ability, user, toolSchemaScope = 'all', maxToolInputElements = McpConfiguration.DEFAULT_MAX_TOOL_INPUT_ELEMENTS })=>{
|
|
10
11
|
const capabilities = {
|
|
11
12
|
logging: {}
|
|
12
13
|
};
|
|
@@ -25,14 +26,21 @@ const createMcpServerWithRegistries = ({ strapi, definitions, isDevMode, ability
|
|
|
25
26
|
name: 'strapi-mcp-server',
|
|
26
27
|
version: '1.0.0'
|
|
27
28
|
}, {
|
|
28
|
-
capabilities
|
|
29
|
+
capabilities,
|
|
30
|
+
maxToolInputElements
|
|
29
31
|
});
|
|
30
32
|
// Bootstrap registries with current definitions
|
|
31
33
|
const tools = new toolRegistry.McpToolRegistry({
|
|
32
34
|
strapi,
|
|
33
35
|
definitions: definitions.tools,
|
|
34
36
|
ability,
|
|
35
|
-
user
|
|
37
|
+
user,
|
|
38
|
+
// A tool the token cannot use stays disabled, so its schemas are never advertised nor used.
|
|
39
|
+
shouldResolveSchemas: (definition)=>(toolSchemaScope === 'all' || toolSchemaScope.has(definition.name)) && syncMcpSessionCapabilities.canUseMcpCapability({
|
|
40
|
+
ability,
|
|
41
|
+
definition,
|
|
42
|
+
isDevMode
|
|
43
|
+
})
|
|
36
44
|
});
|
|
37
45
|
const prompts = new promptRegistry.McpPromptRegistry({
|
|
38
46
|
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 { DEFAULT_MAX_TOOL_INPUT_ELEMENTS } from './McpConfiguration';\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 /** Passed to the SDK as `maxToolInputElements`. */\n maxToolInputElements?: number;\n};\n\nexport const createMcpServerWithRegistries = ({\n strapi,\n definitions,\n isDevMode,\n ability,\n user,\n toolSchemaScope = 'all',\n maxToolInputElements = DEFAULT_MAX_TOOL_INPUT_ELEMENTS,\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 maxToolInputElements,\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","maxToolInputElements","DEFAULT_MAX_TOOL_INPUT_ELEMENTS","capabilities","logging","tools","size","prompts","resources","mcpServer","McpServer","name","version","McpToolRegistry","shouldResolveSchemas","definition","has","canUseMcpCapability","McpPromptRegistry","McpResourceRegistry","bind","syncMcpSessionCapabilities","registries"],"mappings":";;;;;;;;;MAgDaA,6BAAAA,GAAgC,CAAC,EAC5CC,MAAM,EACNC,WAAW,EACXC,SAAS,EACTC,OAAO,EACPC,IAAI,EACJC,eAAAA,GAAkB,KAAK,EACvBC,oBAAAA,GAAuBC,gDAA+B,EAClB,GAAA;AACpC,IAAA,MAAMC,YAAAA,GAAmC;AACvCC,QAAAA,OAAAA,EAAS;AACX,KAAA;;;AAGA,IAAA,IAAIR,WAAAA,CAAYS,KAAK,CAACC,IAAI,GAAG,CAAA,EAAG;QAC9BH,YAAAA,CAAaE,KAAK,GAAG,EAAC;AACxB,IAAA;AACA,IAAA,IAAIT,WAAAA,CAAYW,OAAO,CAACD,IAAI,GAA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AAA;AACAE,YAAAA,OAAAA;AACAC,YAAAA;AACF,SAAA;AACAZ,QAAAA,WAAAA;AACAE,QAAAA,OAAAA;AACAD,QAAAA;AACF,KAAA,CAAA;IAEA,OAAO;AACLY,QAAAA,SAAAA;QACAa,UAAAA,EAAY;AACVjB,YAAAA,KAAAA;AACAE,YAAAA,OAAAA;AACAC,YAAAA;AACF;AACF,KAAA;AACF;;;;"}
|
|
@@ -2,9 +2,10 @@ 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 {
|
|
5
|
+
import { DEFAULT_MAX_TOOL_INPUT_ELEMENTS } from './McpConfiguration.mjs';
|
|
6
|
+
import { canUseMcpCapability, syncMcpSessionCapabilities } from './syncMcpSessionCapabilities.mjs';
|
|
6
7
|
|
|
7
|
-
const createMcpServerWithRegistries = ({ strapi, definitions, isDevMode, ability, user })=>{
|
|
8
|
+
const createMcpServerWithRegistries = ({ strapi, definitions, isDevMode, ability, user, toolSchemaScope = 'all', maxToolInputElements = DEFAULT_MAX_TOOL_INPUT_ELEMENTS })=>{
|
|
8
9
|
const capabilities = {
|
|
9
10
|
logging: {}
|
|
10
11
|
};
|
|
@@ -23,14 +24,21 @@ const createMcpServerWithRegistries = ({ strapi, definitions, isDevMode, ability
|
|
|
23
24
|
name: 'strapi-mcp-server',
|
|
24
25
|
version: '1.0.0'
|
|
25
26
|
}, {
|
|
26
|
-
capabilities
|
|
27
|
+
capabilities,
|
|
28
|
+
maxToolInputElements
|
|
27
29
|
});
|
|
28
30
|
// Bootstrap registries with current definitions
|
|
29
31
|
const tools = new McpToolRegistry({
|
|
30
32
|
strapi,
|
|
31
33
|
definitions: definitions.tools,
|
|
32
34
|
ability,
|
|
33
|
-
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)) && canUseMcpCapability({
|
|
38
|
+
ability,
|
|
39
|
+
definition,
|
|
40
|
+
isDevMode
|
|
41
|
+
})
|
|
34
42
|
});
|
|
35
43
|
const prompts = new McpPromptRegistry({
|
|
36
44
|
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 { DEFAULT_MAX_TOOL_INPUT_ELEMENTS } from './McpConfiguration';\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 /** Passed to the SDK as `maxToolInputElements`. */\n maxToolInputElements?: number;\n};\n\nexport const createMcpServerWithRegistries = ({\n strapi,\n definitions,\n isDevMode,\n ability,\n user,\n toolSchemaScope = 'all',\n maxToolInputElements = DEFAULT_MAX_TOOL_INPUT_ELEMENTS,\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 maxToolInputElements,\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","maxToolInputElements","DEFAULT_MAX_TOOL_INPUT_ELEMENTS","capabilities","logging","tools","size","prompts","resources","mcpServer","McpServer","name","version","McpToolRegistry","shouldResolveSchemas","definition","has","canUseMcpCapability","McpPromptRegistry","McpResourceRegistry","bind","syncMcpSessionCapabilities","registries"],"mappings":";;;;;;;MAgDaA,6BAAAA,GAAgC,CAAC,EAC5CC,MAAM,EACNC,WAAW,EACXC,SAAS,EACTC,OAAO,EACPC,IAAI,EACJC,eAAAA,GAAkB,KAAK,EACvBC,oBAAAA,GAAuBC,+BAA+B,EAClB,GAAA;AACpC,IAAA,MAAMC,YAAAA,GAAmC;AACvCC,QAAAA,OAAAA,EAAS;AACX,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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;AACAZ,QAAAA,WAAAA;AACAE,QAAAA,OAAAA;AACAD,QAAAA;AACF,KAAA,CAAA;IAEA,OAAO;AACLY,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,qBAAqB,EAC1B,yBAAyB,EAC1B,MAAM,kCAAkC,CAAC;AAK1C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,eAAO,MAAM,qBAAqB,EACN,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;AAEvD,qBAAa,eACX,SAAQ,yBAAyB,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,cAAc,CACvF,YAAW,qBAAqB;;
|
|
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,qBAAqB,EAC1B,yBAAyB,EAC1B,MAAM,kCAAkC,CAAC;AAK1C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,eAAO,MAAM,qBAAqB,EACN,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;AAEvD,qBAAa,eACX,SAAQ,yBAAyB,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,cAAc,CACvF,YAAW,qBAAqB;;gBAUpB,GAAG,EAAE;QACf,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC;QACpB,WAAW,EAAE,+BAA+B,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;QACpF,OAAO,EAAE,oBAAoB,CAAC;QAC9B,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB,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
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-registry.js","sources":["../../../src/services/mcp/tool-registry.ts"],"sourcesContent":["import type { McpServer, RegisteredTool, ServerContext } from '@modelcontextprotocol/server';\nimport type { Core, Modules } from '@strapi/types';\nimport { McpCapabilityDefinitionRegistry } from './internal/McpCapabilityDefinitionRegistry';\nimport {\n type McpCapabilityRegistry,\n McpCapabilityRegistryBase,\n} from './internal/McpCapabilityRegistry';\nimport { wrapCapabilityHandlerForMetrics } from './metrics/wrapCapabilityHandlerForMetrics';\nimport { createSafeCapabilityRegistration } from './utils/createSafeCapabilityRegistration';\nimport { createMcpCapabilityHandlerContext } from './utils/createMcpCapabilityHandlerContext';\nimport { toSdkToolResult } from './utils/toSdkMcpCapabilityResult';\nimport type { McpAdminTokenAbility } from './authentication';\n\n/**\n * Defines a Strapi MCP tool with full type inference, ready to pass to\n * `strapi.ai.mcp.registerTool()`. Exposed publicly as `ai.mcp.defineTool`.\n *\n * The returned value is the definition unchanged — this builder only exists to\n * infer the `name`, input/output schemas and handler types, and to narrow the\n * access variant (`devModeOnly` vs `auth`) so the result is directly assignable\n * to `registerTool`.\n *\n * @param tool - The tool definition. Provide either `devModeOnly: true` (dev-only,\n * no auth) or an `auth` policy set — never both.\n * @returns The same definition, with its access variant narrowed.\n *\n * @example\n * ```ts\n * import { ai } from '@strapi/strapi';\n * import { z } from '@strapi/utils';\n *\n * const greet = ai.mcp.defineTool({\n * name: 'greet',\n * title: 'Greet',\n * description: 'Greets a user by name',\n * devModeOnly: true,\n * resolveInputSchema: () => z.object({ name: z.string() }),\n * resolveOutputSchema: () => z.object({ message: z.string() }),\n * createHandler: (strapi) => async ({ args }) => {\n * const message = `Hello, ${args.name}!`;\n * return { content: [{ type: 'text', text: message }], structuredContent: { message } };\n * },\n * });\n *\n * // later, in register() or bootstrap():\n * strapi.ai.mcp.registerTool(greet);\n * ```\n */\nexport const makeMcpToolDefinition = ((definition: Modules.MCP.McpToolDefinition) =>\n definition) as unknown as Modules.MCP.McpToolBuilder;\n\nexport class McpToolRegistry\n extends McpCapabilityRegistryBase<'tool', Modules.MCP.McpToolDefinition, RegisteredTool>\n implements McpCapabilityRegistry\n{\n #strapi: Core.Strapi;\n\n #ability: McpAdminTokenAbility;\n\n #user: Modules.MCP.McpHandlerContext['user'];\n\n constructor(ctx: {\n strapi: Core.Strapi;\n definitions: McpCapabilityDefinitionRegistry<'tool', Modules.MCP.McpToolDefinition>;\n ability: McpAdminTokenAbility;\n user: Modules.MCP.McpHandlerContext['user'];\n }) {\n super(ctx.definitions);\n this.#strapi = ctx.strapi;\n this.#ability = ctx.ability;\n this.#user = ctx.user;\n }\n\n bind(mcpServer: McpServer) {\n const strapi = this.#strapi;\n\n super.register((definition) => {\n const { name, title, description, resolveInputSchema, resolveOutputSchema, createHandler } =\n definition;\n\n // Bind the session ability and token owner into the handler context so handlers can enforce\n // field-level and entity-level permission checks and set creator fields.\n const context: Modules.MCP.McpHandlerContext = {\n userAbility: this.#ability,\n user: this.#user,\n };\n const createHandlerWithContext = (strapi: Core.Strapi) => createHandler(strapi, context);\n\n return createSafeCapabilityRegistration({\n strapi,\n capabilityType: 'Tool',\n name,\n createHandler: createHandlerWithContext,\n createFallbackHandler(errorMessage) {\n return async () => ({\n content: [\n {\n type: 'text' as const,\n text: `Tool \"${name}\" failed to initialize: ${errorMessage}`,\n },\n ],\n isError: true,\n });\n },\n createErrorResult(error) {\n return {\n content: [\n {\n type: 'text' as const,\n text: `Tool \"${name}\" execution failed: ${error.message}`,\n },\n ],\n isError: true,\n };\n },\n registerWithSdk(safeHandler) {\n const inputSchema =\n resolveInputSchema !== undefined ? resolveInputSchema(context) : undefined;\n const outputSchema = resolveOutputSchema(context);\n\n if (inputSchema !== undefined) {\n // Adapt from Strapi's object parameter to the SDK's positional callback.\n const sdkHandler = wrapCapabilityHandlerForMetrics(\n strapi,\n 'tool',\n name,\n definition.telemetry,\n async (args: unknown, context: ServerContext) =>\n toSdkToolResult(\n await safeHandler({\n args,\n extra: createMcpCapabilityHandlerContext(context),\n } as Parameters<typeof safeHandler>[0])\n )\n );\n\n return mcpServer.registerTool(\n name,\n { title, description, inputSchema, outputSchema },\n sdkHandler\n );\n }\n\n const sdkHandler = wrapCapabilityHandlerForMetrics(\n strapi,\n 'tool',\n name,\n definition.telemetry,\n async (context: ServerContext) =>\n toSdkToolResult(\n await safeHandler({\n extra: createMcpCapabilityHandlerContext(context),\n } as Parameters<typeof safeHandler>[0])\n )\n );\n\n return mcpServer.registerTool(name, { title, description, outputSchema }, sdkHandler);\n },\n });\n });\n }\n}\n"],"names":["makeMcpToolDefinition","definition","McpToolRegistry","McpCapabilityRegistryBase","bind","mcpServer","strapi","register","name","title","description","resolveInputSchema","resolveOutputSchema","createHandler","context","userAbility","user","createHandlerWithContext","createSafeCapabilityRegistration","capabilityType","createFallbackHandler","errorMessage","content","type","text","isError","createErrorResult","error","message","registerWithSdk","safeHandler","inputSchema","undefined","outputSchema","sdkHandler","wrapCapabilityHandlerForMetrics","telemetry","args","toSdkToolResult","extra","createMcpCapabilityHandlerContext","registerTool","ctx","definitions","ability"],"mappings":";;;;;;;;;;;;;;;;;;AAaA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCC,IACM,MAAMA,qBAAAA,GAAyB,CAACC,aACrCA;AAMA,IAAA,OAAA,iBAAA,8BAAA,CAAA,SAAA,CAAA,EAEA,QAAA,iBAAA,8BAAA,CAAA,UAAA,C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UoC,YAAY,CAACjC,IAAAA,EAAM;AAAEC,wBAAAA,KAAAA;AAAOC,wBAAAA,WAAAA;AAAauB,wBAAAA;qBAAa,EAAGC,UAAAA,CAAAA;AAC5E,gBAAA;AACF,aAAA,CAAA;AACF,QAAA,CAAA,CAAA;AACF,IAAA;AAnGA,IAAA,WAAA,CAAYQ,GAKX,CAAE;AACD,QAAA,KAAK,CAACA,GAAAA,CAAIC,WAAW,CAAA,EAZvB,MAAA,CAAA,cAAA,CAAA,IAAA,EAAA,OAAA,EAAA;;mBAAA;YAEA,MAAA,CAAA,cAAA,CAAA,IAAA,EAAA,QAAA,EAAA;;mBAAA;YAEA,MAAA,CAAA,cAAA,CAAA,IAAA,EAAA,KAAA,EAAA;;mBAAA;;AASE,QAAA,+BAAA,CAAA,IAAI,EAAC,OAAA,CAAA,CAAA,OAAA,CAAA,GAAUD,IAAIpC,MAAM;AACzB,QAAA,+BAAA,CAAA,IAAI,EAAC,QAAA,CAAA,CAAA,QAAA,CAAA,GAAWoC,IAAIE,OAAO;AAC3B,QAAA,+BAAA,CAAA,IAAI,EAAC,KAAA,CAAA,CAAA,KAAA,CAAA,GAAQF,IAAI1B,IAAI;AACvB,IAAA;AA0FF;;;;;"}
|
|
1
|
+
{"version":3,"file":"tool-registry.js","sources":["../../../src/services/mcp/tool-registry.ts"],"sourcesContent":["import type { McpServer, RegisteredTool, ServerContext } from '@modelcontextprotocol/server';\nimport type { Core, Modules } from '@strapi/types';\nimport { McpCapabilityDefinitionRegistry } from './internal/McpCapabilityDefinitionRegistry';\nimport {\n type McpCapabilityRegistry,\n McpCapabilityRegistryBase,\n} from './internal/McpCapabilityRegistry';\nimport { wrapCapabilityHandlerForMetrics } from './metrics/wrapCapabilityHandlerForMetrics';\nimport { createSafeCapabilityRegistration } from './utils/createSafeCapabilityRegistration';\nimport { createMcpCapabilityHandlerContext } from './utils/createMcpCapabilityHandlerContext';\nimport { toSdkToolResult } from './utils/toSdkMcpCapabilityResult';\nimport type { McpAdminTokenAbility } from './authentication';\n\n/**\n * Defines a Strapi MCP tool with full type inference, ready to pass to\n * `strapi.ai.mcp.registerTool()`. Exposed publicly as `ai.mcp.defineTool`.\n *\n * The returned value is the definition unchanged — this builder only exists to\n * infer the `name`, input/output schemas and handler types, and to narrow the\n * access variant (`devModeOnly` vs `auth`) so the result is directly assignable\n * to `registerTool`.\n *\n * @param tool - The tool definition. Provide either `devModeOnly: true` (dev-only,\n * no auth) or an `auth` policy set — never both.\n * @returns The same definition, with its access variant narrowed.\n *\n * @example\n * ```ts\n * import { ai } from '@strapi/strapi';\n * import { z } from '@strapi/utils';\n *\n * const greet = ai.mcp.defineTool({\n * name: 'greet',\n * title: 'Greet',\n * description: 'Greets a user by name',\n * devModeOnly: true,\n * resolveInputSchema: () => z.object({ name: z.string() }),\n * resolveOutputSchema: () => z.object({ message: z.string() }),\n * createHandler: (strapi) => async ({ args }) => {\n * const message = `Hello, ${args.name}!`;\n * return { content: [{ type: 'text', text: message }], structuredContent: { message } };\n * },\n * });\n *\n * // later, in register() or bootstrap():\n * strapi.ai.mcp.registerTool(greet);\n * ```\n */\nexport const makeMcpToolDefinition = ((definition: Modules.MCP.McpToolDefinition) =>\n definition) as unknown as Modules.MCP.McpToolBuilder;\n\nexport class McpToolRegistry\n extends McpCapabilityRegistryBase<'tool', Modules.MCP.McpToolDefinition, RegisteredTool>\n implements McpCapabilityRegistry\n{\n #strapi: Core.Strapi;\n\n #ability: McpAdminTokenAbility;\n\n #user: Modules.MCP.McpHandlerContext['user'];\n\n #shouldResolveSchemas: (definition: Modules.MCP.McpToolDefinition) => boolean;\n\n constructor(ctx: {\n strapi: Core.Strapi;\n definitions: McpCapabilityDefinitionRegistry<'tool', Modules.MCP.McpToolDefinition>;\n ability: McpAdminTokenAbility;\n user: Modules.MCP.McpHandlerContext['user'];\n /**\n * Whether the current request needs this tool's schemas. Resolving them is the dominant\n * per-request cost, so tools the request never lists nor calls skip it. Defaults to every tool.\n */\n shouldResolveSchemas?: (definition: Modules.MCP.McpToolDefinition) => boolean;\n }) {\n super(ctx.definitions);\n this.#strapi = ctx.strapi;\n this.#ability = ctx.ability;\n this.#user = ctx.user;\n this.#shouldResolveSchemas = ctx.shouldResolveSchemas ?? (() => true);\n }\n\n bind(mcpServer: McpServer) {\n const strapi = this.#strapi;\n\n super.register((definition) => {\n const { name, title, description, resolveInputSchema, resolveOutputSchema, createHandler } =\n definition;\n\n if (this.#shouldResolveSchemas(definition) === false) {\n // Keep the tool known to the SDK so a call answers `Tool <name> disabled` (no permission)\n // rather than `not found`. The request never lists nor runs it, so no schema is needed.\n const unavailableResult = {\n content: [\n {\n type: 'text' as const,\n text: `Tool \"${name}\" is not available in this request`,\n },\n ],\n isError: true,\n };\n\n return createSafeCapabilityRegistration({\n strapi,\n capabilityType: 'Tool',\n name,\n createHandler: () => async () => unavailableResult,\n createFallbackHandler: () => async () => unavailableResult,\n createErrorResult: () => unavailableResult,\n registerWithSdk: (safeHandler) =>\n mcpServer.registerTool(name, { title, description }, safeHandler),\n });\n }\n\n // Bind the session ability and token owner into the handler context so handlers can enforce\n // field-level and entity-level permission checks and set creator fields.\n const context: Modules.MCP.McpHandlerContext = {\n userAbility: this.#ability,\n user: this.#user,\n };\n const createHandlerWithContext = (strapi: Core.Strapi) => createHandler(strapi, context);\n\n return createSafeCapabilityRegistration({\n strapi,\n capabilityType: 'Tool',\n name,\n createHandler: createHandlerWithContext,\n createFallbackHandler(errorMessage) {\n return async () => ({\n content: [\n {\n type: 'text' as const,\n text: `Tool \"${name}\" failed to initialize: ${errorMessage}`,\n },\n ],\n isError: true,\n });\n },\n createErrorResult(error) {\n return {\n content: [\n {\n type: 'text' as const,\n text: `Tool \"${name}\" execution failed: ${error.message}`,\n },\n ],\n isError: true,\n };\n },\n registerWithSdk(safeHandler) {\n const inputSchema =\n resolveInputSchema !== undefined ? resolveInputSchema(context) : undefined;\n const outputSchema = resolveOutputSchema(context);\n\n if (inputSchema !== undefined) {\n // Adapt from Strapi's object parameter to the SDK's positional callback.\n const sdkHandler = wrapCapabilityHandlerForMetrics(\n strapi,\n 'tool',\n name,\n definition.telemetry,\n async (args: unknown, context: ServerContext) =>\n toSdkToolResult(\n await safeHandler({\n args,\n extra: createMcpCapabilityHandlerContext(context),\n } as Parameters<typeof safeHandler>[0])\n )\n );\n\n return mcpServer.registerTool(\n name,\n { title, description, inputSchema, outputSchema },\n sdkHandler\n );\n }\n\n const sdkHandler = wrapCapabilityHandlerForMetrics(\n strapi,\n 'tool',\n name,\n definition.telemetry,\n async (context: ServerContext) =>\n toSdkToolResult(\n await safeHandler({\n extra: createMcpCapabilityHandlerContext(context),\n } as Parameters<typeof safeHandler>[0])\n )\n );\n\n return mcpServer.registerTool(name, { title, description, outputSchema }, sdkHandler);\n },\n });\n });\n }\n}\n"],"names":["makeMcpToolDefinition","definition","McpToolRegistry","McpCapabilityRegistryBase","bind","mcpServer","strapi","register","name","title","description","resolveInputSchema","resolveOutputSchema","createHandler","unavailableResult","content","type","text","isError","createSafeCapabilityRegistration","capabilityType","createFallbackHandler","createErrorResult","registerWithSdk","safeHandler","registerTool","context","userAbility","user","createHandlerWithContext","errorMessage","error","message","inputSchema","undefined","outputSchema","sdkHandler","wrapCapabilityHandlerForMetrics","telemetry","args","toSdkToolResult","extra","createMcpCapabilityHandlerContext","ctx","definitions","ability","shouldResolveSchemas"],"mappings":";;;;;;;;;;;;;;;;;;AAaA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCC,IACM,MAAMA,qBAAAA,GAAyB,CAACC,aACrCA;AAMA,IAAA,OAAA,iBAAA,8BAAA,CAAA,SAAA,CAAA,EAEA,qEAEA,KAAA,iBAAA,8BAAA,CAAA,OAAA,CAAA,EAEA,qBAAA,iBAAA,8BAAA,CAAA,uBAAA,CAAA;AAVK,MAAMC,eAAAA,SACHC,+CAAAA,CAAAA;AA6BRC,IAAAA,IAAAA,CAAKC,SAAoB,EAAE;AACzB,QAAA,MAAMC,MAAAA,GAAS,+BAAA,C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I,EAAC,QAAA,CAAA,CAAA,QAAA,CAAA,GAAWqC,IAAIE,OAAO;AAC3B,QAAA,+BAAA,CAAA,IAAI,EAAC,KAAA,CAAA,CAAA,KAAA,CAAA,GAAQF,IAAIf,IAAI;QACrB,+BAAA,CAAA,IAAI,EAAC,qBAAA,CAAA,CAAA,qBAAA,CAAA,GAAwBe,IAAIG,oBAAoB,KAAK,IAAM,IAAG,CAAA;AACrE,IAAA;AAmHF;;;;;"}
|
|
@@ -49,12 +49,37 @@ function _class_private_field_loose_key(name) {
|
|
|
49
49
|
* strapi.ai.mcp.registerTool(greet);
|
|
50
50
|
* ```
|
|
51
51
|
*/ const makeMcpToolDefinition = (definition)=>definition;
|
|
52
|
-
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");
|
|
52
|
+
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");
|
|
53
53
|
class McpToolRegistry extends McpCapabilityRegistryBase {
|
|
54
54
|
bind(mcpServer) {
|
|
55
55
|
const strapi = _class_private_field_loose_base(this, _strapi)[_strapi];
|
|
56
56
|
super.register((definition)=>{
|
|
57
57
|
const { name, title, description, resolveInputSchema, resolveOutputSchema, createHandler } = definition;
|
|
58
|
+
if (_class_private_field_loose_base(this, _shouldResolveSchemas)[_shouldResolveSchemas](definition) === false) {
|
|
59
|
+
// Keep the tool known to the SDK so a call answers `Tool <name> disabled` (no permission)
|
|
60
|
+
// rather than `not found`. The request never lists nor runs it, so no schema is needed.
|
|
61
|
+
const unavailableResult = {
|
|
62
|
+
content: [
|
|
63
|
+
{
|
|
64
|
+
type: 'text',
|
|
65
|
+
text: `Tool "${name}" is not available in this request`
|
|
66
|
+
}
|
|
67
|
+
],
|
|
68
|
+
isError: true
|
|
69
|
+
};
|
|
70
|
+
return createSafeCapabilityRegistration({
|
|
71
|
+
strapi,
|
|
72
|
+
capabilityType: 'Tool',
|
|
73
|
+
name,
|
|
74
|
+
createHandler: ()=>async ()=>unavailableResult,
|
|
75
|
+
createFallbackHandler: ()=>async ()=>unavailableResult,
|
|
76
|
+
createErrorResult: ()=>unavailableResult,
|
|
77
|
+
registerWithSdk: (safeHandler)=>mcpServer.registerTool(name, {
|
|
78
|
+
title,
|
|
79
|
+
description
|
|
80
|
+
}, safeHandler)
|
|
81
|
+
});
|
|
82
|
+
}
|
|
58
83
|
// Bind the session ability and token owner into the handler context so handlers can enforce
|
|
59
84
|
// field-level and entity-level permission checks and set creator fields.
|
|
60
85
|
const context = {
|
|
@@ -127,10 +152,14 @@ class McpToolRegistry extends McpCapabilityRegistryBase {
|
|
|
127
152
|
}), Object.defineProperty(this, _user, {
|
|
128
153
|
writable: true,
|
|
129
154
|
value: void 0
|
|
155
|
+
}), Object.defineProperty(this, _shouldResolveSchemas, {
|
|
156
|
+
writable: true,
|
|
157
|
+
value: void 0
|
|
130
158
|
});
|
|
131
159
|
_class_private_field_loose_base(this, _strapi)[_strapi] = ctx.strapi;
|
|
132
160
|
_class_private_field_loose_base(this, _ability)[_ability] = ctx.ability;
|
|
133
161
|
_class_private_field_loose_base(this, _user)[_user] = ctx.user;
|
|
162
|
+
_class_private_field_loose_base(this, _shouldResolveSchemas)[_shouldResolveSchemas] = ctx.shouldResolveSchemas ?? (()=>true);
|
|
134
163
|
}
|
|
135
164
|
}
|
|
136
165
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-registry.mjs","sources":["../../../src/services/mcp/tool-registry.ts"],"sourcesContent":["import type { McpServer, RegisteredTool, ServerContext } from '@modelcontextprotocol/server';\nimport type { Core, Modules } from '@strapi/types';\nimport { McpCapabilityDefinitionRegistry } from './internal/McpCapabilityDefinitionRegistry';\nimport {\n type McpCapabilityRegistry,\n McpCapabilityRegistryBase,\n} from './internal/McpCapabilityRegistry';\nimport { wrapCapabilityHandlerForMetrics } from './metrics/wrapCapabilityHandlerForMetrics';\nimport { createSafeCapabilityRegistration } from './utils/createSafeCapabilityRegistration';\nimport { createMcpCapabilityHandlerContext } from './utils/createMcpCapabilityHandlerContext';\nimport { toSdkToolResult } from './utils/toSdkMcpCapabilityResult';\nimport type { McpAdminTokenAbility } from './authentication';\n\n/**\n * Defines a Strapi MCP tool with full type inference, ready to pass to\n * `strapi.ai.mcp.registerTool()`. Exposed publicly as `ai.mcp.defineTool`.\n *\n * The returned value is the definition unchanged — this builder only exists to\n * infer the `name`, input/output schemas and handler types, and to narrow the\n * access variant (`devModeOnly` vs `auth`) so the result is directly assignable\n * to `registerTool`.\n *\n * @param tool - The tool definition. Provide either `devModeOnly: true` (dev-only,\n * no auth) or an `auth` policy set — never both.\n * @returns The same definition, with its access variant narrowed.\n *\n * @example\n * ```ts\n * import { ai } from '@strapi/strapi';\n * import { z } from '@strapi/utils';\n *\n * const greet = ai.mcp.defineTool({\n * name: 'greet',\n * title: 'Greet',\n * description: 'Greets a user by name',\n * devModeOnly: true,\n * resolveInputSchema: () => z.object({ name: z.string() }),\n * resolveOutputSchema: () => z.object({ message: z.string() }),\n * createHandler: (strapi) => async ({ args }) => {\n * const message = `Hello, ${args.name}!`;\n * return { content: [{ type: 'text', text: message }], structuredContent: { message } };\n * },\n * });\n *\n * // later, in register() or bootstrap():\n * strapi.ai.mcp.registerTool(greet);\n * ```\n */\nexport const makeMcpToolDefinition = ((definition: Modules.MCP.McpToolDefinition) =>\n definition) as unknown as Modules.MCP.McpToolBuilder;\n\nexport class McpToolRegistry\n extends McpCapabilityRegistryBase<'tool', Modules.MCP.McpToolDefinition, RegisteredTool>\n implements McpCapabilityRegistry\n{\n #strapi: Core.Strapi;\n\n #ability: McpAdminTokenAbility;\n\n #user: Modules.MCP.McpHandlerContext['user'];\n\n constructor(ctx: {\n strapi: Core.Strapi;\n definitions: McpCapabilityDefinitionRegistry<'tool', Modules.MCP.McpToolDefinition>;\n ability: McpAdminTokenAbility;\n user: Modules.MCP.McpHandlerContext['user'];\n }) {\n super(ctx.definitions);\n this.#strapi = ctx.strapi;\n this.#ability = ctx.ability;\n this.#user = ctx.user;\n }\n\n bind(mcpServer: McpServer) {\n const strapi = this.#strapi;\n\n super.register((definition) => {\n const { name, title, description, resolveInputSchema, resolveOutputSchema, createHandler } =\n definition;\n\n // Bind the session ability and token owner into the handler context so handlers can enforce\n // field-level and entity-level permission checks and set creator fields.\n const context: Modules.MCP.McpHandlerContext = {\n userAbility: this.#ability,\n user: this.#user,\n };\n const createHandlerWithContext = (strapi: Core.Strapi) => createHandler(strapi, context);\n\n return createSafeCapabilityRegistration({\n strapi,\n capabilityType: 'Tool',\n name,\n createHandler: createHandlerWithContext,\n createFallbackHandler(errorMessage) {\n return async () => ({\n content: [\n {\n type: 'text' as const,\n text: `Tool \"${name}\" failed to initialize: ${errorMessage}`,\n },\n ],\n isError: true,\n });\n },\n createErrorResult(error) {\n return {\n content: [\n {\n type: 'text' as const,\n text: `Tool \"${name}\" execution failed: ${error.message}`,\n },\n ],\n isError: true,\n };\n },\n registerWithSdk(safeHandler) {\n const inputSchema =\n resolveInputSchema !== undefined ? resolveInputSchema(context) : undefined;\n const outputSchema = resolveOutputSchema(context);\n\n if (inputSchema !== undefined) {\n // Adapt from Strapi's object parameter to the SDK's positional callback.\n const sdkHandler = wrapCapabilityHandlerForMetrics(\n strapi,\n 'tool',\n name,\n definition.telemetry,\n async (args: unknown, context: ServerContext) =>\n toSdkToolResult(\n await safeHandler({\n args,\n extra: createMcpCapabilityHandlerContext(context),\n } as Parameters<typeof safeHandler>[0])\n )\n );\n\n return mcpServer.registerTool(\n name,\n { title, description, inputSchema, outputSchema },\n sdkHandler\n );\n }\n\n const sdkHandler = wrapCapabilityHandlerForMetrics(\n strapi,\n 'tool',\n name,\n definition.telemetry,\n async (context: ServerContext) =>\n toSdkToolResult(\n await safeHandler({\n extra: createMcpCapabilityHandlerContext(context),\n } as Parameters<typeof safeHandler>[0])\n )\n );\n\n return mcpServer.registerTool(name, { title, description, outputSchema }, sdkHandler);\n },\n });\n });\n }\n}\n"],"names":["makeMcpToolDefinition","definition","McpToolRegistry","McpCapabilityRegistryBase","bind","mcpServer","strapi","register","name","title","description","resolveInputSchema","resolveOutputSchema","createHandler","context","userAbility","user","createHandlerWithContext","createSafeCapabilityRegistration","capabilityType","createFallbackHandler","errorMessage","content","type","text","isError","createErrorResult","error","message","registerWithSdk","safeHandler","inputSchema","undefined","outputSchema","sdkHandler","wrapCapabilityHandlerForMetrics","telemetry","args","toSdkToolResult","extra","createMcpCapabilityHandlerContext","registerTool","ctx","definitions","ability"],"mappings":";;;;;;;;;;;;;;;;AAaA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCC,IACM,MAAMA,qBAAAA,GAAyB,CAACC,aACrCA;AAMA,IAAA,OAAA,iBAAA,8BAAA,CAAA,SAAA,CAAA,EAEA,QAAA,iBAAA,8BAAA,CAAA,UAAA,CAAA,EAEA,KAAA,iBAAA,8BAAA,CAAA,OAAA,CAAA;AARK,MAAMC,eAAAA,SACHC,yBAAAA,CAAAA;AAqBRC,IAAAA,IAAAA,CAAKC,SAAoB,EAAE;AACzB,QAAA,MAAMC,MAAAA,GAAS,+BAAA,CAAA,IAAI,EAAC,OAAA,CAAA,CAAA,OAAA,CAAA;QAEpB,KAAK,CAACC,SAAS,CAACN,UAAAA,GAAAA;AACd,YAAA,MAAM,EAAEO,IAAI,EAAEC,KAAK,EAAEC,WAAW,EAAEC,kBAAkB,EAAEC,mBAAmB,EAAEC,aAAa,EAAE,GACxFZ,UAAAA;;;AAIF,YAAA,MAAMa,OAAAA,GAAyC;AAC7CC,gBAAAA,WAAW,EAAE,+BAAA,CAAA,IAAI,EAAC,QAAA,CAAA,CAAA,QAAA,CAAA;AAClBC,gBAAAA,IAAI,EAAE,+BAAA,CA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AM;AACzB,QAAA,+BAAA,CAAA,IAAI,EAAC,QAAA,CAAA,CAAA,QAAA,CAAA,GAAWoC,IAAIE,OAAO;AAC3B,QAAA,+BAAA,CAAA,IAAI,EAAC,KAAA,CAAA,CAAA,KAAA,CAAA,GAAQF,IAAI1B,IAAI;AACvB,IAAA;AA0FF;;;;"}
|
|
1
|
+
{"version":3,"file":"tool-registry.mjs","sources":["../../../src/services/mcp/tool-registry.ts"],"sourcesContent":["import type { McpServer, RegisteredTool, ServerContext } from '@modelcontextprotocol/server';\nimport type { Core, Modules } from '@strapi/types';\nimport { McpCapabilityDefinitionRegistry } from './internal/McpCapabilityDefinitionRegistry';\nimport {\n type McpCapabilityRegistry,\n McpCapabilityRegistryBase,\n} from './internal/McpCapabilityRegistry';\nimport { wrapCapabilityHandlerForMetrics } from './metrics/wrapCapabilityHandlerForMetrics';\nimport { createSafeCapabilityRegistration } from './utils/createSafeCapabilityRegistration';\nimport { createMcpCapabilityHandlerContext } from './utils/createMcpCapabilityHandlerContext';\nimport { toSdkToolResult } from './utils/toSdkMcpCapabilityResult';\nimport type { McpAdminTokenAbility } from './authentication';\n\n/**\n * Defines a Strapi MCP tool with full type inference, ready to pass to\n * `strapi.ai.mcp.registerTool()`. Exposed publicly as `ai.mcp.defineTool`.\n *\n * The returned value is the definition unchanged — this builder only exists to\n * infer the `name`, input/output schemas and handler types, and to narrow the\n * access variant (`devModeOnly` vs `auth`) so the result is directly assignable\n * to `registerTool`.\n *\n * @param tool - The tool definition. Provide either `devModeOnly: true` (dev-only,\n * no auth) or an `auth` policy set — never both.\n * @returns The same definition, with its access variant narrowed.\n *\n * @example\n * ```ts\n * import { ai } from '@strapi/strapi';\n * import { z } from '@strapi/utils';\n *\n * const greet = ai.mcp.defineTool({\n * name: 'greet',\n * title: 'Greet',\n * description: 'Greets a user by name',\n * devModeOnly: true,\n * resolveInputSchema: () => z.object({ name: z.string() }),\n * resolveOutputSchema: () => z.object({ message: z.string() }),\n * createHandler: (strapi) => async ({ args }) => {\n * const message = `Hello, ${args.name}!`;\n * return { content: [{ type: 'text', text: message }], structuredContent: { message } };\n * },\n * });\n *\n * // later, in register() or bootstrap():\n * strapi.ai.mcp.registerTool(greet);\n * ```\n */\nexport const makeMcpToolDefinition = ((definition: Modules.MCP.McpToolDefinition) =>\n definition) as unknown as Modules.MCP.McpToolBuilder;\n\nexport class McpToolRegistry\n extends McpCapabilityRegistryBase<'tool', Modules.MCP.McpToolDefinition, RegisteredTool>\n implements McpCapabilityRegistry\n{\n #strapi: Core.Strapi;\n\n #ability: McpAdminTokenAbility;\n\n #user: Modules.MCP.McpHandlerContext['user'];\n\n #shouldResolveSchemas: (definition: Modules.MCP.McpToolDefinition) => boolean;\n\n constructor(ctx: {\n strapi: Core.Strapi;\n definitions: McpCapabilityDefinitionRegistry<'tool', Modules.MCP.McpToolDefinition>;\n ability: McpAdminTokenAbility;\n user: Modules.MCP.McpHandlerContext['user'];\n /**\n * Whether the current request needs this tool's schemas. Resolving them is the dominant\n * per-request cost, so tools the request never lists nor calls skip it. Defaults to every tool.\n */\n shouldResolveSchemas?: (definition: Modules.MCP.McpToolDefinition) => boolean;\n }) {\n super(ctx.definitions);\n this.#strapi = ctx.strapi;\n this.#ability = ctx.ability;\n this.#user = ctx.user;\n this.#shouldResolveSchemas = ctx.shouldResolveSchemas ?? (() => true);\n }\n\n bind(mcpServer: McpServer) {\n const strapi = this.#strapi;\n\n super.register((definition) => {\n const { name, title, description, resolveInputSchema, resolveOutputSchema, createHandler } =\n definition;\n\n if (this.#shouldResolveSchemas(definition) === false) {\n // Keep the tool known to the SDK so a call answers `Tool <name> disabled` (no permission)\n // rather than `not found`. The request never lists nor runs it, so no schema is needed.\n const unavailableResult = {\n content: [\n {\n type: 'text' as const,\n text: `Tool \"${name}\" is not available in this request`,\n },\n ],\n isError: true,\n };\n\n return createSafeCapabilityRegistration({\n strapi,\n capabilityType: 'Tool',\n name,\n createHandler: () => async () => unavailableResult,\n createFallbackHandler: () => async () => unavailableResult,\n createErrorResult: () => unavailableResult,\n registerWithSdk: (safeHandler) =>\n mcpServer.registerTool(name, { title, description }, safeHandler),\n });\n }\n\n // Bind the session ability and token owner into the handler context so handlers can enforce\n // field-level and entity-level permission checks and set creator fields.\n const context: Modules.MCP.McpHandlerContext = {\n userAbility: this.#ability,\n user: this.#user,\n };\n const createHandlerWithContext = (strapi: Core.Strapi) => createHandler(strapi, context);\n\n return createSafeCapabilityRegistration({\n strapi,\n capabilityType: 'Tool',\n name,\n createHandler: createHandlerWithContext,\n createFallbackHandler(errorMessage) {\n return async () => ({\n content: [\n {\n type: 'text' as const,\n text: `Tool \"${name}\" failed to initialize: ${errorMessage}`,\n },\n ],\n isError: true,\n });\n },\n createErrorResult(error) {\n return {\n content: [\n {\n type: 'text' as const,\n text: `Tool \"${name}\" execution failed: ${error.message}`,\n },\n ],\n isError: true,\n };\n },\n registerWithSdk(safeHandler) {\n const inputSchema =\n resolveInputSchema !== undefined ? resolveInputSchema(context) : undefined;\n const outputSchema = resolveOutputSchema(context);\n\n if (inputSchema !== undefined) {\n // Adapt from Strapi's object parameter to the SDK's positional callback.\n const sdkHandler = wrapCapabilityHandlerForMetrics(\n strapi,\n 'tool',\n name,\n definition.telemetry,\n async (args: unknown, context: ServerContext) =>\n toSdkToolResult(\n await safeHandler({\n args,\n extra: createMcpCapabilityHandlerContext(context),\n } as Parameters<typeof safeHandler>[0])\n )\n );\n\n return mcpServer.registerTool(\n name,\n { title, description, inputSchema, outputSchema },\n sdkHandler\n );\n }\n\n const sdkHandler = wrapCapabilityHandlerForMetrics(\n strapi,\n 'tool',\n name,\n definition.telemetry,\n async (context: ServerContext) =>\n toSdkToolResult(\n await safeHandler({\n extra: createMcpCapabilityHandlerContext(context),\n } as Parameters<typeof safeHandler>[0])\n )\n );\n\n return mcpServer.registerTool(name, { title, description, outputSchema }, sdkHandler);\n },\n });\n });\n }\n}\n"],"names":["makeMcpToolDefinition","definition","McpToolRegistry","McpCapabilityRegistryBase","bind","mcpServer","strapi","register","name","title","description","resolveInputSchema","resolveOutputSchema","createHandler","unavailableResult","content","type","text","isError","createSafeCapabilityRegistration","capabilityType","createFallbackHandler","createErrorResult","registerWithSdk","safeHandler","registerTool","context","userAbility","user","createHandlerWithContext","errorMessage","error","message","inputSchema","undefined","outputSchema","sdkHandler","wrapCapabilityHandlerForMetrics","telemetry","args","toSdkToolResult","extra","createMcpCapabilityHandlerContext","ctx","definitions","ability","shouldResolveSchemas"],"mappings":";;;;;;;;;;;;;;;;AAaA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCC,IACM,MAAMA,qBAAAA,GAAyB,CAACC,aACrCA;AAMA,IAAA,OAAA,iBAAA,8BAAA,CAAA,SAAA,CAAA,EAEA,qEAEA,KAAA,iBAAA,8BAAA,CAAA,OAAA,CAAA,EAEA,qBAAA,iBAAA,8BAAA,CAAA,uBAAA,CAAA;AAVK,MAAMC,eAAAA,SACHC,yBAAAA,CAAAA;AA6BRC,IAAAA,IAAAA,CAAKC,SAAoB,EAAE;AACzB,QAAA,MAAMC,MAAAA,GAAS,+BAAA,CAAA,IAAI,EAAC,OAAA,CAAA,CAAA,OAAA,CAAA;QAEpB,KAAK,CAACC,SAAS,CAACN,UAAAA,GAAAA;AACd,YAAA,MAAM,EAAEO,IAAI,EAAEC,KAAK,EAAEC,WAAW,EAAEC,kBAAkB,EAAEC,mBAAmB,EAAEC,aAAa,EAAE,GACxFZ,UAAAA;AAEF,YAAA,IAAI,gCAAA,IAAI,EAAC,qBAAA,CAAA,CAAA,qBAAA,CAAA,CAAsBA,gBAAgB,KAAA,EAAO;;;AAGpD,gBAAA,MAAMa,iBAAAA,GAAoB;oBACxBC,OAAAA,EAAS;AACP,wBAAA;4BACEC,IAAAA,EAAM,MAAA;AACNC,4BAAAA,IAAAA,EAAM,CAAC,MAAM,EAAET,IAAAA,CAAK,kCAAkC;AACxD;AACD,qBAAA;oBACDU,OAAAA,EAAS;AACX,iBAAA;AAEA,gBAAA,OAAOC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