@payloadcms/plugin-mcp 4.0.0-internal.5b1e7cd → 4.0.0-internal.c2b57ce
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/bin.js +39 -0
- package/dist/collection/getAccessField.d.ts +12 -0
- package/dist/collection/getAccessField.d.ts.map +1 -0
- package/dist/collection/getAccessField.js +57 -0
- package/dist/collection/getAccessField.js.map +1 -0
- package/dist/collection/index.d.ts +6 -0
- package/dist/collection/index.d.ts.map +1 -0
- package/dist/collection/index.js +59 -0
- package/dist/collection/index.js.map +1 -0
- package/dist/components/AccessField/index.client.d.ts +10 -0
- package/dist/components/AccessField/index.client.d.ts.map +1 -0
- package/dist/components/AccessField/index.client.js +305 -0
- package/dist/components/AccessField/index.client.js.map +1 -0
- package/dist/components/AccessField/index.css +93 -0
- package/dist/defineTool.d.ts +26 -0
- package/dist/defineTool.d.ts.map +1 -0
- package/dist/defineTool.js +37 -0
- package/dist/defineTool.js.map +1 -0
- package/dist/endpoint/access.d.ts +10 -0
- package/dist/endpoint/access.d.ts.map +1 -0
- package/dist/endpoint/access.js +106 -0
- package/dist/endpoint/access.js.map +1 -0
- package/dist/endpoint/index.d.ts +3 -0
- package/dist/endpoint/index.d.ts.map +1 -0
- package/dist/endpoint/index.js +36 -0
- package/dist/endpoint/index.js.map +1 -0
- package/dist/exports/client.d.ts +2 -0
- package/dist/exports/client.d.ts.map +1 -0
- package/dist/exports/client.js +4 -0
- package/dist/exports/client.js.map +1 -0
- package/dist/index.d.ts +4 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +44 -67
- package/dist/index.js.map +1 -1
- package/dist/mcp/buildMcpServer.d.ts +19 -0
- package/dist/mcp/buildMcpServer.d.ts.map +1 -0
- package/dist/mcp/buildMcpServer.js +163 -0
- package/dist/mcp/buildMcpServer.js.map +1 -0
- package/dist/mcp/builtin/collections/authTools.d.ts +7 -0
- package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/authTools.js +250 -0
- package/dist/mcp/builtin/collections/authTools.js.map +1 -0
- package/dist/mcp/builtin/collections/createTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/createTool.js +87 -0
- package/dist/mcp/builtin/collections/createTool.js.map +1 -0
- package/dist/mcp/builtin/collections/deleteTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/deleteTool.js +117 -0
- package/dist/mcp/builtin/collections/deleteTool.js.map +1 -0
- package/dist/mcp/builtin/collections/findTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/findTool.js +159 -0
- package/dist/mcp/builtin/collections/findTool.js.map +1 -0
- package/dist/mcp/builtin/collections/updateTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/updateTool.js +187 -0
- package/dist/mcp/builtin/collections/updateTool.js.map +1 -0
- package/dist/mcp/builtin/globals/findTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/findTool.js +76 -0
- package/dist/mcp/builtin/globals/findTool.js.map +1 -0
- package/dist/mcp/builtin/globals/updateTool.d.ts +2 -0
- package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -0
- package/dist/mcp/builtin/globals/updateTool.js +92 -0
- package/dist/mcp/builtin/globals/updateTool.js.map +1 -0
- package/dist/mcp/builtinTools.d.ts +37 -0
- package/dist/mcp/builtinTools.d.ts.map +1 -0
- package/dist/mcp/builtinTools.js +64 -0
- package/dist/mcp/builtinTools.js.map +1 -0
- package/dist/mcp/sanitizeMCPConfig.d.ts +17 -0
- package/dist/mcp/sanitizeMCPConfig.d.ts.map +1 -0
- package/dist/mcp/sanitizeMCPConfig.js +167 -0
- package/dist/mcp/sanitizeMCPConfig.js.map +1 -0
- package/dist/stdio.d.ts +8 -0
- package/dist/stdio.d.ts.map +1 -0
- package/dist/stdio.js +89 -0
- package/dist/stdio.js.map +1 -0
- package/dist/types.d.ts +262 -455
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +6 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/camelCase.d.ts.map +1 -1
- package/dist/utils/getLogger.d.ts +10 -0
- package/dist/utils/getLogger.d.ts.map +1 -0
- package/dist/utils/getLogger.js +22 -0
- package/dist/utils/getLogger.js.map +1 -0
- package/dist/utils/getPluginConfig.d.ts +12 -0
- package/dist/utils/getPluginConfig.d.ts.map +1 -0
- package/dist/utils/getPluginConfig.js +15 -0
- package/dist/utils/getPluginConfig.js.map +1 -0
- package/dist/utils/localAPIDefaults.d.ts +20 -0
- package/dist/utils/localAPIDefaults.d.ts.map +1 -0
- package/dist/utils/localAPIDefaults.js +19 -0
- package/dist/utils/localAPIDefaults.js.map +1 -0
- package/dist/utils/resolveProjectRoot.d.ts +7 -0
- package/dist/utils/resolveProjectRoot.d.ts.map +1 -0
- package/dist/utils/resolveProjectRoot.js +15 -0
- package/dist/utils/resolveProjectRoot.js.map +1 -0
- package/dist/utils/schemaConversion/prepareCollectionSchema.d.ts +7 -0
- package/dist/utils/schemaConversion/prepareCollectionSchema.d.ts.map +1 -0
- package/dist/utils/schemaConversion/prepareCollectionSchema.js +37 -0
- package/dist/utils/schemaConversion/prepareCollectionSchema.js.map +1 -0
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts +2 -2
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.d.ts.map +1 -1
- package/dist/utils/schemaConversion/removeVirtualFieldsFromSchema.js.map +1 -1
- package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts +2 -2
- package/dist/utils/schemaConversion/sanitizeJsonSchema.d.ts.map +1 -1
- package/dist/utils/schemaConversion/sanitizeJsonSchema.js.map +1 -1
- package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts +2 -2
- package/dist/utils/schemaConversion/simplifyRelationshipFields.d.ts.map +1 -1
- package/dist/utils/schemaConversion/simplifyRelationshipFields.js +7 -4
- package/dist/utils/schemaConversion/simplifyRelationshipFields.js.map +1 -1
- package/dist/utils/schemaConversion/transformPointFields.d.ts +2 -2
- package/dist/utils/schemaConversion/transformPointFields.d.ts.map +1 -1
- package/dist/utils/schemaConversion/transformPointFields.js +7 -1
- package/dist/utils/schemaConversion/transformPointFields.js.map +1 -1
- package/dist/utils/toStandardSchema.d.ts +5 -0
- package/dist/utils/toStandardSchema.d.ts.map +1 -0
- package/dist/utils/toStandardSchema.js +4 -0
- package/dist/utils/toStandardSchema.js.map +1 -0
- package/package.json +35 -10
- package/src/collection/getAccessField.ts +64 -0
- package/src/collection/index.ts +63 -0
- package/src/components/AccessField/index.client.tsx +344 -0
- package/src/components/AccessField/index.css +93 -0
- package/src/defineTool.ts +44 -0
- package/src/endpoint/access.ts +132 -0
- package/src/endpoint/index.ts +35 -0
- package/src/exports/client.ts +2 -0
- package/src/index.ts +35 -85
- package/src/mcp/buildMcpServer.ts +224 -0
- package/src/mcp/builtin/collections/authTools.ts +233 -0
- package/src/mcp/builtin/collections/createTool.ts +116 -0
- package/src/mcp/builtin/collections/deleteTool.ts +123 -0
- package/src/mcp/builtin/collections/findTool.ts +187 -0
- package/src/mcp/builtin/collections/updateTool.ts +205 -0
- package/src/mcp/builtin/globals/findTool.ts +96 -0
- package/src/mcp/builtin/globals/updateTool.ts +118 -0
- package/src/mcp/builtinTools.ts +84 -0
- package/src/mcp/sanitizeMCPConfig.ts +239 -0
- package/src/stdio.ts +98 -0
- package/src/types.ts +295 -490
- package/src/utils/getLogger.ts +22 -0
- package/src/utils/getPluginConfig.ts +24 -0
- package/src/utils/localAPIDefaults.ts +22 -0
- package/src/utils/resolveProjectRoot.ts +17 -0
- package/src/utils/schemaConversion/prepareCollectionSchema.ts +39 -0
- package/src/utils/schemaConversion/removeVirtualFieldsFromSchema.ts +3 -3
- package/src/utils/schemaConversion/sanitizeJsonSchema.ts +4 -4
- package/src/utils/schemaConversion/simplifyRelationshipFields.ts +11 -6
- package/src/utils/schemaConversion/transformPointFields.ts +6 -5
- package/src/utils/toStandardSchema.ts +9 -0
- package/dist/collections/createApiKeysCollection.d.ts +0 -7
- package/dist/collections/createApiKeysCollection.d.ts.map +0 -1
- package/dist/collections/createApiKeysCollection.js +0 -317
- package/dist/collections/createApiKeysCollection.js.map +0 -1
- package/dist/defaults.d.ts +0 -4
- package/dist/defaults.d.ts.map +0 -1
- package/dist/defaults.js +0 -5
- package/dist/defaults.js.map +0 -1
- package/dist/endpoints/mcp.d.ts +0 -4
- package/dist/endpoints/mcp.d.ts.map +0 -1
- package/dist/endpoints/mcp.js +0 -71
- package/dist/endpoints/mcp.js.map +0 -1
- package/dist/mcp/createRequest.d.ts +0 -3
- package/dist/mcp/createRequest.d.ts.map +0 -1
- package/dist/mcp/createRequest.js +0 -14
- package/dist/mcp/createRequest.js.map +0 -1
- package/dist/mcp/getMcpHandler.d.ts +0 -4
- package/dist/mcp/getMcpHandler.d.ts.map +0 -1
- package/dist/mcp/getMcpHandler.js +0 -231
- package/dist/mcp/getMcpHandler.js.map +0 -1
- package/dist/mcp/helpers/config.d.ts +0 -22
- package/dist/mcp/helpers/config.d.ts.map +0 -1
- package/dist/mcp/helpers/config.js +0 -153
- package/dist/mcp/helpers/config.js.map +0 -1
- package/dist/mcp/helpers/fields.d.ts +0 -19
- package/dist/mcp/helpers/fields.d.ts.map +0 -1
- package/dist/mcp/helpers/fields.js +0 -102
- package/dist/mcp/helpers/fields.js.map +0 -1
- package/dist/mcp/helpers/fileValidation.d.ts +0 -67
- package/dist/mcp/helpers/fileValidation.d.ts.map +0 -1
- package/dist/mcp/helpers/fileValidation.js +0 -267
- package/dist/mcp/helpers/fileValidation.js.map +0 -1
- package/dist/mcp/registerTool.d.ts +0 -6
- package/dist/mcp/registerTool.d.ts.map +0 -1
- package/dist/mcp/registerTool.js +0 -18
- package/dist/mcp/registerTool.js.map +0 -1
- package/dist/mcp/tools/auth/auth.d.ts +0 -4
- package/dist/mcp/tools/auth/auth.d.ts.map +0 -1
- package/dist/mcp/tools/auth/auth.js +0 -57
- package/dist/mcp/tools/auth/auth.js.map +0 -1
- package/dist/mcp/tools/auth/forgotPassword.d.ts +0 -4
- package/dist/mcp/tools/auth/forgotPassword.d.ts.map +0 -1
- package/dist/mcp/tools/auth/forgotPassword.js +0 -48
- package/dist/mcp/tools/auth/forgotPassword.js.map +0 -1
- package/dist/mcp/tools/auth/login.d.ts +0 -4
- package/dist/mcp/tools/auth/login.d.ts.map +0 -1
- package/dist/mcp/tools/auth/login.js +0 -51
- package/dist/mcp/tools/auth/login.js.map +0 -1
- package/dist/mcp/tools/auth/resetPassword.d.ts +0 -4
- package/dist/mcp/tools/auth/resetPassword.d.ts.map +0 -1
- package/dist/mcp/tools/auth/resetPassword.js +0 -49
- package/dist/mcp/tools/auth/resetPassword.js.map +0 -1
- package/dist/mcp/tools/auth/unlock.d.ts +0 -4
- package/dist/mcp/tools/auth/unlock.d.ts.map +0 -1
- package/dist/mcp/tools/auth/unlock.js +0 -48
- package/dist/mcp/tools/auth/unlock.js.map +0 -1
- package/dist/mcp/tools/auth/verify.d.ts +0 -4
- package/dist/mcp/tools/auth/verify.d.ts.map +0 -1
- package/dist/mcp/tools/auth/verify.js +0 -45
- package/dist/mcp/tools/auth/verify.js.map +0 -1
- package/dist/mcp/tools/collection/create.d.ts +0 -10
- package/dist/mcp/tools/collection/create.d.ts.map +0 -1
- package/dist/mcp/tools/collection/create.js +0 -139
- package/dist/mcp/tools/collection/create.js.map +0 -1
- package/dist/mcp/tools/collection/delete.d.ts +0 -10
- package/dist/mcp/tools/collection/delete.d.ts.map +0 -1
- package/dist/mcp/tools/collection/delete.js +0 -154
- package/dist/mcp/tools/collection/delete.js.map +0 -1
- package/dist/mcp/tools/collection/find.d.ts +0 -10
- package/dist/mcp/tools/collection/find.d.ts.map +0 -1
- package/dist/mcp/tools/collection/find.js +0 -165
- package/dist/mcp/tools/collection/find.js.map +0 -1
- package/dist/mcp/tools/collection/update.d.ts +0 -10
- package/dist/mcp/tools/collection/update.d.ts.map +0 -1
- package/dist/mcp/tools/collection/update.js +0 -209
- package/dist/mcp/tools/collection/update.js.map +0 -1
- package/dist/mcp/tools/config/find.d.ts +0 -10
- package/dist/mcp/tools/config/find.d.ts.map +0 -1
- package/dist/mcp/tools/config/find.js +0 -97
- package/dist/mcp/tools/config/find.js.map +0 -1
- package/dist/mcp/tools/config/update.d.ts +0 -10
- package/dist/mcp/tools/config/update.d.ts.map +0 -1
- package/dist/mcp/tools/config/update.js +0 -215
- package/dist/mcp/tools/config/update.js.map +0 -1
- package/dist/mcp/tools/global/find.d.ts +0 -5
- package/dist/mcp/tools/global/find.d.ts.map +0 -1
- package/dist/mcp/tools/global/find.js +0 -82
- package/dist/mcp/tools/global/find.js.map +0 -1
- package/dist/mcp/tools/global/update.d.ts +0 -6
- package/dist/mcp/tools/global/update.d.ts.map +0 -1
- package/dist/mcp/tools/global/update.js +0 -124
- package/dist/mcp/tools/global/update.js.map +0 -1
- package/dist/mcp/tools/job/create.d.ts +0 -10
- package/dist/mcp/tools/job/create.d.ts.map +0 -1
- package/dist/mcp/tools/job/create.js +0 -293
- package/dist/mcp/tools/job/create.js.map +0 -1
- package/dist/mcp/tools/job/run.d.ts +0 -10
- package/dist/mcp/tools/job/run.d.ts.map +0 -1
- package/dist/mcp/tools/job/run.js +0 -129
- package/dist/mcp/tools/job/run.js.map +0 -1
- package/dist/mcp/tools/job/update.d.ts +0 -11
- package/dist/mcp/tools/job/update.d.ts.map +0 -1
- package/dist/mcp/tools/job/update.js +0 -186
- package/dist/mcp/tools/job/update.js.map +0 -1
- package/dist/mcp/tools/resource/create.d.ts +0 -6
- package/dist/mcp/tools/resource/create.d.ts.map +0 -1
- package/dist/mcp/tools/resource/create.js +0 -124
- package/dist/mcp/tools/resource/create.js.map +0 -1
- package/dist/mcp/tools/resource/delete.d.ts +0 -5
- package/dist/mcp/tools/resource/delete.d.ts.map +0 -1
- package/dist/mcp/tools/resource/delete.js +0 -151
- package/dist/mcp/tools/resource/delete.js.map +0 -1
- package/dist/mcp/tools/resource/find.d.ts +0 -5
- package/dist/mcp/tools/resource/find.d.ts.map +0 -1
- package/dist/mcp/tools/resource/find.js +0 -170
- package/dist/mcp/tools/resource/find.js.map +0 -1
- package/dist/mcp/tools/resource/update.d.ts +0 -6
- package/dist/mcp/tools/resource/update.d.ts.map +0 -1
- package/dist/mcp/tools/resource/update.js +0 -256
- package/dist/mcp/tools/resource/update.js.map +0 -1
- package/dist/mcp/tools/schemas.d.ts +0 -457
- package/dist/mcp/tools/schemas.d.ts.map +0 -1
- package/dist/mcp/tools/schemas.js +0 -243
- package/dist/mcp/tools/schemas.js.map +0 -1
- package/dist/utils/adminEntitySettings.d.ts +0 -17
- package/dist/utils/adminEntitySettings.d.ts.map +0 -1
- package/dist/utils/adminEntitySettings.js +0 -41
- package/dist/utils/adminEntitySettings.js.map +0 -1
- package/dist/utils/createApiKeyFields.d.ts +0 -15
- package/dist/utils/createApiKeyFields.d.ts.map +0 -1
- package/dist/utils/createApiKeyFields.js +0 -57
- package/dist/utils/createApiKeyFields.js.map +0 -1
- package/dist/utils/getEnabledSlugs.d.ts +0 -13
- package/dist/utils/getEnabledSlugs.d.ts.map +0 -1
- package/dist/utils/getEnabledSlugs.js +0 -32
- package/dist/utils/getEnabledSlugs.js.map +0 -1
- package/dist/utils/schemaConversion/convertCollectionSchemaToZod.d.ts +0 -3
- package/dist/utils/schemaConversion/convertCollectionSchemaToZod.d.ts.map +0 -1
- package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js +0 -43
- package/dist/utils/schemaConversion/convertCollectionSchemaToZod.js.map +0 -1
- package/src/collections/createApiKeysCollection.ts +0 -373
- package/src/defaults.ts +0 -3
- package/src/endpoints/mcp.ts +0 -91
- package/src/mcp/createRequest.ts +0 -13
- package/src/mcp/getMcpHandler.ts +0 -545
- package/src/mcp/helpers/config.ts +0 -213
- package/src/mcp/helpers/fields.ts +0 -154
- package/src/mcp/helpers/fileValidation.ts +0 -362
- package/src/mcp/registerTool.ts +0 -22
- package/src/mcp/tools/auth/auth.ts +0 -71
- package/src/mcp/tools/auth/forgotPassword.ts +0 -70
- package/src/mcp/tools/auth/login.ts +0 -72
- package/src/mcp/tools/auth/resetPassword.ts +0 -61
- package/src/mcp/tools/auth/unlock.ts +0 -64
- package/src/mcp/tools/auth/verify.ts +0 -57
- package/src/mcp/tools/collection/create.ts +0 -210
- package/src/mcp/tools/collection/delete.ts +0 -211
- package/src/mcp/tools/collection/find.ts +0 -224
- package/src/mcp/tools/collection/update.ts +0 -290
- package/src/mcp/tools/config/find.ts +0 -128
- package/src/mcp/tools/config/update.ts +0 -280
- package/src/mcp/tools/global/find.ts +0 -128
- package/src/mcp/tools/global/update.ts +0 -207
- package/src/mcp/tools/job/create.ts +0 -416
- package/src/mcp/tools/job/run.ts +0 -167
- package/src/mcp/tools/job/update.ts +0 -274
- package/src/mcp/tools/resource/create.ts +0 -211
- package/src/mcp/tools/resource/delete.ts +0 -218
- package/src/mcp/tools/resource/find.ts +0 -246
- package/src/mcp/tools/resource/update.ts +0 -383
- package/src/mcp/tools/schemas.ts +0 -520
- package/src/utils/adminEntitySettings.ts +0 -40
- package/src/utils/createApiKeyFields.ts +0 -72
- package/src/utils/getEnabledSlugs.ts +0 -42
- package/src/utils/schemaConversion/convertCollectionSchemaToZod.ts +0 -52
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
2
|
-
import type { PayloadRequest } from 'payload'
|
|
3
|
-
|
|
4
|
-
import { readdirSync, readFileSync, statSync } from 'fs'
|
|
5
|
-
import { extname, join } from 'path'
|
|
6
|
-
|
|
7
|
-
import { toolSchemas } from '../schemas.js'
|
|
8
|
-
|
|
9
|
-
export const readCollections = (
|
|
10
|
-
req: PayloadRequest,
|
|
11
|
-
verboseLogs: boolean,
|
|
12
|
-
collectionsDirPath: string,
|
|
13
|
-
collectionName?: string,
|
|
14
|
-
includeContent: boolean = false,
|
|
15
|
-
includeCount: boolean = false,
|
|
16
|
-
) => {
|
|
17
|
-
const payload = req.payload
|
|
18
|
-
|
|
19
|
-
if (verboseLogs) {
|
|
20
|
-
payload.logger.info(
|
|
21
|
-
`[payload-mcp] Reading collections${collectionName ? ` for: ${collectionName}` : ''}, includeContent: ${includeContent}, includeCount: ${includeCount}`,
|
|
22
|
-
)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
// Read specific Collection (optional)
|
|
27
|
-
if (collectionName) {
|
|
28
|
-
const fileName = `${collectionName.charAt(0).toUpperCase() + collectionName.slice(1)}.ts`
|
|
29
|
-
const filePath = join(collectionsDirPath, fileName)
|
|
30
|
-
|
|
31
|
-
if (!filePath.startsWith(collectionsDirPath)) {
|
|
32
|
-
payload.logger.error(`[payload-mcp] Invalid collection name attempted: ${collectionName}`)
|
|
33
|
-
return {
|
|
34
|
-
content: [{ type: 'text' as const, text: 'Error: Invalid collection name' }],
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
try {
|
|
39
|
-
const content = readFileSync(filePath, 'utf8')
|
|
40
|
-
if (verboseLogs) {
|
|
41
|
-
payload.logger.info(`[payload-mcp] Successfully read collection: ${collectionName}`)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return {
|
|
45
|
-
content: [
|
|
46
|
-
{
|
|
47
|
-
type: 'text' as const,
|
|
48
|
-
text: `Collection: ${collectionName}
|
|
49
|
-
File: ${fileName}
|
|
50
|
-
---
|
|
51
|
-
${content}`,
|
|
52
|
-
},
|
|
53
|
-
],
|
|
54
|
-
}
|
|
55
|
-
} catch (_error) {
|
|
56
|
-
payload.logger.warn(`[payload-mcp] Collection not found: ${collectionName}`)
|
|
57
|
-
return {
|
|
58
|
-
content: [
|
|
59
|
-
{
|
|
60
|
-
type: 'text' as const,
|
|
61
|
-
text: `Error: Collection '${collectionName}' not found`,
|
|
62
|
-
},
|
|
63
|
-
],
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Read all Collections
|
|
69
|
-
const files = readdirSync(collectionsDirPath)
|
|
70
|
-
.filter((file) => extname(file) === '.ts')
|
|
71
|
-
.sort()
|
|
72
|
-
|
|
73
|
-
if (verboseLogs) {
|
|
74
|
-
payload.logger.info(`[payload-mcp] Found ${files.length} collection files in directory`)
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (files.length === 0) {
|
|
78
|
-
payload.logger.warn('[payload-mcp] No collection files found in src/collections directory')
|
|
79
|
-
return {
|
|
80
|
-
content: [
|
|
81
|
-
{
|
|
82
|
-
type: 'text' as const,
|
|
83
|
-
text: 'No collection files found in src/collections directory',
|
|
84
|
-
},
|
|
85
|
-
],
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const results = []
|
|
90
|
-
|
|
91
|
-
// Build complete table as a single markdown string
|
|
92
|
-
let tableContent = `Found ${files.length} collection file(s):\n\n`
|
|
93
|
-
|
|
94
|
-
// Build table header
|
|
95
|
-
let tableHeader = '| Collection | File | Size | Modified'
|
|
96
|
-
let tableSeparator = '|------------|------|------|----------'
|
|
97
|
-
|
|
98
|
-
if (includeCount) {
|
|
99
|
-
tableHeader += ' | Documents'
|
|
100
|
-
tableSeparator += ' |----------'
|
|
101
|
-
}
|
|
102
|
-
tableHeader += ' |'
|
|
103
|
-
tableSeparator += ' |'
|
|
104
|
-
|
|
105
|
-
tableContent += tableHeader + '\n'
|
|
106
|
-
tableContent += tableSeparator + '\n'
|
|
107
|
-
|
|
108
|
-
for (const file of files) {
|
|
109
|
-
const filePath = join(collectionsDirPath, file)
|
|
110
|
-
const stats = statSync(filePath)
|
|
111
|
-
const fileSize = stats.size
|
|
112
|
-
const lastModified = stats.mtime
|
|
113
|
-
|
|
114
|
-
const collectionName = file.replace('.ts', '')
|
|
115
|
-
|
|
116
|
-
// Build table row
|
|
117
|
-
let tableRow = `| **${collectionName}** | ${file} | ${fileSize.toLocaleString()} bytes | ${lastModified.toISOString()}`
|
|
118
|
-
|
|
119
|
-
// Add document count if requested
|
|
120
|
-
if (includeCount) {
|
|
121
|
-
try {
|
|
122
|
-
// For now, we'll skip document counting since we don't have access to payload instance
|
|
123
|
-
tableRow += ' | -'
|
|
124
|
-
} catch (error) {
|
|
125
|
-
tableRow += ` | Error: ${(error as Error).message}`
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
tableRow += ' |'
|
|
129
|
-
|
|
130
|
-
tableContent += tableRow + '\n'
|
|
131
|
-
|
|
132
|
-
if (includeContent) {
|
|
133
|
-
try {
|
|
134
|
-
const content = readFileSync(filePath, 'utf8')
|
|
135
|
-
tableContent += `\n**${collectionName} Content:**\n\`\`\`typescript\n${content}\n\`\`\`\n\n`
|
|
136
|
-
} catch (error) {
|
|
137
|
-
tableContent += `\nError reading content: ${(error as Error).message}\n\n`
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
results.push({
|
|
143
|
-
type: 'text' as const,
|
|
144
|
-
text: tableContent,
|
|
145
|
-
})
|
|
146
|
-
|
|
147
|
-
return {
|
|
148
|
-
content: results,
|
|
149
|
-
}
|
|
150
|
-
} catch (error) {
|
|
151
|
-
const errorMessage = (error as Error).message
|
|
152
|
-
payload.logger.error(`[payload-mcp] Error reading collections: ${errorMessage}`)
|
|
153
|
-
return {
|
|
154
|
-
content: [
|
|
155
|
-
{
|
|
156
|
-
type: 'text' as const,
|
|
157
|
-
text: `❌ **Error reading collections**: ${errorMessage}`,
|
|
158
|
-
},
|
|
159
|
-
],
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// MCP Server tool registration
|
|
165
|
-
export const findCollectionTool = (
|
|
166
|
-
server: McpServer,
|
|
167
|
-
req: PayloadRequest,
|
|
168
|
-
verboseLogs: boolean,
|
|
169
|
-
collectionsDirPath: string,
|
|
170
|
-
) => {
|
|
171
|
-
const tool = (
|
|
172
|
-
collectionName?: string,
|
|
173
|
-
includeContent: boolean = false,
|
|
174
|
-
includeCount: boolean = false,
|
|
175
|
-
) => {
|
|
176
|
-
const payload = req.payload
|
|
177
|
-
|
|
178
|
-
if (verboseLogs) {
|
|
179
|
-
payload.logger.info(
|
|
180
|
-
`[payload-mcp] Finding collections${collectionName ? ` for: ${collectionName}` : ''}, includeContent: ${includeContent}, includeCount: ${includeCount}`,
|
|
181
|
-
)
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
try {
|
|
185
|
-
const result = readCollections(
|
|
186
|
-
req,
|
|
187
|
-
verboseLogs,
|
|
188
|
-
collectionsDirPath,
|
|
189
|
-
collectionName,
|
|
190
|
-
includeContent,
|
|
191
|
-
includeCount,
|
|
192
|
-
)
|
|
193
|
-
|
|
194
|
-
if (verboseLogs) {
|
|
195
|
-
payload.logger.info(`[payload-mcp] Collection search completed`)
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
return result
|
|
199
|
-
} catch (error) {
|
|
200
|
-
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
201
|
-
payload.logger.error(`[payload-mcp] Error finding collections: ${errorMessage}`)
|
|
202
|
-
|
|
203
|
-
return {
|
|
204
|
-
content: [
|
|
205
|
-
{
|
|
206
|
-
type: 'text' as const,
|
|
207
|
-
text: `Error finding collections: ${errorMessage}`,
|
|
208
|
-
},
|
|
209
|
-
],
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
server.registerTool(
|
|
215
|
-
'findCollections',
|
|
216
|
-
{
|
|
217
|
-
description: toolSchemas.findCollections.description,
|
|
218
|
-
inputSchema: toolSchemas.findCollections.parameters.shape,
|
|
219
|
-
},
|
|
220
|
-
({ collectionName, includeContent, includeCount }) => {
|
|
221
|
-
return tool(collectionName, includeContent, includeCount)
|
|
222
|
-
},
|
|
223
|
-
)
|
|
224
|
-
}
|
|
@@ -1,290 +0,0 @@
|
|
|
1
|
-
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
2
|
-
import type { PayloadRequest } from 'payload'
|
|
3
|
-
|
|
4
|
-
import { readFileSync, writeFileSync } from 'fs'
|
|
5
|
-
import { join } from 'path'
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
addFieldsToCollection,
|
|
9
|
-
modifyFieldsInCollection,
|
|
10
|
-
removeFieldsFromCollection,
|
|
11
|
-
} from '../../helpers/fields.js'
|
|
12
|
-
import { validateCollectionFile } from '../../helpers/fileValidation.js'
|
|
13
|
-
import { toolSchemas } from '../schemas.js'
|
|
14
|
-
|
|
15
|
-
export const updateCollection = async (
|
|
16
|
-
req: PayloadRequest,
|
|
17
|
-
verboseLogs: boolean,
|
|
18
|
-
collectionsDirPath: string,
|
|
19
|
-
configFilePath: string,
|
|
20
|
-
collectionName: string,
|
|
21
|
-
updateType: string,
|
|
22
|
-
newFields?: any[],
|
|
23
|
-
fieldNamesToRemove?: string[],
|
|
24
|
-
fieldModifications?: any[],
|
|
25
|
-
configUpdates?: any,
|
|
26
|
-
newContent?: string,
|
|
27
|
-
) => {
|
|
28
|
-
const payload = req.payload
|
|
29
|
-
if (verboseLogs) {
|
|
30
|
-
payload.logger.info(
|
|
31
|
-
`[payload-mcp] Updating collection: ${collectionName}, updateType: ${updateType}`,
|
|
32
|
-
)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const capitalizedName = collectionName.charAt(0).toUpperCase() + collectionName.slice(1)
|
|
36
|
-
const fileName = `${capitalizedName}.ts`
|
|
37
|
-
const filePath = join(collectionsDirPath, fileName)
|
|
38
|
-
|
|
39
|
-
// Security check: ensure we're working with the collections directory
|
|
40
|
-
if (!filePath.startsWith(collectionsDirPath)) {
|
|
41
|
-
payload.logger.error(`[payload-mcp] Invalid collection path attempted: ${filePath}`)
|
|
42
|
-
return {
|
|
43
|
-
content: [
|
|
44
|
-
{
|
|
45
|
-
type: 'text' as const,
|
|
46
|
-
text: '❌ **Error**: Invalid collection path',
|
|
47
|
-
},
|
|
48
|
-
],
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
try {
|
|
53
|
-
// Check if collection file exists
|
|
54
|
-
let currentContent: string
|
|
55
|
-
try {
|
|
56
|
-
currentContent = readFileSync(filePath, 'utf8')
|
|
57
|
-
} catch (_ignore) {
|
|
58
|
-
return {
|
|
59
|
-
content: [
|
|
60
|
-
{
|
|
61
|
-
type: 'text' as const,
|
|
62
|
-
text: `❌ **Error**: Collection file not found: ${fileName}`,
|
|
63
|
-
},
|
|
64
|
-
],
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
let updatedContent: string
|
|
69
|
-
let updateSummary: string[] = []
|
|
70
|
-
|
|
71
|
-
switch (updateType) {
|
|
72
|
-
case 'add_field':
|
|
73
|
-
if (!newFields || newFields.length === 0) {
|
|
74
|
-
return {
|
|
75
|
-
content: [
|
|
76
|
-
{
|
|
77
|
-
type: 'text' as const,
|
|
78
|
-
text: '❌ **Error**: No fields provided for add_field update type',
|
|
79
|
-
},
|
|
80
|
-
],
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
updatedContent = addFieldsToCollection(currentContent, newFields)
|
|
84
|
-
updateSummary = newFields.map((field: any) => `Added field: ${field.name} (${field.type})`)
|
|
85
|
-
break
|
|
86
|
-
|
|
87
|
-
case 'modify_field':
|
|
88
|
-
if (!fieldModifications || fieldModifications.length === 0) {
|
|
89
|
-
return {
|
|
90
|
-
content: [
|
|
91
|
-
{
|
|
92
|
-
type: 'text' as const,
|
|
93
|
-
text: '❌ **Error**: No field modifications provided for modify_field update type',
|
|
94
|
-
},
|
|
95
|
-
],
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
updatedContent = modifyFieldsInCollection(currentContent, fieldModifications)
|
|
99
|
-
updateSummary = fieldModifications.map((mod: any) => `Modified field: ${mod.fieldName}`)
|
|
100
|
-
break
|
|
101
|
-
|
|
102
|
-
case 'remove_field':
|
|
103
|
-
if (!fieldNamesToRemove || fieldNamesToRemove.length === 0) {
|
|
104
|
-
return {
|
|
105
|
-
content: [
|
|
106
|
-
{
|
|
107
|
-
type: 'text' as const,
|
|
108
|
-
text: '❌ **Error**: No field names provided for remove_field update type',
|
|
109
|
-
},
|
|
110
|
-
],
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
updatedContent = removeFieldsFromCollection(currentContent, fieldNamesToRemove)
|
|
114
|
-
updateSummary = fieldNamesToRemove.map((fieldName: string) => `Removed field: ${fieldName}`)
|
|
115
|
-
break
|
|
116
|
-
|
|
117
|
-
case 'replace_content':
|
|
118
|
-
if (!newContent) {
|
|
119
|
-
return {
|
|
120
|
-
content: [
|
|
121
|
-
{
|
|
122
|
-
type: 'text' as const,
|
|
123
|
-
text: '❌ **Error**: No new content provided for replace_content update type',
|
|
124
|
-
},
|
|
125
|
-
],
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
updatedContent = newContent
|
|
129
|
-
updateSummary = ['Replaced entire collection content']
|
|
130
|
-
break
|
|
131
|
-
|
|
132
|
-
case 'update_config':
|
|
133
|
-
if (!configUpdates) {
|
|
134
|
-
return {
|
|
135
|
-
content: [
|
|
136
|
-
{
|
|
137
|
-
type: 'text' as const,
|
|
138
|
-
text: '❌ **Error**: No config updates provided for update_config update type',
|
|
139
|
-
},
|
|
140
|
-
],
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
// For now, we'll use a simple approach since the config helper might not have this functionality
|
|
144
|
-
updatedContent = currentContent
|
|
145
|
-
updateSummary = Object.keys(configUpdates).map((key) => `Updated config: ${key}`)
|
|
146
|
-
break
|
|
147
|
-
|
|
148
|
-
default:
|
|
149
|
-
return {
|
|
150
|
-
content: [
|
|
151
|
-
{
|
|
152
|
-
type: 'text' as const,
|
|
153
|
-
text: `❌ **Error**: Unknown update type: ${updateType}`,
|
|
154
|
-
},
|
|
155
|
-
],
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// Write the updated content back to the file
|
|
160
|
-
writeFileSync(filePath, updatedContent, 'utf8')
|
|
161
|
-
if (verboseLogs) {
|
|
162
|
-
payload.logger.info(`[payload-mcp] Successfully updated collection file: ${filePath}`)
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// Validate the updated file
|
|
166
|
-
const validationResult = await validateCollectionFile(fileName)
|
|
167
|
-
if (validationResult.error) {
|
|
168
|
-
return {
|
|
169
|
-
content: [
|
|
170
|
-
{
|
|
171
|
-
type: 'text' as const,
|
|
172
|
-
text: `❌ **Error**: Updated collection has validation issues:\n\n${validationResult.error}`,
|
|
173
|
-
},
|
|
174
|
-
],
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
return {
|
|
179
|
-
content: [
|
|
180
|
-
{
|
|
181
|
-
type: 'text' as const,
|
|
182
|
-
text: `✅ **Collection updated successfully!**
|
|
183
|
-
|
|
184
|
-
**File**: \`${fileName}\`
|
|
185
|
-
**Update Type**: ${updateType}
|
|
186
|
-
|
|
187
|
-
**Changes Made**:
|
|
188
|
-
${updateSummary.map((summary) => `- ${summary}`).join('\n')}
|
|
189
|
-
|
|
190
|
-
**Updated Collection Code:**
|
|
191
|
-
\`\`\`typescript
|
|
192
|
-
${updatedContent}
|
|
193
|
-
\`\`\``,
|
|
194
|
-
},
|
|
195
|
-
],
|
|
196
|
-
}
|
|
197
|
-
} catch (error) {
|
|
198
|
-
const errorMessage = (error as Error).message
|
|
199
|
-
payload.logger.error(`[payload-mcp] Error updating collection: ${errorMessage}`)
|
|
200
|
-
return {
|
|
201
|
-
content: [
|
|
202
|
-
{
|
|
203
|
-
type: 'text' as const,
|
|
204
|
-
text: `❌ **Error updating collection**: ${errorMessage}`,
|
|
205
|
-
},
|
|
206
|
-
],
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
export const updateCollectionTool = (
|
|
212
|
-
server: McpServer,
|
|
213
|
-
req: PayloadRequest,
|
|
214
|
-
verboseLogs: boolean,
|
|
215
|
-
collectionsDirPath: string,
|
|
216
|
-
configFilePath: string,
|
|
217
|
-
) => {
|
|
218
|
-
const tool = async ({
|
|
219
|
-
collectionName,
|
|
220
|
-
configUpdates,
|
|
221
|
-
fieldModifications,
|
|
222
|
-
fieldNamesToRemove,
|
|
223
|
-
newContent,
|
|
224
|
-
newFields,
|
|
225
|
-
updateType,
|
|
226
|
-
}: {
|
|
227
|
-
collectionName: string
|
|
228
|
-
configUpdates?: any
|
|
229
|
-
fieldModifications?: any[]
|
|
230
|
-
fieldNamesToRemove?: string[]
|
|
231
|
-
newContent?: string
|
|
232
|
-
newFields?: any[]
|
|
233
|
-
updateType: string
|
|
234
|
-
}) => {
|
|
235
|
-
const payload = req.payload
|
|
236
|
-
|
|
237
|
-
if (verboseLogs) {
|
|
238
|
-
payload.logger.info(
|
|
239
|
-
`[payload-mcp] Updating collection: ${collectionName}, updateType: ${updateType}`,
|
|
240
|
-
)
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
try {
|
|
244
|
-
const result = await updateCollection(
|
|
245
|
-
req,
|
|
246
|
-
verboseLogs,
|
|
247
|
-
collectionsDirPath,
|
|
248
|
-
configFilePath,
|
|
249
|
-
collectionName,
|
|
250
|
-
updateType,
|
|
251
|
-
newFields,
|
|
252
|
-
fieldNamesToRemove,
|
|
253
|
-
fieldModifications,
|
|
254
|
-
configUpdates,
|
|
255
|
-
newContent,
|
|
256
|
-
)
|
|
257
|
-
|
|
258
|
-
if (verboseLogs) {
|
|
259
|
-
payload.logger.info(`[payload-mcp] Collection update completed for: ${collectionName}`)
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
return result
|
|
263
|
-
} catch (error) {
|
|
264
|
-
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
265
|
-
payload.logger.error(
|
|
266
|
-
`[payload-mcp] Error updating collection ${collectionName}: ${errorMessage}`,
|
|
267
|
-
)
|
|
268
|
-
|
|
269
|
-
return {
|
|
270
|
-
content: [
|
|
271
|
-
{
|
|
272
|
-
type: 'text' as const,
|
|
273
|
-
text: `Error updating collection "${collectionName}": ${errorMessage}`,
|
|
274
|
-
},
|
|
275
|
-
],
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
server.registerTool(
|
|
281
|
-
'updateCollection',
|
|
282
|
-
{
|
|
283
|
-
description: toolSchemas.updateCollection.description,
|
|
284
|
-
inputSchema: toolSchemas.updateCollection.parameters.shape,
|
|
285
|
-
},
|
|
286
|
-
async (args) => {
|
|
287
|
-
return await tool(args)
|
|
288
|
-
},
|
|
289
|
-
)
|
|
290
|
-
}
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
|
2
|
-
import type { PayloadRequest } from 'payload'
|
|
3
|
-
|
|
4
|
-
import { readFileSync, statSync } from 'fs'
|
|
5
|
-
|
|
6
|
-
import { toolSchemas } from '../schemas.js'
|
|
7
|
-
|
|
8
|
-
export const readConfigFile = (
|
|
9
|
-
req: PayloadRequest,
|
|
10
|
-
verboseLogs: boolean,
|
|
11
|
-
configFilePath: string,
|
|
12
|
-
includeMetadata: boolean = false,
|
|
13
|
-
) => {
|
|
14
|
-
const payload = req.payload
|
|
15
|
-
if (verboseLogs) {
|
|
16
|
-
payload.logger.info(`[payload-mcp] Reading config file, includeMetadata: ${includeMetadata}`)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
try {
|
|
20
|
-
// Security check: ensure we're working with the specified config file
|
|
21
|
-
if (!configFilePath.startsWith(process.cwd()) && !configFilePath.startsWith('/')) {
|
|
22
|
-
payload.logger.error(`[payload-mcp] Invalid config path attempted: ${configFilePath}`)
|
|
23
|
-
return {
|
|
24
|
-
content: [
|
|
25
|
-
{
|
|
26
|
-
type: 'text' as const,
|
|
27
|
-
text: '❌ **Error**: Invalid config path',
|
|
28
|
-
},
|
|
29
|
-
],
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const content = readFileSync(configFilePath, 'utf8')
|
|
34
|
-
const stats = statSync(configFilePath)
|
|
35
|
-
|
|
36
|
-
if (verboseLogs) {
|
|
37
|
-
payload.logger.info(`[payload-mcp] Successfully read config file. Size: ${stats.size} bytes`)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
let responseText = `# Payload Configuration
|
|
41
|
-
|
|
42
|
-
**File**: \`${configFilePath}\``
|
|
43
|
-
|
|
44
|
-
if (includeMetadata) {
|
|
45
|
-
responseText += `
|
|
46
|
-
**Size**: ${stats.size.toLocaleString()} bytes
|
|
47
|
-
**Modified**: ${stats.mtime.toISOString()}
|
|
48
|
-
**Created**: ${stats.birthtime.toISOString()}`
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
responseText += `
|
|
52
|
-
---
|
|
53
|
-
|
|
54
|
-
**Configuration Content:**
|
|
55
|
-
\`\`\`typescript
|
|
56
|
-
${content}
|
|
57
|
-
\`\`\``
|
|
58
|
-
|
|
59
|
-
return {
|
|
60
|
-
content: [
|
|
61
|
-
{
|
|
62
|
-
type: 'text' as const,
|
|
63
|
-
text: responseText,
|
|
64
|
-
},
|
|
65
|
-
],
|
|
66
|
-
}
|
|
67
|
-
} catch (error) {
|
|
68
|
-
const errorMessage = (error as Error).message
|
|
69
|
-
payload.logger.error(`[payload-mcp] Error reading config file: ${errorMessage}`)
|
|
70
|
-
return {
|
|
71
|
-
content: [
|
|
72
|
-
{
|
|
73
|
-
type: 'text' as const,
|
|
74
|
-
text: `❌ **Error reading config file**: ${errorMessage}`,
|
|
75
|
-
},
|
|
76
|
-
],
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// MCP Server tool registration
|
|
82
|
-
export const findConfigTool = (
|
|
83
|
-
server: McpServer,
|
|
84
|
-
req: PayloadRequest,
|
|
85
|
-
verboseLogs: boolean,
|
|
86
|
-
configFilePath: string,
|
|
87
|
-
) => {
|
|
88
|
-
const tool = (includeMetadata: boolean = false) => {
|
|
89
|
-
const payload = req.payload
|
|
90
|
-
|
|
91
|
-
if (verboseLogs) {
|
|
92
|
-
payload.logger.info(`[payload-mcp] Finding config, includeMetadata: ${includeMetadata}`)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
try {
|
|
96
|
-
const result = readConfigFile(req, verboseLogs, configFilePath, includeMetadata)
|
|
97
|
-
|
|
98
|
-
if (verboseLogs) {
|
|
99
|
-
payload.logger.info(`[payload-mcp] Config search completed`)
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return result
|
|
103
|
-
} catch (error) {
|
|
104
|
-
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
105
|
-
payload.logger.error(`[payload-mcp] Error finding config: ${errorMessage}`)
|
|
106
|
-
|
|
107
|
-
return {
|
|
108
|
-
content: [
|
|
109
|
-
{
|
|
110
|
-
type: 'text' as const,
|
|
111
|
-
text: `Error finding config: ${errorMessage}`,
|
|
112
|
-
},
|
|
113
|
-
],
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
server.registerTool(
|
|
119
|
-
'findConfig',
|
|
120
|
-
{
|
|
121
|
-
description: toolSchemas.findConfig.description,
|
|
122
|
-
inputSchema: toolSchemas.findConfig.parameters.shape,
|
|
123
|
-
},
|
|
124
|
-
({ includeMetadata }) => {
|
|
125
|
-
return tool(includeMetadata)
|
|
126
|
-
},
|
|
127
|
-
)
|
|
128
|
-
}
|