mech.app

The mech.app newsletter

Agentic AI, minus the noise.

Get practical field notes on AI agents, automation, developer tools and security delivered to your inbox.

No spam. Unsubscribe anytime.

Dev Tools

Tool Registries Are APIs, Not Config: Why Agent Security Reviews Miss the Attack Surface

Agent tool registries evolve at runtime and carry authority. Treating them as static config creates security blind spots in production deployments.

Source: dev.to
Tool Registries Are APIs, Not Config: Why Agent Security Reviews Miss the Attack Surface

Most agent security reviews focus on prompt injection, jailbreaks, and model behavior. That’s half the picture. The other half is the tool registry: the catalog of functions an agent can invoke, the credentials those functions carry, and the approval boundaries (or lack of them) that gate execution.

In demos, the tool list is static. In production, it grows one PR at a time. Someone adds create_ticket. Someone else adds run_sql for analytics. A third person swaps a read-only GitHub token for one with full repo scope because the agent needs to open PRs now. None of these changes touched a route file, so none of them got the review a new public endpoint would get.

That’s the gap. The tool registry is API surface. It just doesn’t look like it.

Why Tool Registries Are Dynamic API Surfaces

A tool registry is not a config file. It’s a runtime catalog that:

  • Accepts new entries without redeployment. Tools can be registered via admin endpoints, plugin loaders, or dynamic discovery from external sources (MCP servers, OpenAPI specs, function manifests).
  • Carries authority. Each tool wraps a credential, a scope, and a permission boundary. The agent doesn’t authenticate. The tool does.
  • Changes behavior based on context. The same tool name can resolve to different implementations depending on user identity, environment, or feature flags.
  • Exposes schema and metadata. The registry serves tool descriptions, parameter schemas, and examples to the orchestrator. If that metadata is wrong or stale, the agent will misuse the tool.

This is not declarative infrastructure. This is a live API with mutation endpoints, query surfaces, and authorization logic.

The Four Questions for Every Tool

For each tool in the registry, answer these:

  1. What kind of action is it? Read, write, execute, or trigger something external (email, payment, webhook, deploy). These are different risk classes and should be labeled that way.
  2. Whose identity does it run as? The end user’s delegated identity? A shared service account? The agent’s own credential with org-wide scope?
  3. What data can it reach? Not what it’s meant to reach. What the credential and the query surface actually allow.
  4. Where is approval required? Is there a human-in-the-loop step, and is it enforced in the tool layer, or only suggested in the system prompt?

If the answer to #4 lives only in the prompt, you don’t have an approval step. You have a polite request for one.

Failure Mode: The Read Tool That Reads Everything

A support agent has a tool called search_tickets. The tool description says it searches support tickets for the current user. The implementation uses a service account with SELECT on the entire tickets table. The agent is supposed to filter by user_id, but that filter is constructed in the orchestrator, not enforced by the database.

An attacker submits a ticket with a carefully crafted subject line. The agent searches for it. The orchestrator’s query builder mishandles a special character. The filter drops. The agent gets back 10,000 tickets, including ones from other customers. The agent summarizes them. The attacker reads the summary.

This is not a prompt injection. This is a missing authorization boundary in the tool layer.

Failure Mode: Credential Drift

A tool is registered with a GitHub token that has repo:read scope. Six months later, someone rotates the token and grants repo:write because the agent now needs to open PRs. The tool registry entry is not updated. The tool description still says “read-only.” The security review from six months ago is still on file.

The agent can now delete branches, close issues, and force-push to main. No one noticed because the change happened in a secrets manager, not in code.

Architecture: Tool Registry as a Gated API

Here’s what a production-grade tool registry looks like:

Registration Layer

  • Admission control. New tools go through a registration endpoint with schema validation, credential inspection, and risk classification.
  • Versioning. Tools are versioned. The agent specifies which version it wants. Old versions can be deprecated but not silently replaced.
  • Metadata enforcement. Tool descriptions, parameter schemas, and examples are validated against the actual implementation. If the schema says a parameter is required, the runtime enforces it.

Invocation Layer

  • Identity propagation. The agent passes the end user’s identity to the tool. The tool uses it to scope queries and enforce row-level security.
  • Approval gates. High-risk tools (write, execute, external trigger) require explicit approval. The approval step is enforced in the tool wrapper, not the prompt.
  • Rate limiting. Tools have per-user, per-agent, and per-tool rate limits. A runaway agent can’t exhaust a quota or trigger a cost spike.

Observability Layer

  • Audit log. Every tool invocation is logged with: agent ID, user ID, tool name, tool version, parameters, result summary, and approval status.
  • Anomaly detection. Baseline tool usage patterns. Alert when an agent starts calling a tool it’s never used before, or calling it at 10x normal rate.
  • Credential tracking. Log which credential was used for each invocation. When a credential is rotated or revoked, you can see which tools are affected.

