View a markdown version of this page

AgentCore ゲートウェイからプロンプトを取得する - Amazon Bedrock AgentCore

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

AgentCore ゲートウェイからプロンプトを取得する

特定のプロンプトを取得するには、ゲートウェイの MCP エンドポイントに POST リクエストを行い、リクエスト本文の メソッドprompts/getとして 、プロンプトの名前、引数を指定します。

例
2025-11-25 and earlier
POST /mcp HTTP/1.1 Host: ${GatewayEndpoint} Accept: application/json, text/event-stream Content-Type: application/json Authorization: ${Authorization header} MCP-Protocol-Version: ${McpProtocolVersion} ${RequestBody}
2026-07-28

バージョン では2026-07-28、各リクエストは MCP-Protocol-Versionヘッダー、 Mcp-Methodおよび Mcp-Name request-metadata ヘッダー、および本文_metaのバージョンフィールドを保持します。

POST /mcp HTTP/1.1 Host: ${GatewayEndpoint} Accept: application/json, text/event-stream Content-Type: application/json Authorization: ${Authorization header} MCP-Protocol-Version: 2026-07-28 Mcp-Method: prompts/get Mcp-Name: ${PromptName} ${RequestBody}
注記

ゲートウェイは、protocolConfiguration.mcp設定の supportedVersionsフィールドにリストされている MCP プロトコルバージョンのみを受け入れます。バージョン を使用するには2026-07-28、ゲートウェイに supportedVersionsが含まれていることを確認します。サポートされているバージョンは、UpdateGateway API を使用して変更できます。

以下の値を置き換えます:

  • ${GatewayEndpoint} – CreateGateway API のレスポンスで提供されるゲートウェイの URL。

  • ${Authorization header} – インバウンド認可を設定するときの ID プロバイダーからの認可認証情報。

  • ${McpProtocolVersion} – など、リクエストの MCP プロトコルバージョン2025-11-25。バージョンは、ゲートウェイがサポートするバージョンである必要があります。

  • ${PromptName} – リクエスト本文nameの と一致するプロンプトの名前。

  • ${RequestBody} – Model Context Protocol (MCP) の「プロンプトの取得」で指定されているリクエストボディの JSON ペイロード。を prompts/getとして含めmethod、プロンプトnameの とその を含めますarguments。バージョン では2026-07-28、 _meta のバージョンフィールドも含めますparams。

レスポンスは、レンダリングされたプロンプトをメッセージの配列として返し、それぞれにロールとコンテンツがあります。

注記

prompts/get オペレーションは、リクエストをダウンストリーム MCP サーバーにライブでプロキシします。プロンプト名には、ターゲットプレフィックス ( などmyTarget___myPrompt) を含める必要があります。

プロンプトを取得するためのコードサンプル

ゲートウェイからプロンプトを取得する例を表示するには、次のいずれかの方法を選択します。

例
curl (2025-11-25 and earlier)

次の curl リクエストは、ID のゲートウェイmyTarget___code_reviewを介して というプロンプトを取得するリクエストの例を示していますmygateway-abcdefghij。MCP-Protocol-Version ヘッダーをゲートウェイがサポートするバージョンに設定します。

curl -X POST \ https://mygateway-abcdefghij.gateway.bedrock-agentcore.us-west-2.amazonaws.com/mcp \ -H "Accept: application/json, text/event-stream" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \ -H "MCP-Protocol-Version: 2025-11-25" \ -d '{ "jsonrpc": "2.0", "id": "get-prompt-request", "method": "prompts/get", "params": { "name": "myTarget___code_review", "arguments": { "language": "python", "code": "print(\"hello\")" } } }'
curl (2026-07-28)

バージョン では2026-07-28、本文に Mcp-Methodおよび Mcp-Name request-metadata ヘッダーと_metaバージョンフィールドを含めます。MCP-Protocol-Version ヘッダーは と一致する必要があります_meta.io.modelcontextprotocol/protocolVersion。ゲートウェイの には が含まれているsupportedVersions必要があります2026-07-28。

curl -X POST \ https://mygateway-abcdefghij.gateway.bedrock-agentcore.us-west-2.amazonaws.com/mcp \ -H "Accept: application/json, text/event-stream" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \ -H "MCP-Protocol-Version: 2026-07-28" \ -H "Mcp-Method: prompts/get" \ -H "Mcp-Name: myTarget___code_review" \ -d '{ "jsonrpc": "2.0", "id": "get-prompt-request", "method": "prompts/get", "params": { "name": "myTarget___code_review", "arguments": { "language": "python", "code": "print(\"hello\")" }, "_meta": { "io.modelcontextprotocol/protocolVersion": "2026-07-28", "io.modelcontextprotocol/clientInfo": { "name": "my-agent", "version": "1.0.0" }, "io.modelcontextprotocol/clientCapabilities": {} } } }'
Python requests package (2025-11-25 and earlier)

MCP-Protocol-Version ヘッダーをゲートウェイがサポートするバージョンに設定します。

