

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# AgentCore ゲートウェイから進行状況通知を受信する
<a name="gateway-mcp-progress"></a>

進行状況通知により、MCP サーバーターゲットは長時間実行されるツール呼び出しの増分進行状況をレポートできます。ツール呼び出しが完了するまでに時間がかかると、サーバーは`notifications/progress`イベントを送信して、オペレーションのステータスをクライアントに通知し続けることができます。AgentCore Gateway は、これらの通知を MCP サーバーターゲットからサーバー送信イベント (SSE) チャンクとしてクライアントに転送します。

## 前提条件
<a name="gateway-mcp-progress-prereqs"></a>

ゲートウェイから進行状況通知を受信するには:
+  **レスポンスストリーミングが有効** — 進行中の通知は、オープン接続中に SSE チャンクとして配信されます。ゲートウェイの `true`で `streamingConfiguration.enableResponseStreaming`を に設定します`protocolConfiguration.mcp`。
+  **MCP サーバーターゲットタイプ** — 進行状況通知は MCP サーバーターゲットから送信されます。
+  **クライアントが `Accept`ヘッダーを送信する** — ゲートウェイがストリーミング (SSE) レスポンスを返`Accept: application/json, text/event-stream`すことができるように、クライアントは を送信する必要があります。

## 進行状況通知の仕組み
<a name="gateway-mcp-progress-how"></a>

クライアントが`tools/call`リクエストパラメータ`progressToken`で を使用してリクエストを行うと、MCP サーバーターゲットは実行中に`notifications/progress`イベントを送信できます。ゲートウェイは、これらのイベントを最終的なツール結果の前に SSE チャンクとしてクライアントに転送します。

