Skip to main content

ADR-006: Tool Registry Architecture β€” Modular 7-Module Design

Metadata​

FieldValue
StatusAccepted
Date2026-02-06
LinearCAB-841 (Refactoring), CAB-603 (Core vs Proxied), CAB-605 (Consolidation)

Context​

The MCP Gateway's tool registry is the central component for managing AI-accessible tools. Initially implemented as a single 1984-line file, it became unmaintainable as features grew:

  • Core platform tools (stoa_*)
  • Proxied tenant API tools ({tenant}:{api}:{operation})
  • External MCP server tools (Linear, GitHub, etc.)
  • Deprecation management for tool renaming
  • K8s CRD-based tool discovery

The Problem​

"The tool registry grew into a god object. Adding a feature means understanding 2000 lines of code."

The monolithic design caused:

  • Merge conflicts on every PR
  • Cognitive overload for contributors
  • Difficulty testing individual concerns
  • Slow iteration on new features

Decision​

Refactor the tool registry into a modular mixin-based architecture with single-responsibility modules.

Architecture​

File Structure​

mcp-gateway/src/services/tool_registry/
β”œβ”€β”€ __init__.py # ToolRegistry class (mixin composition)
β”œβ”€β”€ models.py # DeprecatedToolAlias dataclass
β”œβ”€β”€ exceptions.py # ToolNotFoundError
β”œβ”€β”€ singleton.py # Module-level get_tool_registry()
β”‚
β”œβ”€β”€ registration.py # RegistrationMixin β€” register/unregister tools
β”œβ”€β”€ lookup.py # LookupMixin β€” get/list/search tools
β”œβ”€β”€ deprecation.py # DeprecationMixin β€” alias management
β”œβ”€β”€ invocation.py # InvocationMixin β€” main invoke() entry point
β”œβ”€β”€ core_routing.py # CoreRoutingMixin β€” route to core tools
β”œβ”€β”€ action_handlers.py # ActionHandlersMixin β€” handle_*_action methods
β”œβ”€β”€ proxied.py # ProxiedMixin β€” invoke proxied tenant tools
β”œβ”€β”€ external.py # ExternalMixin β€” external MCP servers
└── legacy.py # LegacyMixin β€” backward compatibility

Module Responsibilities​

RegistrationMixin (registration.py)​

Handles tool lifecycle:

class RegistrationMixin:
async def register_tool(self, tool: Tool) -> None: ...
async def unregister_tool(self, tool_name: str) -> None: ...
async def _register_core_tools(self) -> None: ...
async def _register_builtin_tools(self) -> None: ...

LookupMixin (lookup.py)​

Tool discovery and search:

class LookupMixin:
async def get_tool(self, name: str) -> Tool | None: ...
async def list_tools(self, tenant_id: str = None) -> list[Tool]: ...
async def search_tools(self, query: str) -> list[Tool]: ...
def _resolve_deprecated_alias(self, name: str) -> str | None: ...

DeprecationMixin (deprecation.py)​

Manages tool renaming with backward compatibility:

class DeprecationMixin:
_deprecated_aliases: dict[str, DeprecatedToolAlias]

async def _register_deprecation_aliases(self) -> None: ...
def add_deprecated_alias(self, old_name: str, new_name: str) -> None: ...

Aliases provide 60-day backward compatibility:

@dataclass
class DeprecatedToolAlias:
old_name: str
new_name: str
deprecated_at: datetime
expires_at: datetime # deprecated_at + 60 days

InvocationMixin (invocation.py)​

Main entry point for tool execution:

class InvocationMixin:
async def invoke(
self,
tool_name: str,
arguments: dict,
context: InvocationContext
) -> ToolResult: ...

Routes to appropriate handler based on tool type.

CoreRoutingMixin (core_routing.py)​

Routes to platform tools:

class CoreRoutingMixin:
async def _invoke_core_tool(
self,
tool: CoreTool,
action: str,
arguments: dict,
context: InvocationContext
) -> ToolResult: ...

ActionHandlersMixin (action_handlers.py)​

Domain-specific action handlers:

class ActionHandlersMixin:
async def _handle_catalog_action(self, action: str, args: dict) -> ToolResult: ...
async def _handle_subscription_action(self, action: str, args: dict) -> ToolResult: ...
async def _handle_observability_action(self, action: str, args: dict) -> ToolResult: ...
async def _handle_platform_action(self, action: str, args: dict) -> ToolResult: ...
async def _handle_uac_action(self, action: str, args: dict) -> ToolResult: ...
async def _handle_security_action(self, action: str, args: dict) -> ToolResult: ...

