View a markdown version of this page

AgentCore 게이트웨이에서 리소스 읽기 - Amazon Bedrock AgentCore

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

AgentCore 게이트웨이에서 리소스 읽기

특정 리소스를 읽으려면 게이트웨이의 MCP 엔드포인트에 POST 요청을 하고를 요청 본문의 메서드 및 리소스의 URIresources/read로 지정합니다.

예
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 버전 필드가 포함됩니다. 의 경우 resources/readMcp-Name는 리소스 입니다uri.

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: resources/read Mcp-Name: ${ResourceUri} ${RequestBody}
참고

게이트웨이는 protocolConfiguration.mcp 구성의 supportedVersions 필드에 나열된 MCP 프로토콜 버전만 허용합니다. 버전를 사용하려면 게이트웨이에 버전이 supportedVersions 포함되어 있는지 2026-07-28확인합니다. UpdateGateway API를 사용하여 지원되는 버전을 변경할 수 있습니다.

다음 값을 교체합니다.

  • ${GatewayEndpoint} - CreateGateway API의 응답에 제공된 게이트웨이의 URL입니다.

  • ${Authorization header} - 인바운드 권한 부여를 설정할 때 자격 증명 공급자의 권한 부여 자격 증명입니다.

  • ${McpProtocolVersion} -와 같은 요청에 대한 MCP 프로토콜 버전입니다2025-11-25. 버전은 게이트웨이가 지원하는 버전이어야 합니다.

  • ${ResourceUri} - 요청 본문의 uri와 일치하는 리소스의 URI입니다.

  • ${RequestBody} - 모델 컨텍스트 프로토콜(MCP)의 리소스 읽기에 지정된 요청 본문의 JSON 페이로드입니다. 를 resources/read로 method 포함하고 리소스uri의를 포함합니다. 버전의 경우에 _meta 버전 필드2026-07-28도 포함합니다params.

응답은 각 항목에 uri, mimeType및 text (텍스트 콘텐츠의 경우) 또는 blob (base64 인코딩 바이너리 콘텐츠)가 포함된 contents 배열을 반환합니다.

참고

resources/read 작업은 요청을 다운스트림 MCP 서버에 라이브로 프록시합니다. 리소스 URI는에서 반환되는 원시 URI입니다resources/list(대상 접두사 없음).

참고

여러 대상이 동일한 리소스 URI를 노출하면 게이트웨이는 가장 낮은 resourcePriority 값을 가진 대상으로 요청을 라우팅합니다.

중요

