@payloadcms/plugin-mcp 4.0.0-internal.d21c039 → 4.0.0-internal.d3909a9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin.js +0 -7
- package/dist/endpoint/index.d.ts.map +1 -1
- package/dist/endpoint/index.js +33 -4
- package/dist/endpoint/index.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/mcp/buildMcpServer.d.ts +1 -1
- package/dist/mcp/buildMcpServer.js +2 -2
- 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 +4 -3
- package/dist/mcp/builtin/collections/authTools.js.map +1 -1
- package/dist/mcp/builtin/collections/createTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/createTool.js.map +1 -1
- package/dist/mcp/builtin/collections/deleteTool.js.map +1 -1
- package/dist/mcp/builtin/collections/duplicateTool.js.map +1 -1
- package/dist/mcp/builtin/collections/findTool.js +1 -1
- package/dist/mcp/builtin/collections/findTool.js.map +1 -1
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.d.ts.map +1 -1
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js +19 -3
- package/dist/mcp/builtin/collections/getCollectionSchemaTool.js.map +1 -1
- package/dist/mcp/builtin/collections/restoreVersionTool.js.map +1 -1
- package/dist/mcp/builtin/collections/updateTool.js.map +1 -1
- package/dist/mcp/builtin/collections/uploadInstructionsTool.js.map +1 -1
- package/dist/mcp/builtin/globals/findTool.js.map +1 -1
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.d.ts.map +1 -1
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js +19 -3
- package/dist/mcp/builtin/globals/getGlobalSchemaTool.js.map +1 -1
- package/dist/mcp/builtin/globals/updateTool.js.map +1 -1
- package/dist/stdio.js +4 -3
- package/dist/stdio.js.map +1 -1
- package/dist/types.d.ts +10 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/toStandardSchema.js.map +1 -1
- package/package.json +22 -25
- package/src/endpoint/index.ts +33 -3
- package/src/index.ts +1 -1
- package/src/mcp/buildMcpServer.ts +3 -3
- package/src/mcp/builtin/collections/authTools.ts +7 -4
- package/src/mcp/builtin/collections/createTool.ts +1 -3
- package/src/mcp/builtin/collections/deleteTool.ts +1 -1
- package/src/mcp/builtin/collections/duplicateTool.ts +1 -1
- package/src/mcp/builtin/collections/findTool.ts +1 -1
- package/src/mcp/builtin/collections/getCollectionSchemaTool.ts +12 -1
- package/src/mcp/builtin/collections/restoreVersionTool.ts +1 -1
- package/src/mcp/builtin/collections/updateTool.ts +1 -1
- package/src/mcp/builtin/collections/uploadInstructionsTool.ts +1 -1
- package/src/mcp/builtin/globals/findTool.ts +1 -1
- package/src/mcp/builtin/globals/getGlobalSchemaTool.ts +11 -1
- package/src/mcp/builtin/globals/updateTool.ts +1 -1
- package/src/stdio.ts +2 -2
- package/src/types.ts +11 -3
- package/src/utils/toStandardSchema.ts +1 -1
package/package.json
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/plugin-mcp",
|
|
3
|
-
"version": "4.0.0-internal.
|
|
3
|
+
"version": "4.0.0-internal.d3909a9",
|
|
4
4
|
"description": "MCP (Model Context Protocol) capabilities with Payload",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"plugin",
|
|
7
6
|
"mcp",
|
|
8
|
-
"model context protocol"
|
|
7
|
+
"model context protocol",
|
|
8
|
+
"plugin"
|
|
9
9
|
],
|
|
10
|
-
"repository": {
|
|
11
|
-
"type": "git",
|
|
12
|
-
"url": "https://github.com/payloadcms/payload.git",
|
|
13
|
-
"directory": "packages/plugin-mcp"
|
|
14
|
-
},
|
|
15
10
|
"license": "MIT",
|
|
16
11
|
"author": "Payload <dev@payloadcms.com> (https://payloadcms.com)",
|
|
17
12
|
"maintainers": [
|
|
@@ -21,7 +16,22 @@
|
|
|
21
16
|
"url": "https://payloadcms.com"
|
|
22
17
|
}
|
|
23
18
|
],
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/payloadcms/payload.git",
|
|
22
|
+
"directory": "packages/plugin-mcp"
|
|
23
|
+
},
|
|
24
|
+
"bin": {
|
|
25
|
+
"payload-mcp": "./bin.js"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"src",
|
|
29
|
+
"dist",
|
|
30
|
+
"bin.js"
|
|
31
|
+
],
|
|
24
32
|
"type": "module",
|
|
33
|
+
"main": "./dist/index.js",
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
25
35
|
"exports": {
|
|
26
36
|
".": {
|
|
27
37
|
"import": "./dist/index.js",
|
|
@@ -44,26 +54,15 @@
|
|
|
44
54
|
"default": "./dist/exports/internal.js"
|
|
45
55
|
}
|
|
46
56
|
},
|
|
47
|
-
"main": "./dist/index.js",
|
|
48
|
-
"types": "./dist/index.d.ts",
|
|
49
|
-
"bin": {
|
|
50
|
-
"payload-mcp": "./bin.js"
|
|
51
|
-
},
|
|
52
|
-
"files": [
|
|
53
|
-
"src",
|
|
54
|
-
"dist",
|
|
55
|
-
"bin.js"
|
|
56
|
-
],
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@modelcontextprotocol/server": "2.
|
|
59
|
-
"tsx": "4.
|
|
58
|
+
"@modelcontextprotocol/server": "2.3.1",
|
|
59
|
+
"tsx": "4.23.15"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"
|
|
63
|
-
"payload": "4.0.0-internal.d21c039"
|
|
62
|
+
"payload": "4.0.0-internal.d3909a9"
|
|
64
63
|
},
|
|
65
64
|
"peerDependencies": {
|
|
66
|
-
"payload": "4.0.0-internal.
|
|
65
|
+
"payload": "4.0.0-internal.d3909a9"
|
|
67
66
|
},
|
|
68
67
|
"//deps_notes": {
|
|
69
68
|
"tsx": "Required by the `bin.js` stdio mcp. Keep the version pinned to whatever `payload` ships to avoid duplicate installs."
|
|
@@ -76,8 +75,6 @@
|
|
|
76
75
|
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
|
77
76
|
"clean": "rimraf {dist,*.tsbuildinfo}",
|
|
78
77
|
"copyfiles": "copyfiles -u 1 -e \"**/*.spec.*\" \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
|
|
79
|
-
"lint": "eslint .",
|
|
80
|
-
"lint:fix": "eslint . --fix",
|
|
81
78
|
"pack:plugin": "pnpm build && pnpm pack"
|
|
82
79
|
}
|
|
83
80
|
}
|
package/src/endpoint/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { PayloadHandler, PayloadRequest } from 'payload'
|
|
|
3
3
|
import {
|
|
4
4
|
createMcpHandler,
|
|
5
5
|
isLegacyRequest,
|
|
6
|
+
readRequestBody,
|
|
6
7
|
WebStandardStreamableHTTPServerTransport,
|
|
7
8
|
} from '@modelcontextprotocol/server'
|
|
8
9
|
import { APIError } from 'payload'
|
|
@@ -33,14 +34,17 @@ export const mcpEndpoint: PayloadHandler = async (req) => {
|
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
const authorizedMCP = await getAuthorizedMCP({ overrideAccess, req })
|
|
37
|
+
const maxRequestBodySize = pluginConfig.mcp?.maxRequestBodySize
|
|
36
38
|
// Payload augments the original web-standard Request in place.
|
|
37
39
|
const mcpRequest = req as PayloadRequest & Request
|
|
40
|
+
const parsedBody = await parseRequestBody({ maxRequestBodySize, request: mcpRequest })
|
|
38
41
|
|
|
39
42
|
// Keep the old JSON-only, stateless behavior because the SDK's 2025 fallback uses SSE.
|
|
40
|
-
if (await isLegacyRequest(mcpRequest)) {
|
|
43
|
+
if (await isLegacyRequest(mcpRequest, parsedBody, { maxRequestBodySize })) {
|
|
41
44
|
const server = buildMcpServer({ authorizedMCP, pluginConfig, req })
|
|
42
45
|
const transport = new WebStandardStreamableHTTPServerTransport({
|
|
43
46
|
enableJsonResponse: true,
|
|
47
|
+
maxRequestBodySize,
|
|
44
48
|
sessionIdGenerator: undefined, // stateless mode
|
|
45
49
|
})
|
|
46
50
|
transport.onerror = (err) => {
|
|
@@ -49,7 +53,7 @@ export const mcpEndpoint: PayloadHandler = async (req) => {
|
|
|
49
53
|
|
|
50
54
|
try {
|
|
51
55
|
await server.connect(transport)
|
|
52
|
-
return await transport.handleRequest(mcpRequest)
|
|
56
|
+
return await transport.handleRequest(mcpRequest, { parsedBody })
|
|
53
57
|
} finally {
|
|
54
58
|
await server.close().catch((err) => {
|
|
55
59
|
req.payload.logger.error({ err, msg: 'Error closing MCP server' })
|
|
@@ -59,6 +63,7 @@ export const mcpEndpoint: PayloadHandler = async (req) => {
|
|
|
59
63
|
|
|
60
64
|
const handler = createMcpHandler(() => buildMcpServer({ authorizedMCP, pluginConfig, req }), {
|
|
61
65
|
legacy: 'reject',
|
|
66
|
+
maxRequestBodySize,
|
|
62
67
|
// SDK subscriptions always use SSE, so disable them to keep every response JSON-only.
|
|
63
68
|
maxSubscriptions: 0,
|
|
64
69
|
onerror: (err) => {
|
|
@@ -68,10 +73,35 @@ export const mcpEndpoint: PayloadHandler = async (req) => {
|
|
|
68
73
|
})
|
|
69
74
|
|
|
70
75
|
try {
|
|
71
|
-
return await handler.fetch(mcpRequest)
|
|
76
|
+
return await handler.fetch(mcpRequest, { parsedBody })
|
|
72
77
|
} finally {
|
|
73
78
|
await handler.close().catch((err) => {
|
|
74
79
|
req.payload.logger.error({ err, msg: 'Error closing modern MCP handler' })
|
|
75
80
|
})
|
|
76
81
|
}
|
|
77
82
|
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Parses a POST body once so the era check and the SDK handler can share it. The SDK
|
|
86
|
+
* skips its size limit for a pre-parsed body, so this reads with the same limit. It reads
|
|
87
|
+
* a clone and returns `undefined` for any body the SDK should reject (too large, unreadable,
|
|
88
|
+
* or not JSON), leaving the original request for the SDK to read and answer.
|
|
89
|
+
*/
|
|
90
|
+
const parseRequestBody = async ({
|
|
91
|
+
maxRequestBodySize,
|
|
92
|
+
request,
|
|
93
|
+
}: {
|
|
94
|
+
maxRequestBodySize?: number
|
|
95
|
+
request: Request
|
|
96
|
+
}): Promise<unknown> => {
|
|
97
|
+
if (request.method.toUpperCase() !== 'POST') {
|
|
98
|
+
return undefined
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
try {
|
|
102
|
+
const body = await readRequestBody(request.clone(), maxRequestBodySize)
|
|
103
|
+
return body.tooLarge ? undefined : JSON.parse(body.text)
|
|
104
|
+
} catch {
|
|
105
|
+
return undefined
|
|
106
|
+
}
|
|
107
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -29,7 +29,7 @@ export const mcpPlugin = definePlugin<MCPPluginConfig>({
|
|
|
29
29
|
const registered = plugins['@payloadcms/plugin-mcp']
|
|
30
30
|
if (registered) {
|
|
31
31
|
// @ts-expect-error
|
|
32
|
-
registered.sanitizedOptions = pluginConfig
|
|
32
|
+
registered.sanitizedOptions = pluginConfig
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
if (pluginConfig.disabled) {
|
|
@@ -25,7 +25,7 @@ import { toStandardSchema } from '../utils/toStandardSchema.js'
|
|
|
25
25
|
*
|
|
26
26
|
* `req` is the request context handlers see. For HTTP it's the live
|
|
27
27
|
* `PayloadRequest` derived from the incoming HTTP request; for stdio it's a
|
|
28
|
-
* synthesized one built via `
|
|
28
|
+
* synthesized one built via `createPayloadRequest`.
|
|
29
29
|
*/
|
|
30
30
|
export const buildMcpServer = ({
|
|
31
31
|
authorizedMCP,
|
|
@@ -250,7 +250,7 @@ const withSlugInput = ({ input }: { input?: ToolInputSchema }): ToolInputSchema
|
|
|
250
250
|
const slugSchema = z.string().check(z.describe(description))
|
|
251
251
|
|
|
252
252
|
if (!input) {
|
|
253
|
-
return strictObject({ slug: slugSchema })
|
|
253
|
+
return strictObject({ slug: slugSchema })
|
|
254
254
|
}
|
|
255
255
|
|
|
256
256
|
if (typeof input === 'object' && input !== null && '~standard' in input) {
|
|
@@ -261,7 +261,7 @@ const withSlugInput = ({ input }: { input?: ToolInputSchema }): ToolInputSchema
|
|
|
261
261
|
return input
|
|
262
262
|
}
|
|
263
263
|
|
|
264
|
-
return addSlugToJSONSchema({ description, schema
|
|
264
|
+
return addSlugToJSONSchema({ description, schema })
|
|
265
265
|
}
|
|
266
266
|
|
|
267
267
|
return addSlugToJSONSchema({ description, schema: input })
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createPayloadRequest, strictObject, z } from 'payload'
|
|
2
2
|
|
|
3
3
|
import type { MCPToolResponse } from '../../../types.js'
|
|
4
4
|
|
|
@@ -53,7 +53,10 @@ export const authCollectionTool = defineCollectionTool({
|
|
|
53
53
|
if (input.headers) {
|
|
54
54
|
authHeaders = new Headers(input.headers)
|
|
55
55
|
}
|
|
56
|
-
const authReq = await
|
|
56
|
+
const authReq = await createPayloadRequest({
|
|
57
|
+
payload: req.payload,
|
|
58
|
+
req: { headers: authHeaders },
|
|
59
|
+
})
|
|
57
60
|
const result = await req.payload.auth({ headers: authHeaders, req: authReq })
|
|
58
61
|
|
|
59
62
|
if (result.user) {
|
|
@@ -232,7 +235,7 @@ export const unlockCollectionTool = defineCollectionTool({
|
|
|
232
235
|
text: `# Account Unlocked\n\n**Collection:** ${slug}\n**Email:** ${input.email}\n**Result:** ${result ? 'Success' : 'Failed'}`,
|
|
233
236
|
},
|
|
234
237
|
],
|
|
235
|
-
doc: { result }
|
|
238
|
+
doc: { result },
|
|
236
239
|
}
|
|
237
240
|
} catch (error) {
|
|
238
241
|
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
@@ -267,7 +270,7 @@ export const verifyCollectionTool = defineCollectionTool({
|
|
|
267
270
|
text: `# Email Verification Successful\n\n**Collection:** ${slug}\n**Result:** ${result ? 'Success' : 'Failed'}`,
|
|
268
271
|
},
|
|
269
272
|
],
|
|
270
|
-
doc: { result }
|
|
273
|
+
doc: { result },
|
|
271
274
|
}
|
|
272
275
|
} catch (error) {
|
|
273
276
|
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
@@ -83,9 +83,7 @@ export const createDocumentsTool = defineCollectionTool({
|
|
|
83
83
|
select: returning ? select : { id: true },
|
|
84
84
|
})
|
|
85
85
|
|
|
86
|
-
docs.push(
|
|
87
|
-
returning ? { doc: result as Record<string, unknown>, index } : { id: result.id, index },
|
|
88
|
-
)
|
|
86
|
+
docs.push(returning ? { doc: result, index } : { id: result.id, index })
|
|
89
87
|
} catch (error) {
|
|
90
88
|
const message = error instanceof Error ? error.message : 'Unknown error'
|
|
91
89
|
const formattedError = formatEntityError({
|
|
@@ -48,7 +48,7 @@ export const deleteDocumentsTool = defineCollectionTool({
|
|
|
48
48
|
text: `Document deleted successfully from collection "${slug}"!\nDeleted document:\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
49
49
|
},
|
|
50
50
|
],
|
|
51
|
-
doc: result
|
|
51
|
+
doc: result,
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -74,7 +74,7 @@ export const duplicateDocumentTool = defineCollectionTool({
|
|
|
74
74
|
text: `Document duplicated successfully in collection "${slug}"!\nDuplicated document:\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
75
75
|
},
|
|
76
76
|
],
|
|
77
|
-
doc: result
|
|
77
|
+
doc: result,
|
|
78
78
|
}
|
|
79
79
|
} catch (error) {
|
|
80
80
|
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
@@ -69,7 +69,7 @@ export const findDocumentsTool = defineCollectionTool({
|
|
|
69
69
|
text: `Document from collection "${slug}":\n${JSON.stringify(doc)}`,
|
|
70
70
|
},
|
|
71
71
|
],
|
|
72
|
-
doc
|
|
72
|
+
doc,
|
|
73
73
|
}
|
|
74
74
|
} catch {
|
|
75
75
|
logger.warn(`Document not found with ID: ${id} in collection: ${slug}`)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getAccessResults, getCollectionInputSchema, getCollectionSchemaInputSchema } from 'payload'
|
|
2
|
+
import { getLLMInstructions } from 'payload/internal'
|
|
2
3
|
|
|
3
4
|
import { defaultAccess } from '../../../defaultAccess.js'
|
|
4
5
|
import { defineCollectionTool } from '../../../defineTool.js'
|
|
@@ -16,7 +17,8 @@ export const getCollectionSchemaTool = defineCollectionTool({
|
|
|
16
17
|
readOnlyHint: true,
|
|
17
18
|
title: 'Get Collection Schema',
|
|
18
19
|
},
|
|
19
|
-
description:
|
|
20
|
+
description:
|
|
21
|
+
'Get the input schema and LLM instructions before creating or updating documents in a collection.',
|
|
20
22
|
input: getCollectionSchemaInputSchema,
|
|
21
23
|
}).handler(async ({ slug, authorizedMCP, req }) => {
|
|
22
24
|
const permissions = authorizedMCP.overrideAccess
|
|
@@ -64,17 +66,26 @@ export const getCollectionSchemaTool = defineCollectionTool({
|
|
|
64
66
|
}
|
|
65
67
|
: { enabled: false }
|
|
66
68
|
|
|
69
|
+
const instructions = await getLLMInstructions({
|
|
70
|
+
slug,
|
|
71
|
+
type: 'collection',
|
|
72
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
73
|
+
req,
|
|
74
|
+
})
|
|
75
|
+
|
|
67
76
|
return {
|
|
68
77
|
content: [
|
|
69
78
|
{
|
|
70
79
|
type: 'text',
|
|
71
80
|
text: `Schema for collection "${slug}":\n\`\`\`json\n${JSON.stringify(inputSchema)}\n\`\`\`\nUpload configuration:\n\`\`\`json\n${JSON.stringify(upload)}\n\`\`\``,
|
|
72
81
|
},
|
|
82
|
+
...(instructions ? [{ type: 'text' as const, text: instructions }] : []),
|
|
73
83
|
],
|
|
74
84
|
structuredContent: {
|
|
75
85
|
slug,
|
|
76
86
|
schema: inputSchema,
|
|
77
87
|
upload,
|
|
88
|
+
...(instructions ? { instructions } : {}),
|
|
78
89
|
},
|
|
79
90
|
}
|
|
80
91
|
})
|
|
@@ -47,7 +47,7 @@ export const restoreVersionTool = defineCollectionTool({
|
|
|
47
47
|
text: `Version "${id}" restored successfully in collection "${slug}"!\nRestored document:\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
48
48
|
},
|
|
49
49
|
],
|
|
50
|
-
doc: result
|
|
50
|
+
doc: result,
|
|
51
51
|
}
|
|
52
52
|
} catch (error) {
|
|
53
53
|
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
@@ -103,7 +103,7 @@ export const updateDocumentTool = defineCollectionTool({
|
|
|
103
103
|
text: `Document updated successfully in collection "${slug}"!\nResult:\n\`\`\`json\n${JSON.stringify(responseResult)}\n\`\`\``,
|
|
104
104
|
},
|
|
105
105
|
],
|
|
106
|
-
doc: responseResult
|
|
106
|
+
doc: responseResult,
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
|
|
@@ -9,7 +9,7 @@ export const getUploadInstructionsTool = defineCollectionTool({
|
|
|
9
9
|
defaultAccess(args) &&
|
|
10
10
|
Boolean(
|
|
11
11
|
args.permissions?.collections?.[args.slug]?.create ||
|
|
12
|
-
|
|
12
|
+
args.permissions?.collections?.[args.slug]?.update,
|
|
13
13
|
),
|
|
14
14
|
annotations: {
|
|
15
15
|
destructiveHint: false,
|
|
@@ -54,7 +54,7 @@ export const findGlobalTool = defineGlobalTool({
|
|
|
54
54
|
text: `Global "${slug}":\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
55
55
|
},
|
|
56
56
|
],
|
|
57
|
-
doc: result
|
|
57
|
+
doc: result,
|
|
58
58
|
}
|
|
59
59
|
} catch (error) {
|
|
60
60
|
const errorMessage = error instanceof Error ? error.message : 'Unknown error'
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getAccessResults, getGlobalInputSchema, getGlobalSchemaInputSchema } from 'payload'
|
|
2
|
+
import { getLLMInstructions } from 'payload/internal'
|
|
2
3
|
|
|
3
4
|
import { defaultAccess } from '../../../defaultAccess.js'
|
|
4
5
|
import { defineGlobalTool } from '../../../defineTool.js'
|
|
@@ -16,7 +17,7 @@ export const getGlobalSchemaTool = defineGlobalTool({
|
|
|
16
17
|
readOnlyHint: true,
|
|
17
18
|
title: 'Get Global Schema',
|
|
18
19
|
},
|
|
19
|
-
description: 'Get the input schema
|
|
20
|
+
description: 'Get the input schema and LLM instructions before updating a global.',
|
|
20
21
|
input: getGlobalSchemaInputSchema,
|
|
21
22
|
}).handler(async ({ slug, authorizedMCP, req }) => {
|
|
22
23
|
const permissions = authorizedMCP.overrideAccess
|
|
@@ -48,16 +49,25 @@ export const getGlobalSchemaTool = defineGlobalTool({
|
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
51
|
|
|
52
|
+
const instructions = await getLLMInstructions({
|
|
53
|
+
slug,
|
|
54
|
+
type: 'global',
|
|
55
|
+
overrideAccess: authorizedMCP.overrideAccess,
|
|
56
|
+
req,
|
|
57
|
+
})
|
|
58
|
+
|
|
51
59
|
return {
|
|
52
60
|
content: [
|
|
53
61
|
{
|
|
54
62
|
type: 'text',
|
|
55
63
|
text: `Schema for global "${slug}":\n\`\`\`json\n${JSON.stringify(inputSchema)}\n\`\`\``,
|
|
56
64
|
},
|
|
65
|
+
...(instructions ? [{ type: 'text' as const, text: instructions }] : []),
|
|
57
66
|
],
|
|
58
67
|
structuredContent: {
|
|
59
68
|
slug,
|
|
60
69
|
schema: inputSchema,
|
|
70
|
+
...(instructions ? { instructions } : {}),
|
|
61
71
|
},
|
|
62
72
|
}
|
|
63
73
|
})
|
|
@@ -82,7 +82,7 @@ export const updateGlobalTool = defineGlobalTool({
|
|
|
82
82
|
text: `Global "${slug}" updated successfully!\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``,
|
|
83
83
|
},
|
|
84
84
|
],
|
|
85
|
-
doc: result
|
|
85
|
+
doc: result,
|
|
86
86
|
}
|
|
87
87
|
} catch (error) {
|
|
88
88
|
const message = error instanceof Error ? error.message : 'Unknown error'
|
package/src/stdio.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { Config, Plugin, SanitizedConfig } from 'payload'
|
|
|
3
3
|
/* eslint-disable no-console */
|
|
4
4
|
import { serveStdio } from '@modelcontextprotocol/server/stdio'
|
|
5
5
|
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
6
|
-
import {
|
|
6
|
+
import { createPayloadRequest, getPayload } from 'payload'
|
|
7
7
|
import { findConfig, loadEnv } from 'payload/node'
|
|
8
8
|
|
|
9
9
|
import type { SanitizedMCPPluginConfig } from './types.js'
|
|
@@ -91,7 +91,7 @@ export const runMcpStdio = async (): Promise<void> => {
|
|
|
91
91
|
headers.set('Authorization', process.env.PAYLOAD_MCP_AUTHORIZATION)
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
const req = await
|
|
94
|
+
const req = await createPayloadRequest({ payload, req: { headers } })
|
|
95
95
|
req.payloadAPI = 'MCP' as const
|
|
96
96
|
const authorizedMCP = await getAuthorizedMCP({ overrideAccess, req })
|
|
97
97
|
|
package/src/types.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
CallToolResult,
|
|
3
3
|
ContentBlock,
|
|
4
|
+
Implementation,
|
|
4
5
|
JsonSchemaType,
|
|
5
|
-
|
|
6
|
+
McpServerOptions,
|
|
6
7
|
ResourceTemplate,
|
|
7
8
|
ServerContext,
|
|
8
9
|
StandardSchemaWithJSON,
|
|
@@ -279,6 +280,13 @@ export type MCPPluginConfig = {
|
|
|
279
280
|
afterToolCall?: MCPAfterToolCallHook[]
|
|
280
281
|
}
|
|
281
282
|
mcp?: {
|
|
283
|
+
/**
|
|
284
|
+
* Largest HTTP request body, in bytes, that the MCP endpoint accepts. Larger requests
|
|
285
|
+
* are answered with `413`. Base64 file uploads count toward this limit.
|
|
286
|
+
*
|
|
287
|
+
* @default 4194304 (4 MiB, the MCP SDK default)
|
|
288
|
+
*/
|
|
289
|
+
maxRequestBodySize?: number
|
|
282
290
|
serverOptions?: MCPServerOptions
|
|
283
291
|
verboseLogs?: boolean
|
|
284
292
|
}
|
|
@@ -304,8 +312,8 @@ export type SanitizedMCPPluginConfig = {
|
|
|
304
312
|
} & Pick<MCPPluginConfig, 'disabled' | 'hooks' | 'mcp' | 'overrideGetAuthorizedMCP'>
|
|
305
313
|
|
|
306
314
|
export type MCPServerOptions = {
|
|
307
|
-
options?:
|
|
308
|
-
serverInfo?: Partial<
|
|
315
|
+
options?: McpServerOptions
|
|
316
|
+
serverInfo?: Partial<Implementation>
|
|
309
317
|
}
|
|
310
318
|
|
|
311
319
|
/**
|
|
@@ -5,5 +5,5 @@ import type { ToolInputSchema } from '../types.js'
|
|
|
5
5
|
/** Normalize a tool/prompt input to a Standard Schema. Raw JSON Schema gets wrapped; Standard Schema instances pass through. */
|
|
6
6
|
export const toStandardSchema = (schema: ToolInputSchema): StandardSchemaWithJSON =>
|
|
7
7
|
typeof schema === 'object' && schema !== null && '~standard' in schema
|
|
8
|
-
?
|
|
8
|
+
? schema
|
|
9
9
|
: fromJsonSchema(schema)
|