@payloadcms/plugin-mcp 4.0.0-internal.fa183d3 → 4.0.0-internal.fec2230
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/endpoint/access.js +2 -2
- package/dist/endpoint/access.js.map +1 -1
- package/dist/mcp/buildMcpServer.d.ts +1 -1
- package/dist/mcp/buildMcpServer.d.ts.map +1 -1
- package/dist/mcp/buildMcpServer.js +35 -23
- package/dist/mcp/buildMcpServer.js.map +1 -1
- package/dist/mcp/builtin/collections/authTools.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/authTools.js +79 -56
- package/dist/mcp/builtin/collections/authTools.js.map +1 -1
- package/dist/mcp/builtin/collections/countTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/countTool.js +9 -14
- package/dist/mcp/builtin/collections/countTool.js.map +1 -1
- package/dist/mcp/builtin/collections/countVersionsTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/countVersionsTool.js +9 -13
- package/dist/mcp/builtin/collections/countVersionsTool.js.map +1 -1
- package/dist/mcp/builtin/collections/createTool.d.ts +1 -1
- package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/createTool.js +104 -63
- package/dist/mcp/builtin/collections/createTool.js.map +1 -1
- package/dist/mcp/builtin/collections/deleteTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/deleteTool.js +44 -43
- package/dist/mcp/builtin/collections/deleteTool.js.map +1 -1
- package/dist/mcp/builtin/collections/duplicateTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/duplicateTool.js +31 -37
- package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -1
- package/dist/mcp/builtin/collections/fileInput.d.ts +21 -13
- package/dist/mcp/builtin/collections/fileInput.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/fileInput.js +52 -64
- package/dist/mcp/builtin/collections/fileInput.js.map +1 -1
- package/dist/mcp/builtin/collections/fileInput.spec.js +20 -6
- package/dist/mcp/builtin/collections/fileInput.spec.js.map +1 -1
- package/dist/mcp/builtin/collections/findDistinctTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/findDistinctTool.js +11 -26
- package/dist/mcp/builtin/collections/findDistinctTool.js.map +1 -1
- package/dist/mcp/builtin/collections/findTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/findTool.js +27 -45
- package/dist/mcp/builtin/collections/findTool.js.map +1 -1
- package/dist/mcp/builtin/collections/findVersionByIDTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/findVersionByIDTool.js +17 -26
- package/dist/mcp/builtin/collections/findVersionByIDTool.js.map +1 -1
- package/dist/mcp/builtin/collections/findVersionsTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/findVersionsTool.js +16 -30
- package/dist/mcp/builtin/collections/findVersionsTool.js.map +1 -1
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +15 -14
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -1
- package/dist/mcp/builtin/collections/restoreVersionTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/restoreVersionTool.js +14 -26
- package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -1
- package/dist/mcp/builtin/collections/updateTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/updateTool.js +58 -90
- package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
- package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts +2 -0
- package/dist/mcp/builtin/collections/uploadInstructionsTool.d.ts.map +1 -0
- package/dist/mcp/builtin/collections/uploadInstructionsTool.js +55 -0
- package/dist/mcp/builtin/collections/uploadInstructionsTool.js.map +1 -0
- package/dist/mcp/builtin/formatEntityError.d.ts +16 -0
- package/dist/mcp/builtin/formatEntityError.d.ts.map +1 -0
- package/dist/mcp/builtin/formatEntityError.js +55 -0
- package/dist/mcp/builtin/formatEntityError.js.map +1 -0
- package/dist/mcp/builtin/getConfigInfoTool.d.ts.map +1 -1
- package/dist/mcp/builtin/getConfigInfoTool.js +3 -2
- package/dist/mcp/builtin/getConfigInfoTool.js.map +1 -1
- package/dist/mcp/builtin/globals/countVersionsTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/countVersionsTool.js +9 -13
- package/dist/mcp/builtin/globals/countVersionsTool.js.map +1 -1
- package/dist/mcp/builtin/globals/findTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/findTool.js +10 -16
- package/dist/mcp/builtin/globals/findTool.js.map +1 -1
- package/dist/mcp/builtin/globals/findVersionByIDTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/findVersionByIDTool.js +13 -24
- package/dist/mcp/builtin/globals/findVersionByIDTool.js.map +1 -1
- package/dist/mcp/builtin/globals/findVersionsTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/findVersionsTool.js +13 -29
- package/dist/mcp/builtin/globals/findVersionsTool.js.map +1 -1
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +11 -11
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -1
- package/dist/mcp/builtin/globals/restoreVersionTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/restoreVersionTool.js +15 -22
- package/dist/mcp/builtin/globals/restoreVersionTool.js.map +1 -1
- package/dist/mcp/builtin/globals/updateTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/updateTool.js +27 -36
- package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
- package/dist/mcp/builtinTools.d.ts +6 -0
- package/dist/mcp/builtinTools.d.ts.map +1 -1
- package/dist/mcp/builtinTools.js +9 -3
- package/dist/mcp/builtinTools.js.map +1 -1
- package/dist/mcp/sanitizeMCPConfig.js +4 -1
- package/dist/mcp/sanitizeMCPConfig.js.map +1 -1
- package/dist/stdio.d.ts.map +1 -1
- package/dist/stdio.js +2 -1
- package/dist/stdio.js.map +1 -1
- package/dist/types.d.ts +4 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +5 -7
- package/src/endpoint/access.ts +2 -3
- package/src/mcp/buildMcpServer.ts +39 -29
- package/src/mcp/builtin/collections/authTools.ts +77 -69
- package/src/mcp/builtin/collections/countTool.ts +9 -21
- package/src/mcp/builtin/collections/countVersionsTool.ts +9 -18
- package/src/mcp/builtin/collections/createTool.ts +110 -86
- package/src/mcp/builtin/collections/deleteTool.ts +36 -64
- package/src/mcp/builtin/collections/duplicateTool.ts +35 -85
- package/src/mcp/builtin/collections/fileInput.spec.ts +20 -6
- package/src/mcp/builtin/collections/fileInput.ts +64 -76
- package/src/mcp/builtin/collections/findDistinctTool.ts +11 -63
- package/src/mcp/builtin/collections/findTool.ts +23 -105
- package/src/mcp/builtin/collections/findVersionByIDTool.ts +15 -58
- package/src/mcp/builtin/collections/findVersionsTool.ts +14 -85
- package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +16 -12
- package/src/mcp/builtin/collections/restoreVersionTool.ts +14 -56
- package/src/mcp/builtin/collections/updateTool.ts +57 -111
- package/src/mcp/builtin/collections/uploadInstructionsTool.ts +64 -0
- package/src/mcp/builtin/formatEntityError.ts +77 -0
- package/src/mcp/builtin/getConfigInfoTool.ts +2 -1
- package/src/mcp/builtin/globals/countVersionsTool.ts +9 -17
- package/src/mcp/builtin/globals/findTool.ts +12 -51
- package/src/mcp/builtin/globals/findVersionByIDTool.ts +13 -52
- package/src/mcp/builtin/globals/findVersionsTool.ts +14 -92
- package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +10 -10
- package/src/mcp/builtin/globals/restoreVersionTool.ts +14 -45
- package/src/mcp/builtin/globals/updateTool.ts +37 -60
- package/src/mcp/builtinTools.ts +9 -2
- package/src/mcp/sanitizeMCPConfig.ts +4 -1
- package/src/stdio.ts +2 -1
- package/src/types.ts +4 -4
- package/dist/mcp/builtin/collections/formatCollectionError.d.ts +0 -9
- package/dist/mcp/builtin/collections/formatCollectionError.d.ts.map +0 -1
- package/dist/mcp/builtin/collections/formatCollectionError.js +0 -60
- package/dist/mcp/builtin/collections/formatCollectionError.js.map +0 -1
- package/dist/mcp/builtin/validateEntityData.d.ts +0 -14
- package/dist/mcp/builtin/validateEntityData.d.ts.map +0 -1
- package/dist/mcp/builtin/validateEntityData.js +0 -82
- package/dist/mcp/builtin/validateEntityData.js.map +0 -1
- package/dist/utils/getVirtualFieldNames.d.ts +0 -14
- package/dist/utils/getVirtualFieldNames.d.ts.map +0 -1
- package/dist/utils/getVirtualFieldNames.js +0 -35
- package/dist/utils/getVirtualFieldNames.js.map +0 -1
- package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts +0 -28
- package/dist/utils/schemaConversion/filterFieldsByAccess.d.ts.map +0 -1
- package/dist/utils/schemaConversion/filterFieldsByAccess.js +0 -71
- package/dist/utils/schemaConversion/filterFieldsByAccess.js.map +0 -1
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts +0 -13
- package/dist/utils/schemaConversion/getEntityInputSchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/getEntityInputSchema.js +0 -66
- package/dist/utils/schemaConversion/getEntityInputSchema.js.map +0 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts +0 -10
- package/dist/utils/schemaConversion/sanitizeEntitySchema.d.ts.map +0 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js +0 -384
- package/dist/utils/schemaConversion/sanitizeEntitySchema.js.map +0 -1
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js +0 -133
- package/dist/utils/schemaConversion/sanitizeEntitySchema.spec.js.map +0 -1
- package/dist/utils/transformPointDataToPayload.d.ts +0 -7
- package/dist/utils/transformPointDataToPayload.d.ts.map +0 -1
- package/dist/utils/transformPointDataToPayload.js +0 -28
- package/dist/utils/transformPointDataToPayload.js.map +0 -1
- package/dist/utils/whereSchema.d.ts +0 -9
- package/dist/utils/whereSchema.d.ts.map +0 -1
- package/dist/utils/whereSchema.js +0 -13
- package/dist/utils/whereSchema.js.map +0 -1
- package/src/mcp/builtin/collections/formatCollectionError.ts +0 -84
- package/src/mcp/builtin/validateEntityData.ts +0 -132
- package/src/utils/getVirtualFieldNames.ts +0 -53
- package/src/utils/schemaConversion/filterFieldsByAccess.ts +0 -123
- package/src/utils/schemaConversion/getEntityInputSchema.ts +0 -96
- package/src/utils/schemaConversion/sanitizeEntitySchema.spec.ts +0 -96
- package/src/utils/schemaConversion/sanitizeEntitySchema.ts +0 -432
- package/src/utils/transformPointDataToPayload.ts +0 -40
- package/src/utils/whereSchema.ts +0 -24
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { z } from '
|
|
1
|
+
import { createLocalReq, strictObject, z } from 'payload'
|
|
2
2
|
|
|
3
3
|
import type { MCPToolResponse } from '../../../types.js'
|
|
4
4
|
|
|
5
|
+
import { defaultAccess } from '../../../defaultAccess.js'
|
|
5
6
|
import { defineCollectionTool } from '../../../defineTool.js'
|
|
6
7
|
import { getLogger } from '../../../utils/getLogger.js'
|
|
7
8
|
|
|
@@ -16,16 +17,16 @@ import { getLogger } from '../../../utils/getLogger.js'
|
|
|
16
17
|
* users collection so all auth-shaped tools live in one place.
|
|
17
18
|
*/
|
|
18
19
|
|
|
19
|
-
const emailSchema = z.
|
|
20
|
+
const emailSchema = z.email().check(z.describe('The user email address.'))
|
|
20
21
|
|
|
21
22
|
const wrapError =
|
|
22
23
|
(name: string) =>
|
|
23
|
-
({
|
|
24
|
+
({ slug, message }: { message: string; slug: string }): MCPToolResponse => {
|
|
24
25
|
return {
|
|
25
26
|
content: [
|
|
26
27
|
{
|
|
27
28
|
type: 'text',
|
|
28
|
-
text: `❌ **Error in ${name}** on ${
|
|
29
|
+
text: `❌ **Error in ${name}** on ${slug}: ${message}`,
|
|
29
30
|
},
|
|
30
31
|
],
|
|
31
32
|
}
|
|
@@ -40,20 +41,38 @@ export const authCollectionTool = defineCollectionTool({
|
|
|
40
41
|
title: 'Check Auth Status',
|
|
41
42
|
},
|
|
42
43
|
description: 'Checks authentication status for the current user.',
|
|
43
|
-
input:
|
|
44
|
+
input: strictObject({
|
|
44
45
|
headers: z
|
|
45
|
-
.record(z.string(), z.string())
|
|
46
|
-
.describe('
|
|
47
|
-
.optional(),
|
|
46
|
+
.optional(z.record(z.string(), z.string()))
|
|
47
|
+
.check(z.describe('Custom headers to send with the authentication request.')),
|
|
48
48
|
}),
|
|
49
|
-
}).handler(async ({
|
|
49
|
+
}).handler(async ({ slug, authorizedMCP, input, req }) => {
|
|
50
50
|
const logger = getLogger({ payload: req.payload })
|
|
51
51
|
try {
|
|
52
52
|
let authHeaders = new Headers()
|
|
53
53
|
if (input.headers) {
|
|
54
54
|
authHeaders = new Headers(input.headers)
|
|
55
55
|
}
|
|
56
|
-
const
|
|
56
|
+
const authReq = await createLocalReq({ req: { headers: authHeaders } }, req.payload)
|
|
57
|
+
const result = await req.payload.auth({ headers: authHeaders, req: authReq })
|
|
58
|
+
|
|
59
|
+
if (result.user) {
|
|
60
|
+
const authenticatedUser = result.user
|
|
61
|
+
// Auth strategies read users with trusted Local API access. Re-read the user with the MCP
|
|
62
|
+
// caller's access level before returning it to the client.
|
|
63
|
+
const user = await req.payload.findByID({
|
|
64
|
+
id: authenticatedUser.id,
|
|
65
|
+
collection: authenticatedUser.collection,
|
|
66
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
67
|
+
req: authReq,
|
|
68
|
+
})
|
|
69
|
+
result.user = {
|
|
70
|
+
...user,
|
|
71
|
+
_sid: authenticatedUser._sid,
|
|
72
|
+
_strategy: authenticatedUser._strategy,
|
|
73
|
+
collection: authenticatedUser.collection,
|
|
74
|
+
}
|
|
75
|
+
}
|
|
57
76
|
return {
|
|
58
77
|
content: [
|
|
59
78
|
{
|
|
@@ -65,8 +84,8 @@ export const authCollectionTool = defineCollectionTool({
|
|
|
65
84
|
}
|
|
66
85
|
} catch (error) {
|
|
67
86
|
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
68
|
-
logger.error(`Error in auth tool on ${
|
|
69
|
-
return wrapError('auth')({
|
|
87
|
+
logger.error(`Error in auth tool on ${slug}: ${errorMessage}`)
|
|
88
|
+
return wrapError('auth')({ slug, message: errorMessage })
|
|
70
89
|
}
|
|
71
90
|
})
|
|
72
91
|
|
|
@@ -79,35 +98,31 @@ export const forgotPasswordCollectionTool = defineCollectionTool({
|
|
|
79
98
|
title: 'Forgot Password',
|
|
80
99
|
},
|
|
81
100
|
description: 'Sends a password reset email to a user.',
|
|
82
|
-
input:
|
|
83
|
-
disableEmail: z
|
|
84
|
-
.boolean()
|
|
85
|
-
.describe('Whether to disable sending the email (for testing)')
|
|
86
|
-
.optional()
|
|
87
|
-
.default(false),
|
|
101
|
+
input: strictObject({
|
|
88
102
|
email: emailSchema,
|
|
89
103
|
}),
|
|
90
|
-
}).handler(async ({
|
|
104
|
+
}).handler(async ({ slug, input, req }) => {
|
|
91
105
|
const logger = getLogger({ payload: req.payload })
|
|
92
106
|
try {
|
|
93
|
-
|
|
94
|
-
collection:
|
|
107
|
+
await req.payload.forgotPassword({
|
|
108
|
+
collection: slug,
|
|
95
109
|
data: { email: input.email },
|
|
96
|
-
disableEmail:
|
|
110
|
+
disableEmail: false,
|
|
111
|
+
overrideAccess: false,
|
|
112
|
+
req,
|
|
97
113
|
})
|
|
98
114
|
return {
|
|
99
115
|
content: [
|
|
100
116
|
{
|
|
101
117
|
type: 'text',
|
|
102
|
-
text:
|
|
118
|
+
text: 'If an account matches that email, password reset instructions have been sent.',
|
|
103
119
|
},
|
|
104
120
|
],
|
|
105
|
-
doc: { result } as Record<string, unknown>,
|
|
106
121
|
}
|
|
107
122
|
} catch (error) {
|
|
108
123
|
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
109
|
-
logger.error(`Error in forgotPassword tool on ${
|
|
110
|
-
return wrapError('forgotPassword')({
|
|
124
|
+
logger.error(`Error in forgotPassword tool on ${slug}: ${errorMessage}`)
|
|
125
|
+
return wrapError('forgotPassword')({ slug, message: errorMessage })
|
|
111
126
|
}
|
|
112
127
|
})
|
|
113
128
|
|
|
@@ -120,45 +135,35 @@ export const loginCollectionTool = defineCollectionTool({
|
|
|
120
135
|
title: 'User Login',
|
|
121
136
|
},
|
|
122
137
|
description: 'Authenticates a user with email and password.',
|
|
123
|
-
input:
|
|
138
|
+
input: strictObject({
|
|
124
139
|
depth: z
|
|
125
|
-
.
|
|
126
|
-
.
|
|
127
|
-
.min(0)
|
|
128
|
-
.max(10)
|
|
129
|
-
.describe('Depth of population for relationships')
|
|
130
|
-
.optional()
|
|
131
|
-
.default(0),
|
|
140
|
+
._default(z.int().check(z.minimum(0), z.maximum(10)), 0)
|
|
141
|
+
.check(z.describe('Depth of population for relationships.')),
|
|
132
142
|
email: emailSchema,
|
|
133
|
-
password: z.string().describe('The user password'),
|
|
134
|
-
showHiddenFields: z
|
|
135
|
-
.boolean()
|
|
136
|
-
.describe('Whether to show hidden fields in the response')
|
|
137
|
-
.optional()
|
|
138
|
-
.default(false),
|
|
143
|
+
password: z.string().check(z.describe('The user password.')),
|
|
139
144
|
}),
|
|
140
|
-
}).handler(async ({
|
|
145
|
+
}).handler(async ({ slug, authorizedMCP, input, req }) => {
|
|
141
146
|
const logger = getLogger({ payload: req.payload })
|
|
142
147
|
try {
|
|
143
148
|
const result = await req.payload.login({
|
|
144
|
-
collection:
|
|
149
|
+
collection: slug,
|
|
145
150
|
data: { email: input.email, password: input.password },
|
|
146
151
|
depth: input.depth,
|
|
147
|
-
|
|
152
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
148
153
|
})
|
|
149
154
|
return {
|
|
150
155
|
content: [
|
|
151
156
|
{
|
|
152
157
|
type: 'text',
|
|
153
|
-
text: `# Login Successful\n\n**User:** ${input.email}\n**Collection:** ${
|
|
158
|
+
text: `# Login Successful\n\n**User:** ${input.email}\n**Collection:** ${slug}\n\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
154
159
|
},
|
|
155
160
|
],
|
|
156
161
|
doc: result as unknown as Record<string, unknown>,
|
|
157
162
|
}
|
|
158
163
|
} catch (error) {
|
|
159
164
|
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
160
|
-
logger.error(`Error in login tool on ${
|
|
161
|
-
return wrapError('login')({
|
|
165
|
+
logger.error(`Error in login tool on ${slug}: ${errorMessage}`)
|
|
166
|
+
return wrapError('login')({ slug, message: errorMessage })
|
|
162
167
|
}
|
|
163
168
|
})
|
|
164
169
|
|
|
@@ -171,35 +176,37 @@ export const resetPasswordCollectionTool = defineCollectionTool({
|
|
|
171
176
|
title: 'Reset Password',
|
|
172
177
|
},
|
|
173
178
|
description: 'Resets a user password with a reset token.',
|
|
174
|
-
input:
|
|
175
|
-
password: z.string().describe('The new password for the user'),
|
|
176
|
-
token: z.string().describe('The password reset token sent to the user email'),
|
|
179
|
+
input: strictObject({
|
|
180
|
+
password: z.string().check(z.describe('The new password for the user.')),
|
|
181
|
+
token: z.string().check(z.describe('The password reset token sent to the user email.')),
|
|
177
182
|
}),
|
|
178
|
-
}).handler(async ({
|
|
183
|
+
}).handler(async ({ slug, authorizedMCP, input, req }) => {
|
|
179
184
|
const logger = getLogger({ payload: req.payload })
|
|
180
185
|
try {
|
|
181
186
|
const result = await req.payload.resetPassword({
|
|
182
|
-
collection:
|
|
187
|
+
collection: slug,
|
|
183
188
|
data: { password: input.password, token: input.token },
|
|
184
|
-
overrideAccess:
|
|
189
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
185
190
|
})
|
|
186
191
|
return {
|
|
187
192
|
content: [
|
|
188
193
|
{
|
|
189
194
|
type: 'text',
|
|
190
|
-
text: `# Password Reset Successful\n\n**Collection:** ${
|
|
195
|
+
text: `# Password Reset Successful\n\n**Collection:** ${slug}\n\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
191
196
|
},
|
|
192
197
|
],
|
|
193
198
|
doc: result as unknown as Record<string, unknown>,
|
|
194
199
|
}
|
|
195
200
|
} catch (error) {
|
|
196
201
|
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
197
|
-
logger.error(`Error in resetPassword tool on ${
|
|
198
|
-
return wrapError('resetPassword')({
|
|
202
|
+
logger.error(`Error in resetPassword tool on ${slug}: ${errorMessage}`)
|
|
203
|
+
return wrapError('resetPassword')({ slug, message: errorMessage })
|
|
199
204
|
}
|
|
200
205
|
})
|
|
201
206
|
|
|
202
207
|
export const unlockCollectionTool = defineCollectionTool({
|
|
208
|
+
access: (args) =>
|
|
209
|
+
defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.unlock),
|
|
203
210
|
annotations: {
|
|
204
211
|
destructiveHint: false,
|
|
205
212
|
idempotentHint: true,
|
|
@@ -208,28 +215,29 @@ export const unlockCollectionTool = defineCollectionTool({
|
|
|
208
215
|
title: 'Unlock Account',
|
|
209
216
|
},
|
|
210
217
|
description: 'Unlocks a user account that has been locked due to failed login attempts.',
|
|
211
|
-
input:
|
|
212
|
-
}).handler(async ({
|
|
218
|
+
input: strictObject({ email: emailSchema }),
|
|
219
|
+
}).handler(async ({ slug, authorizedMCP, input, req }) => {
|
|
213
220
|
const logger = getLogger({ payload: req.payload })
|
|
214
221
|
try {
|
|
215
222
|
const result = await req.payload.unlock({
|
|
216
|
-
collection:
|
|
223
|
+
collection: slug,
|
|
217
224
|
data: { email: input.email },
|
|
218
|
-
overrideAccess:
|
|
225
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
226
|
+
req,
|
|
219
227
|
})
|
|
220
228
|
return {
|
|
221
229
|
content: [
|
|
222
230
|
{
|
|
223
231
|
type: 'text',
|
|
224
|
-
text: `# Account Unlocked\n\n**Collection:** ${
|
|
232
|
+
text: `# Account Unlocked\n\n**Collection:** ${slug}\n**Email:** ${input.email}\n**Result:** ${result ? 'Success' : 'Failed'}`,
|
|
225
233
|
},
|
|
226
234
|
],
|
|
227
235
|
doc: { result } as Record<string, unknown>,
|
|
228
236
|
}
|
|
229
237
|
} catch (error) {
|
|
230
238
|
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
231
|
-
logger.error(`Error in unlock tool on ${
|
|
232
|
-
return wrapError('unlock')({
|
|
239
|
+
logger.error(`Error in unlock tool on ${slug}: ${errorMessage}`)
|
|
240
|
+
return wrapError('unlock')({ slug, message: errorMessage })
|
|
233
241
|
}
|
|
234
242
|
})
|
|
235
243
|
|
|
@@ -242,28 +250,28 @@ export const verifyCollectionTool = defineCollectionTool({
|
|
|
242
250
|
title: 'Email Verification',
|
|
243
251
|
},
|
|
244
252
|
description: 'Verifies a user email with a verification token.',
|
|
245
|
-
input:
|
|
246
|
-
token: z.string().describe('The verification token sent to the user email'),
|
|
253
|
+
input: strictObject({
|
|
254
|
+
token: z.string().check(z.describe('The verification token sent to the user email.')),
|
|
247
255
|
}),
|
|
248
|
-
}).handler(async ({
|
|
256
|
+
}).handler(async ({ slug, input, req }) => {
|
|
249
257
|
const logger = getLogger({ payload: req.payload })
|
|
250
258
|
try {
|
|
251
259
|
const result = await req.payload.verifyEmail({
|
|
252
|
-
collection:
|
|
260
|
+
collection: slug,
|
|
253
261
|
token: input.token,
|
|
254
262
|
})
|
|
255
263
|
return {
|
|
256
264
|
content: [
|
|
257
265
|
{
|
|
258
266
|
type: 'text',
|
|
259
|
-
text: `# Email Verification Successful\n\n**Collection:** ${
|
|
267
|
+
text: `# Email Verification Successful\n\n**Collection:** ${slug}\n**Result:** ${result ? 'Success' : 'Failed'}`,
|
|
260
268
|
},
|
|
261
269
|
],
|
|
262
270
|
doc: { result } as Record<string, unknown>,
|
|
263
271
|
}
|
|
264
272
|
} catch (error) {
|
|
265
273
|
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
266
|
-
logger.error(`Error in verify tool on ${
|
|
267
|
-
return wrapError('verify')({
|
|
274
|
+
logger.error(`Error in verify tool on ${slug}: ${errorMessage}`)
|
|
275
|
+
return wrapError('verify')({ slug, message: errorMessage })
|
|
268
276
|
}
|
|
269
277
|
})
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { countDocumentsInputSchema } from 'payload'
|
|
2
2
|
|
|
3
3
|
import { defaultAccess } from '../../../defaultAccess.js'
|
|
4
4
|
import { defineCollectionTool } from '../../../defineTool.js'
|
|
5
5
|
import { getLogger } from '../../../utils/getLogger.js'
|
|
6
|
-
import { whereSchema } from '../../../utils/whereSchema.js'
|
|
7
6
|
|
|
8
7
|
const DEFAULT_DESCRIPTION =
|
|
9
8
|
'Count documents in any collection by passing the collection slug and optional where clause.'
|
|
10
9
|
|
|
11
10
|
export const countDocumentsTool = defineCollectionTool({
|
|
12
11
|
access: (args) =>
|
|
13
|
-
defaultAccess(args) && Boolean(args.permissions?.collections?.[args.
|
|
12
|
+
defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.read),
|
|
14
13
|
annotations: {
|
|
15
14
|
destructiveHint: false,
|
|
16
15
|
idempotentHint: true,
|
|
@@ -19,28 +18,17 @@ export const countDocumentsTool = defineCollectionTool({
|
|
|
19
18
|
title: 'Count Documents',
|
|
20
19
|
},
|
|
21
20
|
description: DEFAULT_DESCRIPTION,
|
|
22
|
-
input:
|
|
23
|
-
|
|
24
|
-
trash: z
|
|
25
|
-
.boolean()
|
|
26
|
-
.describe('Optional: include soft-deleted documents when trash is enabled on the collection')
|
|
27
|
-
.optional(),
|
|
28
|
-
where: whereSchema
|
|
29
|
-
.describe(
|
|
30
|
-
'Optional: where clause for filtering. Use field names with Payload operators, and/or arrays for grouping. Example: {"title":{"contains":"test"}}',
|
|
31
|
-
)
|
|
32
|
-
.optional(),
|
|
33
|
-
}),
|
|
34
|
-
}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {
|
|
21
|
+
input: countDocumentsInputSchema,
|
|
22
|
+
}).handler(async ({ slug, authorizedMCP, input, req }) => {
|
|
35
23
|
const payload = req.payload
|
|
36
24
|
const logger = getLogger({ payload })
|
|
37
25
|
const { locale, trash, where } = input
|
|
38
26
|
|
|
39
|
-
logger.info(`Counting documents in collection: ${
|
|
27
|
+
logger.info(`Counting documents in collection: ${slug}`)
|
|
40
28
|
|
|
41
29
|
try {
|
|
42
30
|
const result = await payload.count({
|
|
43
|
-
collection:
|
|
31
|
+
collection: slug,
|
|
44
32
|
overrideAccess: authorizedMCP.overrideAccess,
|
|
45
33
|
req,
|
|
46
34
|
...(locale ? { locale } : {}),
|
|
@@ -52,19 +40,19 @@ export const countDocumentsTool = defineCollectionTool({
|
|
|
52
40
|
content: [
|
|
53
41
|
{
|
|
54
42
|
type: 'text',
|
|
55
|
-
text: `Collection "${
|
|
43
|
+
text: `Collection "${slug}" contains ${result.totalDocs} matching documents.\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
56
44
|
},
|
|
57
45
|
],
|
|
58
46
|
doc: result,
|
|
59
47
|
}
|
|
60
48
|
} catch (error) {
|
|
61
49
|
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
62
|
-
logger.error(`Error counting documents in ${
|
|
50
|
+
logger.error(`Error counting documents in ${slug}: ${errorMessage}`)
|
|
63
51
|
return {
|
|
64
52
|
content: [
|
|
65
53
|
{
|
|
66
54
|
type: 'text',
|
|
67
|
-
text: `❌ **Error counting documents in collection "${
|
|
55
|
+
text: `❌ **Error counting documents in collection "${slug}":** ${errorMessage}`,
|
|
68
56
|
},
|
|
69
57
|
],
|
|
70
58
|
isError: true,
|
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { countVersionsInputSchema } from 'payload'
|
|
2
2
|
|
|
3
3
|
import { defaultAccess } from '../../../defaultAccess.js'
|
|
4
4
|
import { defineCollectionTool } from '../../../defineTool.js'
|
|
5
5
|
import { getLogger } from '../../../utils/getLogger.js'
|
|
6
|
-
import { whereSchema } from '../../../utils/whereSchema.js'
|
|
7
6
|
|
|
8
7
|
const DEFAULT_DESCRIPTION =
|
|
9
8
|
'Count document versions in any version-enabled collection by passing the collection slug and optional where clause.'
|
|
10
9
|
|
|
11
10
|
export const countVersionsTool = defineCollectionTool({
|
|
12
11
|
access: (args) =>
|
|
13
|
-
defaultAccess(args) &&
|
|
14
|
-
Boolean(args.permissions?.collections?.[args.collectionSlug]?.readVersions),
|
|
12
|
+
defaultAccess(args) && Boolean(args.permissions?.collections?.[args.slug]?.readVersions),
|
|
15
13
|
annotations: {
|
|
16
14
|
destructiveHint: false,
|
|
17
15
|
idempotentHint: true,
|
|
@@ -20,24 +18,17 @@ export const countVersionsTool = defineCollectionTool({
|
|
|
20
18
|
title: 'Count Versions',
|
|
21
19
|
},
|
|
22
20
|
description: DEFAULT_DESCRIPTION,
|
|
23
|
-
input:
|
|
24
|
-
|
|
25
|
-
where: whereSchema
|
|
26
|
-
.describe(
|
|
27
|
-
'Optional: where clause for filtering versions. Version document fields are usually under "version". Example: {"version.title":{"contains":"test"}}',
|
|
28
|
-
)
|
|
29
|
-
.optional(),
|
|
30
|
-
}),
|
|
31
|
-
}).handler(async ({ authorizedMCP, collectionSlug, input, req }) => {
|
|
21
|
+
input: countVersionsInputSchema,
|
|
22
|
+
}).handler(async ({ slug, authorizedMCP, input, req }) => {
|
|
32
23
|
const payload = req.payload
|
|
33
24
|
const logger = getLogger({ payload })
|
|
34
25
|
const { locale, where } = input
|
|
35
26
|
|
|
36
|
-
logger.info(`Counting versions in collection: ${
|
|
27
|
+
logger.info(`Counting versions in collection: ${slug}`)
|
|
37
28
|
|
|
38
29
|
try {
|
|
39
30
|
const result = await payload.countVersions({
|
|
40
|
-
collection:
|
|
31
|
+
collection: slug,
|
|
41
32
|
overrideAccess: authorizedMCP.overrideAccess,
|
|
42
33
|
req,
|
|
43
34
|
...(locale ? { locale } : {}),
|
|
@@ -48,19 +39,19 @@ export const countVersionsTool = defineCollectionTool({
|
|
|
48
39
|
content: [
|
|
49
40
|
{
|
|
50
41
|
type: 'text',
|
|
51
|
-
text: `Collection "${
|
|
42
|
+
text: `Collection "${slug}" contains ${result.totalDocs} matching versions.\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
52
43
|
},
|
|
53
44
|
],
|
|
54
45
|
doc: result,
|
|
55
46
|
}
|
|
56
47
|
} catch (error) {
|
|
57
48
|
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
58
|
-
logger.error(`Error counting versions in ${
|
|
49
|
+
logger.error(`Error counting versions in ${slug}: ${errorMessage}`)
|
|
59
50
|
return {
|
|
60
51
|
content: [
|
|
61
52
|
{
|
|
62
53
|
type: 'text',
|
|
63
|
-
text: `❌ **Error counting versions in collection "${
|
|
54
|
+
text: `❌ **Error counting versions in collection "${slug}":** ${errorMessage}`,
|
|
64
55
|
},
|
|
65
56
|
],
|
|
66
57
|
isError: true,
|