@payloadcms/plugin-mcp 3.81.0-internal.181753b → 3.82.0-canary.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/utils/schemaConversion/convertCollectionSchemaToZod.d.ts.map +1 -1
- package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js +33 -23
- package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js.map +1 -1
- package/package.json +3 -3
- package/src/utils/schemaConversion/convertCollectionSchemaToZod.ts +37 -24
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convertCollectionSchemaToZod.d.ts","sourceRoot":"","sources":["../../../src/utils/schemaConversion/convertCollectionSchemaToZod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAU9C,eAAO,MAAM,4BAA4B,WAAY,WAAW,
|
|
1
|
+
{"version":3,"file":"convertCollectionSchemaToZod.d.ts","sourceRoot":"","sources":["../../../src/utils/schemaConversion/convertCollectionSchemaToZod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAU9C,eAAO,MAAM,4BAA4B,WAAY,WAAW,QAyC/D,CAAA"}
|
|
@@ -5,29 +5,39 @@ import { sanitizeJsonSchema } from './sanitizeJsonSchema.js';
|
|
|
5
5
|
import { simplifyRelationshipFields } from './simplifyRelationshipFields.js';
|
|
6
6
|
import { transformPointFieldsForMCP } from './transformPointFields.js';
|
|
7
7
|
export const convertCollectionSchemaToZod = (schema)=>{
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
8
|
+
try {
|
|
9
|
+
// Clone to avoid mutating the original schema (used elsewhere for tool listing)
|
|
10
|
+
const schemaClone = JSON.parse(JSON.stringify(schema));
|
|
11
|
+
const sanitized = sanitizeJsonSchema(schemaClone);
|
|
12
|
+
const pointTransformed = transformPointFieldsForMCP(sanitized);
|
|
13
|
+
const zodSchemaAsString = jsonSchemaToZod(simplifyRelationshipFields(pointTransformed));
|
|
14
|
+
// Transpile TypeScript to JavaScript
|
|
15
|
+
const transpileResult = ts.transpileModule(zodSchemaAsString, {
|
|
16
|
+
compilerOptions: {
|
|
17
|
+
module: ts.ModuleKind.CommonJS,
|
|
18
|
+
removeComments: true,
|
|
19
|
+
strict: false,
|
|
20
|
+
target: ts.ScriptTarget.ES2018
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
/**
|
|
24
|
+
* This Function evaluation is safe because:
|
|
25
|
+
* 1. The input schema comes from Payload's collection configuration, which is controlled by the application developer
|
|
26
|
+
* 2. The jsonSchemaToZod library converts JSON Schema to Zod schema definitions, producing only type validation code
|
|
27
|
+
* 3. The transpiled output contains only Zod schema definitions (z.string(), z.number(), etc.) - no executable logic
|
|
28
|
+
* 4. The resulting Zod schema is used only for parameter validation in MCP tools, not for data processing
|
|
29
|
+
* 5. No user input or external data is involved in the schema generation process
|
|
30
|
+
*/ // eslint-disable-next-line @typescript-eslint/no-implied-eval
|
|
31
|
+
return new Function('z', `return ${transpileResult.outputText}`)(z);
|
|
32
|
+
} catch (error) {
|
|
33
|
+
// If schema conversion fails (e.g., due to Zod v4 toJSONSchema null-check bug
|
|
34
|
+
// with record schemas that have undefined valueType, or bundler transforms
|
|
35
|
+
// stripping Zod internals), return a permissive schema so tools/list doesn't
|
|
36
|
+
// crash entirely. The tool will still be listed but without strict validation.
|
|
37
|
+
// See: https://github.com/colinhacks/zod/issues/5821
|
|
38
|
+
console.warn(`[plugin-mcp] Schema conversion failed, using permissive fallback:`, error instanceof Error ? error.message : error);
|
|
39
|
+
return z.record(z.any());
|
|
40
|
+
}
|
|
31
41
|
};
|
|
32
42
|
|
|
33
43
|
//# sourceMappingURL=convertCollectionSchemaToZod.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/schemaConversion/convertCollectionSchemaToZod.ts"],"sourcesContent":["import type { JSONSchema4 } from 'json-schema'\n\nimport { jsonSchemaToZod } from 'json-schema-to-zod'\nimport * as ts from 'typescript'\nimport { z } from 'zod'\n\nimport { sanitizeJsonSchema } from './sanitizeJsonSchema.js'\nimport { simplifyRelationshipFields } from './simplifyRelationshipFields.js'\nimport { transformPointFieldsForMCP } from './transformPointFields.js'\n\nexport const convertCollectionSchemaToZod = (schema: JSONSchema4) => {\n // Clone to avoid mutating the original schema (used elsewhere for tool listing)\n
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/schemaConversion/convertCollectionSchemaToZod.ts"],"sourcesContent":["import type { JSONSchema4 } from 'json-schema'\n\nimport { jsonSchemaToZod } from 'json-schema-to-zod'\nimport * as ts from 'typescript'\nimport { z } from 'zod'\n\nimport { sanitizeJsonSchema } from './sanitizeJsonSchema.js'\nimport { simplifyRelationshipFields } from './simplifyRelationshipFields.js'\nimport { transformPointFieldsForMCP } from './transformPointFields.js'\n\nexport const convertCollectionSchemaToZod = (schema: JSONSchema4) => {\n try {\n // Clone to avoid mutating the original schema (used elsewhere for tool listing)\n const schemaClone = JSON.parse(JSON.stringify(schema)) as JSONSchema4\n\n const sanitized = sanitizeJsonSchema(schemaClone)\n const pointTransformed = transformPointFieldsForMCP(sanitized)\n const zodSchemaAsString = jsonSchemaToZod(simplifyRelationshipFields(pointTransformed))\n\n // Transpile TypeScript to JavaScript\n const transpileResult = ts.transpileModule(zodSchemaAsString, {\n compilerOptions: {\n module: ts.ModuleKind.CommonJS,\n removeComments: true,\n strict: false,\n target: ts.ScriptTarget.ES2018,\n },\n })\n\n /**\n * This Function evaluation is safe because:\n * 1. The input schema comes from Payload's collection configuration, which is controlled by the application developer\n * 2. The jsonSchemaToZod library converts JSON Schema to Zod schema definitions, producing only type validation code\n * 3. The transpiled output contains only Zod schema definitions (z.string(), z.number(), etc.) - no executable logic\n * 4. The resulting Zod schema is used only for parameter validation in MCP tools, not for data processing\n * 5. No user input or external data is involved in the schema generation process\n */\n // eslint-disable-next-line @typescript-eslint/no-implied-eval\n return new Function('z', `return ${transpileResult.outputText}`)(z)\n } catch (error) {\n // If schema conversion fails (e.g., due to Zod v4 toJSONSchema null-check bug\n // with record schemas that have undefined valueType, or bundler transforms\n // stripping Zod internals), return a permissive schema so tools/list doesn't\n // crash entirely. The tool will still be listed but without strict validation.\n // See: https://github.com/colinhacks/zod/issues/5821\n console.warn(\n `[plugin-mcp] Schema conversion failed, using permissive fallback:`,\n error instanceof Error ? error.message : error,\n )\n return z.record(z.any())\n }\n}\n"],"names":["jsonSchemaToZod","ts","z","sanitizeJsonSchema","simplifyRelationshipFields","transformPointFieldsForMCP","convertCollectionSchemaToZod","schema","schemaClone","JSON","parse","stringify","sanitized","pointTransformed","zodSchemaAsString","transpileResult","transpileModule","compilerOptions","module","ModuleKind","CommonJS","removeComments","strict","target","ScriptTarget","ES2018","Function","outputText","error","console","warn","Error","message","record","any"],"mappings":"AAEA,SAASA,eAAe,QAAQ,qBAAoB;AACpD,YAAYC,QAAQ,aAAY;AAChC,SAASC,CAAC,QAAQ,MAAK;AAEvB,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,0BAA0B,QAAQ,kCAAiC;AAC5E,SAASC,0BAA0B,QAAQ,4BAA2B;AAEtE,OAAO,MAAMC,+BAA+B,CAACC;IAC3C,IAAI;QACF,gFAAgF;QAChF,MAAMC,cAAcC,KAAKC,KAAK,CAACD,KAAKE,SAAS,CAACJ;QAE9C,MAAMK,YAAYT,mBAAmBK;QACrC,MAAMK,mBAAmBR,2BAA2BO;QACpD,MAAME,oBAAoBd,gBAAgBI,2BAA2BS;QAErE,qCAAqC;QACrC,MAAME,kBAAkBd,GAAGe,eAAe,CAACF,mBAAmB;YAC5DG,iBAAiB;gBACfC,QAAQjB,GAAGkB,UAAU,CAACC,QAAQ;gBAC9BC,gBAAgB;gBAChBC,QAAQ;gBACRC,QAAQtB,GAAGuB,YAAY,CAACC,MAAM;YAChC;QACF;QAEA;;;;;;;KAOC,GACD,8DAA8D;QAC9D,OAAO,IAAIC,SAAS,KAAK,CAAC,OAAO,EAAEX,gBAAgBY,UAAU,EAAE,EAAEzB;IACnE,EAAE,OAAO0B,OAAO;QACd,8EAA8E;QAC9E,2EAA2E;QAC3E,6EAA6E;QAC7E,+EAA+E;QAC/E,qDAAqD;QACrDC,QAAQC,IAAI,CACV,CAAC,iEAAiE,CAAC,EACnEF,iBAAiBG,QAAQH,MAAMI,OAAO,GAAGJ;QAE3C,OAAO1B,EAAE+B,MAAM,CAAC/B,EAAEgC,GAAG;IACvB;AACF,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/plugin-mcp",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.82.0-canary.0",
|
|
4
4
|
"description": "MCP (Model Context Protocol) capabilities with Payload",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"plugin",
|
|
@@ -45,10 +45,10 @@
|
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@payloadcms/eslint-config": "3.28.0",
|
|
48
|
-
"payload": "3.
|
|
48
|
+
"payload": "3.82.0-canary.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"payload": "3.
|
|
51
|
+
"payload": "3.82.0-canary.0"
|
|
52
52
|
},
|
|
53
53
|
"homepage:": "https://payloadcms.com",
|
|
54
54
|
"scripts": {
|
|
@@ -9,31 +9,44 @@ import { simplifyRelationshipFields } from './simplifyRelationshipFields.js'
|
|
|
9
9
|
import { transformPointFieldsForMCP } from './transformPointFields.js'
|
|
10
10
|
|
|
11
11
|
export const convertCollectionSchemaToZod = (schema: JSONSchema4) => {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
try {
|
|
13
|
+
// Clone to avoid mutating the original schema (used elsewhere for tool listing)
|
|
14
|
+
const schemaClone = JSON.parse(JSON.stringify(schema)) as JSONSchema4
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
const sanitized = sanitizeJsonSchema(schemaClone)
|
|
17
|
+
const pointTransformed = transformPointFieldsForMCP(sanitized)
|
|
18
|
+
const zodSchemaAsString = jsonSchemaToZod(simplifyRelationshipFields(pointTransformed))
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
// Transpile TypeScript to JavaScript
|
|
21
|
+
const transpileResult = ts.transpileModule(zodSchemaAsString, {
|
|
22
|
+
compilerOptions: {
|
|
23
|
+
module: ts.ModuleKind.CommonJS,
|
|
24
|
+
removeComments: true,
|
|
25
|
+
strict: false,
|
|
26
|
+
target: ts.ScriptTarget.ES2018,
|
|
27
|
+
},
|
|
28
|
+
})
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
/**
|
|
31
|
+
* This Function evaluation is safe because:
|
|
32
|
+
* 1. The input schema comes from Payload's collection configuration, which is controlled by the application developer
|
|
33
|
+
* 2. The jsonSchemaToZod library converts JSON Schema to Zod schema definitions, producing only type validation code
|
|
34
|
+
* 3. The transpiled output contains only Zod schema definitions (z.string(), z.number(), etc.) - no executable logic
|
|
35
|
+
* 4. The resulting Zod schema is used only for parameter validation in MCP tools, not for data processing
|
|
36
|
+
* 5. No user input or external data is involved in the schema generation process
|
|
37
|
+
*/
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-implied-eval
|
|
39
|
+
return new Function('z', `return ${transpileResult.outputText}`)(z)
|
|
40
|
+
} catch (error) {
|
|
41
|
+
// If schema conversion fails (e.g., due to Zod v4 toJSONSchema null-check bug
|
|
42
|
+
// with record schemas that have undefined valueType, or bundler transforms
|
|
43
|
+
// stripping Zod internals), return a permissive schema so tools/list doesn't
|
|
44
|
+
// crash entirely. The tool will still be listed but without strict validation.
|
|
45
|
+
// See: https://github.com/colinhacks/zod/issues/5821
|
|
46
|
+
console.warn(
|
|
47
|
+
`[plugin-mcp] Schema conversion failed, using permissive fallback:`,
|
|
48
|
+
error instanceof Error ? error.message : error,
|
|
49
|
+
)
|
|
50
|
+
return z.record(z.any())
|
|
51
|
+
}
|
|
39
52
|
}
|