aws / aws/bedrock-agentcore-sdk-python

Agentcore Search Tool plugin must covers allow list

Open
#580 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
761
Forks
147
Avg merge
1d 23h
Merged PRs (30d)
7

Description

**Is your feature request related to a problem? Please describe.**
When defining McpClient for agentcoregateway we can define an allowlist , but using the semantic search using Agentcore Search Tool breaks the alowlist functionality and can introduce extra level of halucination and difficulties during agent loop and tool selection.

**Describe the solution you'd like**
The Plugin can apply the allowlist after semantic search call , this way , even agentcore gateway retourns Many tools form an OpenApi Spec ( etc..) this allow list validation will only return the tools that are present in allow list.

**Describe alternatives you've considered**
In every project we create a custom plugin to apply the solution. while this works but create a lot of repeated code for all strands agent SDK users

**Additional context**
A example of plugin used

```python
import logging

from bedrock_agentcore.gateway.integrations.strands.plugins import AgentCoreToolSearchPlugin
from strands.hooks import BeforeInvocationEvent
from strands.plugins import Plugin, hook
from strands.tools.mcp import MCPClient

from .intent import _UNIFIED_INTENT_PROVIDER, UnifiedIntentProvider

logger = logging.getLogger(__name__)

class McpClientSearchPlugin(AgentCoreToolSearchPlugin):
"""Tool-search plugin scoped to one gateway's MCP client, driven by ``ParallelToolSearchPlugin``."""

def __init__(
self,
mcp_client: MCPClient,
*,
name: str,
domain: str,
allowed_tool_names: frozenset[str] = frozenset(),
):
"""
Args:
mcp_client: MCP client connected to this gateway.
name: Plugin name for each gateway.
domain: ``UnifiedIntentDecision`` field name this gateway's intent comes from.
allowed_tool_names: Drops search results not in this set; empty (default) means no restriction.
"""
self.name = name
self.domain = domain
super().__init__(mcp_client)
self._allowed_tool_names = allowed_tool_names

def search_and_filter_tools(self, intent: str) -> list:
"""Search the gateway for given intent. And filter allowed tools """
if not intent:
logger.info("%s loaded 0 tool(s): intent empty or out of scope", self.name)
return []

try:
result = self._mcp_client.call_tool_sync(
tool_use_id="intent-search",
name="x_amz_bedrock_agentcore_search",
arguments={"query": intent},
)
agent_tools = self._build_tools_from_search_result(result)
except Exception as e:
logger.error("AgentCore Gateway search failed: %s", e)
return []

if not self._allowed_tool_names:
return agent_tools

allowed, dropped = [], []
for agent_tool in agent_tools:
(allowed if agent_tool.tool_name in self._allowed_tool_names else dropped).append(agent_tool)
if dropped:
logger.warning(
"%s: dropping non-allowlisted tool(s) surfaced by search: %s",
self.name,
sorted(t.tool_name for t in dropped),
)
return allowed

def apply_tools(self, event: BeforeInvocationEvent, agent_tools: list) -> None:
"""Swap the tools this plugin registered in a previous invocation of this session for ``agent_tools``."""
for name in list(self._loaded_tool_names):
event.agent.tool_registry.registry.pop(name, None)
self._loaded_tool_names.clear()

for agent_tool in agent_tools:
event.agent.tool_registry.register_tool(agent_tool)
self._loaded_tool_names.add(agent_tool.tool_name)

logger.info(
"%s loaded %d tool(s): %s",
self.name,
len(self._loaded_tool_names),
sorted(self._loaded_tool_names),
)

```

Contributor guide

Open the contributing guide

Research direction

Start by reading AgentCoreToolSearchPlugin and its search_and_filter_tools entry point, including the x_amz_bedrock_agentcore_search call and _build_tools_from_search_result flow. Implement the allowlist behavior shown in the example so semantic-search results include only permitted tools, while an empty allowlist keeps the current unrestricted behavior. Verify both restricted and unrestricted searches.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, python
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
64/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.