ProxiedMixin (proxied.py)​

Invokes tenant API tools:

class ProxiedMixin:
async def _invoke_proxied_tool(
self,
tool: ProxiedTool,
arguments: dict,
context: InvocationContext
) -> ToolResult: ...

ExternalMixin (external.py)​

Manages external MCP servers (Linear, GitHub, etc.):

class ExternalMixin:
async def register_external_server(self, server: ExternalMCPServer) -> None: ...
async def invoke_external_tool(self, tool_name: str, args: dict) -> ToolResult: ...

Tool Types​

Core Tools (stoa_*)​

Platform-provided tools with action-based design:

ToolDomainActions
stoa_catalogCATALOGlist_apis, get_api, search
stoa_subscriptionSUBSCRIPTIONlist, create, revoke
stoa_observabilityOBSERVABILITYget_metrics, get_logs
stoa_platformPLATFORMget_status, list_tenants
stoa_uacUACvalidate, generate
stoa_securitySECURITYcheck_policy, audit

Proxied Tools ({tenant}:{api}:{operation})​

Dynamically registered from tenant APIs:

# Example: acme:payment-api:create_payment
ProxiedTool(
name="acme:payment-api:create_payment",
tenant_id="acme",
api_id="payment-api",
operation="create_payment",
endpoint="https://api.<YOUR_DOMAIN>/acme/payment-api/v1/payments",
method="POST"
)

External Tools​

Tools from external MCP servers:

ExternalTool(
name="linear:create_issue",
server_id="linear-mcp",
original_name="create_issue"
)

Class Composition​

The main ToolRegistry class composes all mixins:

class ToolRegistry(
DeprecationMixin,
RegistrationMixin,
LookupMixin,
InvocationMixin,
CoreRoutingMixin,
ActionHandlersMixin,
ProxiedMixin,
ExternalMixin,
LegacyMixin,
):
def __init__(self) -> None:
self._core_tools: dict[str, CoreTool] = {}
self._proxied_tools: dict[str, ProxiedTool] = {}
self._external_tools: dict[str, ExternalTool] = {}
self._deprecated_aliases: dict[str, DeprecatedToolAlias] = {}
self._http_client: httpx.AsyncClient | None = None

Storage Strategy​

Different tool types use separate dictionaries:

StorageKey FormatTool Type
_core_toolsstoa_DOMAINCoreTool
_proxied_toolsTENANT:API:OPERATIONProxiedTool
_external_toolsSERVER:TOOL_NAMEExternalTool
_deprecated_aliasesOLD_NAMEDeprecatedToolAlias

Consequences​

Positive​

  • Single Responsibility β€” Each mixin handles one concern
  • Testability β€” Mixins can be tested in isolation
  • Readability β€” Files are 200-400 lines instead of 2000
  • Parallelism β€” Multiple developers can work on different mixins
  • Extensibility β€” New tool types add new mixins

Negative​

  • Mixin Complexity β€” Multiple inheritance requires careful ordering
  • Discoverability β€” Code spread across files
  • Circular Dependencies β€” Mixins must avoid importing each other

Mitigations​

ChallengeMitigation
Mixin orderingDocumented in __init__.py, CI enforces
DiscoverabilityClear file naming, docstrings
Circular depsPass dependencies via __init__, not imports

Performance​

Tool lookup is O(1) via dictionary:

async def get_tool(self, name: str) -> Tool | None:
# Check core tools first (most common)
if name in self._core_tools:
return self._core_tools[name]

# Check deprecated aliases
resolved = self._resolve_deprecated_alias(name)
if resolved:
return await self.get_tool(resolved)

# Check proxied tools
if name in self._proxied_tools:
return self._proxied_tools[name]

# Check external tools
return self._external_tools.get(name)

References​


Standard Marchemalo: A 40-year veteran architect understands in 30 seconds

Cookies and privacy

With your permission, we use cookies to measure visits and understand navigation to improve the site.

Learn more

Google Analytics measures visits and useful clicks. Microsoft Clarity provides masked interaction replays. No advertising use. Your choice is saved for six months. You can change or withdraw it at any time using the β€œCookies” button.

Read the audience measurement details