import requests import json def get_prompt(gateway_url, access_token, prompt_name, arguments): headers = { "Content-Type": "application/json", "Authorization": f"Bearer {access_token}", "MCP-Protocol-Version": "2025-11-25" } payload = { "jsonrpc": "2.0", "id": "get-prompt-request", "method": "prompts/get", "params": { "name": prompt_name, "arguments": arguments } } response = requests.post(gateway_url, headers=headers, json=payload) return response.json() # Example usage gateway_url = "https://${GatewayEndpoint}/mcp" # Replace with your actual gateway endpoint access_token = "${AccessToken}" # Replace with your actual access token result = get_prompt( gateway_url, access_token, "myTarget___code_review", # Replace with {targetName}___{promptName} {"language": "python", "code": "print('hello')"} ) print(json.dumps(result, indent=2))
Python requests package (2026-07-28)

バージョン では2026-07-28、本文に Mcp-Methodおよび Mcp-Name request-metadata ヘッダーと_metaバージョンフィールドを含めます。MCP-Protocol-Version ヘッダーは と一致する必要があります_meta.io.modelcontextprotocol/protocolVersion。ゲートウェイの には が含まれているsupportedVersions必要があります2026-07-28。

import requests import json def get_prompt(gateway_url, access_token, prompt_name, arguments): headers = { "Content-Type": "application/json", "Authorization": f"Bearer {access_token}", "MCP-Protocol-Version": "2026-07-28", "Mcp-Method": "prompts/get", "Mcp-Name": prompt_name } payload = { "jsonrpc": "2.0", "id": "get-prompt-request", "method": "prompts/get", "params": { "name": prompt_name, "arguments": arguments, "_meta": { "io.modelcontextprotocol/protocolVersion": "2026-07-28", "io.modelcontextprotocol/clientInfo": {"name": "my-agent", "version": "1.0.0"}, "io.modelcontextprotocol/clientCapabilities": {} } } } response = requests.post(gateway_url, headers=headers, json=payload) return response.json() # Example usage gateway_url = "https://${GatewayEndpoint}/mcp" # Replace with your actual gateway endpoint access_token = "${AccessToken}" # Replace with your actual access token result = get_prompt( gateway_url, access_token, "myTarget___code_review", # Replace with {targetName}___{promptName} {"language": "python", "code": "print('hello')"} ) print(json.dumps(result, indent=2))
MCP Client
from mcp import ClientSession from mcp.client.streamable_http import streamablehttp_client import asyncio async def execute_mcp( url, token, prompt_name, prompt_arguments, headers=None ): default_headers = { "Authorization": f"Bearer {token}" } headers = {**default_headers, **(headers or {})} async with streamablehttp_client( url=url, headers=headers, ) as ( read_stream, write_stream, callA, ): async with ClientSession(read_stream, write_stream) as session: # 1. Perform initialization handshake print("Initializing MCP...") _init_response = await session.initialize() print(f"MCP Server Initialize successful! - {_init_response}") # 2. Get specific prompt print(f"Getting prompt: {prompt_name}") prompt_response = await session.get_prompt( name=prompt_name, arguments=prompt_arguments ) print(f"Prompt response: {prompt_response}") return prompt_response async def main(): url = "https://${GatewayEndpoint}/mcp" token = "your_bearer_token_here" prompt_name = "myTarget___code_review" prompt_arguments = { "language": "python", "code": "print('hello')" } await execute_mcp( url=url, token=token, prompt_name=prompt_name, prompt_arguments=prompt_arguments ) if __name__ == "__main__": asyncio.run(main())
LangGraph MCP Client

注: LangGraph MCP アダプタープロンプトのサポートは異なる場合があります。最も信頼性の高いprompts/get実装には、前述の MCP クライアントアプローチを使用します。

import asyncio from mcp import ClientSession from mcp.client.streamable_http import streamablehttp_client async def get_prompt(url, token, prompt_name, arguments): headers = {"Authorization": f"Bearer {token}"} async with streamablehttp_client(url=url, headers=headers) as ( read_stream, write_stream, callA ): async with ClientSession(read_stream, write_stream) as session: await session.initialize() response = await session.get_prompt( name=prompt_name, arguments=arguments ) for message in response.messages: print(f"{message.role}: {message.content}") asyncio.run(get_prompt( "https://${GatewayEndpoint}/mcp", "${AccessToken}", "myTarget___code_review", {"language": "python", "code": "print('hello')"} ))

エラー

prompts/get オペレーションは、次のタイプのエラーを返すことができます。

  • HTTP ステータスコードの一部として返されるエラー:

    AuthenticationError

    認証情報が無効であるため、リクエストは失敗しました。

    HTTP ステータスコード: 401

    AuthorizationError

    発信者にはプロンプトを取得するアクセス許可がありません。

    HTTP ステータスコード: 403

    ResourceNotFoundError

    指定されたプロンプトは存在しません。

    HTTP ステータスコード: 404

    ValidationError

    指定された引数は、プロンプトの必須引数を満たしていません。

    HTTP ステータスコード: 400

    InternalServerError

    内部サーバーエラーが発生しました。

    HTTP ステータスコード: 500

  • MCP エラー。これらのタイプのエラーの詳細については、Model Context Protocol (MCP) ドキュメントの「プロンプト」を参照してください。