@payloadcms/plugin-mcp 0.0.1-alpha.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.
Files changed (173) hide show
  1. package/LICENSE.md +22 -0
  2. package/README.md +7 -0
  3. package/dist/collections/createApiKeysCollection.d.ts +7 -0
  4. package/dist/collections/createApiKeysCollection.d.ts.map +1 -0
  5. package/dist/collections/createApiKeysCollection.js +315 -0
  6. package/dist/collections/createApiKeysCollection.js.map +1 -0
  7. package/dist/endpoints/mcp.d.ts +4 -0
  8. package/dist/endpoints/mcp.d.ts.map +1 -0
  9. package/dist/endpoints/mcp.js +44 -0
  10. package/dist/endpoints/mcp.js.map +1 -0
  11. package/dist/index.d.ts +10 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +67 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/mcp/createRequest.d.ts +3 -0
  16. package/dist/mcp/createRequest.d.ts.map +1 -0
  17. package/dist/mcp/createRequest.js +14 -0
  18. package/dist/mcp/createRequest.js.map +1 -0
  19. package/dist/mcp/getMcpHandler.d.ts +4 -0
  20. package/dist/mcp/getMcpHandler.d.ts.map +1 -0
  21. package/dist/mcp/getMcpHandler.js +179 -0
  22. package/dist/mcp/getMcpHandler.js.map +1 -0
  23. package/dist/mcp/helpers/config.d.ts +30 -0
  24. package/dist/mcp/helpers/config.d.ts.map +1 -0
  25. package/dist/mcp/helpers/config.js +217 -0
  26. package/dist/mcp/helpers/config.js.map +1 -0
  27. package/dist/mcp/helpers/conversion.d.ts +2 -0
  28. package/dist/mcp/helpers/conversion.d.ts.map +1 -0
  29. package/dist/mcp/helpers/conversion.js +5 -0
  30. package/dist/mcp/helpers/conversion.js.map +1 -0
  31. package/dist/mcp/helpers/fields.d.ts +38 -0
  32. package/dist/mcp/helpers/fields.d.ts.map +1 -0
  33. package/dist/mcp/helpers/fields.js +96 -0
  34. package/dist/mcp/helpers/fields.js.map +1 -0
  35. package/dist/mcp/helpers/fileValidation.d.ts +69 -0
  36. package/dist/mcp/helpers/fileValidation.d.ts.map +1 -0
  37. package/dist/mcp/helpers/fileValidation.js +305 -0
  38. package/dist/mcp/helpers/fileValidation.js.map +1 -0
  39. package/dist/mcp/helpers/validation.d.ts +9 -0
  40. package/dist/mcp/helpers/validation.d.ts.map +1 -0
  41. package/dist/mcp/helpers/validation.js +22 -0
  42. package/dist/mcp/helpers/validation.js.map +1 -0
  43. package/dist/mcp/registerTool.d.ts +6 -0
  44. package/dist/mcp/registerTool.d.ts.map +1 -0
  45. package/dist/mcp/registerTool.js +18 -0
  46. package/dist/mcp/registerTool.js.map +1 -0
  47. package/dist/mcp/tools/auth/auth.d.ts +4 -0
  48. package/dist/mcp/tools/auth/auth.d.ts.map +1 -0
  49. package/dist/mcp/tools/auth/auth.js +54 -0
  50. package/dist/mcp/tools/auth/auth.js.map +1 -0
  51. package/dist/mcp/tools/auth/forgotPassword.d.ts +4 -0
  52. package/dist/mcp/tools/auth/forgotPassword.d.ts.map +1 -0
  53. package/dist/mcp/tools/auth/forgotPassword.js +45 -0
  54. package/dist/mcp/tools/auth/forgotPassword.js.map +1 -0
  55. package/dist/mcp/tools/auth/login.d.ts +4 -0
  56. package/dist/mcp/tools/auth/login.d.ts.map +1 -0
  57. package/dist/mcp/tools/auth/login.js +48 -0
  58. package/dist/mcp/tools/auth/login.js.map +1 -0
  59. package/dist/mcp/tools/auth/resetPassword.d.ts +4 -0
  60. package/dist/mcp/tools/auth/resetPassword.d.ts.map +1 -0
  61. package/dist/mcp/tools/auth/resetPassword.js +46 -0
  62. package/dist/mcp/tools/auth/resetPassword.js.map +1 -0
  63. package/dist/mcp/tools/auth/unlock.d.ts +4 -0
  64. package/dist/mcp/tools/auth/unlock.d.ts.map +1 -0
  65. package/dist/mcp/tools/auth/unlock.js +45 -0
  66. package/dist/mcp/tools/auth/unlock.js.map +1 -0
  67. package/dist/mcp/tools/auth/verify.d.ts +4 -0
  68. package/dist/mcp/tools/auth/verify.d.ts.map +1 -0
  69. package/dist/mcp/tools/auth/verify.js +42 -0
  70. package/dist/mcp/tools/auth/verify.js.map +1 -0
  71. package/dist/mcp/tools/collection/create.d.ts +10 -0
  72. package/dist/mcp/tools/collection/create.d.ts.map +1 -0
  73. package/dist/mcp/tools/collection/create.js +159 -0
  74. package/dist/mcp/tools/collection/create.js.map +1 -0
  75. package/dist/mcp/tools/collection/delete.d.ts +10 -0
  76. package/dist/mcp/tools/collection/delete.d.ts.map +1 -0
  77. package/dist/mcp/tools/collection/delete.js +162 -0
  78. package/dist/mcp/tools/collection/delete.js.map +1 -0
  79. package/dist/mcp/tools/collection/find.d.ts +10 -0
  80. package/dist/mcp/tools/collection/find.d.ts.map +1 -0
  81. package/dist/mcp/tools/collection/find.js +162 -0
  82. package/dist/mcp/tools/collection/find.js.map +1 -0
  83. package/dist/mcp/tools/collection/update.d.ts +10 -0
  84. package/dist/mcp/tools/collection/update.d.ts.map +1 -0
  85. package/dist/mcp/tools/collection/update.js +206 -0
  86. package/dist/mcp/tools/collection/update.js.map +1 -0
  87. package/dist/mcp/tools/config/find.d.ts +10 -0
  88. package/dist/mcp/tools/config/find.d.ts.map +1 -0
  89. package/dist/mcp/tools/config/find.js +94 -0
  90. package/dist/mcp/tools/config/find.js.map +1 -0
  91. package/dist/mcp/tools/config/update.d.ts +10 -0
  92. package/dist/mcp/tools/config/update.d.ts.map +1 -0
  93. package/dist/mcp/tools/config/update.js +212 -0
  94. package/dist/mcp/tools/config/update.js.map +1 -0
  95. package/dist/mcp/tools/job/create.d.ts +10 -0
  96. package/dist/mcp/tools/job/create.d.ts.map +1 -0
  97. package/dist/mcp/tools/job/create.js +293 -0
  98. package/dist/mcp/tools/job/create.js.map +1 -0
  99. package/dist/mcp/tools/job/run.d.ts +10 -0
  100. package/dist/mcp/tools/job/run.d.ts.map +1 -0
  101. package/dist/mcp/tools/job/run.js +147 -0
  102. package/dist/mcp/tools/job/run.js.map +1 -0
  103. package/dist/mcp/tools/job/update.d.ts +11 -0
  104. package/dist/mcp/tools/job/update.d.ts.map +1 -0
  105. package/dist/mcp/tools/job/update.js +211 -0
  106. package/dist/mcp/tools/job/update.js.map +1 -0
  107. package/dist/mcp/tools/resource/create.d.ts +6 -0
  108. package/dist/mcp/tools/resource/create.d.ts.map +1 -0
  109. package/dist/mcp/tools/resource/create.js +75 -0
  110. package/dist/mcp/tools/resource/create.js.map +1 -0
  111. package/dist/mcp/tools/resource/delete.d.ts +5 -0
  112. package/dist/mcp/tools/resource/delete.d.ts.map +1 -0
  113. package/dist/mcp/tools/resource/delete.js +140 -0
  114. package/dist/mcp/tools/resource/delete.js.map +1 -0
  115. package/dist/mcp/tools/resource/find.d.ts +5 -0
  116. package/dist/mcp/tools/resource/find.d.ts.map +1 -0
  117. package/dist/mcp/tools/resource/find.js +119 -0
  118. package/dist/mcp/tools/resource/find.js.map +1 -0
  119. package/dist/mcp/tools/resource/update.d.ts +6 -0
  120. package/dist/mcp/tools/resource/update.d.ts.map +1 -0
  121. package/dist/mcp/tools/resource/update.js +201 -0
  122. package/dist/mcp/tools/resource/update.js.map +1 -0
  123. package/dist/mcp/tools/schemas.d.ts +374 -0
  124. package/dist/mcp/tools/schemas.d.ts.map +1 -0
  125. package/dist/mcp/tools/schemas.js +201 -0
  126. package/dist/mcp/tools/schemas.js.map +1 -0
  127. package/dist/types.d.ts +379 -0
  128. package/dist/types.d.ts.map +1 -0
  129. package/dist/types.js +3 -0
  130. package/dist/types.js.map +1 -0
  131. package/dist/utils/camelCase.d.ts +9 -0
  132. package/dist/utils/camelCase.d.ts.map +1 -0
  133. package/dist/utils/camelCase.js +11 -0
  134. package/dist/utils/camelCase.js.map +1 -0
  135. package/dist/utils/convertCollectionSchemaToZod.d.ts +3 -0
  136. package/dist/utils/convertCollectionSchemaToZod.d.ts.map +1 -0
  137. package/dist/utils/convertCollectionSchemaToZod.js +30 -0
  138. package/dist/utils/convertCollectionSchemaToZod.js.map +1 -0
  139. package/package.json +64 -0
  140. package/src/collections/createApiKeysCollection.ts +393 -0
  141. package/src/endpoints/mcp.ts +60 -0
  142. package/src/index.ts +86 -0
  143. package/src/mcp/createRequest.ts +13 -0
  144. package/src/mcp/getMcpHandler.ts +433 -0
  145. package/src/mcp/helpers/config.ts +326 -0
  146. package/src/mcp/helpers/conversion.ts +3 -0
  147. package/src/mcp/helpers/fields.ts +158 -0
  148. package/src/mcp/helpers/fileValidation.ts +417 -0
  149. package/src/mcp/helpers/validation.ts +32 -0
  150. package/src/mcp/registerTool.ts +22 -0
  151. package/src/mcp/tools/auth/auth.ts +69 -0
  152. package/src/mcp/tools/auth/forgotPassword.ts +68 -0
  153. package/src/mcp/tools/auth/login.ts +70 -0
  154. package/src/mcp/tools/auth/resetPassword.ts +59 -0
  155. package/src/mcp/tools/auth/unlock.ts +62 -0
  156. package/src/mcp/tools/auth/verify.ts +55 -0
  157. package/src/mcp/tools/collection/create.ts +236 -0
  158. package/src/mcp/tools/collection/delete.ts +227 -0
  159. package/src/mcp/tools/collection/find.ts +222 -0
  160. package/src/mcp/tools/collection/update.ts +288 -0
  161. package/src/mcp/tools/config/find.ts +126 -0
  162. package/src/mcp/tools/config/update.ts +282 -0
  163. package/src/mcp/tools/job/create.ts +420 -0
  164. package/src/mcp/tools/job/run.ts +189 -0
  165. package/src/mcp/tools/job/update.ts +319 -0
  166. package/src/mcp/tools/resource/create.ts +121 -0
  167. package/src/mcp/tools/resource/delete.ts +210 -0
  168. package/src/mcp/tools/resource/find.ts +194 -0
  169. package/src/mcp/tools/resource/update.ts +314 -0
  170. package/src/mcp/tools/schemas.ts +373 -0
  171. package/src/types.ts +405 -0
  172. package/src/utils/camelCase.ts +12 -0
  173. package/src/utils/convertCollectionSchemaToZod.ts +35 -0
