feat(agentcore): Add operational Policy tools sub-package#3193
Open
sundargthb wants to merge 1 commit intoawslabs:mainfrom
Open
feat(agentcore): Add operational Policy tools sub-package#3193sundargthb wants to merge 1 commit intoawslabs:mainfrom
sundargthb wants to merge 1 commit intoawslabs:mainfrom
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3193 +/- ##
==========================================
+ Coverage 92.49% 92.52% +0.02%
==========================================
Files 859 867 +8
Lines 68021 68346 +325
Branches 10900 10926 +26
==========================================
+ Hits 62919 63239 +320
- Misses 3080 3084 +4
- Partials 2022 2023 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes
Summary
Adds the AgentCore Policy primitive to the unified
amazon-bedrock-agentcore-mcp-serveras an operational sub-package(Pattern A), following the same pattern as Memory, Runtime, Browser,
and Code Interpreter.
Exposes 15 MCP tools covering all 14 public Policy control-plane
APIs plus a comprehensive static guide:
policy_engine_{create,get,update,delete,list}policy_{create,get,update,delete,list}policy_generation_{start,get,list,list_assets}get_policy_guideAll operations go through
bedrock-agentcore-control— Policy has nodata plane, so the sub-package uses a single cached boto3 client.
Cost & Gating — Read This Before Approving
The unified MCP server autoregisters tools; AI coding agents can
discover and call any registered tool without explicit user action.
Some Policy APIs incur AWS charges, and one (policy generation) is
potentially expensive. This PR applies the same safeguards we added
after the Code Interpreter billing incident.
Per-tool risk tier
Billable (incur AWS charges —
COST WARNINGin docstring):policy_engine_createpolicy_createpolicy_updatepolicy_generation_startDestructive (irreversible):
policy_engine_delete— requires zero associated policies firstpolicy_deleteRead-only (no cost):
All
*_get,*_list, andget_policy_guide— 8 tools total,including the guide.
How the guardrails are enforced
COST WARNING:prefixed in its docstring,placed prominently so the LLM sees it before deciding to call.
policy_generation_startexplicitly calls out "typically the mostexpensive Policy operation per call."
__init__.pymodule docstring groups all 15 tools by risk tier.get_policy_guideoutput under"Tool Cost Tiers."
AGENTCORE_DISABLE_TOOLS=policy, and the integration test suiteincludes a
test_list_tools_policy_disabledtest asserting thisworks.
Known limitation
_is_service_enabled('policy')is on by default, matching all otherprimitives. There is no per-tool gating today (e.g., "disable policy
generation but keep read-only"). If we want finer-grained gating
after this lands, it should be a cross-cutting change applied to all
primitives, not a Policy-specific bolt-on.
Architecture
Design decisions
we use one cached
bedrock-agentcore-controlclient viaget_policy_client(). User-agent isbuild_user_agent('policy')(no
-controlsuffix, matching the single-client pattern used bybrowserandcode-interpreter).get_policy_guidereturnsPolicyGuideResponse(guide=...)rather thandict[str, str]—every tool in the sub-package returns a
BaseModel, including theguide.
clear_clients()or other cleanup. boto3 clients don't holdopen connections; there's nothing to shut down. The sub-package
does not hook into
server_lifespan.(
policy_engine_id,policy_id,policy_generation_id), operationnames, and counts — never user-provided Cedar statements,
natural-language generation inputs, or descriptions.
Files Changed
New — sub-package (8 files)
New — tests (9 files)
Modified (3 files)
server.py— adds the_is_service_enabled('policy')blockwith import-error fallback. Tool count logged as 15.
tests/test_tools.py— addsTestPolicyToolclass exercisingthe guide tool and its Pydantic response. Existing
TestMemoryTooland
TestGatewayToolare unchanged.tests/browser/test_integ_mcp_protocol.py— addsPOLICY_TOOLSset (15 tools), registers policy in
_build_server(), adds twoschema tests (
test_policy_tools_require_policy_engine_id,test_policy_engine_create_has_optional_params), a discovery opt-outtest (
test_list_tools_policy_disabled), and one protocolinvocation test (
test_policy_guide_invocation). Existing testsupdated to include
POLICY_TOOLSin the default-config expectation.Checklist
If your change doesn't seem to apply, please leave them unchecked.
Is this a breaking change? N
RFC issue number:
Checklist:
Acknowledgment
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.