各進行状況通知には以下が含まれます。
+  `progressToken` — 元のリクエストで指定されたトークンと一致します。
+  `progress` — 現在の進行状況値 (数値）。
+  `total` — 完了ターゲットを示すオプションの合計値。
+  `message` — 現在のステータスの人間が読める説明。

## コードサンプル
<a name="gateway-mcp-progress-examples"></a>

**Example**  
進行状況トークンを使用してツールを呼び出します。`MCP-Protocol-Version` ヘッダーをゲートウェイがサポートするバージョンに設定します。  

```
curl -N -X POST \
  https://mygateway-abcdefghij.gateway.bedrock-agentcore.us-west-2.amazonaws.com/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "MCP-Protocol-Version: 2025-11-25" \
  -d '{
    "jsonrpc": "2.0",
    "id": "tool-call-1",
    "method": "tools/call",
    "params": {
      "name": "analyzeDataset",
      "arguments": {
        "datasetId": "ds-12345"
      },
      "_meta": {
        "progressToken": "progress-1"
      }
    }
}'
```
ゲートウェイは、進行状況通知とそれに続く最終結果を含む SSE ストリームを返します。  

```
event: message
data: {"jsonrpc":"2.0","method":"notifications/progress","params":{"progressToken":"progress-1","progress":1,"total":4,"message":"Loading dataset..."}}

event: message
data: {"jsonrpc":"2.0","method":"notifications/progress","params":{"progressToken":"progress-1","progress":2,"total":4,"message":"Running analysis..."}}

event: message
data: {"jsonrpc":"2.0","method":"notifications/progress","params":{"progressToken":"progress-1","progress":3,"total":4,"message":"Generating report..."}}

event: message
data: {"jsonrpc":"2.0","method":"notifications/progress","params":{"progressToken":"progress-1","progress":4,"total":4,"message":"Complete"}}

event: message
data: {"jsonrpc":"2.0","id":"tool-call-1","result":{"content":[{"type":"text","text":"Analysis complete. Found 3 anomalies in dataset ds-12345."}]}}
```
バージョン では`2026-07-28`、本文に `Mcp-Method`および `Mcp-Name` request-metadata ヘッダーと`_meta`バージョンフィールドを含めます。進捗通知をオプトイン`_meta`するには、 `progressToken`をそのまま使用します。`MCP-Protocol-Version` ヘッダーは と一致する必要があります`_meta.io.modelcontextprotocol/protocolVersion`。ゲートウェイの には が含まれている`supportedVersions`必要があります`2026-07-28`。  

```
curl -N -X POST \
  https://mygateway-abcdefghij.gateway.bedrock-agentcore.us-west-2.amazonaws.com/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "MCP-Protocol-Version: 2026-07-28" \
  -H "Mcp-Method: tools/call" \
  -H "Mcp-Name: analyzeDataset" \
  -d '{
    "jsonrpc": "2.0",
    "id": "tool-call-1",
    "method": "tools/call",
    "params": {
      "name": "analyzeDataset",
      "arguments": {
        "datasetId": "ds-12345"
      },
      "_meta": {
        "io.modelcontextprotocol/protocolVersion": "2026-07-28",
        "io.modelcontextprotocol/clientInfo": {
          "name": "my-agent",
          "version": "1.0.0"
        },
        "io.modelcontextprotocol/clientCapabilities": {},
        "progressToken": "progress-1"
      }
    }
}'
```
ゲートウェイは、進行状況通知とそれに続く最終結果を含む SSE ストリームを返します。  

```
event: message
data: {"jsonrpc":"2.0","method":"notifications/progress","params":{"progressToken":"progress-1","progress":1,"total":4,"message":"Loading dataset..."}}

event: message
data: {"jsonrpc":"2.0","method":"notifications/progress","params":{"progressToken":"progress-1","progress":2,"total":4,"message":"Running analysis..."}}

event: message
data: {"jsonrpc":"2.0","method":"notifications/progress","params":{"progressToken":"progress-1","progress":3,"total":4,"message":"Generating report..."}}

event: message
data: {"jsonrpc":"2.0","method":"notifications/progress","params":{"progressToken":"progress-1","progress":4,"total":4,"message":"Complete"}}

event: message
data: {"jsonrpc":"2.0","id":"tool-call-1","result":{"content":[{"type":"text","text":"Analysis complete. Found 3 anomalies in dataset ds-12345."}]}}
```
`MCP-Protocol-Version` ヘッダーをゲートウェイがサポートするバージョンに設定します。  

```
import requests
import json
import sseclient

gateway_url = "https://mygateway-abcdefghij.gateway.bedrock-agentcore.us-west-2.amazonaws.com/mcp"
headers = {
    "Content-Type": "application/json",
    "Accept": "application/json, text/event-stream",
    "Authorization": "Bearer YOUR_ACCESS_TOKEN",
    "MCP-Protocol-Version": "2025-11-25"
}

# Call tool with progress token (streaming response)
response = requests.post(gateway_url, headers=headers, json={
    "jsonrpc": "2.0",
    "id": "tool-call-1",
    "method": "tools/call",
    "params": {
        "name": "analyzeDataset",
        "arguments": {"datasetId": "ds-12345"},
        "_meta": {"progressToken": "progress-1"}
    }
}, stream=True)

# Process SSE events
client = sseclient.SSEClient(response)
for event in client.events():
    data = json.loads(event.data)
    if data.get("method") == "notifications/progress":
        params = data["params"]
        print(f"Progress: {params['progress']}/{params.get('total', '?')} - {params.get('message', '')}")
    elif "result" in data:
        print(f"Tool result: {data['result']}")
        break
```
バージョン で`2026-07-28`、、`MCP-Protocol-Version`、`Mcp-Method`および `Mcp-Name`ヘッダーを追加し、リクエスト本文に`_meta`バージョンフィールドを含めます。進捗通知をオプトイン`_meta`するには、 `progressToken`をそのまま使用します。ゲートウェイの には が含まれている`supportedVersions`必要があります`2026-07-28`。  

```
import requests
import json
import sseclient

gateway_url = "https://mygateway-abcdefghij.gateway.bedrock-agentcore.us-west-2.amazonaws.com/mcp"
headers = {
    "Content-Type": "application/json",
    "Accept": "application/json, text/event-stream",
    "Authorization": "Bearer YOUR_ACCESS_TOKEN",
    "MCP-Protocol-Version": "2026-07-28",
    "Mcp-Method": "tools/call",
    "Mcp-Name": "analyzeDataset"
}

# Call tool with progress token (streaming response)
response = requests.post(gateway_url, headers=headers, json={
    "jsonrpc": "2.0",
    "id": "tool-call-1",
    "method": "tools/call",
    "params": {
        "name": "analyzeDataset",
        "arguments": {"datasetId": "ds-12345"},
        "_meta": {
            "io.modelcontextprotocol/protocolVersion": "2026-07-28",
            "io.modelcontextprotocol/clientInfo": {"name": "my-agent", "version": "1.0.0"},
            "io.modelcontextprotocol/clientCapabilities": {},
            "progressToken": "progress-1"
        }
    }
}, stream=True)

# Process SSE events
client = sseclient.SSEClient(response)
for event in client.events():
    data = json.loads(event.data)
    if data.get("method") == "notifications/progress":
        params = data["params"]
        print(f"Progress: {params['progress']}/{params.get('total', '?')} - {params.get('message', '')}")
    elif "result" in data:
        print(f"Tool result: {data['result']}")
        break
```

```
from mcp import ClientSession
from mcp.client.streamable_http import streamablehttp_client
import asyncio

async def progress_handler(progress_token, progress, total, message=None):
    """Handle progress notifications."""
    print(f"[{progress}/{total}] {message or ''}")

async def use_progress(url, token):
    headers = {"Authorization": f"Bearer {token}"}

    async with streamablehttp_client(url=url, headers=headers) as (
        read_stream, write_stream, _
    ):
        async with ClientSession(
            read_stream, write_stream,
            progress_handler=progress_handler
        ) as session:
            await session.initialize()

            # Call tool with progress token - notifications handled by callback
            result = await session.call_tool(
                name="analyzeDataset",
                arguments={"datasetId": "ds-12345"}
            )
            print(f"Tool result: {result}")
            return result

asyncio.run(use_progress(
    url="https://mygateway-abcdefghij.gateway.bedrock-agentcore.us-west-2.amazonaws.com/mcp",
    token="YOUR_ACCESS_TOKEN"
))
```

```
from mcp.client.streamable_http import streamablehttp_client
from strands import Agent
from strands.tools.mcp import MCPClient

mcp_url = "https://mygateway-abcdefghij.gateway.bedrock-agentcore.us-west-2.amazonaws.com/mcp"
access_token = "YOUR_ACCESS_TOKEN"

mcp_client = MCPClient(
    lambda: streamablehttp_client(
        mcp_url, headers={"Authorization": f"Bearer {access_token}"}
    )
)

# Strands handles streaming and progress notifications automatically
with mcp_client:
    agent = Agent(tools=mcp_client.list_tools_sync())
    response = agent("Analyze dataset ds-12345")
    print(response)
```