@payloadcms/plugin-mcp 3.90.1 → 3.90.2

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.
@@ -1,3 +1,4 @@
1
1
  import type { JSONSchema4 } from 'json-schema';
2
- export declare const convertCollectionSchemaToZod: (schema: JSONSchema4) => any;
2
+ import { z } from 'zod';
3
+ export declare const convertCollectionSchemaToZod: (schema: JSONSchema4) => z.ZodObject<any, any, any, any, any>;
3
4
  //# sourceMappingURL=convertCollectionSchemaToZod.d.ts.map
@@ -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,QAyC/D,CAAA"}
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;AAI9C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAMvB,eAAO,MAAM,4BAA4B,WAAY,WAAW,yCA6D/D,CAAA"}
@@ -20,6 +20,19 @@ export const convertCollectionSchemaToZod = (schema)=>{
20
20
  target: ts.ScriptTarget.ES2018
21
21
  }
22
22
  });
23
+ // TypeScript 6 prepends a `"use strict";` directive to the transpiled module
24
+ // output (TypeScript 5 did not). Combined with the `return ${output}` wrapper
25
+ // below, that becomes `return "use strict"; <schema>`, so the evaluated
26
+ // function returns the *string* `"use strict"` instead of the Zod schema, and
27
+ // the create/update tools then throw `convertedFields.partial is not a
28
+ // function`, aborting MCP tool registration for the entire endpoint.
29
+ //
30
+ // Strip the directive AND the whitespace that follows it: the transpiled
31
+ // output is `"use strict";\n<expr>`, and stripping only the directive leaves
32
+ // `return \n<expr>`, where ASI inserts a semicolon after `return` — yielding
33
+ // `undefined` and an empty input schema. Consuming the trailing whitespace
34
+ // keeps the expression on the `return` line.
35
+ const transpiledOutput = transpileResult.outputText.replace(/^\s*['"]use strict['"];?\s*/, '');
23
36
  /**
24
37
  * This Function evaluation is safe because:
25
38
  * 1. The input schema comes from Payload's collection configuration, which is controlled by the application developer
@@ -28,15 +41,20 @@ export const convertCollectionSchemaToZod = (schema)=>{
28
41
  * 4. The resulting Zod schema is used only for parameter validation in MCP tools, not for data processing
29
42
  * 5. No user input or external data is involved in the schema generation process
30
43
  */ // eslint-disable-next-line @typescript-eslint/no-implied-eval
31
- return new Function('z', `return ${transpileResult.outputText}`)(z);
44
+ const converted = new Function('z', `return ${transpiledOutput}`)(z);
45
+ // Callers (the create/update tools) rely on the result being a ZodObject —
46
+ // they spread `.partial().shape`. If conversion produced anything else, fall
47
+ // back to a permissive object so tool registration can't crash.
48
+ return converted instanceof z.ZodObject ? converted : z.object({}).passthrough();
32
49
  } catch (error) {
33
50
  // If schema conversion fails (e.g., due to Zod v4 toJSONSchema null-check bug
34
51
  // with record schemas that have undefined valueType, or bundler transforms
35
52
  // stripping Zod internals), return a permissive schema so tools/list doesn't
36
53
  // crash entirely. The tool will still be listed but without strict validation.
37
- // See: https://github.com/colinhacks/zod/issues/5821
54
+ // A ZodObject (rather than z.record) is returned so callers that rely on
55
+ // .partial()/.shape don't throw. See: https://github.com/colinhacks/zod/issues/5821
38
56
  console.warn(`[plugin-mcp] Schema conversion failed, using permissive fallback:`, error instanceof Error ? error.message : error);
39
- return z.record(z.any());
57
+ return z.object({}).passthrough();
40
58
  }
41
59
  };
42
60
 
