Skip to content

Commit 335bb87

Browse files
authored
Merge pull request modelcontextprotocol#16 from modelcontextprotocol/davidsp/prompt-notification
feat: add prompts/list_changed notification
2 parents b03fd43 + 8a99233 commit 335bb87

File tree

4 files changed

+125
-26
lines changed

4 files changed

+125
-26
lines changed

docs/spec/prompts.md

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,36 @@ Prompts enable servers to provide templated conversations or instructions to cli
99
An example of a prompt as a slash command in the Zed editor:
1010
![Slash Command Example](slash-command.png)
1111

12+
## Capabilities
13+
14+
To indicate support for the Prompts API, servers MUST include a `prompts` capability in their `ServerCapabilities` during initialization. The `prompts` capability SHOULD be an empty object:
15+
16+
```json
17+
{
18+
"capabilities": {
19+
"prompts": {}
20+
}
21+
}
22+
```
23+
24+
Clients SHOULD check for this capability before using the Prompts API.
25+
26+
Servers MAY support notifications for changes to the prompt list. If a server supports this feature, it SHOULD include a `listChanged` property in its `prompts` capability:
27+
28+
```json
29+
{
30+
"capabilities": {
31+
"prompts": {
32+
"listChanged": true
33+
}
34+
}
35+
}
36+
```
37+
38+
If a server supports this capability, it MAY send `notifications/prompts/list_changed` notifications to inform the client about changes to the available prompts.
39+
40+
## Concepts
41+
1242
### Prompt
1343

1444
A Prompt in the Model Context Protocol (MCP) represents a pre-defined set of messages or instructions that a server can provide to clients. Each Prompt is uniquely identified by a name and may have associated metadata such as a description and required arguments. Prompts can represent various types of interactions, including code reviews, data analysis tasks, or creative writing prompts.
@@ -221,24 +251,29 @@ Example:
221251
}
222252
```
223253

224-
## Error Handling
225-
226-
Clients MUST be prepared to handle cases where listed prompts become unavailable between listing and retrieval attempts. Servers SHOULD provide appropriate error responses in such scenarios.
227-
228-
## Security Considerations
254+
### Prompt List Changed Notification
229255

230-
Implementations MUST carefully consider the security implications of exposing prompts, especially when dealing with sensitive data or customizable templates. Proper authentication and authorization mechanisms SHOULD be in place to prevent unauthorized access to prompts.
256+
If the server supports the `listChanged` capability for prompts, it MAY send a `notifications/prompts/list_changed` notification to inform the client that the list of available prompts has changed.
231257

232-
## Capabilities
258+
#### Notification
233259

234-
To indicate support for the Prompts API, servers MUST include a `prompts` capability in their `ServerCapabilities` during initialization. The `prompts` capability SHOULD be an empty object:
260+
Method: `notifications/prompts/list_changed`
261+
Params: None
235262

263+
Example:
236264
```json
237265
{
238-
"capabilities": {
239-
"prompts": {}
240-
}
266+
"jsonrpc": "2.0",
267+
"method": "notifications/prompts/list_changed"
241268
}
242269
```
243270

244-
Clients SHOULD check for this capability before using the Prompts API.
271+
Upon receiving this notification, clients SHOULD request an updated prompt list using the `prompts/list` method to ensure they have the most up-to-date information about available prompts.
272+
273+
## Error Handling
274+
275+
Clients MUST be prepared to handle cases where listed prompts become unavailable between listing and retrieval attempts. Servers SHOULD provide appropriate error responses in such scenarios.
276+
277+
## Security Considerations
278+
279+
Implementations MUST carefully consider the security implications of exposing prompts, especially when dealing with sensitive data or customizable templates. Proper authentication and authorization mechanisms SHOULD be in place to prevent unauthorized access to prompts.

docs/spec/resources.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ weight: 4
77

88
Resources enable servers to expose arbitrary data to clients in a structured way, specifically for providing context to language models. Clients can discover available resources, read their contents, and optionally subscribe to updates. Users may explicitly attach resources via the client UI, or clients can intelligently select appropriate resources to add to the context. Each resource is uniquely identified by a [URI](https://datatracker.ietf.org/doc/html/rfc3986).
99

10-
## Required Capabilities
10+
## Capabilities
1111

12-
To use resources, the server MUST include the `resources` capability in its `ServerCapabilities` object during the initialization process. The `resources` capability MAY include a `subscribe` field set to `true` if the server supports resource subscriptions.
12+
To use resources, the server MUST include the `resources` capability in its `ServerCapabilities` object during the initialization process. The `resources` capability MAY include a `subscribe` field set to `true` if the server supports resource subscriptions. Additionally, the `resources` capability MAY include a `listChanged` field set to `true` if the server supports notifications for changes to the resource list.
1313

1414
Clients intending to use resources SHOULD check for the presence of the `resources` capability in the server's capabilities before attempting to use any resource-related methods. If the capability is not present, the client MUST NOT attempt to use resource-related methods, as the server does not support them.
1515

@@ -22,19 +22,20 @@ Example of server capabilities with basic resource support:
2222
}
2323
```
2424

25-
Example of server capabilities including resource support:
25+
Example of server capabilities including resource support with subscriptions and list change notifications:
2626

2727
```json
2828
{
2929
"capabilities": {
3030
"resources": {
31-
"subscribe": true
31+
"subscribe": true,
32+
"listChanged": true
3233
}
3334
}
3435
}
3536
```
3637

37-
In this example, the server supports both basic resource operations and subscriptions. If `subscribe` is omitted or set to `false`, the server only supports basic resource operations without subscriptions.
38+
In this example, the server supports basic resource operations, subscriptions, and notifications for resource list changes. If `subscribe` is omitted or set to `false`, the server only supports basic resource operations without subscriptions. Similarly, if `listChanged` is omitted or set to `false`, the server does not support notifications for changes to the resource list.
3839

