@payloadcms/plugin-mcp 3.77.0 → 3.78.0-internal-debug.f663370
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/package.json +3 -3
- package/dist/utils/convertCollectionSchemaToZod.d.ts +0 -3
- package/dist/utils/convertCollectionSchemaToZod.d.ts.map +0 -1
- package/dist/utils/convertCollectionSchemaToZod.js +0 -80
- package/dist/utils/convertCollectionSchemaToZod.js.map +0 -1
- package/dist/utils/transformPointFields.d.ts +0 -3
- package/dist/utils/transformPointFields.d.ts.map +0 -1
- package/dist/utils/transformPointFields.js +0 -51
- package/dist/utils/transformPointFields.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/plugin-mcp",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.78.0-internal-debug.f663370",
|
|
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.78.0-internal-debug.f663370"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"payload": "3.
|
|
51
|
+
"payload": "3.78.0-internal-debug.f663370"
|
|
52
52
|
},
|
|
53
53
|
"homepage:": "https://payloadcms.com",
|
|
54
54
|
"scripts": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"convertCollectionSchemaToZod.d.ts","sourceRoot":"","sources":["../../src/utils/convertCollectionSchemaToZod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAsD9C,eAAO,MAAM,4BAA4B,WAAY,WAAW,QAwC/D,CAAA"}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { jsonSchemaToZod } from 'json-schema-to-zod';
|
|
2
|
-
import * as ts from 'typescript';
|
|
3
|
-
import { z } from 'zod';
|
|
4
|
-
import { transformPointFieldsForMCP } from './transformPointFields.js';
|
|
5
|
-
/**
|
|
6
|
-
* Recursively processes JSON schema properties to simplify relationship fields.
|
|
7
|
-
* For create/update validation we only need to accept IDs (string/number),
|
|
8
|
-
* not populated objects. This removes the $ref option from oneOf unions
|
|
9
|
-
* that represent relationship fields, leaving only the ID shape.
|
|
10
|
-
*
|
|
11
|
-
* NOTE: This function must operate on a cloned schema to avoid mutating
|
|
12
|
-
* the original JSON schema used for tool listing.
|
|
13
|
-
*/ function simplifyRelationshipFields(schema) {
|
|
14
|
-
if (!schema || typeof schema !== 'object') {
|
|
15
|
-
return schema;
|
|
16
|
-
}
|
|
17
|
-
const processed = {
|
|
18
|
-
...schema
|
|
19
|
-
};
|
|
20
|
-
if (Array.isArray(processed.oneOf)) {
|
|
21
|
-
const hasRef = processed.oneOf.some((option)=>option && typeof option === 'object' && '$ref' in option);
|
|
22
|
-
processed.oneOf = processed.oneOf.map((option)=>{
|
|
23
|
-
if (option && typeof option === 'object' && '$ref' in option) {
|
|
24
|
-
// Replace unresolved $ref with a permissive object schema to keep the union shape
|
|
25
|
-
return {
|
|
26
|
-
type: 'object',
|
|
27
|
-
additionalProperties: true
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
return simplifyRelationshipFields(option);
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
if (processed.properties && typeof processed.properties === 'object') {
|
|
34
|
-
processed.properties = Object.fromEntries(Object.entries(processed.properties).map(([key, value])=>[
|
|
35
|
-
key,
|
|
36
|
-
simplifyRelationshipFields(value)
|
|
37
|
-
]));
|
|
38
|
-
}
|
|
39
|
-
if (processed.items && typeof processed.items === 'object' && !Array.isArray(processed.items)) {
|
|
40
|
-
processed.items = simplifyRelationshipFields(processed.items);
|
|
41
|
-
}
|
|
42
|
-
return processed;
|
|
43
|
-
}
|
|
44
|
-
export const convertCollectionSchemaToZod = (schema)=>{
|
|
45
|
-
// Clone to avoid mutating the original schema (used elsewhere for tool listing)
|
|
46
|
-
const schemaClone = JSON.parse(JSON.stringify(schema));
|
|
47
|
-
// Remove properties that should not be included in the Zod schema
|
|
48
|
-
delete schemaClone?.properties?.id;
|
|
49
|
-
delete schemaClone?.properties?.createdAt;
|
|
50
|
-
delete schemaClone?.properties?.updatedAt;
|
|
51
|
-
if (Array.isArray(schemaClone.required)) {
|
|
52
|
-
schemaClone.required = schemaClone.required.filter((field)=>field !== 'id');
|
|
53
|
-
if (schemaClone.required.length === 0) {
|
|
54
|
-
delete schemaClone.required;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
const pointTransformed = transformPointFieldsForMCP(schemaClone);
|
|
58
|
-
const simplifiedSchema = simplifyRelationshipFields(pointTransformed);
|
|
59
|
-
const zodSchemaAsString = jsonSchemaToZod(simplifiedSchema);
|
|
60
|
-
// Transpile TypeScript to JavaScript
|
|
61
|
-
const transpileResult = ts.transpileModule(zodSchemaAsString, {
|
|
62
|
-
compilerOptions: {
|
|
63
|
-
module: ts.ModuleKind.CommonJS,
|
|
64
|
-
removeComments: true,
|
|
65
|
-
strict: false,
|
|
66
|
-
target: ts.ScriptTarget.ES2018
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
/**
|
|
70
|
-
* This Function evaluation is safe because:
|
|
71
|
-
* 1. The input schema comes from Payload's collection configuration, which is controlled by the application developer
|
|
72
|
-
* 2. The jsonSchemaToZod library converts JSON Schema to Zod schema definitions, producing only type validation code
|
|
73
|
-
* 3. The transpiled output contains only Zod schema definitions (z.string(), z.number(), etc.) - no executable logic
|
|
74
|
-
* 4. The resulting Zod schema is used only for parameter validation in MCP tools, not for data processing
|
|
75
|
-
* 5. No user input or external data is involved in the schema generation process
|
|
76
|
-
*/ // eslint-disable-next-line @typescript-eslint/no-implied-eval
|
|
77
|
-
return new Function('z', `return ${transpileResult.outputText}`)(z);
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
//# sourceMappingURL=convertCollectionSchemaToZod.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/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 { transformPointFieldsForMCP } from './transformPointFields.js'\n\n/**\n * Recursively processes JSON schema properties to simplify relationship fields.\n * For create/update validation we only need to accept IDs (string/number),\n * not populated objects. This removes the $ref option from oneOf unions\n * that represent relationship fields, leaving only the ID shape.\n *\n * NOTE: This function must operate on a cloned schema to avoid mutating\n * the original JSON schema used for tool listing.\n */\nfunction simplifyRelationshipFields(schema: JSONSchema4): JSONSchema4 {\n if (!schema || typeof schema !== 'object') {\n return schema\n }\n\n const processed = { ...schema }\n\n if (Array.isArray(processed.oneOf)) {\n const hasRef = processed.oneOf.some(\n (option) => option && typeof option === 'object' && '$ref' in option,\n )\n\n processed.oneOf = processed.oneOf.map((option) => {\n if (option && typeof option === 'object' && '$ref' in option) {\n // Replace unresolved $ref with a permissive object schema to keep the union shape\n return { type: 'object', additionalProperties: true }\n }\n return simplifyRelationshipFields(option)\n })\n }\n\n if (processed.properties && typeof processed.properties === 'object') {\n processed.properties = Object.fromEntries(\n Object.entries(processed.properties).map(([key, value]) => [\n key,\n simplifyRelationshipFields(value),\n ]),\n )\n }\n\n if (processed.items && typeof processed.items === 'object' && !Array.isArray(processed.items)) {\n processed.items = simplifyRelationshipFields(processed.items)\n }\n\n return processed\n}\n\nexport const convertCollectionSchemaToZod = (schema: JSONSchema4) => {\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 // Remove properties that should not be included in the Zod schema\n delete schemaClone?.properties?.id\n delete schemaClone?.properties?.createdAt\n delete schemaClone?.properties?.updatedAt\n if (Array.isArray(schemaClone.required)) {\n schemaClone.required = schemaClone.required.filter((field) => field !== 'id')\n if (schemaClone.required.length === 0) {\n delete schemaClone.required\n }\n }\n\n const pointTransformed = transformPointFieldsForMCP(schemaClone)\n const simplifiedSchema = simplifyRelationshipFields(pointTransformed)\n\n const zodSchemaAsString = jsonSchemaToZod(simplifiedSchema)\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}\n"],"names":["jsonSchemaToZod","ts","z","transformPointFieldsForMCP","simplifyRelationshipFields","schema","processed","Array","isArray","oneOf","hasRef","some","option","map","type","additionalProperties","properties","Object","fromEntries","entries","key","value","items","convertCollectionSchemaToZod","schemaClone","JSON","parse","stringify","id","createdAt","updatedAt","required","filter","field","length","pointTransformed","simplifiedSchema","zodSchemaAsString","transpileResult","transpileModule","compilerOptions","module","ModuleKind","CommonJS","removeComments","strict","target","ScriptTarget","ES2018","Function","outputText"],"mappings":"AAEA,SAASA,eAAe,QAAQ,qBAAoB;AACpD,YAAYC,QAAQ,aAAY;AAChC,SAASC,CAAC,QAAQ,MAAK;AAEvB,SAASC,0BAA0B,QAAQ,4BAA2B;AAEtE;;;;;;;;CAQC,GACD,SAASC,2BAA2BC,MAAmB;IACrD,IAAI,CAACA,UAAU,OAAOA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UAAU;QACxE,IAAIT,YAAYO,QAAQ,CAACG,MAAM,KAAK,GAAG;YACrC,OAAOV,YAAYO,QAAQ;QAC7B;IACF;IAEA,MAAMI,mBAAmBhC,2BAA2BqB;IACpD,MAAMY,mBAAmBhC,2BAA2B+B;IAEpD,MAAME,oBAAoBrC,gBAAgBoC;IAE1C,qCAAqC;IACrC,MAAME,kBAAkBrC,GAAGsC,eAAe,CAACF,mBAAmB;QAC5DG,iBAAiB;YACfC,QAAQxC,GAAGyC,UAAU,CAACC,QAAQ;YAC9BC,gBAAgB;YAChBC,QAAQ;YACRC,QAAQ7C,GAAG8C,YAAY,CAACC,MAAM;QAChC;IACF;IAEA;;;;;;;GAOC,GACD,8DAA8D;IAC9D,OAAO,IAAIC,SAAS,KAAK,CAAC,OAAO,EAAEX,gBAAgBY,UAAU,EAAE,EAAEhD;AACnE,EAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transformPointFields.d.ts","sourceRoot":"","sources":["../../src/utils/transformPointFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE9C,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,WAAW,GAAG,WAAW,CAoD3E"}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
export function transformPointFieldsForMCP(schema) {
|
|
2
|
-
if (!schema || typeof schema !== 'object') {
|
|
3
|
-
return schema;
|
|
4
|
-
}
|
|
5
|
-
const transformed = {
|
|
6
|
-
...schema
|
|
7
|
-
};
|
|
8
|
-
if (transformed.properties && typeof transformed.properties === 'object') {
|
|
9
|
-
transformed.properties = Object.fromEntries(Object.entries(transformed.properties).map(([key, value])=>{
|
|
10
|
-
const isArrayType = value.type === 'array' || Array.isArray(value.type) && value.type.includes('array');
|
|
11
|
-
if (value && typeof value === 'object' && isArrayType && Array.isArray(value.items) && value.items.length === 2 && value.items.every((item)=>item?.type === 'number')) {
|
|
12
|
-
// Transform to object format
|
|
13
|
-
const isNullable = Array.isArray(value.type) && value.type.includes('null');
|
|
14
|
-
return [
|
|
15
|
-
key,
|
|
16
|
-
{
|
|
17
|
-
type: isNullable ? [
|
|
18
|
-
'object',
|
|
19
|
-
'null'
|
|
20
|
-
] : 'object',
|
|
21
|
-
description: value.description || 'Geographic coordinates (longitude, latitude)',
|
|
22
|
-
properties: {
|
|
23
|
-
latitude: {
|
|
24
|
-
type: 'number',
|
|
25
|
-
description: 'Latitude coordinate'
|
|
26
|
-
},
|
|
27
|
-
longitude: {
|
|
28
|
-
type: 'number',
|
|
29
|
-
description: 'Longitude coordinate'
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
required: [
|
|
33
|
-
'longitude',
|
|
34
|
-
'latitude'
|
|
35
|
-
]
|
|
36
|
-
}
|
|
37
|
-
];
|
|
38
|
-
}
|
|
39
|
-
return [
|
|
40
|
-
key,
|
|
41
|
-
transformPointFieldsForMCP(value)
|
|
42
|
-
];
|
|
43
|
-
}));
|
|
44
|
-
}
|
|
45
|
-
if (transformed.items && typeof transformed.items === 'object' && !Array.isArray(transformed.items)) {
|
|
46
|
-
transformed.items = transformPointFieldsForMCP(transformed.items);
|
|
47
|
-
}
|
|
48
|
-
return transformed;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
//# sourceMappingURL=transformPointFields.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/transformPointFields.ts"],"sourcesContent":["import type { JSONSchema4 } from 'json-schema'\n\nexport function transformPointFieldsForMCP(schema: JSONSchema4): JSONSchema4 {\n if (!schema || typeof schema !== 'object') {\n return schema\n }\n\n const transformed = { ...schema }\n\n if (transformed.properties && typeof transformed.properties === 'object') {\n transformed.properties = Object.fromEntries(\n Object.entries(transformed.properties).map(([key, value]) => {\n const isArrayType =\n value.type === 'array' || (Array.isArray(value.type) && value.type.includes('array'))\n\n if (\n value &&\n typeof value === 'object' &&\n isArrayType &&\n Array.isArray(value.items) &&\n value.items.length === 2 &&\n value.items.every((item: JSONSchema4) => item?.type === 'number')\n ) {\n // Transform to object format\n const isNullable = Array.isArray(value.type) && value.type.includes('null')\n\n return [\n key,\n {\n type: isNullable ? ['object', 'null'] : 'object',\n description: value.description || 'Geographic coordinates (longitude, latitude)',\n properties: {\n latitude: { type: 'number', description: 'Latitude coordinate' },\n longitude: { type: 'number', description: 'Longitude coordinate' },\n },\n required: ['longitude', 'latitude'],\n },\n ]\n }\n\n return [key, transformPointFieldsForMCP(value)]\n }),\n )\n }\n\n if (\n transformed.items &&\n typeof transformed.items === 'object' &&\n !Array.isArray(transformed.items)\n ) {\n transformed.items = transformPointFieldsForMCP(transformed.items)\n }\n\n return transformed\n}\n"],"names":["transformPointFieldsForMCP","schema","transformed","properties","Object","fromEntries","entries","map","key","value","isArrayType","type","Array","isArray","includes","items","length","every","item","isNullable","description","latitude","longitude","required"],"mappings":"AAEA,OAAO,SAASA,2BAA2BC,MAAmB;IAC5D,IAAI,CAACA,UAAU,OAAOA,WAAW,UAAU;QACzC,OAAOA;IACT;IAEA,MAAMC,cAAc;QAAE,GAAGD,MAAM;IAAC;IAEhC,IAAIC,YAAYC,UAAU,IAAI,OAAOD,YAAYC,UAAU,KAAK,UAAU;QACxED,YAAYC,UAAU,GAAGC,OAAOC,WAAW,CACzCD,OAAOE,OAAO,CAACJ,YAAYC,UAAU,EAAEI,GAAG,CAAC,CAAC,CAACC,KAAKC,MAAM;YACtD,MAAMC,cACJD,MAAME,IAAI,KAAK,WAAYC,MAAMC,OAAO,CAACJ,MAAME,IAAI,KAAKF,MAAME,IAAI,CAACG,QAAQ,CAAC;YAE9E,IACEL,SACA,OAAOA,UAAU,YACjBC,eACAE,MAAMC,OAAO,CAACJ,MAAMM,KAAK,KACzBN,MAAMM,KAAK,CAACC,MAAM,KAAK,KACvBP,MAAMM,KAAK,CAACE,KAAK,CAAC,CAACC,OAAsBA,MAAMP,SAAS,WACxD;gBACA,6BAA6B;gBAC7B,MAAMQ,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