@@ -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 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"}
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 // TypeScript 6 prepends a `\"use strict\";` directive to the transpiled module\n // output (TypeScript 5 did not). Combined with the `return ${output}` wrapper\n // below, that becomes `return \"use strict\"; <schema>`, so the evaluated\n // function returns the *string* `\"use strict\"` instead of the Zod schema, and\n // the create/update tools then throw `convertedFields.partial is not a\n // function`, aborting MCP tool registration for the entire endpoint.\n //\n // Strip the directive AND the whitespace that follows it: the transpiled\n // output is `\"use strict\";\\n<expr>`, and stripping only the directive leaves\n // `return \\n<expr>`, where ASI inserts a semicolon after `return` — yielding\n // `undefined` and an empty input schema. Consuming the trailing whitespace\n // keeps the expression on the `return` line.\n const transpiledOutput = transpileResult.outputText.replace(/^\\s*['\"]use strict['\"];?\\s*/, '')\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 const converted = new Function('z', `return ${transpiledOutput}`)(z)\n\n // Callers (the create/update tools) rely on the result being a ZodObject —\n // they spread `.partial().shape`. If conversion produced anything else, fall\n // back to a permissive object so tool registration can't crash.\n return converted instanceof z.ZodObject ? converted : z.object({}).passthrough()\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 // A ZodObject (rather than z.record) is returned so callers that rely on\n // .partial()/.shape don't throw. 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.object({}).passthrough()\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","transpiledOutput","outputText","replace","converted","Function","ZodObject","object","passthrough","error","console","warn","Error","message"],"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,6EAA6E;QAC7E,8EAA8E;QAC9E,wEAAwE;QACxE,8EAA8E;QAC9E,uEAAuE;QACvE,qEAAqE;QACrE,EAAE;QACF,yEAAyE;QACzE,6EAA6E;QAC7E,6EAA6E;QAC7E,2EAA2E;QAC3E,6CAA6C;QAC7C,MAAMC,mBAAmBX,gBAAgBY,UAAU,CAACC,OAAO,CAAC,+BAA+B;QAE3F;;;;;;;KAOC,GACD,8DAA8D;QAC9D,MAAMC,YAAY,IAAIC,SAAS,KAAK,CAAC,OAAO,EAAEJ,kBAAkB,EAAExB;QAElE,2EAA2E;QAC3E,6EAA6E;QAC7E,gEAAgE;QAChE,OAAO2B,qBAAqB3B,EAAE6B,SAAS,GAAGF,YAAY3B,EAAE8B,MAAM,CAAC,CAAC,GAAGC,WAAW;IAChF,EAAE,OAAOC,OAAO;QACd,8EAA8E;QAC9E,2EAA2E;QAC3E,6EAA6E;QAC7E,+EAA+E;QAC/E,yEAAyE;QACzE,oFAAoF;QACpFC,QAAQC,IAAI,CACV,CAAC,iEAAiE,CAAC,EACnEF,iBAAiBG,QAAQH,MAAMI,OAAO,GAAGJ;QAE3C,OAAOhC,EAAE8B,MAAM,CAAC,CAAC,GAAGC,WAAW;IACjC;AACF,EAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/plugin-mcp",
3
- "version": "3.90.1",
3
+ "version": "3.90.2",
4
4
  "description": "MCP (Model Context Protocol) capabilities with Payload",
5
5
  "keywords": [
6
6
  "plugin",
@@ -44,11 +44,11 @@
44
44
  "zod": "^3.25.50"
45
45
  },
46
46
  "devDependencies": {
47
- "@payloadcms/eslint-config": "3.28.0",
48
- "payload": "3.90.1"
47
+ "payload": "3.90.2",
48
+ "@payloadcms/eslint-config": "3.28.0"
49
49
  },
50
50
  "peerDependencies": {
51
- "payload": "3.90.1"
51
+ "payload": "3.90.2"
52
52
  },
53
53
  "homepage:": "https://payloadcms.com",
54
54
  "scripts": {
@@ -27,6 +27,20 @@ export const convertCollectionSchemaToZod = (schema: JSONSchema4) => {
27
27
  },
28
28
  })
29
29
 
30
+ // TypeScript 6 prepends a `"use strict";` directive to the transpiled module
31
+ // output (TypeScript 5 did not). Combined with the `return ${output}` wrapper
32
+ // below, that becomes `return "use strict"; <schema>`, so the evaluated
33
+ // function returns the *string* `"use strict"` instead of the Zod schema, and
34
+ // the create/update tools then throw `convertedFields.partial is not a
35
+ // function`, aborting MCP tool registration for the entire endpoint.
36
+ //
37
+ // Strip the directive AND the whitespace that follows it: the transpiled
38
+ // output is `"use strict";\n<expr>`, and stripping only the directive leaves
39
+ // `return \n<expr>`, where ASI inserts a semicolon after `return` — yielding
40
+ // `undefined` and an empty input schema. Consuming the trailing whitespace
41
+ // keeps the expression on the `return` line.
42
+ const transpiledOutput = transpileResult.outputText.replace(/^\s*['"]use strict['"];?\s*/, '')
43
+
30
44
  /**
31
45
  * This Function evaluation is safe because:
32
46
  * 1. The input schema comes from Payload's collection configuration, which is controlled by the application developer
@@ -36,17 +50,23 @@ export const convertCollectionSchemaToZod = (schema: JSONSchema4) => {
36
50
  * 5. No user input or external data is involved in the schema generation process
37
51
  */
38
52
  // eslint-disable-next-line @typescript-eslint/no-implied-eval
39
- return new Function('z', `return ${transpileResult.outputText}`)(z)
53
+ const converted = new Function('z', `return ${transpiledOutput}`)(z)
54
+
55
+ // Callers (the create/update tools) rely on the result being a ZodObject —
56
+ // they spread `.partial().shape`. If conversion produced anything else, fall
57
+ // back to a permissive object so tool registration can't crash.
58
+ return converted instanceof z.ZodObject ? converted : z.object({}).passthrough()
40
59
  } catch (error) {
41
60
  // If schema conversion fails (e.g., due to Zod v4 toJSONSchema null-check bug
42
61
  // with record schemas that have undefined valueType, or bundler transforms
43
62
  // stripping Zod internals), return a permissive schema so tools/list doesn't
44
63
  // crash entirely. The tool will still be listed but without strict validation.
45
- // See: https://github.com/colinhacks/zod/issues/5821
64
+ // A ZodObject (rather than z.record) is returned so callers that rely on
65
+ // .partial()/.shape don't throw. See: https://github.com/colinhacks/zod/issues/5821
46
66
  console.warn(
47
67
  `[plugin-mcp] Schema conversion failed, using permissive fallback:`,
48
68
  error instanceof Error ? error.message : error,
49
69
  )
50
- return z.record(z.any())
70
+ return z.object({}).passthrough()
51
71
  }
52
72
  }