Skip to content

Prompts

Documentation Index

完全なドキュメント索引を取得してください: modelcontextprotocol.io/llms.txt

さらに先へ進む前に、利用可能なすべてのページを把握するために、このファイルを使用してください。

The Model Context Protocol (MCP) は、server が prompt template を client に公開するための標準化された方法を提供します。Prompt により、server は language model とやり取りするための構造化メッセージや instruction を提供できます。client は利用可能な prompt を見つけ、その内容を取得し、必要に応じて引数を渡してカスタマイズできます。

User Interaction Model

Prompt は user-controlled になるよう設計されています。つまり、server から client に公開され、ユーザーが明示的に選んで使えることを意図しています。

通常、prompt はユーザーインターフェイス内のユーザー主導コマンドを通じて起動されます。これにより、ユーザーは利用可能な prompt を自然に見つけて呼び出せます。

たとえば、slash command として公開できます。

ただし、実装者は自身の要件に合う任意のインターフェイスパターンで prompt を公開して構いません。プロトコル自体は、特定のユーザーインタラクションモデルを義務付けていません。

Capabilities

prompt をサポートする server は、初期化時に prompts capability を宣言しなければなりません (MUST)。

{
  "capabilities": {
    "prompts": {
      "listChanged": true
    }
  }
}

listChanged は、利用可能な prompt の一覧が変わったときに server が notification を送るかどうかを示します。

Protocol Messages

Listing Prompts

利用可能な prompt を取得するために、client は prompts/list request を送信します。この操作は pagination をサポートします。

Request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "prompts/list",
  "params": {
    "cursor": "optional-cursor-value"
  }
}

Response:

{
  "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"
  }
}

Getting a Prompt

特定の prompt を取得するために、client は prompts/get request を送信します。引数は completion API を通じて自動補完できる場合があります。

Request:

{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "prompts/get",
  "params": {
    "name": "code_review",
    "arguments": {
      "code": "def hello():\n    print('world')"
    }
  }
}

Response:

{
  "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')"
        }
      }
    ]
  }
}

List Changed Notification

利用可能な prompt の一覧が変わったとき、listChanged capability を宣言している server は notification を送るべきです (SHOULD)。

{
  "jsonrpc": "2.0",
  "method": "notifications/prompts/list_changed"
}

Message Flow

sequenceDiagram participant Client participant Server Note over Client,Server: Discovery Client->>Server: prompts/list Server-->>Client: List of prompts Note over Client,Server: Usage Client->>Server: prompts/get Server-->>Client: Prompt content opt listChanged Note over Client,Server: Changes Server--)Client: prompts/list_changed Client->>Server: prompts/list Server-->>Client: Updated prompts end

Data Types

Prompt

prompt 定義には次が含まれます。

  • name: prompt の一意な識別子
  • title: 表示用の、人が読める任意の prompt 名
  • description: 人が読める任意の説明
  • icons: ユーザーインターフェイスで表示するための任意の icon 配列
  • arguments: カスタマイズのための任意の引数一覧

PromptMessage

prompt 内の message には次を含められます。

  • role: 話者を示す "user" または "assistant"
  • content: 次のいずれかの content type

prompt message 内のすべての content type は、audience、priority、modification time に関する metadata のための任意の annotation をサポートします。

Text Content

text content は、通常のテキストメッセージを表します。

{
  "type": "text",
  "text": "The text content of the message"
}

これは、自然言語のやり取りで最も一般的に使われる content type です。

Image Content

image content により、message に視覚情報を含められます。

{
  "type": "image",
  "data": "base64-encoded-image-data",
  "mimeType": "image/png"
}

image data は base64-encoded されており、有効な MIME type を含まなければなりません (MUST)。これにより、視覚的な context が重要な multi-modal interaction が可能になります。

Audio Content

audio content により、message に音声情報を含められます。

{
  "type": "audio",
  "data": "base64-encoded-audio-data",
  "mimeType": "audio/wav"
}

audio data は base64-encoded されており、有効な MIME type を含まなければなりません (MUST)。これにより、音声の context が重要な multi-modal interaction が可能になります。

Embedded Resources

embedded resource により、server 側の resource を message 内で直接参照できます。

{
  "type": "resource",
  "resource": {
    "uri": "resource://example",
    "mimeType": "text/plain",
    "text": "Resource content"
  }
}

resource は text または binary(blob)data のいずれかを含められ、次を必ず含まなければなりません (MUST)。

  • 有効な resource URI
  • 適切な MIME type
  • text content または base64-encoded された blob data のいずれか

embedded resource により、documentation、code sample、そのほかの参照資料のような server 管理の content を、会話フローの中に自然に組み込めます。

Error Handling

server は、一般的な失敗ケースに対して標準の JSON-RPC error を返すべきです (SHOULD)。

  • 無効な prompt 名: -32602(Invalid params)
  • 必須引数の不足: -32602(Invalid params)
  • 内部 error: -32603(Internal error)

Implementation Considerations

  1. server は、処理前に prompt 引数を検証すべきである (SHOULD)
  2. client は、大きな prompt 一覧に対して pagination を処理すべきである (SHOULD)
  3. 双方は capability negotiation を尊重すべきである (SHOULD)

Security

実装は、injection attack や resource への不正アクセスを防ぐために、すべての prompt input と output を慎重に検証しなければなりません (MUST)。