3940
## Concepts
4041
### Resource
@@ -345,7 +346,9 @@ Servers MUST only send this notification for resources that clients have explici
345346

346347
### Resource List Changed Notification
347348

348-
When the list of available resources has changed, the server MUST send a `notifications/resources/list_changed` notification to the client.
349+
If the server supports the `listChanged` capability for resources, it MAY send a `notifications/resources/list_changed` notification to inform the client that the list of available resources has changed.
350+
351+
#### Notification
349352

350353
Method: `notifications/resources/list_changed`
351354
Params: None
@@ -358,7 +361,7 @@ Example:
358361
}
359362
```
360363

361-
Upon receiving this notification, clients SHOULD request an updated resource list using the `resources/list` method.
364+
Upon receiving this notification, clients SHOULD request an updated resource list using the `resources/list` method to ensure they have the most up-to-date information about available resources.
362365

363366
## Security Considerations
364367

schema/schema.json

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,30 @@
998998
],
999999
"type": "object"
10001000
},
1001+
"PromptListChangedNotification": {
1002+
"description": "An optional notification from the server to the client, informing it that the list of prompts it offers has changed. This may be issued by servers without any previous subscription from the client.",
1003+
"properties": {
1004+
"method": {
1005+
"const": "notifications/prompts/list_changed",
1006+
"type": "string"
1007+
},
1008+
"params": {
1009+
"additionalProperties": {},
1010+
"properties": {
1011+
"_meta": {
1012+
"additionalProperties": {},
1013+
"description": "This parameter name is reserved by MCP to allow clients and servers to attach additional metadata to their notifications.",
1014+
"type": "object"
1015+
}
1016+
},
1017+
"type": "object"
1018+
}
1019+
},
1020+
"required": [
1021+
"method"
1022+
],
1023+
"type": "object"
1024+
},
10011025
"PromptReference": {
10021026
"description": "Identifies a prompt.",
10031027
"properties": {
@@ -1302,14 +1326,22 @@
13021326
"type": "object"
13031327
},
13041328
"prompts": {
1305-
"additionalProperties": true,
13061329
"description": "Present if the server offers any prompt templates.",
1307-
"properties": {},
1330+
"properties": {
1331+
"listChanged": {
1332+
"description": "Whether this server supports notifications for changes to the prompt list.",
1333+
"type": "boolean"
1334+
}
1335+
},
13081336
"type": "object"
13091337
},
13101338
"resources": {
13111339
"description": "Present if the server offers any resources to read.",
13121340
"properties": {
1341+
"listChanged": {
1342+
"description": "Whether this server supports notifications for changes to the resource list.",
1343+
"type": "boolean"
1344+
},
13131345
"subscribe": {
13141346
"description": "Whether this server supports subscribing to resource updates.",
13151347
"type": "boolean"
@@ -1318,9 +1350,13 @@
13181350
"type": "object"
13191351
},
13201352
"tools": {
1321-
"additionalProperties": true,
13221353
"description": "Present if the server offers any tools to call.",
1323-
"properties": {},
1354+
"properties": {
1355+
"listChanged": {
1356+
"description": "Whether this server supports notifications for changes to the tool list.",
1357+
"type": "boolean"
1358+
}
1359+
},
13241360
"type": "object"
13251361
}
13261362
},
@@ -1337,6 +1373,9 @@
13371373
{
13381374
"$ref": "#/definitions/ResourceUpdatedNotification"
13391375
},
1376+
{
1377+
"$ref": "#/definitions/PromptListChangedNotification"
1378+
},
13401379
{
13411380
"$ref": "#/definitions/ToolListChangedNotification"
13421381
},

schema/schema.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,12 @@ export interface ServerCapabilities {
173173
/**
174174
* Present if the server offers any prompt templates.
175175
*/
176-
prompts?: object;
176+
prompts?: {
177+
/**
178+
* Whether this server supports notifications for changes to the prompt list.
179+
*/
180+
listChanged?: boolean;
181+
};
177182
/**
178183
* Present if the server offers any resources to read.
179184
*/
@@ -182,11 +187,20 @@ export interface ServerCapabilities {
182187
* Whether this server supports subscribing to resource updates.
183188
*/
184189
subscribe?: boolean;
190+
/**
191+
* Whether this server supports notifications for changes to the resource list.
192+
*/
193+
listChanged?: boolean;
185194
};
186195
/**
187196
* Present if the server offers any tools to call.
188197
*/
189-
tools?: object;
198+
tools?: {
199+
/**
200+
* Whether this server supports notifications for changes to the tool list.
201+
*/
202+
listChanged?: boolean;
203+
};
190204
}
191205

192206
/**
@@ -494,6 +508,13 @@ export interface PromptArgument {
494508
required?: boolean;
495509
}
496510

511+
/**
512+
* An optional notification from the server to the client, informing it that the list of prompts it offers has changed. This may be issued by servers without any previous subscription from the client.
513+
*/
514+
export interface PromptListChangedNotification extends Notification {
515+
method: "notifications/prompts/list_changed";
516+
}
517+
497518
/* Tools */
498519
/**
499520
* Sent from the client to request a list of tools the server has.
@@ -771,7 +792,8 @@ export type ServerNotification =
771792
| LoggingMessageNotification
772793
| ResourceUpdatedNotification
773794
| ResourceListChangedNotification
774-
| ToolListChangedNotification;
795+
| ToolListChangedNotification
796+
| PromptListChangedNotification;
775797

776798
export type ServerResult =
777799
| EmptyResult

0 commit comments

Comments
 (0)