uri 파라미터는 삭제 없이 다운스트림 MCP 서버 대상으로 전달됩니다. 사용자가 제공한 리소스 URI에는 SSRF 공격용 악성 URL 엔드포인트가 포함되거나 로컬 파일 시스템 경로(예: file:///etc/passwd)를 읽으려고 시도할 수 있습니다. 를 호출하기 전에 예상 URIs 체계 및 패턴의 허용 목록에 대해 리소스 URI를 검증합니다resources/read. 신뢰할 수 있는 MCP 서버 대상resources/list에서가 반환한 URIs만 사용합니다.

리소스를 읽기 위한 코드 샘플

게이트웨이에서 리소스를 읽는 예를 보려면 다음 방법 중 하나를 선택합니다.

예
curl (2025-11-25 and earlier)

다음 curl 요청은 ID가 인 게이트웨이를 config://app-settings 통해 URI가 인 리소스를 읽는 요청의 예를 보여줍니다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": "read-resource-request", "method": "resources/read", "params": { "uri": "config://app-settings" } }'
curl (2026-07-28)

버전 에서는 본문에 Mcp-Method 및 Mcp-Name 요청 메타데이터 헤더와 _meta 버전 필드를 2026-07-28포함합니다. 의 경우 resources/readMcp-Name는 리소스 uri이고 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: resources/read" \ -H "Mcp-Name: config://app-settings" \ -d '{ "jsonrpc": "2.0", "id": "read-resource-request", "method": "resources/read", "params": { "uri": "config://app-settings", "_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 read_resource(gateway_url, access_token, resource_uri): headers = { "Content-Type": "application/json", "Authorization": f"Bearer {access_token}", "MCP-Protocol-Version": "2025-11-25" } payload = { "jsonrpc": "2.0", "id": "read-resource-request", "method": "resources/read", "params": { "uri": resource_uri } } 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 = read_resource( gateway_url, access_token, "config://app-settings" # Replace with the resource URI from resources/list ) print(json.dumps(result, indent=2))
Python requests package (2026-07-28)

버전 에서는 본문에 Mcp-Method 및 Mcp-Name 요청 메타데이터 헤더와 _meta 버전 필드를 2026-07-28포함합니다. 의 경우 resources/readMcp-Name는 리소스 uri이고 MCP-Protocol-Version 헤더는와 일치해야 합니다_meta.io.modelcontextprotocol/protocolVersion. 게이트웨이의 에는가 포함되어야 supportedVersions 합니다2026-07-28.

import requests import json def read_resource(gateway_url, access_token, resource_uri): headers = { "Content-Type": "application/json", "Authorization": f"Bearer {access_token}", "MCP-Protocol-Version": "2026-07-28", "Mcp-Method": "resources/read", "Mcp-Name": resource_uri } payload = { "jsonrpc": "2.0", "id": "read-resource-request", "method": "resources/read", "params": { "uri": resource_uri, "_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 = read_resource( gateway_url, access_token, "config://app-settings" # Replace with the resource URI from resources/list ) print(json.dumps(result, indent=2))
MCP Client
from mcp import ClientSession from mcp.client.streamable_http import streamablehttp_client from pydantic import AnyUrl import asyncio async def execute_mcp( url, token, resource_uri, 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. Read specific resource print(f"Reading resource: {resource_uri}") resource_response = await session.read_resource(uri=AnyUrl(resource_uri)) for content in resource_response.contents: print(f"URI: {content.uri}, MIME: {content.mimeType}") if hasattr(content, 'text') and content.text: print(f"Text: {content.text}") elif hasattr(content, 'blob') and content.blob: print(f"Blob (base64): {content.blob[:100]}...") return resource_response async def main(): url = "https://${GatewayEndpoint}/mcp" token = "your_bearer_token_here" resource_uri = "config://app-settings" await execute_mcp( url=url, token=token, resource_uri=resource_uri ) if __name__ == "__main__": asyncio.run(main())
Strands MCP Client

참고: Strands SDK 리소스 지원은 다를 수 있습니다. 가장 안정적인 resources/read 구현을 위해 이전에 표시된 MCP 클라이언트 접근 방식을 사용합니다.

from strands.tools.mcp.mcp_client import MCPClient from mcp.client.streamable_http import streamablehttp_client def create_streamable_http_transport(mcp_url: str, access_token: str): return streamablehttp_client(mcp_url, headers={"Authorization": f"Bearer {access_token}"}) def run_agent(mcp_url: str, access_token: str): mcp_client = MCPClient(lambda: create_streamable_http_transport(mcp_url, access_token)) with mcp_client: result = mcp_client.read_resource_sync(uri="config://app-settings") print(result) run_agent(<MCP URL>, <Access token>)
LangGraph MCP Client

참고: LangGraph MCP 어댑터 리소스 지원은 다를 수 있습니다. 가장 안정적인 resources/read 구현을 위해 이전에 표시된 MCP 클라이언트 접근 방식을 사용합니다.

import asyncio from mcp import ClientSession from mcp.client.streamable_http import streamablehttp_client from pydantic import AnyUrl async def read_resource(url, token, resource_uri): 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.read_resource(uri=AnyUrl(resource_uri)) for content in response.contents: if hasattr(content, 'text') and content.text: print(f"{content.uri}: {content.text}") elif hasattr(content, 'blob') and content.blob: print(f"{content.uri}: <blob, {len(content.blob)} chars base64>") asyncio.run(read_resource( "https://${GatewayEndpoint}/mcp", "${AccessToken}", "config://app-settings" ))

오류

resources/read 작업은 다음과 같은 유형의 오류를 반환할 수 있습니다.

  • HTTP 상태 코드의 일부로 반환되는 오류:

    AuthenticationError

    잘못된 인증 자격 증명으로 인해 요청이 실패했습니다.

    HTTP 상태 코드: 401

    AuthorizationError

    호출자에게 리소스를 읽을 수 있는 권한이 없습니다.

    HTTP 상태 코드: 403

    ResourceNotFoundError

    지정된 리소스 URI가 존재하지 않거나 대상에 의해 노출되지 않습니다.

    HTTP 상태 코드: 404

    ValidationError

    제공된 URI의 형식이 잘못되었거나 누락되었습니다.

    HTTP 상태 코드: 400

    InternalServerError

    내부 서버 오류가 발생했습니다.

    HTTP 상태 코드: 500

  • MCP 오류. 이러한 유형의 오류에 대한 자세한 내용은 모델 컨텍스트 프로토콜(MCP) 설명서의 리소스를 참조하세요.