@@ -0,0 +1,179 @@
1
+ import { createMcpHandler } from '@vercel/mcp-adapter';
2
+ import { join } from 'path';
3
+ import { APIError, configToJSONSchema } from 'payload';
4
+ import { toCamelCase } from '../utils/camelCase.js';
5
+ import { registerTool } from './registerTool.js';
6
+ // Tools
7
+ import { createResourceTool } from './tools/resource/create.js';
8
+ import { deleteResourceTool } from './tools/resource/delete.js';
9
+ import { findResourceTool } from './tools/resource/find.js';
10
+ import { updateResourceTool } from './tools/resource/update.js';
11
+ // Experimental Tools
12
+ import { authTool } from './tools/auth/auth.js';
13
+ import { forgotPasswordTool } from './tools/auth/forgotPassword.js';
14
+ import { loginTool } from './tools/auth/login.js';
15
+ import { resetPasswordTool } from './tools/auth/resetPassword.js';
16
+ import { unlockTool } from './tools/auth/unlock.js';
17
+ import { verifyTool } from './tools/auth/verify.js';
18
+ import { createCollectionTool } from './tools/collection/create.js';
19
+ import { deleteCollectionTool } from './tools/collection/delete.js';
20
+ import { findCollectionTool } from './tools/collection/find.js';
21
+ import { updateCollectionTool } from './tools/collection/update.js';
22
+ import { findConfigTool } from './tools/config/find.js';
23
+ import { updateConfigTool } from './tools/config/update.js';
24
+ import { createJobTool } from './tools/job/create.js';
25
+ import { runJobTool } from './tools/job/run.js';
26
+ import { updateJobTool } from './tools/job/update.js';
27
+ export const getMCPHandler = (pluginOptions, toolSettings, req)=>{
28
+ const { payload } = req;
29
+ const configSchema = configToJSONSchema(payload.config);
30
+ // User
31
+ const user = toolSettings.user;
32
+ // MCP Server and Handler Options
33
+ const MCPOptions = pluginOptions.mcp || {};
34
+ const customMCPTools = MCPOptions.tools || [];
35
+ const customMCPPrompts = MCPOptions.prompts || [];
36
+ const customMCPResources = MCPOptions.resources || [];
37
+ const MCPHandlerOptions = MCPOptions.handlerOptions || {};
38
+ const serverOptions = MCPOptions.serverOptions || {};
39
+ const useVerboseLogs = MCPHandlerOptions.verboseLogs ?? false;
40
+ // Experimental MCP Tool Requirements
41
+ const isDevelopment = process.env.NODE_ENV === 'development';
42
+ const experimentalTools = pluginOptions?.experimental?.tools || {};
43
+ const collectionsPluginConfig = pluginOptions.collections || {};
44
+ const collectionsDirPath = experimentalTools && experimentalTools.collections?.collectionsDirPath ? experimentalTools.collections.collectionsDirPath : join(process.cwd(), 'src/collections');
45
+ const configFilePath = experimentalTools && experimentalTools.config?.configFilePath ? experimentalTools.config.configFilePath : join(process.cwd(), 'src/payload.config.ts');
46
+ const jobsDirPath = experimentalTools && experimentalTools.jobs?.jobsDirPath ? experimentalTools.jobs.jobsDirPath : join(process.cwd(), 'src/jobs');
47
+ try {
48
+ return createMcpHandler((server)=>{
49
+ const enabledCollectionSlugs = Object.keys(collectionsPluginConfig || {}).filter((collection)=>{
50
+ const fullyEnabled = typeof collectionsPluginConfig?.[collection]?.enabled === 'boolean' && collectionsPluginConfig?.[collection]?.enabled;
51
+ if (fullyEnabled) {
52
+ return true;
53
+ }
54
+ const partiallyEnabled = typeof collectionsPluginConfig?.[collection]?.enabled !== 'boolean' && (typeof collectionsPluginConfig?.[collection]?.enabled?.find === 'boolean' && collectionsPluginConfig?.[collection]?.enabled?.find === true || typeof collectionsPluginConfig?.[collection]?.enabled?.create === 'boolean' && collectionsPluginConfig?.[collection]?.enabled?.create === true || typeof collectionsPluginConfig?.[collection]?.enabled?.update === 'boolean' && collectionsPluginConfig?.[collection]?.enabled?.update === true || typeof collectionsPluginConfig?.[collection]?.enabled?.delete === 'boolean' && collectionsPluginConfig?.[collection]?.enabled?.delete === true);
55
+ if (partiallyEnabled) {
56
+ return true;
57
+ }
58
+ });
59
+ // Collection Operation Tools
60
+ enabledCollectionSlugs.forEach((enabledCollectionSlug)=>{
61
+ try {
62
+ const schema = configSchema.definitions?.[enabledCollectionSlug];
63
+ const toolCapabilities = toolSettings?.[`${toCamelCase(enabledCollectionSlug)}`];
64
+ const allowCreate = toolCapabilities['create'];
65
+ const allowUpdate = toolCapabilities['update'];
66
+ const allowFind = toolCapabilities['find'];
67
+ const allowDelete = toolCapabilities['delete'];
68
+ if (allowCreate) {
69
+ registerTool(allowCreate, `Create ${enabledCollectionSlug}`, ()=>createResourceTool(server, req, user, useVerboseLogs, enabledCollectionSlug, collectionsPluginConfig, schema), payload, useVerboseLogs);
70
+ }
71
+ if (allowUpdate) {
72
+ registerTool(allowUpdate, `Update ${enabledCollectionSlug}`, ()=>updateResourceTool(server, req, user, useVerboseLogs, enabledCollectionSlug, collectionsPluginConfig, schema), payload, useVerboseLogs);
73
+ }
74
+ if (allowFind) {
75
+ registerTool(allowFind, `Find ${enabledCollectionSlug}`, ()=>findResourceTool(server, req, user, useVerboseLogs, enabledCollectionSlug, collectionsPluginConfig), payload, useVerboseLogs);
76
+ }
77
+ if (allowDelete) {
78
+ registerTool(allowDelete, `Delete ${enabledCollectionSlug}`, ()=>deleteResourceTool(server, req, user, useVerboseLogs, enabledCollectionSlug, collectionsPluginConfig), payload, useVerboseLogs);
79
+ }
80
+ } catch (error) {
81
+ throw new APIError(`Error registering tools for collection ${enabledCollectionSlug}: ${String(error)}`, 500);
82
+ }
83
+ });
84
+ // Custom tools
85
+ customMCPTools.forEach((tool)=>{
86
+ const camelCasedToolName = toCamelCase(tool.name);
87
+ const isToolEnabled = toolSettings.custom?.[camelCasedToolName] ?? true;
88
+ registerTool(isToolEnabled, tool.name, ()=>server.tool(tool.name, tool.description, tool.parameters, tool.handler), payload, useVerboseLogs);
89
+ });
90
+ // Custom prompts
91
+ customMCPPrompts.forEach((prompt)=>{
92
+ server.registerPrompt(prompt.name, {
93
+ argsSchema: prompt.argsSchema,
94
+ description: prompt.description,
95
+ title: prompt.title
96
+ }, prompt.handler);
97
+ if (useVerboseLogs) {
98
+ payload.logger.info(`[payload-mcp] ✅ Prompt: ${prompt.title} Registered.`);
99
+ }
100
+ });
101
+ // Custom resources
102
+ customMCPResources.forEach((resource)=>{
103
+ server.registerResource(resource.name, // @ts-expect-error - Overload type is not working however -- ResourceTemplate OR String is a valid type
104
+ resource.uri, {
105
+ description: resource.description,
106
+ mimeType: resource.mimeType,
107
+ title: resource.title
108
+ }, resource.handler);
109
+ if (useVerboseLogs) {
110
+ payload.logger.info(`[payload-mcp] ✅ Resource: ${resource.title} Registered.`);
111
+ }
112
+ });
113
+ // Experimental - Collection Schema Modfication Tools
114
+ if (toolSettings.collections?.create && experimentalTools.collections?.enabled && isDevelopment) {
115
+ registerTool(toolSettings.collections.create, 'Create Collection', ()=>createCollectionTool(server, req, useVerboseLogs, collectionsDirPath, configFilePath), payload, useVerboseLogs);
116
+ }
117
+ if (toolSettings.collections?.delete && experimentalTools.collections?.enabled && isDevelopment) {
118
+ registerTool(toolSettings.collections.delete, 'Delete Collection', ()=>deleteCollectionTool(server, req, useVerboseLogs, collectionsDirPath, configFilePath), payload, useVerboseLogs);
119
+ }
120
+ if (toolSettings.collections?.find && experimentalTools.collections?.enabled && isDevelopment) {
121
+ registerTool(toolSettings.collections.find, 'Find Collection', ()=>findCollectionTool(server, req, useVerboseLogs, collectionsDirPath), payload, useVerboseLogs);
122
+ }
123
+ if (toolSettings.collections?.update && experimentalTools.collections?.enabled && isDevelopment) {
124
+ registerTool(toolSettings.collections.update, 'Update Collection', ()=>updateCollectionTool(server, req, useVerboseLogs, collectionsDirPath, configFilePath), payload, useVerboseLogs);
125
+ }
126
+ // Experimental - Payload Config Modification Tools
127
+ if (toolSettings.config?.find && experimentalTools.config?.enabled && isDevelopment) {
128
+ registerTool(toolSettings.config.find, 'Find Config', ()=>findConfigTool(server, req, useVerboseLogs, configFilePath), payload, useVerboseLogs);
129
+ }
130
+ if (toolSettings.config?.update && experimentalTools.config?.enabled && isDevelopment) {
131
+ registerTool(toolSettings.config.update, 'Update Config', ()=>updateConfigTool(server, req, useVerboseLogs, configFilePath), payload, useVerboseLogs);
132
+ }
133
+ // Experimental - Job Modification Tools
134
+ if (toolSettings.jobs?.create && experimentalTools.jobs?.enabled && isDevelopment) {
135
+ registerTool(toolSettings.jobs.create, 'Create Job', ()=>createJobTool(server, req, useVerboseLogs, jobsDirPath), payload, useVerboseLogs);
136
+ }
137
+ if (toolSettings.jobs?.update && experimentalTools.jobs?.enabled && isDevelopment) {
138
+ registerTool(toolSettings.jobs.update, 'Update Job', ()=>updateJobTool(server, req, useVerboseLogs, jobsDirPath), payload, useVerboseLogs);
139
+ }
140
+ if (toolSettings.jobs?.run && experimentalTools.jobs?.enabled && isDevelopment) {
141
+ registerTool(toolSettings.jobs.run, 'Run Job', ()=>runJobTool(server, req, useVerboseLogs), payload, useVerboseLogs);
142
+ }
143
+ // Experimental - Auth Modification Tools
144
+ if (toolSettings.auth?.auth && experimentalTools.auth?.enabled && isDevelopment) {
145
+ registerTool(toolSettings.auth.auth, 'Auth', ()=>authTool(server, req, useVerboseLogs), payload, useVerboseLogs);
146
+ }
147
+ if (toolSettings.auth?.login && experimentalTools.auth?.enabled && isDevelopment) {
148
+ registerTool(toolSettings.auth.login, 'Login', ()=>loginTool(server, req, useVerboseLogs), payload, useVerboseLogs);
149
+ }
150
+ if (toolSettings.auth?.verify && experimentalTools.auth?.enabled && isDevelopment) {
151
+ registerTool(toolSettings.auth.verify, 'Verify', ()=>verifyTool(server, req, useVerboseLogs), payload, useVerboseLogs);
152
+ }
153
+ if (toolSettings.auth?.resetPassword && experimentalTools.auth?.enabled) {
154
+ registerTool(toolSettings.auth.resetPassword, 'Reset Password', ()=>resetPasswordTool(server, req, useVerboseLogs), payload, useVerboseLogs);
155
+ }
156
+ if (toolSettings.auth?.forgotPassword && experimentalTools.auth?.enabled) {
157
+ registerTool(toolSettings.auth.forgotPassword, 'Forgot Password', ()=>forgotPasswordTool(server, req, useVerboseLogs), payload, useVerboseLogs);
158
+ }
159
+ if (toolSettings.auth?.unlock && experimentalTools.auth?.enabled) {
160
+ registerTool(toolSettings.auth.unlock, 'Unlock', ()=>unlockTool(server, req, useVerboseLogs), payload, useVerboseLogs);
161
+ }
162
+ if (useVerboseLogs) {
163
+ payload.logger.info('[payload-mcp] 🚀 MCP Server Ready.');
164
+ }
165
+ }, {
166
+ serverInfo: serverOptions.serverInfo
167
+ }, {
168
+ basePath: MCPHandlerOptions.basePath || '/api',
169
+ maxDuration: MCPHandlerOptions.maxDuration || 60,
170
+ // INFO: Disabled until developer clarity is reached for server side streaming and we have an auth pattern for all SSE patterns
171
+ // redisUrl: MCPHandlerOptions.redisUrl || process.env.REDIS_URL,
172
+ verboseLogs: useVerboseLogs
173
+ });
174
+ } catch (error) {
175
+ throw new APIError(`Error initializing MCP handler: ${String(error)}`, 500);
176
+ }
177
+ };
178
+
179
+ //# sourceMappingURL=getMcpHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/mcp/getMcpHandler.ts"],"sourcesContent":["import type { JSONSchema4 } from 'json-schema'\n\nimport { createMcpHandler } from '@vercel/mcp-adapter'\nimport { join } from 'path'\nimport { APIError, configToJSONSchema, type PayloadRequest, type TypedUser } from 'payload'\n\nimport type { PluginMCPServerConfig, ToolSettings } from '../types.js'\n\nimport { toCamelCase } from '../utils/camelCase.js'\nimport { registerTool } from './registerTool.js'\n\n// Tools\nimport { createResourceTool } from './tools/resource/create.js'\nimport { deleteResourceTool } from './tools/resource/delete.js'\nimport { findResourceTool } from './tools/resource/find.js'\nimport { updateResourceTool } from './tools/resource/update.js'\n\n// Experimental Tools\nimport { authTool } from './tools/auth/auth.js'\nimport { forgotPasswordTool } from './tools/auth/forgotPassword.js'\nimport { loginTool } from './tools/auth/login.js'\nimport { resetPasswordTool } from './tools/auth/resetPassword.js'\nimport { unlockTool } from './tools/auth/unlock.js'\nimport { verifyTool } from './tools/auth/verify.js'\nimport { createCollectionTool } from './tools/collection/create.js'\nimport { deleteCollectionTool } from './tools/collection/delete.js'\nimport { findCollectionTool } from './tools/collection/find.js'\nimport { updateCollectionTool } from './tools/collection/update.js'\nimport { findConfigTool } from './tools/config/find.js'\nimport { updateConfigTool } from './tools/config/update.js'\nimport { createJobTool } from './tools/job/create.js'\nimport { runJobTool } from './tools/job/run.js'\nimport { updateJobTool } from './tools/job/update.js'\n\nexport const getMCPHandler = (\n pluginOptions: PluginMCPServerConfig,\n toolSettings: ToolSettings,\n req: PayloadRequest,\n) => {\n const { payload } = req\n const configSchema = configToJSONSchema(payload.config)\n\n // User\n const user = toolSettings.user as TypedUser\n\n // MCP Server and Handler Options\n const MCPOptions = pluginOptions.mcp || {}\n const customMCPTools = MCPOptions.tools || []\n const customMCPPrompts = MCPOptions.prompts || []\n const customMCPResources = MCPOptions.resources || []\n const MCPHandlerOptions = MCPOptions.handlerOptions || {}\n const serverOptions = MCPOptions.serverOptions || {}\n const useVerboseLogs = MCPHandlerOptions.verboseLogs ?? false\n\n // Experimental MCP Tool Requirements\n const isDevelopment = process.env.NODE_ENV === 'development'\n const experimentalTools: NonNullable<PluginMCPServerConfig['experimental']>['tools'] =\n pluginOptions?.experimental?.tools || {}\n const collectionsPluginConfig = pluginOptions.collections || {}\n const collectionsDirPath =\n experimentalTools && experimentalTools.collections?.collectionsDirPath\n ? experimentalTools.collections.collectionsDirPath\n : join(process.cwd(), 'src/collections')\n const configFilePath =\n experimentalTools && experimentalTools.config?.configFilePath\n ? experimentalTools.config.configFilePath\n : join(process.cwd(), 'src/payload.config.ts')\n const jobsDirPath =\n experimentalTools && experimentalTools.jobs?.jobsDirPath\n ? experimentalTools.jobs.jobsDirPath\n : join(process.cwd(), 'src/jobs')\n\n try {\n return createMcpHandler(\n (server) => {\n const enabledCollectionSlugs = Object.keys(collectionsPluginConfig || {}).filter(\n (collection) => {\n const fullyEnabled =\n typeof collectionsPluginConfig?.[collection]?.enabled === 'boolean' &&\n collectionsPluginConfig?.[collection]?.enabled\n\n if (fullyEnabled) {\n return true\n }\n\n const partiallyEnabled =\n typeof collectionsPluginConfig?.[collection]?.enabled !== 'boolean' &&\n ((typeof collectionsPluginConfig?.[collection]?.enabled?.find === 'boolean' &&\n collectionsPluginConfig?.[collection]?.enabled?.find === true) ||\n (typeof collectionsPluginConfig?.[collection]?.enabled?.create === 'boolean' &&\n collectionsPluginConfig?.[collection]?.enabled?.create === true) ||\n (typeof collectionsPluginConfig?.[collection]?.enabled?.update === 'boolean' &&\n collectionsPluginConfig?.[collection]?.enabled?.update === true) ||\n (typeof collectionsPluginConfig?.[collection]?.enabled?.delete === 'boolean' &&\n collectionsPluginConfig?.[collection]?.enabled?.delete === true))\n\n if (partiallyEnabled) {\n return true\n }\n },\n )\n\n // Collection Operation Tools\n enabledCollectionSlugs.forEach((enabledCollectionSlug) => {\n try {\n const schema = configSchema.definitions?.[enabledCollectionSlug] as JSONSchema4\n\n const toolCapabilities = toolSettings?.[\n `${toCamelCase(enabledCollectionSlug)}`\n ] as Record<string, unknown>\n const allowCreate: boolean | undefined = toolCapabilities['create'] as boolean\n const allowUpdate: boolean | undefined = toolCapabilities['update'] as boolean\n const allowFind: boolean | undefined = toolCapabilities['find'] as boolean\n const allowDelete: boolean | undefined = toolCapabilities['delete'] as boolean\n\n if (allowCreate) {\n registerTool(\n allowCreate,\n `Create ${enabledCollectionSlug}`,\n () =>\n createResourceTool(\n server,\n req,\n user,\n useVerboseLogs,\n enabledCollectionSlug,\n collectionsPluginConfig,\n schema,\n ),\n payload,\n useVerboseLogs,\n )\n }\n if (allowUpdate) {\n registerTool(\n allowUpdate,\n `Update ${enabledCollectionSlug}`,\n () =>\n updateResourceTool(\n server,\n req,\n user,\n useVerboseLogs,\n enabledCollectionSlug,\n collectionsPluginConfig,\n schema,\n ),\n payload,\n useVerboseLogs,\n )\n }\n if (allowFind) {\n registerTool(\n allowFind,\n `Find ${enabledCollectionSlug}`,\n () =>\n findResourceTool(\n server,\n req,\n user,\n useVerboseLogs,\n enabledCollectionSlug,\n collectionsPluginConfig,\n ),\n payload,\n useVerboseLogs,\n )\n }\n if (allowDelete) {\n registerTool(\n allowDelete,\n `Delete ${enabledCollectionSlug}`,\n () =>\n deleteResourceTool(\n server,\n req,\n user,\n useVerboseLogs,\n enabledCollectionSlug,\n collectionsPluginConfig,\n ),\n payload,\n useVerboseLogs,\n )\n }\n } catch (error) {\n throw new APIError(\n `Error registering tools for collection ${enabledCollectionSlug}: ${String(error)}`,\n 500,\n )\n }\n })\n\n // Custom tools\n customMCPTools.forEach((tool) => {\n const camelCasedToolName = toCamelCase(tool.name)\n const isToolEnabled = toolSettings.custom?.[camelCasedToolName] ?? true\n\n registerTool(\n isToolEnabled,\n tool.name,\n () => server.tool(tool.name, tool.description, tool.parameters, tool.handler),\n payload,\n useVerboseLogs,\n )\n })\n\n // Custom prompts\n customMCPPrompts.forEach((prompt) => {\n server.registerPrompt(\n prompt.name,\n {\n argsSchema: prompt.argsSchema,\n description: prompt.description,\n title: prompt.title,\n },\n prompt.handler,\n )\n if (useVerboseLogs) {\n payload.logger.info(`[payload-mcp] ✅ Prompt: ${prompt.title} Registered.`)\n }\n })\n\n // Custom resources\n customMCPResources.forEach((resource) => {\n server.registerResource(\n resource.name,\n // @ts-expect-error - Overload type is not working however -- ResourceTemplate OR String is a valid type\n resource.uri,\n {\n description: resource.description,\n mimeType: resource.mimeType,\n title: resource.title,\n },\n resource.handler,\n )\n\n if (useVerboseLogs) {\n payload.logger.info(`[payload-mcp] ✅ Resource: ${resource.title} Registered.`)\n }\n })\n\n // Experimental - Collection Schema Modfication Tools\n if (\n toolSettings.collections?.create &&\n experimentalTools.collections?.enabled &&\n isDevelopment\n ) {\n registerTool(\n toolSettings.collections.create,\n 'Create Collection',\n () =>\n createCollectionTool(server, req, useVerboseLogs, collectionsDirPath, configFilePath),\n payload,\n useVerboseLogs,\n )\n }\n if (\n toolSettings.collections?.delete &&\n experimentalTools.collections?.enabled &&\n isDevelopment\n ) {\n registerTool(\n toolSettings.collections.delete,\n 'Delete Collection',\n () =>\n deleteCollectionTool(server, req, useVerboseLogs, collectionsDirPath, configFilePath),\n payload,\n useVerboseLogs,\n )\n }\n\n if (\n toolSettings.collections?.find &&\n experimentalTools.collections?.enabled &&\n isDevelopment\n ) {\n registerTool(\n toolSettings.collections.find,\n 'Find Collection',\n () => findCollectionTool(server, req, useVerboseLogs, collectionsDirPath),\n payload,\n useVerboseLogs,\n )\n }\n\n if (\n toolSettings.collections?.update &&\n experimentalTools.collections?.enabled &&\n isDevelopment\n ) {\n registerTool(\n toolSettings.collections.update,\n 'Update Collection',\n () =>\n updateCollectionTool(server, req, useVerboseLogs, collectionsDirPath, configFilePath),\n payload,\n useVerboseLogs,\n )\n }\n\n // Experimental - Payload Config Modification Tools\n if (toolSettings.config?.find && experimentalTools.config?.enabled && isDevelopment) {\n registerTool(\n toolSettings.config.find,\n 'Find Config',\n () => findConfigTool(server, req, useVerboseLogs, configFilePath),\n payload,\n useVerboseLogs,\n )\n }\n\n if (toolSettings.config?.update && experimentalTools.config?.enabled && isDevelopment) {\n registerTool(\n toolSettings.config.update,\n 'Update Config',\n () => updateConfigTool(server, req, useVerboseLogs, configFilePath),\n payload,\n useVerboseLogs,\n )\n }\n\n // Experimental - Job Modification Tools\n if (toolSettings.jobs?.create && experimentalTools.jobs?.enabled && isDevelopment) {\n registerTool(\n toolSettings.jobs.create,\n 'Create Job',\n () => createJobTool(server, req, useVerboseLogs, jobsDirPath),\n payload,\n useVerboseLogs,\n )\n }\n\n if (toolSettings.jobs?.update && experimentalTools.jobs?.enabled && isDevelopment) {\n registerTool(\n toolSettings.jobs.update,\n 'Update Job',\n () => updateJobTool(server, req, useVerboseLogs, jobsDirPath),\n payload,\n useVerboseLogs,\n )\n }\n\n if (toolSettings.jobs?.run && experimentalTools.jobs?.enabled && isDevelopment) {\n registerTool(\n toolSettings.jobs.run,\n 'Run Job',\n () => runJobTool(server, req, useVerboseLogs),\n payload,\n useVerboseLogs,\n )\n }\n\n // Experimental - Auth Modification Tools\n if (toolSettings.auth?.auth && experimentalTools.auth?.enabled && isDevelopment) {\n registerTool(\n toolSettings.auth.auth,\n 'Auth',\n () => authTool(server, req, useVerboseLogs),\n payload,\n useVerboseLogs,\n )\n }\n\n if (toolSettings.auth?.login && experimentalTools.auth?.enabled && isDevelopment) {\n registerTool(\n toolSettings.auth.login,\n 'Login',\n () => loginTool(server, req, useVerboseLogs),\n payload,\n useVerboseLogs,\n )\n }\n\n if (toolSettings.auth?.verify && experimentalTools.auth?.enabled && isDevelopment) {\n registerTool(\n toolSettings.auth.verify,\n 'Verify',\n () => verifyTool(server, req, useVerboseLogs),\n payload,\n useVerboseLogs,\n )\n }\n\n if (toolSettings.auth?.resetPassword && experimentalTools.auth?.enabled) {\n registerTool(\n toolSettings.auth.resetPassword,\n 'Reset Password',\n () => resetPasswordTool(server, req, useVerboseLogs),\n payload,\n useVerboseLogs,\n )\n }\n\n if (toolSettings.auth?.forgotPassword && experimentalTools.auth?.enabled) {\n registerTool(\n toolSettings.auth.forgotPassword,\n 'Forgot Password',\n () => forgotPasswordTool(server, req, useVerboseLogs),\n payload,\n useVerboseLogs,\n )\n }\n\n if (toolSettings.auth?.unlock && experimentalTools.auth?.enabled) {\n registerTool(\n toolSettings.auth.unlock,\n 'Unlock',\n () => unlockTool(server, req, useVerboseLogs),\n payload,\n useVerboseLogs,\n )\n }\n\n if (useVerboseLogs) {\n payload.logger.info('[payload-mcp] 🚀 MCP Server Ready.')\n }\n },\n {\n serverInfo: serverOptions.serverInfo,\n },\n {\n basePath: MCPHandlerOptions.basePath || '/api',\n maxDuration: MCPHandlerOptions.maxDuration || 60,\n // INFO: Disabled until developer clarity is reached for server side streaming and we have an auth pattern for all SSE patterns\n // redisUrl: MCPHandlerOptions.redisUrl || process.env.REDIS_URL,\n verboseLogs: useVerboseLogs,\n },\n )\n } catch (error) {\n throw new APIError(`Error initializing MCP handler: ${String(error)}`, 500)\n }\n}\n"],"names":["createMcpHandler","join","APIError","configToJSONSchema","toCamelCase","registerTool","createResourceTool","deleteResourceTool","findResourceTool","updateResourceTool","authTool","forgotPasswordTool","loginTool","resetPasswordTool","unlockTool","verifyTool","createCollectionTool","deleteCollectionTool","findCollectionTool","updateCollectionTool","findConfigTool","updateConfigTool","createJobTool","runJobTool","updateJobTool","getMCPHandler","pluginOptions","toolSettings","req","payload","configSchema","config","user","MCPOptions","mcp","customMCPTools","tools","customMCPPrompts","prompts","customMCPResources","resources","MCPHandlerOptions","handlerOptions","serverOptions","useVerboseLogs","verboseLogs","isDevelopment","process","env","NODE_ENV","experimentalTools","experimental","collectionsPluginConfig","collections","collectionsDirPath","cwd","configFilePath","jobsDirPath","jobs","server","enabledCollectionSlugs","Object","keys","filter","collection","fullyEnabled","enabled","partiallyEnabled","find","create","update","delete","forEach","enabledCollectionSlug","schema","definitions","toolCapabilities","allowCreate","allowUpdate","allowFind","allowDelete","error","String","tool","camelCasedToolName","name","isToolEnabled","custom","description","parameters","handler","prompt","registerPrompt","argsSchema","title","logger","info","resource","registerResource","uri","mimeType","run","auth","login","verify","resetPassword","forgotPassword","unlock","serverInfo","basePath","maxDuration"],"mappings":"AAEA,SAASA,gBAAgB,QAAQ,sBAAqB;AACtD,SAASC,IAAI,QAAQ,OAAM;AAC3B,SAASC,QAAQ,EAAEC,kBAAkB,QAA6C,UAAS;AAI3F,SAASC,WAAW,QAAQ,wBAAuB;AACnD,SAASC,YAAY,QAAQ,oBAAmB;AAEhD,QAAQ;AACR,SAASC,kBAAkB,QAAQ,6BAA4B;AAC/D,SAASC,kBAAkB,QAAQ,6BAA4B;AAC/D,SAASC,gBAAgB,QAAQ,2BAA0B;AAC3D,SAASC,kBAAkB,QAAQ,6BAA4B;AAE/D,qBAAqB;AACrB,SAASC,QAAQ,QAAQ,uBAAsB;AAC/C,SAASC,kBAAkB,QAAQ,iCAAgC;AACnE,SAASC,SAAS,QAAQ,wBAAuB;AACjD,SAASC,iBAAiB,QAAQ,gCAA+B;AACjE,SAASC,UAAU,QAAQ,yBAAwB;AACnD,SAASC,UAAU,QAAQ,yBAAwB;AACnD,SAASC,oBAAoB,QAAQ,+BAA8B;AACnE,SAASC,oBAAoB,QAAQ,+BAA8B;AACnE,SAASC,kBAAkB,QAAQ,6BAA4B;AAC/D,SAASC,oBAAoB,QAAQ,+BAA8B;AACnE,SAASC,cAAc,QAAQ,yBAAwB;AACvD,SAASC,gBAAgB,QAAQ,2BAA0B;AAC3D,SAASC,aAAa,QAAQ,wBAAuB;AACrD,SAASC,UAAU,QAAQ,qBAAoB;AAC/C,SAASC,aAAa,QAAQ,wBAAuB;AAErD,OAAO,MAAMC,gBAAgB,CAC3BC,eACAC,cACAC;IAEA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I/E,SAAS,CAAC,gCAAgC,EAAEgF,OAAOD,QAAQ,EAAE;IACzE;AACF,EAAC"}
@@ -0,0 +1,30 @@
1
+ import type { AdminConfig, CollectionConfigUpdates, DatabaseConfig, GeneralConfig, PluginUpdates } from '../../types.js';
2
+ /**
3
+ * Adds a collection to the payload.config.ts file
4
+ */
5
+ export declare function addCollectionToConfig(content: string, collectionName: string): string;
6
+ /**
7
+ * Removes a collection from the payload.config.ts file
8
+ */
9
+ export declare function removeCollectionFromConfig(content: string, collectionName: string): string;
10
+ /**
11
+ * Updates admin configuration in payload.config.ts
12
+ */
13
+ export declare function updateAdminConfig(content: string, adminConfig: AdminConfig): string;
14
+ /**
15
+ * Updates database configuration in payload.config.ts
16
+ */
17
+ export declare function updateDatabaseConfig(content: string, databaseConfig: DatabaseConfig): string;
18
+ /**
19
+ * Updates plugins configuration in payload.config.ts
20
+ */
21
+ export declare function updatePluginsConfig(content: string, pluginUpdates: PluginUpdates): string;
22
+ /**
23
+ * Updates general configuration options in payload.config.ts
24
+ */
25
+ export declare function updateGeneralConfig(content: string, generalConfig: GeneralConfig): string;
26
+ /**
27
+ * Updates collection-level configuration in a collection file
28
+ */
29
+ export declare function updateCollectionConfig(content: string, updates: CollectionConfigUpdates, collectionName: string): string;
30
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/mcp/helpers/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,uBAAuB,EACvB,cAAc,EACd,aAAa,EACb,aAAa,EACd,MAAM,gBAAgB,CAAA;AAEvB;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,MAAM,CAwCrF;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,MAAM,CAgC1F;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,GAAG,MAAM,CAoDnF;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,cAAc,GAAG,MAAM,CAkB5F;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,aAAa,GAAG,MAAM,CA6CzF;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,aAAa,GAAG,MAAM,CA+BzF;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,uBAAuB,EAChC,cAAc,EAAE,MAAM,GACrB,MAAM,CA8DR"}
@@ -0,0 +1,217 @@
1
+ /**
2
+ * Adds a collection to the payload.config.ts file
3
+ */ export function addCollectionToConfig(content, collectionName) {
4
+ const capitalizedName = collectionName.charAt(0).toUpperCase() + collectionName.slice(1);
5
+ // Add import statement
6
+ const importRegex = /import.*from\s*['"]\.\/collections\/.*['"]/g;
7
+ const importMatches = content.match(importRegex);
8
+ if (importMatches && importMatches.length > 0) {
9
+ const lastImport = importMatches[importMatches.length - 1];
10
+ const newImport = `import { ${capitalizedName} } from './collections/${capitalizedName}'`;
11
+ // Check if import already exists
12
+ if (lastImport && !content.includes(newImport)) {
13
+ content = content.replace(lastImport, `${lastImport}\n${newImport}`);
14
+ }
15
+ } else {
16
+ // Add import after existing imports
17
+ const importInsertPoint = content.indexOf("import sharp from 'sharp'");
18
+ if (importInsertPoint !== -1) {
19
+ const lineEnd = content.indexOf('\n', importInsertPoint);
20
+ const newImport = `import { ${capitalizedName} } from './collections/${capitalizedName}'`;
21
+ content = content.slice(0, lineEnd + 1) + newImport + '\n' + content.slice(lineEnd + 1);
22
+ }
23
+ }
24
+ // Add to collections array
25
+ const collectionsRegex = /collections:\s*\[([\s\S]*?)\]/;
26
+ const collectionsMatch = content.match(collectionsRegex);
27
+ if (collectionsMatch && collectionsMatch[1]) {
28
+ const collectionsContent = collectionsMatch[1].trim();
29
+ if (!collectionsContent.includes(capitalizedName)) {
30
+ const newCollections = collectionsContent ? `${collectionsContent}, ${capitalizedName}` : capitalizedName;
31
+ content = content.replace(collectionsRegex, `collections: [${newCollections}]`);
32
+ }
33
+ }
34
+ return content;
35
+ }
36
+ /**
37
+ * Removes a collection from the payload.config.ts file
38
+ */ export function removeCollectionFromConfig(content, collectionName) {
39
+ const capitalizedName = collectionName.charAt(0).toUpperCase() + collectionName.slice(1);
40
+ // Remove import statement
41
+ const importRegex = new RegExp(`import\\s*{\\s*${capitalizedName}\\s*}\\s*from\\s*['"]\\./collections/${capitalizedName}['"]\\s*\\n?`, 'g');
42
+ content = content.replace(importRegex, '');
43
+ // Remove from collections array
44
+ const collectionsRegex = /collections:\s*\[([\s\S]*?)\]/;
45
+ const collectionsMatch = content.match(collectionsRegex);
46
+ if (collectionsMatch && collectionsMatch[1]) {
47
+ let collectionsContent = collectionsMatch[1];
48
+ // Remove the collection name and clean up commas
49
+ collectionsContent = collectionsContent.replace(new RegExp(`\\s*,?\\s*${capitalizedName}\\s*,?`, 'g'), '');
50
+ collectionsContent = collectionsContent.replace(/,\s*,/g, ',') // Remove double commas
51
+ ;
52
+ collectionsContent = collectionsContent.replace(/^\s*,|,\s*$/g, '') // Remove leading/trailing commas
53
+ ;
54
+ content = content.replace(collectionsRegex, `collections: [${collectionsContent}]`);
55
+ }
56
+ // Clean up any double newlines from removed imports
57
+ content = content.replace(/\n{3,}/g, '\n\n');
58
+ return content;
59
+ }
60
+ /**
61
+ * Updates admin configuration in payload.config.ts
62
+ */ export function updateAdminConfig(content, adminConfig) {
63
+ const adminRegex = /admin:\s*\{([^}]*)\}/;
64
+ const adminMatch = content.match(adminRegex);
65
+ if (adminMatch && adminMatch[1]) {
66
+ let adminContent = adminMatch[1];
67
+ // Update specific admin properties
68
+ if (adminConfig.user) {
69
+ if (adminContent.includes('user:')) {
70
+ adminContent = adminContent.replace(/user:[^,}]*/, `user: ${adminConfig.user}.slug`);
71
+ } else {
72
+ adminContent = `\n user: ${adminConfig.user}.slug,${adminContent}`;
73
+ }
74
+ }
75
+ if (adminConfig.meta) {
76
+ const metaConfig = Object.entries(adminConfig.meta).map(([key, value])=>` ${key}: '${value}'`).join(',\n');
77
+ if (adminContent.includes('meta:')) {
78
+ adminContent = adminContent.replace(/meta:\s*\{[^}]*\}/, `meta: {\n${metaConfig}\n }`);
79
+ } else {
80
+ adminContent = `${adminContent}\n meta: {\n${metaConfig}\n },`;
81
+ }
82
+ }
83
+ content = content.replace(adminRegex, `admin: {${adminContent}\n }`);
84
+ } else {
85
+ // Add admin config if it doesn't exist
86
+ const adminConfigEntries = [];
87
+ if (adminConfig.user) {
88
+ adminConfigEntries.push(` user: ${adminConfig.user}.slug`);
89
+ }
90
+ if (adminConfig.meta) {
91
+ const metaConfig = Object.entries(adminConfig.meta).map(([key, value])=>` ${key}: '${value}'`).join(',\n');
92
+ adminConfigEntries.push(` meta: {\n${metaConfig}\n }`);
93
+ }
94
+ const adminConfigString = `admin: {\n${adminConfigEntries.join(',\n')}\n },`;
95
+ content = content.replace(/export default buildConfig\(\{/, `export default buildConfig({\n ${adminConfigString}`);
96
+ }
97
+ return content;
98
+ }
99
+ /**
100
+ * Updates database configuration in payload.config.ts
101
+ */ export function updateDatabaseConfig(content, databaseConfig) {
102
+ if (databaseConfig.type === 'mongodb') {
103
+ // Update to MongoDB adapter
104
+ const dbRegex = /db:[^,}]*(?:,|\})/;
105
+ const mongoImportRegex = /import.*mongooseAdapter.*from.*@payloadcms\/db-mongodb.*/;
106
+ if (!content.match(mongoImportRegex)) {
107
+ content = content.replace(/(import.*from.*payload.*\n)/, `$1import { mongooseAdapter } from '@payloadcms/db-mongodb'\n`);
108
+ }
109
+ const dbConfig = `db: mongooseAdapter({\n url: process.env.DATABASE_URI || '${databaseConfig.url || ''}',\n })`;
110
+ content = content.replace(dbRegex, `${dbConfig},`);
111
+ }
112
+ return content;
113
+ }
114
+ /**
115
+ * Updates plugins configuration in payload.config.ts
116
+ */ export function updatePluginsConfig(content, pluginUpdates) {
117
+ // Add plugin imports
118
+ if (pluginUpdates.add) {
119
+ pluginUpdates.add.forEach((pluginImport)=>{
120
+ if (!content.includes(pluginImport)) {
121
+ content = content.replace(/(import.*from.*payload.*\n)/, `$1${pluginImport}\n`);
122
+ }
123
+ });
124
+ }
125
+ // Handle plugins array
126
+ const pluginsRegex = /plugins:\s*\[([\s\S]*?)\]/;
127
+ const pluginsMatch = content.match(pluginsRegex);
128
+ if (pluginsMatch && pluginsMatch[1]) {
129
+ let pluginsContent = pluginsMatch[1];
130
+ // Remove plugins
131
+ if (pluginUpdates.remove) {
132
+ pluginUpdates.remove.forEach((pluginName)=>{
133
+ const pluginRegex = new RegExp(`\\s*${pluginName}\\(\\)\\s*,?`, 'g');
134
+ pluginsContent = pluginsContent.replace(pluginRegex, '');
135
+ });
136
+ }
137
+ // Add plugins
138
+ if (pluginUpdates.add) {
139
+ pluginUpdates.add.forEach((pluginImport)=>{
140
+ // This will match: import { PluginName } from '...';
141
+ const match = pluginImport.match(/import\s*\{\s*(\w+)\s*\}/);
142
+ if (match && match[1]) {
143
+ const pluginName = match[1];
144
+ if (!pluginsContent.includes(`${pluginName}(`)) {
145
+ pluginsContent = pluginsContent.trim() ? `${pluginsContent}\n ${pluginName}(),` : `\n ${pluginName}(),`;
146
+ }
147
+ }
148
+ });
149
+ }
150
+ content = content.replace(pluginsRegex, `plugins: [${pluginsContent}\n ]`);
151
+ }
152
+ return content;
153
+ }
154
+ /**
155
+ * Updates general configuration options in payload.config.ts
156
+ */ export function updateGeneralConfig(content, generalConfig) {
157
+ // Update various general configuration options
158
+ Object.entries(generalConfig).forEach(([key, value])=>{
159
+ if (value !== undefined && value !== null) {
160
+ const configRegex = new RegExp(`${key}:\\s*[^,}]*`, 'g');
161
+ if (content.match(configRegex)) {
162
+ if (typeof value === 'string') {
163
+ content = content.replace(configRegex, `${key}: '${value}'`);
164
+ } else if (typeof value === 'boolean') {
165
+ content = content.replace(configRegex, `${key}: ${value}`);
166
+ } else if (typeof value === 'object') {
167
+ content = content.replace(configRegex, `${key}: ${JSON.stringify(value, null, 2)}`);
168
+ }
169
+ } else {
170
+ // Add new config option
171
+ const configValue = typeof value === 'string' ? `'${value}'` : typeof value === 'object' ? JSON.stringify(value, null, 2) : value;
172
+ content = content.replace(/export default buildConfig\(\{/, `export default buildConfig({\n ${key}: ${configValue},`);
173
+ }
174
+ }
175
+ });
176
+ return content;
177
+ }
178
+ /**
179
+ * Updates collection-level configuration in a collection file
180
+ */ export function updateCollectionConfig(content, updates, collectionName) {
181
+ let updatedContent = content;
182
+ if (updates.slug) {
183
+ updatedContent = updatedContent.replace(/slug:\s*'[^']*'/, `slug: '${updates.slug}'`);
184
+ }
185
+ if (updates.access) {
186
+ const accessRegex = /access:\s*\{[^}]*\}/;
187
+ if (updatedContent.match(accessRegex)) {
188
+ // Update existing access config
189
+ Object.entries(updates.access).forEach(([key, value])=>{
190
+ if (value !== undefined) {
191
+ updatedContent = updatedContent.replace(new RegExp(`${key}:\\s*[^,}]*`), `${key}: ${value}`);
192
+ }
193
+ });
194
+ } else {
195
+ // Add access config
196
+ const accessConfig = Object.entries(updates.access).filter(([, value])=>value !== undefined).map(([key, value])=>` ${key}: ${value}`).join(',\n');
197
+ updatedContent = updatedContent.replace(/slug:\s*'[^']*',/, `slug: '${collectionName}',\n access: {\n${accessConfig}\n },`);
198
+ }
199
+ }
200
+ if (updates.timestamps !== undefined) {
201
+ if (updatedContent.includes('timestamps:')) {
202
+ updatedContent = updatedContent.replace(/timestamps:[^,}]*/, `timestamps: ${updates.timestamps}`);
203
+ } else {
204
+ updatedContent = updatedContent.replace(/fields:\s*\[/, `timestamps: ${updates.timestamps},\n fields: [`);
205
+ }
206
+ }
207
+ if (updates.versioning !== undefined) {
208
+ if (updatedContent.includes('versioning:')) {
209
+ updatedContent = updatedContent.replace(/versioning:[^,}]*/, `versioning: ${updates.versioning}`);
210
+ } else {
211
+ updatedContent = updatedContent.replace(/fields:\s*\[/, `versioning: ${updates.versioning},\n fields: [`);
212
+ }
213
+ }
214
+ return updatedContent;
215
+ }
216
+
217
+ //# sourceMappingURL=config.js.map
@@ -0,0 +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,mBAAmB;IACzB,MAAMC,mBAAmBlB,QAAQQ,KAAK,CAACS;IAEvC,IAAIC,oBAAoBA,gBAAgB,CAAC,EAAE,EAAE;QAC3C,MAAMC,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C,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"}
@@ -0,0 +1,2 @@
1
+ export declare const toCamelCase: (str: string) => string;
2
+ //# sourceMappingURL=conversion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conversion.d.ts","sourceRoot":"","sources":["../../../src/mcp/helpers/conversion.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,QAAS,MAAM,KAAG,MAEzC,CAAA"}
@@ -0,0 +1,5 @@
1
+ export const toCamelCase = (str)=>{
2
+ return str.replace(/-([a-z])/g, (match, letter)=>letter.toUpperCase());
3
+ };
4
+
5
+ //# sourceMappingURL=conversion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/mcp/helpers/conversion.ts"],"sourcesContent":["export const toCamelCase = (str: string): string => {\n return str.replace(/-([a-z])/g, (match, letter) => letter.toUpperCase())\n}\n"],"names":["toCamelCase","str","replace","match","letter","toUpperCase"],"mappings":"AAAA,OAAO,MAAMA,cAAc,CAACC;IAC1B,OAAOA,IAAIC,OAAO,CAAC,aAAa,CAACC,OAAOC,SAAWA,OAAOC,WAAW;AACvE,EAAC"}
@@ -0,0 +1,38 @@
1
+ type FieldDefinition = {
2
+ description?: string;
3
+ name: string;
4
+ options?: {
5
+ label: string;
6
+ value: string;
7
+ }[];
8
+ position?: 'main' | 'sidebar';
9
+ required?: boolean;
10
+ type: string;
11
+ };
12
+ type FieldModification = {
13
+ changes: {
14
+ description?: string;
15
+ options?: {
16
+ label: string;
17
+ value: string;
18
+ }[];
19
+ position?: 'main' | 'sidebar';
20
+ required?: boolean;
21
+ type?: string;
22
+ };
23
+ fieldName: string;
24
+ };
25
+ /**
26
+ * Adds new fields to a collection file content
27
+ */
28
+ export declare function addFieldsToCollection(content: string, newFields: FieldDefinition[]): string;
29
+ /**
30
+ * Removes fields from a collection file content
31
+ */
32
+ export declare function removeFieldsFromCollection(content: string, fieldNames: string[]): string;
33
+ /**
34
+ * Modifies existing fields in a collection file content
35
+ */
36
+ export declare function modifyFieldsInCollection(content: string, modifications: FieldModification[]): string;
37
+ export {};
38
+ //# sourceMappingURL=fields.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../../../src/mcp/helpers/fields.ts"],"names":[],"mappings":"AAAA,KAAK,eAAe,GAAG;IACrB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;IAC5C,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,KAAK,iBAAiB,GAAG;IACvB,OAAO,EAAE;QACP,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB,OAAO,CAAC,EAAE;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,MAAM,CAAA;SAAE,EAAE,CAAA;QAC5C,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;QAC7B,QAAQ,CAAC,EAAE,OAAO,CAAA;QAClB,IAAI,CAAC,EAAE,MAAM,CAAA;KACd,CAAA;IACD,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,GAAG,MAAM,CAuD3F;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,MAAM,CAiBxF;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,MAAM,EACf,aAAa,EAAE,iBAAiB,EAAE,GACjC,MAAM,CAiDR"}