Skip to content

Commit f1c1112

Browse files
Merge pull request modelcontextprotocol#34 from modelcontextprotocol/justin/resources-in-messages
Support embedding resource contents in prompts
2 parents 27317bf + 6747d28 commit f1c1112

File tree

3 files changed

+101
-7
lines changed

3 files changed

+101
-7
lines changed

docs/spec/prompts.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ A Prompt in the Model Context Protocol (MCP) represents a pre-defined set of mes
4747

4848
Prompt Templates are prompts that can be dynamically generated or customized based on provided arguments. They allow servers to expose a flexible set of prompts that can be tailored to specific use cases. Clients can use these templates by providing the required arguments when retrieving the prompt.
4949

50+
### Embedded Resource Contents
51+
52+
Prompts can include embedded resource contents from the MCP server. This allows servers to provide context-rich prompts that incorporate relevant data or files directly into the prompt structure.
53+
5054
## Use Cases
5155

5256
Common use cases for prompts include providing standardized instructions for code reviews, data analysis tasks, or creative writing exercises. Here are examples of kinds of prompts that an MCP server could expose:
@@ -222,7 +226,7 @@ Example:
222226
The server MUST respond with a `GetPromptResult` containing:
223227

224228
- `description`: An optional string describing the prompt
225-
- `messages`: An array of `SamplingMessage` objects representing the prompt content
229+
- `messages`: An array of `PromptMessage` objects representing the prompt content, which may include embedded resource contents
226230

227231
Example:
228232
```json
@@ -245,6 +249,22 @@ Example:
245249
"type": "text",
246250
"text": "Certainly! I'd be happy to review the Python code snippet and provide feedback on its quality and potential improvements. Let's analyze it:"
247251
}
252+
},
253+
{
254+
"role": "user",
255+
"content": {
256+
"type": "resource",
257+
"uri": "file:///workspace/project/requirements.txt",
258+
"mimeType": "text/plain",
259+
"text": "flask==2.0.1\nnumpy==1.21.0\npandas==1.3.0\n"
260+
}
261+
},
262+
{
263+
"role": "assistant",
264+
"content": {
265+
"type": "text",
266+
"text": "I see you've also provided the contents of the requirements.txt file. This gives us additional context about the project environment. Let's consider these dependencies in our code review as well."
267+
}
248268
}
249269
]
250270
}

schema/schema.json

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@
416416
},
417417
"messages": {
418418
"items": {
419-
"$ref": "#/definitions/SamplingMessage"
419+
"$ref": "#/definitions/PromptMessage"
420420
},
421421
"type": "array"
422422
}
@@ -1195,6 +1195,36 @@
11951195
],
11961196
"type": "object"
11971197
},
1198+
"PromptMessage": {
1199+
"description": "Describes a message returned as part of a prompt.\n\nThis is similar to `SamplingMessage`, but also supports the embedding of\nresource contents from the MCP server.",
1200+
"properties": {
1201+
"content": {
1202+
"anyOf": [
1203+
{
1204+
"$ref": "#/definitions/TextContent"
1205+
},
1206+
{
1207+
"$ref": "#/definitions/ImageContent"
1208+
},
1209+
{
1210+
"$ref": "#/definitions/PromptResourceContents"
1211+
}
1212+
]
1213+
},
1214+
"role": {
1215+
"enum": [
1216+
"assistant",
1217+
"user"
1218+
],
1219+
"type": "string"
1220+
}
1221+
},
1222+
"required": [
1223+
"content",
1224+
"role"
1225+
],
1226+
"type": "object"
1227+
},
11981228
"PromptReference": {
11991229
"description": "Identifies a prompt.",
12001230
"properties": {
@@ -1213,6 +1243,29 @@
12131243
],
12141244
"type": "object"
12151245
},
1246+
"PromptResourceContents": {
1247+
"description": "The contents of a resource, embedded into a prompt.\n\nIt is up to the client how best to render embedded resources for the benefit\nof the LLM and/or the user.",
1248+
"properties": {
1249+
"mimeType": {
1250+
"description": "The MIME type of this resource, if known.",
1251+
"type": "string"
1252+
},
1253+
"type": {
1254+
"const": "resource",
1255+
"type": "string"
1256+
},
1257+
"uri": {
1258+
"description": "The URI of this resource.",
1259+
"format": "uri",
1260+
"type": "string"
1261+
}
1262+
},
1263+
"required": [
1264+
"type",
1265+
"uri"
1266+
],
1267+
"type": "object"
1268+
},
12161269
"ReadResourceRequest": {
12171270
"description": "Sent from the client to the server, to read a specific resource URI.",
12181271
"properties": {

schema/schema.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,6 @@ export interface ClientCapabilities {
157157
* Experimental, non-standard capabilities that the client supports.
158158
*/
159159
experimental?: { [key: string]: object };
160-
/**
161-
* Present if the client supports sampling from an LLM.
162-
*/
163-
sampling?: object;
164160
/**
165161
* Present if the client supports listing roots.
166162
*/
@@ -170,6 +166,10 @@ export interface ClientCapabilities {
170166
*/
171167
listChanged?: boolean;
172168
};
169+
/**
170+
* Present if the client supports sampling from an LLM.
171+
*/
172+
sampling?: object;
173173
}
174174

175175
/**
@@ -515,7 +515,7 @@ export interface GetPromptResult extends Result {
515515
* An optional description for the prompt.
516516
*/
517517
description?: string;
518-
messages: SamplingMessage[];
518+
messages: PromptMessage[];
519519
}
520520

521521
/**
@@ -554,6 +554,27 @@ export interface PromptArgument {
554554
required?: boolean;
555555
}
556556

557+
/**
558+
* Describes a message returned as part of a prompt.
559+
*
560+
* This is similar to `SamplingMessage`, but also supports the embedding of
561+
* resource contents from the MCP server.
562+
*/
563+
export interface PromptMessage {
564+
role: "user" | "assistant";
565+
content: TextContent | ImageContent | PromptResourceContents;
566+
}
567+
568+
/**
569+
* The contents of a resource, embedded into a prompt.
570+
*
571+
* It is up to the client how best to render embedded resources for the benefit
572+
* of the LLM and/or the user.
573+
*/
574+
export interface PromptResourceContents extends ResourceContents {
575+
type: "resource";
576+
}
577+
557578
/**
558579
* 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.
559580
*/

0 commit comments

Comments
 (0)