@payloadcms/plugin-mcp 3.69.0-internal.2883df2 → 3.69.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/endpoints/mcp.d.ts.map +1 -1
- package/dist/endpoints/mcp.js +4 -0
- package/dist/endpoints/mcp.js.map +1 -1
- package/dist/mcp/helpers/config.js +1 -1
- package/dist/mcp/helpers/config.js.map +1 -1
- package/package.json +3 -3
- package/src/endpoints/mcp.ts +9 -1
- package/src/mcp/helpers/config.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../src/endpoints/mcp.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,cAAc,
|
|
1
|
+
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../src/endpoints/mcp.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,cAAc,EAAiD,MAAM,SAAS,CAAA;AAE5F,OAAO,KAAK,EAAqB,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAK3E,eAAO,MAAM,oBAAoB,kBAAmB,qBAAqB,mBAuExE,CAAA"}
|
package/dist/endpoints/mcp.js
CHANGED
|
@@ -37,6 +37,10 @@ export const initializeMCPHandler = (pluginOptions)=>{
|
|
|
37
37
|
if (useVerboseLogs) {
|
|
38
38
|
payload.logger.info('[payload-mcp] API Key is valid');
|
|
39
39
|
}
|
|
40
|
+
const user = docs[0]?.user;
|
|
41
|
+
const customUserCollection = typeof pluginOptions.userCollection === 'string' ? pluginOptions.userCollection : pluginOptions.userCollection?.slug;
|
|
42
|
+
user.collection = customUserCollection ?? 'users';
|
|
43
|
+
user._strategy = 'mcp-api-key';
|
|
40
44
|
return docs[0];
|
|
41
45
|
};
|
|
42
46
|
const mcpAccessSettings = pluginOptions.overrideAuth ? await pluginOptions.overrideAuth(req, getDefaultMcpAccessSettings) : await getDefaultMcpAccessSettings();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/endpoints/mcp.ts"],"sourcesContent":["import crypto from 'crypto'\nimport { type PayloadHandler, UnauthorizedError, type Where } from 'payload'\n\nimport type { MCPAccessSettings, PluginMCPServerConfig } from '../types.js'\n\nimport { createRequestFromPayloadRequest } from '../mcp/createRequest.js'\nimport { getMCPHandler } from '../mcp/getMcpHandler.js'\n\nexport const initializeMCPHandler = (pluginOptions: PluginMCPServerConfig) => {\n const mcpHandler: PayloadHandler = async (req) => {\n const { payload } = req\n const MCPOptions = pluginOptions.mcp || {}\n const MCPHandlerOptions = MCPOptions.handlerOptions || {}\n const useVerboseLogs = MCPHandlerOptions.verboseLogs ?? false\n\n req.payloadAPI = 'MCP' as const\n\n const getDefaultMcpAccessSettings = async (overrideApiKey?: null | string) => {\n const apiKey =\n (overrideApiKey ?? req.headers.get('Authorization')?.startsWith('Bearer '))\n ? req.headers.get('Authorization')?.replace('Bearer ', '').trim()\n : null\n\n if (apiKey === null) {\n throw new UnauthorizedError()\n }\n\n const sha256APIKeyIndex = crypto\n .createHmac('sha256', payload.secret)\n .update(apiKey || '')\n .digest('hex')\n\n const apiKeyConstraints = [\n {\n apiKeyIndex: {\n equals: sha256APIKeyIndex,\n },\n },\n ]\n\n const where: Where = {\n or: apiKeyConstraints,\n }\n\n const { docs } = await payload.find({\n collection: 'payload-mcp-api-keys',\n limit: 1,\n pagination: false,\n where,\n })\n\n if (docs.length === 0) {\n throw new UnauthorizedError()\n }\n\n if (useVerboseLogs) {\n payload.logger.info('[payload-mcp] API Key is valid')\n }\n\n return docs[0] as unknown as MCPAccessSettings\n }\n\n const mcpAccessSettings = pluginOptions.overrideAuth\n ? await pluginOptions.overrideAuth(req, getDefaultMcpAccessSettings)\n : await getDefaultMcpAccessSettings()\n\n const handler = getMCPHandler(pluginOptions, mcpAccessSettings, req)\n const request = createRequestFromPayloadRequest(req)\n return await handler(request)\n }\n return mcpHandler\n}\n"],"names":["crypto","UnauthorizedError","createRequestFromPayloadRequest","getMCPHandler","initializeMCPHandler","pluginOptions","mcpHandler","req","payload","MCPOptions","mcp","MCPHandlerOptions","handlerOptions","useVerboseLogs","verboseLogs","payloadAPI","getDefaultMcpAccessSettings","overrideApiKey","apiKey","headers","get","startsWith","replace","trim","sha256APIKeyIndex","createHmac","secret","update","digest","apiKeyConstraints","apiKeyIndex","equals","where","or","docs","find","collection","limit","pagination","length","logger","info","mcpAccessSettings","overrideAuth","handler","request"],"mappings":"AAAA,OAAOA,YAAY,SAAQ;AAC3B,
|
|
1
|
+
{"version":3,"sources":["../../src/endpoints/mcp.ts"],"sourcesContent":["import crypto from 'crypto'\nimport { type PayloadHandler, type TypedUser, UnauthorizedError, type Where } from 'payload'\n\nimport type { MCPAccessSettings, PluginMCPServerConfig } from '../types.js'\n\nimport { createRequestFromPayloadRequest } from '../mcp/createRequest.js'\nimport { getMCPHandler } from '../mcp/getMcpHandler.js'\n\nexport const initializeMCPHandler = (pluginOptions: PluginMCPServerConfig) => {\n const mcpHandler: PayloadHandler = async (req) => {\n const { payload } = req\n const MCPOptions = pluginOptions.mcp || {}\n const MCPHandlerOptions = MCPOptions.handlerOptions || {}\n const useVerboseLogs = MCPHandlerOptions.verboseLogs ?? false\n\n req.payloadAPI = 'MCP' as const\n\n const getDefaultMcpAccessSettings = async (overrideApiKey?: null | string) => {\n const apiKey =\n (overrideApiKey ?? req.headers.get('Authorization')?.startsWith('Bearer '))\n ? req.headers.get('Authorization')?.replace('Bearer ', '').trim()\n : null\n\n if (apiKey === null) {\n throw new UnauthorizedError()\n }\n\n const sha256APIKeyIndex = crypto\n .createHmac('sha256', payload.secret)\n .update(apiKey || '')\n .digest('hex')\n\n const apiKeyConstraints = [\n {\n apiKeyIndex: {\n equals: sha256APIKeyIndex,\n },\n },\n ]\n\n const where: Where = {\n or: apiKeyConstraints,\n }\n\n const { docs } = await payload.find({\n collection: 'payload-mcp-api-keys',\n limit: 1,\n pagination: false,\n where,\n })\n\n if (docs.length === 0) {\n throw new UnauthorizedError()\n }\n\n if (useVerboseLogs) {\n payload.logger.info('[payload-mcp] API Key is valid')\n }\n\n const user = docs[0]?.user as TypedUser\n const customUserCollection =\n typeof pluginOptions.userCollection === 'string'\n ? pluginOptions.userCollection\n : pluginOptions.userCollection?.slug\n user.collection = customUserCollection ?? 'users'\n user._strategy = 'mcp-api-key' as const\n\n return docs[0] as unknown as MCPAccessSettings\n }\n\n const mcpAccessSettings = pluginOptions.overrideAuth\n ? await pluginOptions.overrideAuth(req, getDefaultMcpAccessSettings)\n : await getDefaultMcpAccessSettings()\n\n const handler = getMCPHandler(pluginOptions, mcpAccessSettings, req)\n const request = createRequestFromPayloadRequest(req)\n return await handler(request)\n }\n return mcpHandler\n}\n"],"names":["crypto","UnauthorizedError","createRequestFromPayloadRequest","getMCPHandler","initializeMCPHandler","pluginOptions","mcpHandler","req","payload","MCPOptions","mcp","MCPHandlerOptions","handlerOptions","useVerboseLogs","verboseLogs","payloadAPI","getDefaultMcpAccessSettings","overrideApiKey","apiKey","headers","get","startsWith","replace","trim","sha256APIKeyIndex","createHmac","secret","update","digest","apiKeyConstraints","apiKeyIndex","equals","where","or","docs","find","collection","limit","pagination","length","logger","info","user","customUserCollection","userCollection","slug","_strategy","mcpAccessSettings","overrideAuth","handler","request"],"mappings":"AAAA,OAAOA,YAAY,SAAQ;AAC3B,SAA8CC,iBAAiB,QAAoB,UAAS;AAI5F,SAASC,+BAA+B,QAAQ,0BAAyB;AACzE,SAASC,aAAa,QAAQ,0BAAyB;AAEvD,OAAO,MAAMC,uBAAuB,CAACC;IACnC,MAAMC,aAA6B,OAAOC;QACxC,MAAM,EAAEC,OAAO,EAAE,GAAGD;QACpB,MAAME,aAAaJ,cAAcK,GAAG,IAAI,CAAC;QACzC,MAAMC,oBAAoBF,WAAWG,cAAc,IAAI,CAAC;QACxD,MAAMC,iBAAiBF,kBAAkBG,WAAW,IAAI;QAExDP,IAAIQ,UAAU,GAAG;QAEjB,MAAMC,8BAA8B,OAAOC;YACzC,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egex)) {
|
|
105
105
|
content = content.replace(/(import.*from.*payload.*\n)/, `$1import { mongooseAdapter } from '@payloadcms/db-mongodb'\n`);
|
|
106
106
|
}
|
|
107
|
-
const dbConfig = `db: mongooseAdapter({\n url: process.env.
|
|
107
|
+
const dbConfig = `db: mongooseAdapter({\n url: process.env.DATABASE_URL || '${databaseConfig.url || ''}',\n })`;
|
|
108
108
|
content = content.replace(dbRegex, `${dbConfig},`);
|
|
109
109
|
}
|
|
110
110
|
return content;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/mcp/helpers/config.ts"],"sourcesContent":["import type {\n AdminConfig,\n CollectionConfigUpdates,\n DatabaseConfig,\n GeneralConfig,\n PluginUpdates,\n} from '../../types.js'\n\n/**\n * Adds a collection to the payload.config.ts file\n */\nexport function addCollectionToConfig(content: string, collectionName: string): string {\n const capitalizedName = collectionName.charAt(0).toUpperCase() + collectionName.slice(1)\n\n // Add import statement\n const importRegex = /import.*from\\s*['\"]\\.\\/collections\\/.*['\"]/g\n const importMatches = content.match(importRegex)\n\n if (importMatches && importMatches.length > 0) {\n const lastImport = importMatches[importMatches.length - 1]\n const newImport = `import { ${capitalizedName} } from './collections/${capitalizedName}'`\n\n // Check if import already exists\n if (lastImport && !content.includes(newImport)) {\n content = content.replace(lastImport, `${lastImport}\\n${newImport}`)\n }\n } else {\n // Add import after existing imports\n const importInsertPoint = content.indexOf(\"import sharp from 'sharp'\")\n if (importInsertPoint !== -1) {\n const lineEnd = content.indexOf('\\n', importInsertPoint)\n const newImport = `import { ${capitalizedName} } from './collections/${capitalizedName}'`\n content = content.slice(0, lineEnd + 1) + newImport + '\\n' + content.slice(lineEnd + 1)\n }\n }\n\n // Add to collections array\n const collectionsRegex = /collections:\\s*\\[([\\s\\S]*?)\\]/\n const collectionsMatch = content.match(collectionsRegex)\n\n if (collectionsMatch && collectionsMatch[1]) {\n const collectionsContent = collectionsMatch[1].trim()\n if (!collectionsContent.includes(capitalizedName)) {\n const newCollections = collectionsContent\n ? `${collectionsContent}, ${capitalizedName}`\n : capitalizedName\n content = content.replace(collectionsRegex, `collections: [${newCollections}]`)\n }\n }\n\n return content\n}\n\n/**\n * Removes a collection from the payload.config.ts file\n */\nexport function removeCollectionFromConfig(content: string, collectionName: string): string {\n const capitalizedName = collectionName.charAt(0).toUpperCase() + collectionName.slice(1)\n\n // Remove import statement\n const importRegex = new RegExp(\n `import\\\\s*{\\\\s*${capitalizedName}\\\\s*}\\\\s*from\\\\s*['\"]\\\\./collections/${capitalizedName}['\"]\\\\s*\\\\n?`,\n 'g',\n )\n content = content.replace(importRegex, '')\n\n // Remove from collections array\n const collectionsRegex = /collections:\\s*\\[([\\s\\S]*?)\\]/\n const collectionsMatch = content.match(collectionsRegex)\n\n if (collectionsMatch && collectionsMatch[1]) {\n let collectionsContent = collectionsMatch[1]\n\n // Remove the collection name and clean up commas\n collectionsContent = collectionsContent.replace(\n new RegExp(`\\\\s*,?\\\\s*${capitalizedName}\\\\s*,?`, 'g'),\n '',\n )\n collectionsContent = collectionsContent.replace(/,\\s*,/g, ',') // Remove double commas\n collectionsContent = collectionsContent.replace(/^\\s*,|,\\s*$/g, '') // Remove leading/trailing commas\n\n content = content.replace(collectionsRegex, `collections: [${collectionsContent}]`)\n }\n\n // Clean up any double newlines from removed imports\n content = content.replace(/\\n{3,}/g, '\\n\\n')\n\n return content\n}\n\n/**\n * Updates admin configuration in payload.config.ts\n */\nexport function updateAdminConfig(content: string, adminConfig: AdminConfig): string {\n const adminRegex = /admin:\\s*\\{([^}]*)\\}/\n const adminMatch = content.match(adminRegex)\n\n if (adminMatch && adminMatch[1]) {\n let adminContent = adminMatch[1]\n\n // Update specific admin properties\n if (adminConfig.user) {\n if (adminContent.includes('user:')) {\n adminContent = adminContent.replace(/user:[^,}]*/, `user: ${adminConfig.user}.slug`)\n } else {\n adminContent = `\\n user: ${adminConfig.user}.slug,${adminContent}`\n }\n }\n\n if (adminConfig.meta) {\n const metaConfig = Object.entries(adminConfig.meta)\n .map(([key, value]) => ` ${key}: '${value}'`)\n .join(',\\n')\n\n if (adminContent.includes('meta:')) {\n adminContent = adminContent.replace(/meta:\\s*\\{[^}]*\\}/, `meta: {\\n${metaConfig}\\n }`)\n } else {\n adminContent = `${adminContent}\\n meta: {\\n${metaConfig}\\n },`\n }\n }\n\n content = content.replace(adminRegex, `admin: {${adminContent}\\n }`)\n } else {\n // Add admin config if it doesn't exist\n const adminConfigEntries = []\n\n if (adminConfig.user) {\n adminConfigEntries.push(` user: ${adminConfig.user}.slug`)\n }\n\n if (adminConfig.meta) {\n const metaConfig = Object.entries(adminConfig.meta)\n .map(([key, value]) => ` ${key}: '${value}'`)\n .join(',\\n')\n adminConfigEntries.push(` meta: {\\n${metaConfig}\\n }`)\n }\n\n const adminConfigString = `admin: {\\n${adminConfigEntries.join(',\\n')}\\n },`\n content = content.replace(\n /export default buildConfig\\(\\{/,\n `export default buildConfig({\\n ${adminConfigString}`,\n )\n }\n\n return content\n}\n\n/**\n * Updates database configuration in payload.config.ts\n */\nexport function updateDatabaseConfig(content: string, databaseConfig: DatabaseConfig): string {\n if (databaseConfig.type === 'mongodb') {\n // Update to MongoDB adapter\n const dbRegex = /db:[^,}]*(?:,|\\})/\n const mongoImportRegex = /import.*mongooseAdapter.*from.*@payloadcms\\/db-mongodb.*/\n\n if (!content.match(mongoImportRegex)) {\n content = content.replace(\n /(import.*from.*payload.*\\n)/,\n `$1import { mongooseAdapter } from '@payloadcms/db-mongodb'\\n`,\n )\n }\n\n const dbConfig = `db: mongooseAdapter({\\n url: process.env.DATABASE_URI || '${databaseConfig.url || ''}',\\n })`\n content = content.replace(dbRegex, `${dbConfig},`)\n }\n\n return content\n}\n\n/**\n * Updates plugins configuration in payload.config.ts\n */\nexport function updatePluginsConfig(content: string, pluginUpdates: PluginUpdates): string {\n // Add plugin imports\n if (pluginUpdates.add) {\n pluginUpdates.add.forEach((pluginImport: string) => {\n if (!content.includes(pluginImport)) {\n content = content.replace(/(import.*from.*payload.*\\n)/, `$1${pluginImport}\\n`)\n }\n })\n }\n\n // Handle plugins array\n const pluginsRegex = /plugins:\\s*\\[([\\s\\S]*?)\\]/\n const pluginsMatch = content.match(pluginsRegex)\n\n if (pluginsMatch && pluginsMatch[1]) {\n let pluginsContent = pluginsMatch[1]\n\n // Remove plugins\n if (pluginUpdates.remove) {\n pluginUpdates.remove.forEach((pluginName: string) => {\n const pluginRegex = new RegExp(`\\\\s*${pluginName}\\\\(\\\\)\\\\s*,?`, 'g')\n pluginsContent = pluginsContent.replace(pluginRegex, '')\n })\n }\n\n // Add plugins\n if (pluginUpdates.add) {\n pluginUpdates.add.forEach((pluginImport: string) => {\n // This will match: import { PluginName } from '...';\n const match = pluginImport.match(/import\\s*\\{\\s*(\\w+)\\s*\\}/)\n if (match && match[1]) {\n const pluginName = match[1]\n if (!pluginsContent.includes(`${pluginName}(`)) {\n pluginsContent = pluginsContent.trim()\n ? `${pluginsContent}\\n ${pluginName}(),`\n : `\\n ${pluginName}(),`\n }\n }\n })\n }\n\n content = content.replace(pluginsRegex, `plugins: [${pluginsContent}\\n ]`)\n }\n\n return content\n}\n\n/**\n * Updates general configuration options in payload.config.ts\n */\nexport function updateGeneralConfig(content: string, generalConfig: GeneralConfig): string {\n // Update various general configuration options\n Object.entries(generalConfig).forEach(([key, value]) => {\n if (value !== undefined && value !== null) {\n const configRegex = new RegExp(`${key}:\\\\s*[^,}]*`, 'g')\n\n if (content.match(configRegex)) {\n if (typeof value === 'string') {\n content = content.replace(configRegex, `${key}: '${value}'`)\n } else if (typeof value === 'boolean') {\n content = content.replace(configRegex, `${key}: ${value}`)\n } else if (typeof value === 'object') {\n content = content.replace(configRegex, `${key}: ${JSON.stringify(value, null, 2)}`)\n }\n } else {\n // Add new config option\n const configValue =\n typeof value === 'string'\n ? `'${value}'`\n : typeof value === 'object'\n ? JSON.stringify(value, null, 2)\n : value\n content = content.replace(\n /export default buildConfig\\(\\{/,\n `export default buildConfig({\\n ${key}: ${configValue},`,\n )\n }\n }\n })\n\n return content\n}\n\n/**\n * Updates collection-level configuration in a collection file\n */\nexport function updateCollectionConfig(\n content: string,\n updates: CollectionConfigUpdates,\n collectionName: string,\n): string {\n let updatedContent = content\n\n if (updates.slug) {\n updatedContent = updatedContent.replace(/slug:\\s*'[^']*'/, `slug: '${updates.slug}'`)\n }\n\n if (updates.access) {\n const accessRegex = /access:\\s*\\{[^}]*\\}/\n if (updatedContent.match(accessRegex)) {\n // Update existing access config\n Object.entries(updates.access).forEach(([key, value]) => {\n if (value !== undefined) {\n updatedContent = updatedContent.replace(\n new RegExp(`${key}:\\\\s*[^,}]*`),\n `${key}: ${value}`,\n )\n }\n })\n } else {\n // Add access config\n const accessConfig = Object.entries(updates.access)\n .filter(([, value]) => value !== undefined)\n .map(([key, value]) => ` ${key}: ${value}`)\n .join(',\\n')\n\n updatedContent = updatedContent.replace(\n /slug:\\s*'[^']*',/,\n `slug: '${collectionName}',\\n access: {\\n${accessConfig}\\n },`,\n )\n }\n }\n\n if (updates.timestamps !== undefined) {\n if (updatedContent.includes('timestamps:')) {\n updatedContent = updatedContent.replace(\n /timestamps:[^,}]*/,\n `timestamps: ${updates.timestamps}`,\n )\n } else {\n updatedContent = updatedContent.replace(\n /fields:\\s*\\[/,\n `timestamps: ${updates.timestamps},\\n fields: [`,\n )\n }\n }\n\n if (updates.versioning !== undefined) {\n if (updatedContent.includes('versioning:')) {\n updatedContent = updatedContent.replace(\n /versioning:[^,}]*/,\n `versioning: ${updates.versioning}`,\n )\n } else {\n updatedContent = updatedContent.replace(\n /fields:\\s*\\[/,\n `versioning: ${updates.versioning},\\n fields: [`,\n )\n }\n }\n\n return updatedContent\n}\n"],"names":["addCollectionToConfig","content","collectionName","capitalizedName","charAt","toUpperCase","slice","importRegex","importMatches","match","length","lastImport","newImport","includes","replace","importInsertPoint","indexOf","lineEnd","collectionsRegex","collectionsMatch","collectionsContent","trim","newCollections","removeCollectionFromConfig","RegExp","updateAdminConfig","adminConfig","adminRegex","adminMatch","adminContent","user","meta","metaConfig","Object","entries","map","key","value","join","adminConfigEntries","push","adminConfigString","updateDatabaseConfig","databaseConfig","type","dbRegex","mongoImportRegex","dbConfig","url","updatePluginsConfig","pluginUpdates","add","forEach","pluginImport","pluginsRegex","pluginsMatch","pluginsContent","remove","pluginName","pluginRegex","updateGeneralConfig","generalConfig","undefined","configRegex","JSON","stringify","configValue","updateCollectionConfig","updates","updatedContent","slug","access","accessRegex","accessConfig","filter","timestamps","versioning"],"mappings":"AAQA;;CAEC,GACD,OAAO,SAASA,sBAAsBC,OAAe,EAAEC,cAAsB;IAC3E,MAAMC,kBAAkBD,eAAeE,MAAM,CAAC,GAAGC,WAAW,KAAKH,eAAeI,KAAK,CAAC;IAEtF,uBAAuB;IACvB,MAAMC,cAAc;IACpB,MAAMC,gBAAgBP,QAAQQ,KAAK,CAACF;IAEpC,IAAIC,iBAAiBA,cAAcE,MAAM,GAAG,GAAG;QAC7C,MAAMC,aAAaH,aAAa,CAACA,cAAcE,MAAM,GAAG,EAAE;QAC1D,MAAME,YAAY,CAAC,SAAS,EAAET,gBAAgB,uBAAuB,EAAEA,gBAAgB,CAAC,CAAC;QAEzF,iCAAiC;QACjC,IAAIQ,cAAc,CAACV,QAAQY,QAAQ,CAACD,YAAY;YAC9CX,UAAUA,QAAQa,OAAO,CAACH,YAAY,GAAGA,WAAW,EAAE,EAAEC,WAAW;QACrE;IACF,OAAO;QACL,oCAAoC;QACpC,MAAMG,oBAAoBd,QAAQe,OAAO,CAAC;QAC1C,IAAID,sBAAsB,CAAC,GAAG;YAC5B,MAAME,UAAUhB,QAAQe,OAAO,CAAC,MAAMD;YACtC,MAAMH,YAAY,CAAC,SAAS,EAAET,gBAAgB,uBAAuB,EAAEA,gBAAgB,CAAC,CAAC;YACzFF,UAAUA,QAAQK,KAAK,CAAC,GAAGW,UAAU,KAAKL,YAAY,OAAOX,QAAQK,KAAK,CAACW,UAAU;QACvF;IACF;IAEA,2BAA2B;IAC3B,MAAMC,mBA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W,CAAC,GAC9B,GAAGA,IAAI,EAAE,EAAEC,OAAO;gBAEtB;YACF;QACF,OAAO;YACL,oBAAoB;YACpB,MAAMoC,eAAexC,OAAOC,OAAO,CAACkC,QAAQG,MAAM,EAC/CG,MAAM,CAAC,CAAC,GAAGrC,MAAM,GAAKA,UAAUyB,WAChC3B,GAAG,CAAC,CAAC,CAACC,KAAKC,MAAM,GAAK,CAAC,IAAI,EAAED,IAAI,EAAE,EAAEC,OAAO,EAC5CC,IAAI,CAAC;YAER+B,iBAAiBA,eAAevD,OAAO,CACrC,oBACA,CAAC,OAAO,EAAEZ,eAAe,iBAAiB,EAAEuE,aAAa,MAAM,CAAC;QAEpE;IACF;IAEA,IAAIL,QAAQO,UAAU,KAAKb,WAAW;QACpC,IAAIO,eAAexD,QAAQ,CAAC,gBAAgB;YAC1CwD,iBAAiBA,eAAevD,OAAO,CACrC,qBACA,CAAC,YAAY,EAAEsD,QAAQO,UAAU,EAAE;QAEvC,OAAO;YACLN,iBAAiBA,eAAevD,OAAO,CACrC,gBACA,CAAC,YAAY,EAAEsD,QAAQO,UAAU,CAAC,cAAc,CAAC;QAErD;IACF;IAEA,IAAIP,QAAQQ,UAAU,KAAKd,WAAW;QACpC,IAAIO,eAAexD,QAAQ,CAAC,gBAAgB;YAC1CwD,iBAAiBA,eAAevD,OAAO,CACrC,qBACA,CAAC,YAAY,EAAEsD,QAAQQ,UAAU,EAAE;QAEvC,OAAO;YACLP,iBAAiBA,eAAevD,OAAO,CACrC,gBACA,CAAC,YAAY,EAAEsD,QAAQQ,UAAU,CAAC,cAAc,CAAC;QAErD;IACF;IAEA,OAAOP;AACT"}
|
|
1
|
+
{"version":3,"sources":["../../../src/mcp/helpers/config.ts"],"sourcesContent":["import type {\n AdminConfig,\n CollectionConfigUpdates,\n DatabaseConfig,\n GeneralConfig,\n PluginUpdates,\n} from '../../types.js'\n\n/**\n * Adds a collection to the payload.config.ts file\n */\nexport function addCollectionToConfig(content: string, collectionName: string): string {\n const capitalizedName = collectionName.charAt(0).toUpperCase() + collectionName.slice(1)\n\n // Add import statement\n const importRegex = /import.*from\\s*['\"]\\.\\/collections\\/.*['\"]/g\n const importMatches = content.match(importRegex)\n\n if (importMatches && importMatches.length > 0) {\n const lastImport = importMatches[importMatches.length - 1]\n const newImport = `import { ${capitalizedName} } from './collections/${capitalizedName}'`\n\n // Check if import already exists\n if (lastImport && !content.includes(newImport)) {\n content = content.replace(lastImport, `${lastImport}\\n${newImport}`)\n }\n } else {\n // Add import after existing imports\n const importInsertPoint = content.indexOf(\"import sharp from 'sharp'\")\n if (importInsertPoint !== -1) {\n const lineEnd = content.indexOf('\\n', importInsertPoint)\n const newImport = `import { ${capitalizedName} } from './collections/${capitalizedName}'`\n content = content.slice(0, lineEnd + 1) + newImport + '\\n' + content.slice(lineEnd + 1)\n }\n }\n\n // Add to collections array\n const collectionsRegex = /collections:\\s*\\[([\\s\\S]*?)\\]/\n const collectionsMatch = content.match(collectionsRegex)\n\n if (collectionsMatch && collectionsMatch[1]) {\n const collectionsContent = collectionsMatch[1].trim()\n if (!collectionsContent.includes(capitalizedName)) {\n const newCollections = collectionsContent\n ? `${collectionsContent}, ${capitalizedName}`\n : capitalizedName\n content = content.replace(collectionsRegex, `collections: [${newCollections}]`)\n }\n }\n\n return content\n}\n\n/**\n * Removes a collection from the payload.config.ts file\n */\nexport function removeCollectionFromConfig(content: string, collectionName: string): string {\n const capitalizedName = collectionName.charAt(0).toUpperCase() + collectionName.slice(1)\n\n // Remove import statement\n const importRegex = new RegExp(\n `import\\\\s*{\\\\s*${capitalizedName}\\\\s*}\\\\s*from\\\\s*['\"]\\\\./collections/${capitalizedName}['\"]\\\\s*\\\\n?`,\n 'g',\n )\n content = content.replace(importRegex, '')\n\n // Remove from collections array\n const collectionsRegex = /collections:\\s*\\[([\\s\\S]*?)\\]/\n const collectionsMatch = content.match(collectionsRegex)\n\n if (collectionsMatch && collectionsMatch[1]) {\n let collectionsContent = collectionsMatch[1]\n\n // Remove the collection name and clean up commas\n collectionsContent = collectionsContent.replace(\n new RegExp(`\\\\s*,?\\\\s*${capitalizedName}\\\\s*,?`, 'g'),\n '',\n )\n collectionsContent = collectionsContent.replace(/,\\s*,/g, ',') // Remove double commas\n collectionsContent = collectionsContent.replace(/^\\s*,|,\\s*$/g, '') // Remove leading/trailing commas\n\n content = content.replace(collectionsRegex, `collections: [${collectionsContent}]`)\n }\n\n // Clean up any double newlines from removed imports\n content = content.replace(/\\n{3,}/g, '\\n\\n')\n\n return content\n}\n\n/**\n * Updates admin configuration in payload.config.ts\n */\nexport function updateAdminConfig(content: string, adminConfig: AdminConfig): string {\n const adminRegex = /admin:\\s*\\{([^}]*)\\}/\n const adminMatch = content.match(adminRegex)\n\n if (adminMatch && adminMatch[1]) {\n let adminContent = adminMatch[1]\n\n // Update specific admin properties\n if (adminConfig.user) {\n if (adminContent.includes('user:')) {\n adminContent = adminContent.replace(/user:[^,}]*/, `user: ${adminConfig.user}.slug`)\n } else {\n adminContent = `\\n user: ${adminConfig.user}.slug,${adminContent}`\n }\n }\n\n if (adminConfig.meta) {\n const metaConfig = Object.entries(adminConfig.meta)\n .map(([key, value]) => ` ${key}: '${value}'`)\n .join(',\\n')\n\n if (adminContent.includes('meta:')) {\n adminContent = adminContent.replace(/meta:\\s*\\{[^}]*\\}/, `meta: {\\n${metaConfig}\\n }`)\n } else {\n adminContent = `${adminContent}\\n meta: {\\n${metaConfig}\\n },`\n }\n }\n\n content = content.replace(adminRegex, `admin: {${adminContent}\\n }`)\n } else {\n // Add admin config if it doesn't exist\n const adminConfigEntries = []\n\n if (adminConfig.user) {\n adminConfigEntries.push(` user: ${adminConfig.user}.slug`)\n }\n\n if (adminConfig.meta) {\n const metaConfig = Object.entries(adminConfig.meta)\n .map(([key, value]) => ` ${key}: '${value}'`)\n .join(',\\n')\n adminConfigEntries.push(` meta: {\\n${metaConfig}\\n }`)\n }\n\n const adminConfigString = `admin: {\\n${adminConfigEntries.join(',\\n')}\\n },`\n content = content.replace(\n /export default buildConfig\\(\\{/,\n `export default buildConfig({\\n ${adminConfigString}`,\n )\n }\n\n return content\n}\n\n/**\n * Updates database configuration in payload.config.ts\n */\nexport function updateDatabaseConfig(content: string, databaseConfig: DatabaseConfig): string {\n if (databaseConfig.type === 'mongodb') {\n // Update to MongoDB adapter\n const dbRegex = /db:[^,}]*(?:,|\\})/\n const mongoImportRegex = /import.*mongooseAdapter.*from.*@payloadcms\\/db-mongodb.*/\n\n if (!content.match(mongoImportRegex)) {\n content = content.replace(\n /(import.*from.*payload.*\\n)/,\n `$1import { mongooseAdapter } from '@payloadcms/db-mongodb'\\n`,\n )\n }\n\n const dbConfig = `db: mongooseAdapter({\\n url: process.env.DATABASE_URL || '${databaseConfig.url || ''}',\\n })`\n content = content.replace(dbRegex, `${dbConfig},`)\n }\n\n return content\n}\n\n/**\n * Updates plugins configuration in payload.config.ts\n */\nexport function updatePluginsConfig(content: string, pluginUpdates: PluginUpdates): string {\n // Add plugin imports\n if (pluginUpdates.add) {\n pluginUpdates.add.forEach((pluginImport: string) => {\n if (!content.includes(pluginImport)) {\n content = content.replace(/(import.*from.*payload.*\\n)/, `$1${pluginImport}\\n`)\n }\n })\n }\n\n // Handle plugins array\n const pluginsRegex = /plugins:\\s*\\[([\\s\\S]*?)\\]/\n const pluginsMatch = content.match(pluginsRegex)\n\n if (pluginsMatch && pluginsMatch[1]) {\n let pluginsContent = pluginsMatch[1]\n\n // Remove plugins\n if (pluginUpdates.remove) {\n pluginUpdates.remove.forEach((pluginName: string) => {\n const pluginRegex = new RegExp(`\\\\s*${pluginName}\\\\(\\\\)\\\\s*,?`, 'g')\n pluginsContent = pluginsContent.replace(pluginRegex, '')\n })\n }\n\n // Add plugins\n if (pluginUpdates.add) {\n pluginUpdates.add.forEach((pluginImport: string) => {\n // This will match: import { PluginName } from '...';\n const match = pluginImport.match(/import\\s*\\{\\s*(\\w+)\\s*\\}/)\n if (match && match[1]) {\n const pluginName = match[1]\n if (!pluginsContent.includes(`${pluginName}(`)) {\n pluginsContent = pluginsContent.trim()\n ? `${pluginsContent}\\n ${pluginName}(),`\n : `\\n ${pluginName}(),`\n }\n }\n })\n }\n\n content = content.replace(pluginsRegex, `plugins: [${pluginsContent}\\n ]`)\n }\n\n return content\n}\n\n/**\n * Updates general configuration options in payload.config.ts\n */\nexport function updateGeneralConfig(content: string, generalConfig: GeneralConfig): string {\n // Update various general configuration options\n Object.entries(generalConfig).forEach(([key, value]) => {\n if (value !== undefined && value !== null) {\n const configRegex = new RegExp(`${key}:\\\\s*[^,}]*`, 'g')\n\n if (content.match(configRegex)) {\n if (typeof value === 'string') {\n content = content.replace(configRegex, `${key}: '${value}'`)\n } else if (typeof value === 'boolean') {\n content = content.replace(configRegex, `${key}: ${value}`)\n } else if (typeof value === 'object') {\n content = content.replace(configRegex, `${key}: ${JSON.stringify(value, null, 2)}`)\n }\n } else {\n // Add new config option\n const configValue =\n typeof value === 'string'\n ? `'${value}'`\n : typeof value === 'object'\n ? JSON.stringify(value, null, 2)\n : value\n content = content.replace(\n /export default buildConfig\\(\\{/,\n `export default buildConfig({\\n ${key}: ${configValue},`,\n )\n }\n }\n })\n\n return content\n}\n\n/**\n * Updates collection-level configuration in a collection file\n */\nexport function updateCollectionConfig(\n content: string,\n updates: CollectionConfigUpdates,\n collectionName: string,\n): string {\n let updatedContent = content\n\n if (updates.slug) {\n updatedContent = updatedContent.replace(/slug:\\s*'[^']*'/, `slug: '${updates.slug}'`)\n }\n\n if (updates.access) {\n const accessRegex = /access:\\s*\\{[^}]*\\}/\n if (updatedContent.match(accessRegex)) {\n // Update existing access config\n Object.entries(updates.access).forEach(([key, value]) => {\n if (value !== undefined) {\n updatedContent = updatedContent.replace(\n new RegExp(`${key}:\\\\s*[^,}]*`),\n `${key}: ${value}`,\n )\n }\n })\n } else {\n // Add access config\n const accessConfig = Object.entries(updates.access)\n .filter(([, value]) => value !== undefined)\n .map(([key, value]) => ` ${key}: ${value}`)\n .join(',\\n')\n\n updatedContent = updatedContent.replace(\n /slug:\\s*'[^']*',/,\n `slug: '${collectionName}',\\n access: {\\n${accessConfig}\\n },`,\n )\n }\n }\n\n if (updates.timestamps !== undefined) {\n if (updatedContent.includes('timestamps:')) {\n updatedContent = updatedContent.replace(\n /timestamps:[^,}]*/,\n `timestamps: ${updates.timestamps}`,\n )\n } else {\n updatedContent = updatedContent.replace(\n /fields:\\s*\\[/,\n `timestamps: ${updates.timestamps},\\n fields: [`,\n )\n }\n }\n\n if (updates.versioning !== undefined) {\n if (updatedContent.includes('versioning:')) {\n updatedContent = updatedContent.replace(\n /versioning:[^,}]*/,\n `versioning: ${updates.versioning}`,\n )\n } else {\n updatedContent = updatedContent.replace(\n /fields:\\s*\\[/,\n `versioning: ${updates.versioning},\\n fields: [`,\n )\n }\n }\n\n return updatedContent\n}\n"],"names":["addCollectionToConfig","content","collectionName","capitalizedName","charAt","toUpperCase","slice","importRegex","importMatches","match","length","lastImport","newImport","includes","replace","importInsertPoint","indexOf","lineEnd","collectionsRegex","collectionsMatch","collectionsContent","trim","newCollections","removeCollectionFromConfig","RegExp","updateAdminConfig","adminConfig","adminRegex","adminMatch","adminContent","user","meta","metaConfig","Object","entries","map","key","value","join","adminConfigEntries","push","adminConfigString","updateDatabaseConfig","databaseConfig","type","dbRegex","mongoImportRegex","dbConfig","url","updatePluginsConfig","pluginUpdates","add","forEach","pluginImport","pluginsRegex","pluginsMatch","pluginsContent","remove","pluginName","pluginRegex","updateGeneralConfig","generalConfig","undefined","configRegex","JSON","stringify","configValue","updateCollectionConfig","updates","updatedContent","slug","access","accessRegex","accessConfig","filter","timestamps","versioning"],"mappings":"AAQA;;CAEC,GACD,OAAO,SAASA,sBAAsBC,OAAe,EAAEC,cAAsB;IAC3E,MAAMC,kBAAkBD,eAAeE,MAAM,CAAC,GAAGC,WAAW,KAAKH,eAAeI,KAAK,CAAC;IAEtF,uBAAuB;IACvB,MAAMC,cAAc;IACpB,MAAMC,gBAAgBP,QAAQQ,KAAK,CAACF;IAEpC,IAA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AO,CACrC,qBACA,CAAC,YAAY,EAAEsD,QAAQO,UAAU,EAAE;QAEvC,OAAO;YACLN,iBAAiBA,eAAevD,OAAO,CACrC,gBACA,CAAC,YAAY,EAAEsD,QAAQO,UAAU,CAAC,cAAc,CAAC;QAErD;IACF;IAEA,IAAIP,QAAQQ,UAAU,KAAKd,WAAW;QACpC,IAAIO,eAAexD,QAAQ,CAAC,gBAAgB;YAC1CwD,iBAAiBA,eAAevD,OAAO,CACrC,qBACA,CAAC,YAAY,EAAEsD,QAAQQ,UAAU,EAAE;QAEvC,OAAO;YACLP,iBAAiBA,eAAevD,OAAO,CACrC,gBACA,CAAC,YAAY,EAAEsD,QAAQQ,UAAU,CAAC,cAAc,CAAC;QAErD;IACF;IAEA,OAAOP;AACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/plugin-mcp",
|
|
3
|
-
"version": "3.69.0
|
|
3
|
+
"version": "3.69.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.69.0
|
|
48
|
+
"payload": "3.69.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"payload": "3.69.0
|
|
51
|
+
"payload": "3.69.0"
|
|
52
52
|
},
|
|
53
53
|
"homepage:": "https://payloadcms.com",
|
|
54
54
|
"scripts": {
|
package/src/endpoints/mcp.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import crypto from 'crypto'
|
|
2
|
-
import { type PayloadHandler, UnauthorizedError, type Where } from 'payload'
|
|
2
|
+
import { type PayloadHandler, type TypedUser, UnauthorizedError, type Where } from 'payload'
|
|
3
3
|
|
|
4
4
|
import type { MCPAccessSettings, PluginMCPServerConfig } from '../types.js'
|
|
5
5
|
|
|
@@ -57,6 +57,14 @@ export const initializeMCPHandler = (pluginOptions: PluginMCPServerConfig) => {
|
|
|
57
57
|
payload.logger.info('[payload-mcp] API Key is valid')
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
const user = docs[0]?.user as TypedUser
|
|
61
|
+
const customUserCollection =
|
|
62
|
+
typeof pluginOptions.userCollection === 'string'
|
|
63
|
+
? pluginOptions.userCollection
|
|
64
|
+
: pluginOptions.userCollection?.slug
|
|
65
|
+
user.collection = customUserCollection ?? 'users'
|
|
66
|
+
user._strategy = 'mcp-api-key' as const
|
|
67
|
+
|
|
60
68
|
return docs[0] as unknown as MCPAccessSettings
|
|
61
69
|
}
|
|
62
70
|
|
|
@@ -161,7 +161,7 @@ export function updateDatabaseConfig(content: string, databaseConfig: DatabaseCo
|
|
|
161
161
|
)
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
-
const dbConfig = `db: mongooseAdapter({\n url: process.env.
|
|
164
|
+
const dbConfig = `db: mongooseAdapter({\n url: process.env.DATABASE_URL || '${databaseConfig.url || ''}',\n })`
|
|
165
165
|
content = content.replace(dbRegex, `${dbConfig},`)
|
|
166
166
|
}
|
|
167
167
|
|