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 요청 메타데이터 헤더 및 _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 프로토콜 버전만 허용합니다. 버전를 사용하려면 게이트웨이에 버전이 supportedVersions 포함되어 있는지 2026-07-28확인합니다. UpdateGateway API를 사용하여 지원되는 버전을 변경할 수 있습니다.

다음 값을 교체합니다.

응답은 렌더링된 프롬프트를 각각 역할 및 콘텐츠가 포함된 메시지 배열로 반환합니다.

참고

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)

버전 에서는 본문에 Mcp-Method 및 Mcp-Name 요청 메타데이터 헤더와 _meta 버전 필드를 2026-07-28포함합니다. 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)

버전 에서는 본문에 Mcp-Method 및 Mcp-Name 요청 메타데이터 헤더와 _meta 버전 필드를 2026-07-28포함합니다. 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 오류. 이러한 유형의 오류에 대한 자세한 내용은 모델 컨텍스트 프로토콜(MCP) 설명서의 프롬프트를 참조하세요.