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))

정책 응답

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

{ "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 } }