From 430ab131dc8434bcafce0d25422a332010532d65 Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Mon, 4 Nov 2024 15:32:31 +0000 Subject: [PATCH 1/3] Allow prompts to embed resources --- schema/schema.json | 32 +++++++++++++++++++++++++++++++- schema/schema.ts | 22 +++++++++++++++++----- 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/schema/schema.json b/schema/schema.json index 16588516a..fc81c311f 100644 --- a/schema/schema.json +++ b/schema/schema.json @@ -418,7 +418,7 @@ }, "messages": { "items": { - "$ref": "#/definitions/SamplingMessage" + "$ref": "#/definitions/PromptMessage" }, "type": "array" } @@ -1166,6 +1166,36 @@ ], "type": "object" }, + "PromptMessage": { + "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. The client MUST decide how to render\nembedded resources for the benefit of the LLM and/or the user.", + "properties": { + "content": { + "anyOf": [ + { + "$ref": "#/definitions/ResourceContents" + }, + { + "$ref": "#/definitions/TextContent" + }, + { + "$ref": "#/definitions/ImageContent" + } + ] + }, + "role": { + "enum": [ + "assistant", + "user" + ], + "type": "string" + } + }, + "required": [ + "content", + "role" + ], + "type": "object" + }, "PromptReference": { "description": "Identifies a prompt.", "properties": { diff --git a/schema/schema.ts b/schema/schema.ts index cc2d5999d..74c8acda9 100644 --- a/schema/schema.ts +++ b/schema/schema.ts @@ -157,10 +157,6 @@ export interface ClientCapabilities { * Experimental, non-standard capabilities that the client supports. */ experimental?: { [key: string]: object }; - /** - * Present if the client supports sampling from an LLM. - */ - sampling?: object; /** * Present if the client supports listing roots. */ @@ -170,6 +166,10 @@ export interface ClientCapabilities { */ listChanged?: boolean; }; + /** + * Present if the client supports sampling from an LLM. + */ + sampling?: object; } /** @@ -515,7 +515,7 @@ export interface GetPromptResult extends Result { * An optional description for the prompt. */ description?: string; - messages: SamplingMessage[]; + messages: PromptMessage[]; } /** @@ -554,6 +554,18 @@ export interface PromptArgument { required?: boolean; } +/** + * Describes a message returned as part of a prompt. + * + * This is similar to `SamplingMessage`, but also supports the embedding of + * resource contents from the MCP server. The client MUST decide how to render + * embedded resources for the benefit of the LLM and/or the user. + */ +export interface PromptMessage { + role: "user" | "assistant"; + content: TextContent | ImageContent | ResourceContents; +} + /** * 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. */ From 685198fced0859dc99ec7086ab2ce789cf61985b Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Mon, 4 Nov 2024 15:34:36 +0000 Subject: [PATCH 2/3] Update prompts doc page --- docs/spec/prompts.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/docs/spec/prompts.md b/docs/spec/prompts.md index 1d7c6b209..d1734000a 100644 --- a/docs/spec/prompts.md +++ b/docs/spec/prompts.md @@ -47,6 +47,10 @@ A Prompt in the Model Context Protocol (MCP) represents a pre-defined set of mes 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. +### Embedded Resource Contents + +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. + ## Use Cases 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: The server MUST respond with a `GetPromptResult` containing: - `description`: An optional string describing the prompt -- `messages`: An array of `SamplingMessage` objects representing the prompt content +- `messages`: An array of `PromptMessage` objects representing the prompt content, which may include embedded resource contents Example: ```json @@ -245,6 +249,21 @@ Example: "type": "text", "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:" } + }, + { + "role": "user", + "content": { + "uri": "file:///workspace/project/requirements.txt", + "mimeType": "text/plain", + "text": "flask==2.0.1\nnumpy==1.21.0\npandas==1.3.0\n" + } + }, + { + "role": "assistant", + "content": { + "type": "text", + "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." + } } ] } From 6747d2811df823b380880ee57d53458cbc691e9d Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Mon, 4 Nov 2024 15:36:44 +0000 Subject: [PATCH 3/3] Add "type": "resource" key --- docs/spec/prompts.md | 1 + schema/schema.json | 31 +++++++++++++++++++++++++++---- schema/schema.ts | 15 ++++++++++++--- 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/docs/spec/prompts.md b/docs/spec/prompts.md index d1734000a..6bc437f7d 100644 --- a/docs/spec/prompts.md +++ b/docs/spec/prompts.md @@ -253,6 +253,7 @@ Example: { "role": "user", "content": { + "type": "resource", "uri": "file:///workspace/project/requirements.txt", "mimeType": "text/plain", "text": "flask==2.0.1\nnumpy==1.21.0\npandas==1.3.0\n" diff --git a/schema/schema.json b/schema/schema.json index fc81c311f..23022b2af 100644 --- a/schema/schema.json +++ b/schema/schema.json @@ -1167,18 +1167,18 @@ "type": "object" }, "PromptMessage": { - "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. The client MUST decide how to render\nembedded resources for the benefit of the LLM and/or the user.", + "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.", "properties": { "content": { "anyOf": [ - { - "$ref": "#/definitions/ResourceContents" - }, { "$ref": "#/definitions/TextContent" }, { "$ref": "#/definitions/ImageContent" + }, + { + "$ref": "#/definitions/PromptResourceContents" } ] }, @@ -1214,6 +1214,29 @@ ], "type": "object" }, + "PromptResourceContents": { + "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.", + "properties": { + "mimeType": { + "description": "The MIME type of this resource, if known.", + "type": "string" + }, + "type": { + "const": "resource", + "type": "string" + }, + "uri": { + "description": "The URI of this resource.", + "format": "uri", + "type": "string" + } + }, + "required": [ + "type", + "uri" + ], + "type": "object" + }, "ReadResourceRequest": { "description": "Sent from the client to the server, to read a specific resource URI.", "properties": { diff --git a/schema/schema.ts b/schema/schema.ts index 74c8acda9..c74480442 100644 --- a/schema/schema.ts +++ b/schema/schema.ts @@ -558,12 +558,21 @@ export interface PromptArgument { * Describes a message returned as part of a prompt. * * This is similar to `SamplingMessage`, but also supports the embedding of - * resource contents from the MCP server. The client MUST decide how to render - * embedded resources for the benefit of the LLM and/or the user. + * resource contents from the MCP server. */ export interface PromptMessage { role: "user" | "assistant"; - content: TextContent | ImageContent | ResourceContents; + content: TextContent | ImageContent | PromptResourceContents; +} + +/** + * The contents of a resource, embedded into a prompt. + * + * It is up to the client how best to render embedded resources for the benefit + * of the LLM and/or the user. + */ +export interface PromptResourceContents extends ResourceContents { + type: "resource"; } /**