Implementation: Tool Registry with Approval Gates

from enum import Enum
from dataclasses import dataclass
from typing import Callable, Any

class RiskClass(Enum):
    READ = "read"
    WRITE = "write"
    EXECUTE = "execute"
    EXTERNAL = "external"

@dataclass
class Tool:
    name: str
    version: str
    risk_class: RiskClass
    requires_approval: bool
    credential_id: str
    implementation: Callable
    schema: dict

class ToolRegistry:
    def __init__(self, approval_service):
        self.tools = {}
        self.audit_log = []
        self.approval_service = approval_service
    
    def register(self, tool: Tool):
        # Validate schema matches implementation signature
        self._validate_schema(tool)
        # Store with version key
        key = f"{tool.name}:{tool.version}"
        self.tools[key] = tool
    
    async def invoke(self, tool_name: str, version: str, 
                     user_id: str, agent_id: str, params: dict) -> Any:
        key = f"{tool_name}:{version}"
        tool = self.tools.get(key)
        if not tool:
            raise ValueError(f"Tool {key} not found")
        
        # Check approval requirement
        if tool.requires_approval:
            approved = await self.approval_service.request_approval(
                user_id=user_id,
                tool_name=tool_name,
                params=params
            )
            if not approved:
                raise PermissionError("Approval denied")
        
        # Execute with credential
        credential = self._get_credential(tool.credential_id, user_id)
        result = await tool.implementation(credential, params)
        
        # Audit
        self.audit_log.append({
            "agent_id": agent_id,
            "user_id": user_id,
            "tool": key,
            "params": params,
            "approved": tool.requires_approval,
            "credential_id": tool.credential_id
        })
        
        return result
    
    def _validate_schema(self, tool: Tool):
        # Check that schema matches implementation signature
        # Check that required params are actually required
        # Check that credential has necessary scopes
        pass
    
    def _get_credential(self, credential_id: str, user_id: str):
        # Fetch credential, potentially scoped to user_id
        # Return a credential object that enforces boundaries
        pass

This is a sketch, not production code. The key points:

  • Tools are versioned and validated at registration time.
  • High-risk tools require approval before execution.
  • Every invocation is logged with full context.
  • Credentials are fetched per-invocation, not cached in the tool definition.

Observability: What to Log and Alert On

SignalWhat to LogWhen to Alert
New tool registrationTool name, version, risk class, credential ID, registrantAny tool with EXECUTE or EXTERNAL risk class
Tool invocationAgent ID, user ID, tool name, version, params, result summary, approval statusInvocation of a tool the agent has never used before
Approval denialUser ID, tool name, params, reasonRepeated denials for the same user or agent
Credential rotationOld credential ID, new credential ID, affected toolsAny rotation that changes scope or permissions
Schema mismatchTool name, expected schema, actual paramsAny mismatch (indicates orchestrator bug or attack)
Rate limit breachTool name, user ID, agent ID, rate, limitAny breach (indicates runaway agent or abuse)

Comparison: Static Config vs. API Surface

AspectStatic ConfigAPI Surface
Change frequencyDeploy-time onlyRuntime, via registration endpoint
Review processCode review, security scanAdmission control, schema validation, risk classification
Identity modelShared service accountPer-user delegation or scoped credentials
Approval gatesSuggested in promptEnforced in tool wrapper
ObservabilityApplication logsStructured audit log with anomaly detection
Failure modeMisconfiguration at deploy timePrivilege escalation at runtime

When Tool Registries Become Attack Surfaces

Three scenarios where the registry itself is the vulnerability:

  1. Unauthenticated registration endpoint. If the tool registration API is exposed without authentication, an attacker can register a malicious tool that exfiltrates data or escalates privileges.
  2. Schema injection. If tool schemas are not validated, an attacker can register a tool with a schema that tricks the orchestrator into passing sensitive data as parameters.
  3. Credential leakage. If the registry returns full credential details (not just IDs) in tool metadata, an attacker who can query the registry can harvest credentials.

All three are real. All three have happened in production agent systems.

Technical Verdict

Use a gated tool registry when:

  • Your agent has more than five tools.
  • Any tool can write data, execute code, or trigger external actions.
  • Tools are added or modified more than once per quarter.
  • Multiple agents share the same tool catalog.
  • You need per-user or per-tenant authorization boundaries.

Avoid dynamic tool registration when:

  • Your agent is a single-purpose automation with a fixed tool set.
  • All tools are read-only and scoped to public data.
  • You can enforce tool boundaries at the orchestrator level with static configuration.

If you’re building a financial agent, a support agent, or any agent that touches customer data, treat the tool registry as API surface. Review it like you would review a new REST endpoint. Log it like you would log an authentication boundary. Monitor it like you would monitor a payment gateway.

The model picks the tool. The tool carries the authority. Secure the second half of that sentence.

Tags

agentic-ai orchestration infrastructure

Primary Source

dev.to ↗