Skip to content

Logging

Documentation Index

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

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

The Model Context Protocol (MCP) は、server が構造化された log message を client に送るための標準化された方法を提供します。client は最小 log level を設定することで logging の詳細度を制御でき、server は severity level、任意の logger 名、そして任意の JSON-serializable data を含む notification を送信します。

User Interaction Model

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

Capabilities

log message notification を発行する server は、logging capability を宣言しなければなりません (MUST)。

{
  "capabilities": {
    "logging": {}
  }
}

Log Levels

このプロトコルは、RFC 5424 で定義された標準の syslog severity level に従います。

Level Description Example Use Case
debug 詳細な debug 情報 function の entry/exit point
info 一般的な情報メッセージ operation の進捗更新
notice 通常だが重要な event 設定変更
warning 警告状態 deprecated な feature の使用
error error 状態 operation の失敗
critical 重大な状態 system component の障害
alert 直ちに対処が必要 data corruption の検出
emergency system が使用不能 system 全体の障害

Protocol Messages

Setting Log Level

最小 log level を設定するために、client は logging/setLevel request を送信しても構いません (MAY)。

Request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "logging/setLevel",
  "params": {
    "level": "info"
  }
}

Log Message Notifications

server は notifications/message notification を使って log message を送信します。

{
  "jsonrpc": "2.0",
  "method": "notifications/message",
  "params": {
    "level": "error",
    "logger": "database",
    "data": {
      "error": "Connection failed",
      "details": {
        "host": "localhost",
        "port": 5432
      }
    }
  }
}

Message Flow

sequenceDiagram participant Client participant Server Note over Client,Server: Configure Logging Client->>Server: logging/setLevel (info) Server-->>Client: Empty Result Note over Client,Server: Server Activity Server--)Client: notifications/message (info) Server--)Client: notifications/message (warning) Server--)Client: notifications/message (error) Note over Client,Server: Level Change Client->>Server: logging/setLevel (error) Server-->>Client: Empty Result Note over Server: Only sends error level<br/>and above

Error Handling

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

  • 無効な log level: -32602(Invalid params)
  • 設定 error: -32603(Internal error)

Implementation Considerations

  1. server は次を行うべきです (SHOULD)。

    • log message を rate limit する
    • data field に関連する context を含める
    • 一貫した logger 名を使う
    • 機微情報を除去する
  2. client は次を行っても構いません (MAY)。

    • UI に log message を表示する
    • log の絞り込みや検索を実装する
    • severity を視覚的に表示する
    • log message を永続化する

Security

  1. log message には次を含めてはなりません (MUST NOT)。

    • credential や secret
    • 個人識別情報
    • 攻撃を助け得る内部 system 詳細
  2. 実装は次を行うべきです (SHOULD)。

    • message を rate limit する
    • すべての data field を検証する
    • log へのアクセスを制御する
    • 機微な content を監視する