Build a Scoped Tool Registry for AI Agents: Metadata, Scopes, and Safe Publishing A developer published a plain-Python tutorial for building a scoped tool registry for AI agents, covering frozen tool records with owner, version, input/output schemas, risk category and approval flags, a nested scope tree, publishing rules, and an audited call wrapper. The design aims to prevent tool drift, invisible access, unsafe actions and retry accidents across multi-agent projects, and stores metadata clean enough to expose through protocols such as MCP and A2A. An AI agent tool registry is a central catalog where every tool an agent can call is described once, with its owner, inputs, outputs, scope, and risk level, then published only to the agents allowed to use it. This tutorial builds a small one in Python, with nested scopes, approval flags, and an audited call wrapper. Most agent projects start by defining tools inline, next to the prompt. That works for one agent. At ten agents, the same "send email" function exists in four slightly different versions, nobody knows which agent can call which, and a rename breaks something silently. A registry fixes this early. Think of the registry as the contract between tool authors and agent builders. Authors register a tool once with everything a caller needs to know. Builders pick tools from the catalog instead of writing glue code. The platform checks the contract on every call. A useful registry answers five questions about any tool. Who owns it? What does it accept and return? How risky is it? Which scope built it? And which projects may call it today? If your tool definitions cannot answer all five, you have a pile of functions, not a registry. The design also supports open standards. Protocols such as MCP describe how agents discover and call tools, and A2A describes how agents call each other. A registry that stores clean tool metadata can expose the same tools through either, without a rewrite. We will build four pieces: a tool record, a scope tree, publishing rules, and a governed caller. The code is plain Python with no dependencies, so you can read it in one sitting and adapt it to whatever framework your agents use. Before writing code, it helps to name the failures a registry prevents. Each one shows up in almost every team that scales past a handful of agents, and each one costs more to fix later than to design away now. Drift. Two agents define "lookup customer" differently. One returns an email field, the other does not. A downstream step fails only for one of them, and the bug looks like model flakiness. A single registered definition removes the drift. Invisible access. An agent built for support quietly gains a refund tool because a developer copied a file. Nobody reviews it, because tools live in code, not in a catalog. A registry makes access something you can list and audit. Unsafe actions. A read tool and a payment tool look identical to a framework. Without a category and an approval flag, nothing tells the runtime to pause before money moves. Metadata is what lets policy attach to the right calls. Retry accidents. Agents retry on failure. A tool that creates an order is not safe to retry unless it is idempotent. If that fact lives only in a developer's head, a network blip turns into two shipments. Step 1: Model the Tool Record Start with the data. A tool record carries everything the registry and runtime need, so keep it explicit. Frozen dataclasses prevent accidental edits after registration, which matters when a tool's contract is what other teams rely on. from dataclasses import dataclass from enum import Enum class Level str, Enum : SYSTEM = "system" ORG = "organization" PROJECT = "project" @dataclass frozen=True class ToolRecord: name: str version: str owner: str category: str "read" or "action" scope id: str the scope that built it description: str input schema: dict {"required": ... , "properties": {...}} output schema: dict requires approval: bool = False idempotent: bool = True A few choices deserve explanation. The version is part of the identity, so a breaking change becomes a new record instead of a silent edit. Category separates reads from actions. Idempotent states whether a retry is safe, which the caller can use later. The tool metadata here is deliberately small. In production you would add a data classification, a cost estimate, a deprecation date, and a link to the owning team's runbook. The principle stays the same: anything policy might need should be a field, not a comment. Step 2: Add Scopes So Tools Do Not Leak Tools need a home in your organization. A tool built for one project should not appear in every other project's catalog. A tool every team needs should be approved once, centrally. Nested scopes give you both with one small structure. @dataclass class ScopeNode: id: str level: Level parent: str | None = None class ScopeTree: def init self, nodes : self.nodes = {n.id: n for n in nodes} python def chain self, scope id : """scope id plus every ancestor, nearest first.""" out, cur = , self.nodes.get scope id while cur: out.append cur.id cur = self.nodes.get cur.parent if cur.parent else None return out The rule we will enforce has two directions. Assets, such as tools, flow upward: a tool built in a project is visible to that project, its organization, and the system. Access flows downward: a project can only use what an ancestor scope has published to it. Separating visibility from usability is the key idea. Governance needs to see everything built beneath it, so visibility travels up. Builders must never reach beyond what their parent granted, so usability travels down through explicit publishing. Step 3: Register, Publish, and Resolve Now the registry itself. Registration stores the record and checks that its scope exists. Publishing grants a specific project the right to call a tool, and only a scope on the project's own chain can publish into it. class ToolRegistry: python def init self, tree: ScopeTree : self.tree = tree self. tools = {} name, version - ToolRecord self. published = {} project id - set of name, version def register self, tool: ToolRecord : key = tool.name, tool.version if key in self. tools: raise ValueError f"{key} already registered" if tool.scope id not in self.tree.nodes: raise ValueError f"unknown scope {tool.scope id}" self. tools key = tool def publish self, name, version, project id : tool = self. tools name, version if tool.scope id not in self.tree.chain project id : raise PermissionError "tool scope is not above this project" self. published.setdefault project id, set .add name, version def visible to self, scope id : """Assets flow up: tools built here or in any descendant scope.""" return t for t in self. tools.values if scope id in self.tree.chain t.scope id def get published self, project id, name, version : if name, version not in self. published.get project id, set : raise PermissionError f"{name}@{version} not published to {project id}" return self. tools name, version Notice what the code refuses. A tool built in one project cannot be published into a sibling project, because the owning scope is not on the sibling's chain. A project cannot call anything that was not published to it. Both rules are two lines each. Step 4: Wrap Every Call With Checks and an Audit Record The last piece is a caller that agents must go through. It resolves the tool from the registry, validates inputs, enforces approval for risky tools, and writes an audit record whether the call succeeds or fails. import time, uuid def validate schema: dict, payload: dict : missing = k for k in schema.get "required", if k not in payload unknown = k for k in payload if k not in schema.get "properties", {} if missing or unknown: raise ValueError f"missing={missing} unknown={unknown}" class GovernedCaller: def init self, registry, executors, audit sink : self.registry, self.executors, self.audit = registry, executors, audit sink python def call self, project id, agent id, name, version, payload, approved by=None : tool = self.registry.get published project id, name, version validate tool.input schema, payload if tool.requires approval and not approved by: raise PermissionError f"{name} needs a named approver" started, status = time.time , "ok" try: return self.executors name, version payload except Exception: status = "error" raise finally: self.audit { "call id": str uuid.uuid4 , "project": project id, "agent": agent id, "tool": f"{name}@{version}", "category": tool.category, "approved by": approved by, "status": status, "ms": int time.time - started 1000 , } The finally block is the important part. Failed calls get logged too, and failures are exactly what you need in an incident. Wire audit sink to whatever store you already trust, and keep the records tamper-resistant. Here is a short run that shows the rules working together: tree = ScopeTree ScopeNode "sys", Level.SYSTEM , ScopeNode "finance", Level.ORG, "sys" , ScopeNode "claims", Level.PROJECT, "finance" , ScopeNode "billing", Level.PROJECT, "finance" , reg = ToolRegistry tree reg.register ToolRecord "issue refund", "1.0", "payments-team", "action", "finance", "Refund a charge", {"required": "charge id", "amount" , "properties": {"charge id": {}, "amount": {}}}, {}, requires approval=True, idempotent=False reg.publish "issue refund", "1.0", "claims" allowed: finance is above claims log = caller = GovernedCaller reg, { "issue refund", "1.0" : lambda charge id, amount: "refunded"}, log.append caller.call "claims", "agent-7", "issue refund", "1.0", {"charge id": "ch 1", "amount": 20}, approved by="d.mehta" Extending the AI Agent Tool Registry https://www.covasant.com/platform/seraa-enterprise-intelligence-platform to MCP and Other Agents Once tools live in one catalog, exposing them to other systems is mostly translation. Each record already holds a name, description, and input schema, which is most of what an MCP tool listing needs. A thin adapter can serve the published tools for a project over MCP. Third-party agents are the same story. Register each external agent as a callable with its own scope, owner, and category, then compose it into workflows through A2A instead of wrapping it in custom code. The same approval flags and audit records apply, whoever built the agent. When you grow beyond one process, add a few features in order of value. Deprecation dates come first, so teams can retire tools safely. Per-tool rate limits come next, to protect downstream systems. Cost metadata follows, so spend rolls up by tool. A full agentic AI platform bundles all of these around the same record. Finally, test the boundaries, not just the happy path. Write tests that try to publish a tool into a sibling project, call an unpublished tool, skip an approval, and send an unknown field. Every one of those should fail. They are the tests that keep the registry honest as the code evolves. One last design note on idempotency. Keep the flag, and use it. Have the caller attach an idempotency key to every action tool and refuse automatic retries when the flag is false. A safe retry policy costs a few lines now and saves a duplicate-shipment postmortem later. What is an AI agent tool registry? It is a central catalog of every tool agents can call, with metadata about owner, inputs, outputs, scope, risk, and version. Agents receive tools through publishing rules, and every call passes through checks and logging, so access is visible, reviewable, and consistent across teams. Why version tools instead of editing them? Other agents depend on a tool's contract. A silent change to inputs or outputs breaks callers in ways that look like model errors. Making the version part of the tool's identity turns a breaking change into a new record that teams adopt deliberately. How does this relate to MCP? MCP is a protocol for exposing tools to agents. A registry is the system of record behind it. Store clean metadata and scopes in the registry, then serve the published subset to each project over MCP, so the protocol layer never becomes the place where access decisions are made. Do I need approval flags on every tool? No. Read-only tools usually need none. Mark tools that move money, change customer records, send external messages, or delete data. Review the flags with real approval data, and relax them for actions that humans approve unchanged almost every time.