You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Removes `override` from the plugin config
- Updates documentation
#14595 makes it so we support
MCP context in hooks, so the config no longer needs an `override` as a
way of modifying model data.
|`collections`|`object`| An object of collection slugs to use for MCP capabilities. |
77
-
|`collections[slug]`|`object`| An object of collection slugs to use for MCP capabilities. |
78
-
|`collections[slug].description`|`string`| A description for the collection. |
79
-
|`collections[slug].override`|`function`| A function that allows you to override the data generated by the LLM before it is used in an operation. |
80
-
|`collections[slug].overrideResponse`|`function`| A function that allows you to override the response from the operation tool call |
81
-
|`collections[slug].enabled`|`object or boolean`| Determines whether the LLM can find, create, update, and delete documents in the collection. |
82
-
|`collections[slug].enabled.find`|`boolean`| Whether to allow the LLM to find documents in the collection. |
83
-
|`collections[slug].enabled.create`|`boolean`| Whether to allow the LLM to create documents in the collection. |
84
-
|`collections[slug].enabled.update`|`boolean`| Whether to allow the LLM to update documents in the collection. |
85
-
|`collections[slug].enabled.delete`|`boolean`| Whether to allow the LLM to delete documents in the collection. |
86
-
|`disabled`|`boolean`| Disable the MCP plugin while keeping database schema consistent. |
87
-
|`overrideApiKeyCollection`|`function`| A function that allows you to override the automatically generated API Keys collection. |
88
-
|`mcp`|`object`| MCP options that allow you to customize the MCP server. |
89
-
|`mcp.tools`|`array`| An array of tools to add to the MCP server. |
90
-
|`mcp.tools.name`|`string`| The name of the tool. |
91
-
|`mcp.tools.description`|`string`| The description of the tool. |
92
-
|`mcp.tools.handler`|`function`| The handler function for the tool. |
93
-
|`mcp.tools.parameters`|`object`| The parameters for the tool (Zod schema). |
94
-
|`mcp.prompts`|`array`| An array of prompts to add to the MCP server. |
95
-
|`mcp.prompts.name`|`string`| The name of the prompt. |
96
-
|`mcp.prompts.title`|`string`| The title of the prompt (used by LLMs to determine when to use it). |
97
-
|`mcp.prompts.description`|`string`| The description of the prompt. |
98
-
|`mcp.prompts.handler`|`function`| The handler function for the prompt. |
99
-
|`mcp.prompts.argsSchema`|`object`| The arguments schema for the prompt (Zod schema). |
100
-
|`mcp.resources`|`array`| An array of resources to add to the MCP server. |
101
-
|`mcp.resources.name`|`string`| The name of the resource. |
102
-
|`mcp.resources.title`|`string`| The title of the resource (used by LLMs to determine when to use it). |
103
-
|`mcp.resources.description`|`string`| The description of the resource. |
104
-
|`mcp.resources.handler`|`function`| The handler function for the resource. |
105
-
|`mcp.resources.uri`|`string or object`| The URI of the resource (can be a string or ResourceTemplate for dynamic URIs). |
106
-
|`mcp.resources.mimeType`|`string`| The MIME type of the resource. |
107
-
|`mcp.handlerOptions`|`object`| The handler options for the MCP server. |
108
-
|`mcp.handlerOptions.basePath`|`string`| The base path for the MCP server (default: '/api'). |
109
-
|`mcp.handlerOptions.verboseLogs`|`boolean`| Whether to log verbose logs to the console (default: false). |
110
-
|`mcp.handlerOptions.maxDuration`|`number`| The maximum duration for the MCP server requests (default: 60). |
111
-
|`mcp.serverOptions`|`object`| The server options for the MCP server. |
112
-
|`mcp.serverOptions.serverInfo`|`object`| The server info for the MCP server. |
113
-
|`mcp.serverOptions.serverInfo.name`|`string`| The name of the MCP server (default: 'Payload MCP Server'). |
114
-
|`mcp.serverOptions.serverInfo.version`|`string`| The version of the MCP server (default: '1.0.0'). |
115
-
116
-
## Override API Keys Collection
117
-
118
-
The plugin automatically creates an **API Keys** collection that provides high-resolution control over MCP capabilities. This collection allows admins to:
119
-
120
-
- Create API keys for MCP clients
121
-
- Allow or disallow specific MCP capabilities in real-time
122
-
- Control which collections can be accessed via MCP
123
-
- Enable or disable tools
124
-
125
-
You can customize this collection using the `overrideApiKeyCollection` option:
Tools allow you to extend MCP capabilities beyond basic CRUD operations. Use them when you need to perform complex queries, aggregations, or business logic that isn't covered by the standard collection operations.
265
193
@@ -294,6 +222,71 @@ tools: [
294
222
]
295
223
```
296
224
225
+
## Override API Keys Collection
226
+
227
+
The plugin automatically creates an **API Keys** collection that provides high-resolution control over MCP capabilities. This collection allows admins to:
228
+
229
+
- Create API keys for MCP clients
230
+
- Allow or disallow specific MCP capabilities in real-time
231
+
- Control which collections can be accessed via MCP
232
+
- Enable or disable tools
233
+
234
+
You can customize this collection using the `overrideApiKeyCollection` option:
235
+
236
+
```ts
237
+
mcpPlugin({
238
+
overrideApiKeyCollection: (collection) => {
239
+
// Add fields to the API Keys collection
240
+
collection.fields.push({
241
+
name: 'department',
242
+
type: 'select',
243
+
options: [
244
+
{ label: 'Development', value: 'dev' },
245
+
{ label: 'Marketing', value: 'marketing' },
246
+
],
247
+
})
248
+
returncollection
249
+
},
250
+
// ... other options
251
+
})
252
+
```
253
+
254
+
## Hooks
255
+
256
+
To understand or modify data returned by models at runtime use a collection [Hook](https://payloadcms.com/docs/hooks/collections). Within a hook you can look up the API context. If the context is `MCP` that collection was triggered by the MCP Plugin. This does not apply to custom tools or resources that have their own context, and can make unrelated database calls.
257
+
258
+
In this example, Post titles are modified to include '(MCP Hook Override)' when they are read using MCP.
259
+
260
+
```ts
261
+
importtype { CollectionConfig } from'payload'
262
+
263
+
exportconst Posts:CollectionConfig= {
264
+
slug: 'posts',
265
+
fields: [
266
+
{
267
+
name: 'title',
268
+
type: 'text',
269
+
admin: {
270
+
description: 'The title of the post',
271
+
},
272
+
required: true,
273
+
},
274
+
275
+
// ... other fields
276
+
],
277
+
hooks: {
278
+
beforeRead: [
279
+
({ doc, req }) => {
280
+
if (req.payloadAPI==='MCP') {
281
+
doc.title=`${doc.title} (MCP Hook Override)`
282
+
}
283
+
returndoc
284
+
},
285
+
],
286
+
},
287
+
}
288
+
```
289
+
297
290
## Performance
298
291
299
292
The description you choose to use for your collection greatly impacts the way a model will decide to use it.
Copy file name to clipboardExpand all lines: packages/plugin-mcp/src/types.ts
-7Lines changed: 0 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -26,13 +26,6 @@ export type PluginMCPServerConfig = {
26
26
update?: boolean
27
27
}
28
28
|boolean
29
-
/**
30
-
* Override the data generated by the MCP client. This allows you to modify the data that is sent to the MCP client. This is useful for adding additional data to the response, data normalization, or verifying data.
31
-
*/
32
-
override?: (
33
-
original: Record<string,unknown>,
34
-
req: PayloadRequest,
35
-
)=>Record<string,unknown>
36
29
37
30
/**
38
31
* Override the response generated by the MCP client. This allows you to modify the response that is sent to the MCP client. This is useful for adding additional data to the response, data normalization, or verifying data.
0 commit comments