MCP Prompts: discover templates and verify the user's selection
Declare prompts under spec 2025-11-25, read every list page, call prompts/get with the user's arguments, and check the messages.
Prepare the input and environment · Mechanism and data flow · Workflow map
At a glance
This article relies only on the Prompts page of MCP spec 2025-11-25. It describes how a client discovers a server's prompt templates, lets the user pick one, and turns the user's arguments into messages with prompts/get. The spec treats prompts as user-controlled entry points. They are not system instructions that run automatically, and they are not tool-call or argument-completion results. The article separates three kinds of content: behavior the official page reports, editor-recommended checks and stopping conditions, and what this batch did not execute. The last two are not official behavior.
Runtime and applicability
- Article type
- Engineering practice
- Verified
- Applies to
- MCP Documented mcp task and conditions
Execution locations and responsibilities
- MCP client and server Define the configuration or request shown here and check its inputs, outputs and failure branches.
When to use
- You need an existing MCP client and server connected so that JSON-RPC requests can be exchanged. This article gives no installation, connection or authentication method, so confirm those against the official instructions for your own environment.
When not to use
- The official page does not specify a user interface, nor initialization, transport, authentication or credential handling. It gives no cancellation API, retry policy or performance guarantee, and none of these may be presented as spec content.
Prepare the input and environment
- You need an existing MCP client and server connected so that JSON-RPC requests can be exchanged. This article gives no installation, connection or authentication method, so confirm those against the official instructions for your own environment.
- The server must declare the
promptscapability during initialization. The spec says servers that support prompts MUST do this, so a client should not assume prompt templates exist when the capability is missing. - The client needs an interface where the user can explicitly select a prompt and fill in arguments. The spec says prompts are typically triggered by commands in the user interface, such as slash commands, but it also says the protocol does not mandate any interaction model.
- If your connection uses tokens or session credentials, you must plan their cleanup yourself. The official page does not discuss this, so the cleanup requirements below are editorial recommendations.
Mechanism and data flow
Capability and user control: The spec requires servers that support prompts to declare the prompts capability at initialization. The example declaration sets capabilities.prompts.listChanged to true. listChanged indicates whether the server will emit notifications when the list of available prompts changes. It describes notifications, not prompt content. The second part is control: prompts are meant to be selected explicitly by the user, not chosen quietly by the model or the client. The spec gives slash commands only as a typical example and says the protocol mandates no specific interface. The protocol mandates no interaction model. This task adopts an explicit user-action selection policy, implemented by the application's interface.
Discovery: prompts/list and pagination: The client retrieves the catalog with prompts/list, where params.cursor is optional. The spec says the operation supports pagination and that clients SHOULD handle pagination for large prompt lists. In the example response, each entry in the prompts array has a required unique name and optional title, description, icons and arguments. The example response also carries nextCursor. Editorial recommendation: use the nextCursor value as the cursor of the next request until a response no longer gives one, then merge all pages into the catalog the user sees. Showing only the first page would hide the remaining templates.
Retrieval and message mapping: prompts/get: Once the user picks a prompt, the client sends prompts/get, with the prompt name in params.name and an argument object in params.arguments. In the example, the prompt code_review declares one argument, code, with required set to true, so the request supplies code. That is the declaration of this one example and does not mean every prompt requires an argument. Whether an argument is required comes from that prompt's argument definition in the list. The response messages is an array of items with role and content. role is user or assistant, and content types include text, image, audio and embedded resource. In the official example, the code argument ends up inside one user text message.
Errors, changes and security: The spec says servers SHOULD return standard JSON-RPC errors for common failures: -32602 for an invalid prompt name or missing required arguments, and -32603 for internal errors. Servers SHOULD also validate arguments before processing. Servers that declared listChanged SHOULD send notifications/prompts/list_changed when the list changes, so the notification is a recommendation, not an absolute guarantee. The spec further says implementations MUST carefully validate all prompt inputs and outputs to prevent injection attacks or unauthorized access to resources. This article does not expand that requirement into a specific detection algorithm; that is each implementation's own design work.
Workflow map
| Stage | What happens |
|---|---|
| Capability and user control | The spec requires servers that support prompts to declare the prompts capability at initialization. |
Discovery: prompts/list and pagination | The client retrieves the catalog with prompts/list, where params.cursor is optional. |
Retrieval and message mapping: prompts/get | Once the user picks a prompt, the client sends prompts/get, with the prompt name in params.name and an argument object in params.arguments. |
| Errors, changes and security | The spec says servers SHOULD return standard JSON-RPC errors for common failures: -32602 for an invalid prompt name or missing required arguments, and -32603 for internal errors. |
Complete the task
Confirm the server declared the prompts capability: Look at the server's capabilities in the initialization result. Continue with discovery only if prompts is present. If listChanged is also true, note that the server signals it will send notifications when the list changes. If it is absent, do not assume notifications will arrive, and request the list again when you need fresh data. The spec does not say which refresh policy a client must use here, so re-requesting is an editorial recommendation.
Send prompts/list and read every page (editorial recommendation): omit cursor when starting a complete catalog read, then use only the previous response's nextCursor to continue. The official optional-cursor-value is a placeholder, not a value to send or an arbitrary starting cursor. Save each page's prompts and merge them once no nextCursor remains. If reading stops midway, preserve the incomplete state instead of presenting a complete catalog.
Let the user explicitly pick a prompt and fill arguments: Show each prompt's name and its optional title and description to the user. Falling back to name when title is missing is an editorial suggestion. This task's user-selection policy requires a user action, such as a slash command or application interface. That is an editorial recommendation for this flow, not a protocol-mandated interaction model. Then collect arguments from the selected prompt's arguments list, and have the client enforce only those marked required. The code argument being required in the example cannot be applied to other prompts. The page also mentions that arguments may be auto-completed through the completion API, but completion is a separate task and is not covered here.
Send prompts/get with the chosen name and arguments: Fill in name as in the official request and put the user's values in the arguments object. Newlines and quotes inside strings must be escaped under JSON rules, as the code value in the official example shows with its escaped newline. If the server returns -32602, the spec ties it to an invalid prompt name or missing required arguments. The client should then ask the user to fix the selection or arguments instead of guessing values, which is an editorial recommendation. Ending on internal error -32603 is also an editorial recommendation.
Check the returned messages: This flow uses at least one result.messages entry as an editorial acceptance condition; this spec page gives no minimum count. Then check that each role is user or assistant, and that each content.type is one the spec lists. Image and audio content MUST carry base64-encoded data and a valid MIME type. An embedded resource MUST carry a valid resource URI, the appropriate MIME type, and either text or base64 blob data. These are structural checks. They do not prove the content is semantically correct or trustworthy. Because the spec requires careful validation of prompt inputs and outputs, treat the content under your own security policy and do not run it automatically as a system instruction.
Handle the list-changed notification (editorial recommendation): When notifications/prompts/list_changed arrives, mark the local catalog stale and read every page of prompts/list again. The notification carries no new catalog, so the list cannot be updated from it alone. You have reason to expect it only if the server declared listChanged. The spec does not say whether a prompt the user has already selected and is filling in should be kept. Decide that yourself, and after the refresh check that its name still exists.
Close out each exit path and clean up: The stopping conditions and cleanup below are editorial recommendations, not official behavior. The official page provides no cancellation API, and this article invents none. Success: the messages pass the structural check and the user confirms. Failure: a JSON-RPC error, a structural mismatch or an interrupted page read; do not record partial results as success. Empty output: an empty catalog or an empty messages array; tell the user and stop. User stops: send no further requests and discard uncommitted arguments. On every path, clear the tokens, session credentials and temporary argument caches that you created for this flow, and leave resources you do not own alone.
Worked example
An editorial walkthrough follows the official message samples. The capability object declares prompts and listChanged:true. The list-request sample uses id:1, and its response contains code_review, required argument code and nextCursor. Continuing with the returned cursor, user selection and later confirmation are recommended flow steps; s1 does not show the next-page response. The official prompts/get sample uses id:2 and a code argument, with one user text message beginning "Please review this Python code:". The capability object is a configuration fragment and the remaining samples are separate protocol messages, not executable programs. Sending them and matching responses requires an existing host. The original samples are official; this assembled walkthrough is editorial and was not executed here.
{
"capabilities": {
"prompts": {
"listChanged": true
}
}
}
{
"jsonrpc": "2.0",
"id": 1,
"method": "prompts/list",
"params": {
"cursor": "optional-cursor-value"
}
}
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"prompts": [
{
"name": "code_review",
"title": "Request Code Review",
"description": "Asks the LLM to analyze code quality and suggest improvements",
"arguments": [
{
"name": "code",
"description": "The code to review",
"required": true
}
],
"icons": [
{
"src": "https://example.com/review-icon.svg",
"mimeType": "image/svg+xml",
"sizes": ["any"]
}
]
}
],
"nextCursor": "next-page-cursor"
}
}
{
"jsonrpc": "2.0",
"id": 2,
"method": "prompts/get",
"params": {
"name": "code_review",
"arguments": {
"code": "def hello():\n print('world')"
}
}
}
{
"jsonrpc": "2.0",
"id": 2,
"result": {
"description": "Code review prompt",
"messages": [
{
"role": "user",
"content": {
"type": "text",
"text": "Please review this Python code:\ndef hello():\n print('world')"
}
}
]
}
}
{
"jsonrpc": "2.0",
"method": "notifications/prompts/list_changed"
}
Check the result and failure paths
- Success condition: initialization declared
prompts, every page was read, the user explicitly chose a prompt, required arguments are present, and the responsemessagespass the structural check. These checks are editorial recommendations. - Failure condition:
-32602or-32603arrives, discovery starts without thepromptscapability, pagination stops partway, or image, audio or resource content lacks fields the spec requires. Do not record success in these cases. - Empty output condition: the
promptsarray is empty ormessagesis empty. Report it as empty and do not invent templates or messages. - User stopping condition: if the user abandons the run while choosing or filling arguments, stop further requests. The spec defines no cancellation API for this, so this is the client's own control step.
- Cleanup condition: on all four exits, success, failure, empty output and user stop, remove the credentials and temporary data you created and clean up only your own resources.
Scope and limits
- A prompt is not a tool call and not an argument-completion result, so do not mix them, and do not run returned messages automatically as system instructions. The use of
-32602and-32603is a server SHOULD, not a guarantee from every implementation. - Structural checks confirm fields and types only. They do not prove that prompt content is semantically correct or safe, and protection against injection and unauthorized access needs separate design under the spec's MUST requirement.
No product, client, server or API was run in this batch, and no software was installed. The JSON requests and responses are the official documentation's examples, not results observed here. The completion checks and manual control steps are editorial recommendations, not official behavior.
Sources
All links are official pages; verification dates are listed per source, and links point to the version checked.