View a markdown version of this page

AgentCore에서 정책과 함께 AgentCore 게이트웨이 사용 - Amazon Bedrock AgentCore

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

AgentCore에서 정책과 함께 AgentCore 게이트웨이 사용

게이트웨이 권한 부여 및 인증 가이드에 따라 게이트웨이 액세스에 필요한 자격 증명을 얻습니다.

MCP 도구만 해당

정책 평가는 MCP 도구에만 적용됩니다. 정책 평가 모드에 관계없이 게이트웨이는 항상 MCP 프롬프트(prompts/list, prompts/get) 및 리소스(resources/list, resources/read, )를 허용합니다resources/templates/list.

AgentCore에서 정책을 사용하여 AgentCore 게이트웨이 도구 나열

도구 목록은 메타 작업 으로 처리됩니다. 보안 주체가 사용 가능한 도구를 나열하면 정책 엔진은 특정 도구 호출(예: 입력 파라미터)의 전체 컨텍스트를 평가하지 않습니다.

보안 주체는 정책에 따라 호출할 수 있는 목록의 도구만 볼 수 있습니다. 나열 중에 도구 호출의 전체 컨텍스트를 사용할 수 없으므로 해당 도구에 대한 호출이 허용되는 상황 집합이 있는 경우 보안 주체가 도구를 나열할 수 있습니다.

따라서 목록에 표시되는 도구가 해당 도구에 대한 후속 호출이 승인된다는 보장은 없습니다. 실제 도구 호출에 대한 권한 부여 결정은 입력 파라미터를 포함한 전체 요청 컨텍스트를 사용하여 별도로 평가됩니다.

다음 방법 중 하나를 선택합니다.

예
curl
  1. curl -X POST \ https://mygateway-abcdefghij.gateway.bedrock-agentcore.us-west-2.amazonaws.com/mcp \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \ -d '{ "jsonrpc": "2.0", "id": "list-tools-request", "method": "tools/list" }'
Python requests package
  1. import requests import json def list_tools(gateway_url, access_token): headers = { "Content-Type": "application/json", "Authorization": f"Bearer {access_token}" } payload = { "jsonrpc": "2.0", "id": "list-tools-request", "method": "tools/list" } response = requests.post(gateway_url, headers=headers, json=payload) return response.json() # Example usage gateway_url = "https://mygateway-abcdefghij.gateway.bedrock-agentcore.us-west-2.amazonaws.com/mcp" access_token = "YOUR_ACCESS_TOKEN" tools = list_tools(gateway_url, access_token) print(json.dumps(tools, indent=2))

    응답은 정책에서 볼 수 있도록 허용하는 도구만 반환합니다. 정책에 의해 거부된 도구는 목록에 표시되지 않습니다.

정책을 사용하여 게이트웨이 도구 호출

게이트웨이에 도구 호출을 수행합니다. 정책 평가는 호출의 허용 또는 거부 여부를 결정합니다.

다음 방법 중 하나를 선택합니다.

예
curl
  1. # Call a tool to test policy enforcement curl -X POST \ https://mygateway-abcdefghij.gateway.bedrock-agentcore.us-west-2.amazonaws.com/mcp \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \ -d '{ "jsonrpc": "2.0", "id": "test-policy", "method": "tools/call", "params": { "name": "tool_name", "arguments": {arguments} } }'
Python requests package
  1. import requests import json def call_gateway_tool(gateway_url, access_token, tool_name, arguments): headers = { "Content-Type": "application/json", "Authorization": f"Bearer {access_token}" } payload = { "jsonrpc": "2.0", "id": "test-policy", "method": "tools/call", "params": { "name": tool_name, "arguments": arguments } } response = requests.post(gateway_url, headers=headers, json=payload) return response.json() # Example usage gateway_url = "https://mygateway-abcdefghij.gateway.bedrock-agentcore.us-west-2.amazonaws.com/mcp" access_token = "YOUR_ACCESS_TOKEN" result = call_gateway_tool( gateway_url, access_token, "RefundTool___process_refund", { "orderId": "12345", "amount": 450, "reason": "Defective product" } ) print(json.dumps(result, indent=2))

임시 정책에 대한 정책 세션 ID 전달

시간 정책 평가를 활성화하려면 요청에 x-amzn-bedrock-agentcore-policy-session-id 헤더를 포함합니다. 세션 인식 정책 적용을 위해 여러 호출을 단일 세션으로 그룹화합니다.

curl -X POST \ https://mygateway-abcdefghij.gateway.bedrock-agentcore.us-west-2.amazonaws.com/mcp \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \ -H "x-amzn-bedrock-agentcore-policy-session-id: YOUR_SESSION_ID" \ -d '{ "jsonrpc": "2.0", "id": "test-temporal-policy", "method": "tools/call", "params": { "name": "tool_name", "arguments": {arguments} } }'

게이트웨이는 사용자를 대신하여 세션 ID를 생성하지 않습니다. 세션 ID를 생성하여 첫 번째 요청부터 모든 요청에 전송해야 합니다. 헤더를 생략하거나 빈 값을 보내면 게이트웨이가 세션을 설정하지 않습니다. 연결된 정책 엔진에 시간 정책이 포함된 경우 세션 ID가 없는 요청은 검증 오류와 함께 실패합니다. 동일한 세션의 모든 요청과 함께 동일한 ID를 전송합니다.

정책 응답

정책이 요청을 허용하는 경우:

{ "jsonrpc": "2.0", "id": 2, "result": { "isError": false, "content": [ { "type": "text", "text": "ToolResult" } ] } }

정책이 요청을 거부하는 경우:

{ "jsonrpc": "2.0", "id": 2, "result": { "content": [ { "type": "text", "text": "AuthorizeActionException - Tool Execution Denied: Tool call not allowed due to policy enforcement [No policy applies to the request (denied by default).]" } ], "isError": true } }