MCP Specification · 2026-07-28 · zh-TW
提示詞
Prompts
Server 提供由使用者明確選擇的 prompt templates,client 可列舉、帶參數取得內容並追蹤清單變更。
MCP 讓 server 以標準方式向 client 暴露 prompt templates。Client 可以列舉可用 prompts、取得內容,並提供 arguments 來客製化結果。
本頁範例為簡潔省略 _meta;實際每個 request 仍 MUST(必須)包含 io.modelcontextprotocol/protocolVersion 與 io.modelcontextprotocol/clientCapabilities。io.modelcontextprotocol/clientInfo 為選用欄位,但 client SHOULD(應該)在未特別停用時提供。
使用者互動模型(User Interaction Model)
Prompts 是 user-controlled primitive:server 撰寫 prompt 內容,但使用者決定何時使用。常見 UI 包含 slash commands、menu options 或其他使用者主動選擇的介面;protocol 不強制特定 UI。
能力宣告(Capabilities)
支援 prompts 的 server MUST(必須)在 DiscoverResult.capabilities 宣告:
{
"capabilities": {
"prompts": { "listChanged": true }
}
}
listChanged 表示 server 是否會在 prompt 清單變更時發通知。宣告 prompts capability 的 server MUST(必須)回應 prompts/list;集合 MAY(可以)為空,也 MAY(可以)隨時間改變,但 MUST NOT(不得)因 connection 本身或同一 connection 上其他 request 的副作用而變化。集合 MAY(可以)依每次 request 帶的 authorization 而不同。
列出提示詞(Listing Prompts)
Client 送出 prompts/list。此 operation 支援 pagination 與 caching。
{
"jsonrpc": "2.0",
"id": 1,
"method": "prompts/list",
"params": { "cursor": "optional-cursor-value" }
}
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"resultType": "complete",
"prompts": [{
"name": "code_review",
"title": "Request Code Review",
"description": "Analyze code quality",
"arguments": [{"name": "code", "required": true}]
}],
"nextCursor": "next-page-cursor",
"ttlMs": 600000,
"cacheScope": "public"
}
}
取得提示詞(Getting a Prompt)
Client 以 prompts/get 取得特定 prompt;arguments 可以透過 Completion API 自動完成。
{
"jsonrpc": "2.0",
"id": 2,
"method": "prompts/get",
"params": {
"name": "code_review",
"arguments": {"code": "def hello(): ..."}
}
}
Server 回傳 messages。若還需要額外輸入,server MAY(可以)回 InputRequiredResult;client 重試原始 request 時依 MRTR 帶入 inputResponses,並在 server 有提供時原樣帶回 requestState。
清單變更通知(List Changed Notification)
若 server 宣告 listChanged,當 prompts 清單改變時 SHOULD(應該)對已用 subscriptions/listen 訂閱 promptsListChanged: true 的 client 發:
{
"jsonrpc": "2.0",
"method": "notifications/prompts/list_changed"
}
資料型別(Data Types)
提示詞(Prompt)
name:唯一識別字。title:選用、給使用者看的名稱。description:選用描述。icons:選用 UI icons。arguments:選用的客製化參數。
提示詞訊息(PromptMessage)
訊息的 role 為 user 或 assistant;content 可為 text、image、audio、resource link 或 embedded resource。所有 content type 都可附加 Resources 定義的 annotations(audience、priority、lastModified)。
- Image data MUST(必須)以 Base64 編碼並包含有效 MIME type。
- Audio data MUST(必須)以 Base64 編碼並包含有效 MIME type。
- Prompt message MAY(可以)透過 resource link 指向可由 client 取得的 Resource;resource link 可使用與一般 Resource 相同的 annotations。
- Embedded resource MUST(必須)包含有效 resource URI、適當 MIME type,以及 text content 或 Base64-encoded blob data。
錯誤處理與安全(Errors and Security)
Server SHOULD(應該)對常見失敗回傳標準 JSON-RPC errors:
- 無效 prompt name:
-32602 Invalid params。 - 缺少 required arguments:
-32602 Invalid params。 - server internal error:
-32603 Internal error。
此外:
- Server SHOULD(應該)在處理前驗證 prompt arguments。
- Client SHOULD(應該)支援大型 prompt list 的 pagination。
- 雙方 SHOULD(應該)尊重 capability negotiation。
- Implementation MUST(必須)仔細驗證 prompt inputs / outputs,避免 injection 與未授權 resource access。