VOOZH about

URL: https://deepwiki.com/WordPress/mcp-adapter/3.1-core-system-components

⇱ Core System Components | WordPress/mcp-adapter | DeepWiki


Loading...
Menu

Core System Components

This page documents the foundational classes that form the core of the MCP Adapter system: the McpAdapter singleton, McpServer instances, McpComponentRegistry, and the multi-server architecture pattern. These components work together to manage MCP server creation, configuration, and lifecycle.

For details on how requests are processed through these components, see Request Processing Pipeline. For information about the security model applied at these levels, see Security and Permissions.

System Overview

The MCP Adapter uses a three-tier component architecture where a single McpAdapter singleton manages multiple McpServer instances, each containing its own McpComponentRegistry for tracking tools, resources, and prompts.


Sources: includes/Core/McpAdapter.php25-318 includes/Core/McpServer.php includes/Core/McpComponentRegistry.php README.md148-168

McpAdapter Singleton

The McpAdapter class is the central registry that manages all MCP servers within a WordPress installation. It implements the singleton pattern to ensure only one instance exists throughout the application lifecycle.

Class Structure

PropertyTypePurpose
$instanceMcpAdapterStatic singleton instance
$serversMcpServer[]Array of registered servers indexed by server ID
$initializedboolFlag to prevent duplicate initialization
MethodPurpose
instance()Returns the singleton instance and sets up initialization hooks
init()Initializes the adapter, creates default server, fires mcp_adapter_init action
create_server()Creates and registers a new MCP server instance
get_server()Retrieves a server by ID
get_servers()Returns all registered servers

Sources: includes/Core/McpAdapter.php25-86 includes/Core/McpAdapter.php236-247

Singleton Initialization Flow


Sources: includes/Core/McpAdapter.php55-69 includes/Core/McpAdapter.php76-86 includes/Core/McpAdapter.php254-265

Initialization Context

The adapter initializes at different WordPress hooks depending on the execution context:

  • HTTP Context: Hooks into rest_api_init at priority 15 to ensure REST API infrastructure is available
  • WP-CLI Context: Hooks into init at priority 20 to ensure commands have immediate server access

Sources: includes/Core/McpAdapter.php60-66

Server Creation and Validation

The create_server() method performs comprehensive validation before creating a server:


Sources: includes/Core/McpAdapter.php107-227

Handler Validation

The adapter validates that error and observability handlers implement the required interfaces:

Handler TypeRequired InterfaceDefault Implementation
Error HandlerMcpErrorHandlerInterfaceNullMcpErrorHandler
Observability HandlerMcpObservabilityHandlerInterfaceNullMcpObservabilityHandler

Sources: includes/Core/McpAdapter.php109-162

McpServer Instances

Each McpServer represents a single MCP endpoint with its own configuration, components, transports, and handlers. Multiple servers can coexist within a single WordPress installation, each with isolated functionality.

Server Configuration


Sources: includes/Core/McpServer.php README.md159-168

Server Endpoints

Each server exposes its functionality through REST API endpoints constructed from the namespace and route:

ComponentPatternExample
Namespace{route_namespace}/{server_id}mcp/mcp-adapter-default-server
Route{route}/
Full Path/wp-json/{namespace}/{route}/wp-json/mcp/mcp-adapter-default-server

Sources: README.md290-291 README.md453-471

Component Registration

Each server maintains its own component registry populated during server creation:


Sources: includes/Core/McpServer.php includes/Domain/Tools/RegisterAbilityAsMcpTool.php includes/Domain/Resources/RegisterAbilityAsMcpResource.php includes/Domain/Prompts/RegisterAbilityAsMcpPrompt.php

McpComponentRegistry

The McpComponentRegistry maintains collections of tools, resources, and prompts for a single server. It provides type-safe storage and retrieval methods for each component type.

Registry Structure


Sources: includes/Core/McpComponentRegistry.php includes/Domain/Tools/McpTool.php includes/Domain/Resources/McpResource.php includes/Domain/Prompts/McpPrompt.php

Component Lookup Methods

The registry provides three categories of lookup methods for each component type:

Method PatternPurposeReturns
add_*()Register a new componentvoid
get_*()Retrieve a specific component by identifierComponent or null
get_all_*()Retrieve all components of a typeComponent[]
has_*()Check if a component existsbool

Sources: includes/Core/McpComponentRegistry.php

Multi-Server Architecture Pattern

The MCP Adapter supports running multiple independent MCP servers within a single WordPress installation. Each server operates in isolation with its own configuration and components.

Server Isolation


Sources: README.md449-471 includes/Core/McpAdapter.php107-227

Server Independence

Each server maintains complete independence in:

AspectScopeConfiguration Method
EndpointREST API namespace and routeserver_route_namespace, server_route parameters
ComponentsTools, resources, prompts$tools, $resources, $prompts arrays
TransportCommunication protocols$mcp_transports array
AuthenticationPermission checking$transport_permission_callback parameter
Error HandlingError logging and reporting$error_handler class name
ObservabilityMetrics and event tracking$observability_handler class name

Sources: includes/Core/McpAdapter.php107-227

Server Lifecycle and Initialization

The server lifecycle follows a specific sequence of WordPress hooks and actions to ensure proper initialization order.

Lifecycle Phases


Sources: includes/Core/McpAdapter.php76-86 includes/Core/McpAdapter.php254-265 includes/Servers/DefaultServerFactory.php

Initialization Hooks

HookPriorityPurpose
plugins_loadedDefaultPlugin loading phase (mcp-adapter.php loaded)
wp_abilities_api_categories_initDefaultRegister ability categories
wp_abilities_api_initDefaultRegister WordPress abilities
rest_api_init or init15-20Initialize McpAdapter
mcp_adapter_initN/AServer creation phase (custom servers)

Sources: includes/Core/McpAdapter.php60-66 includes/Core/McpAdapter.php261-264 mcp-adapter.php1-58

Default Server Creation

The default server is created automatically unless disabled via filter:


When enabled, the default server:

  1. Registers the mcp-adapter ability category
  2. Registers three built-in abilities: DiscoverAbilitiesAbility, GetAbilityInfoAbility, ExecuteAbilityAbility
  3. Creates a server with ID mcp-adapter-default-server
  4. Exposes endpoint at /wp-json/mcp/mcp-adapter-default-server
  5. Uses HttpTransport for communication
  6. Applies default error and observability handlers

Sources: includes/Core/McpAdapter.php254-265 includes/Core/McpAdapter.php268-292 includes/Servers/DefaultServerFactory.php

Server Registry Access

Once initialized, servers can be accessed through the singleton:

Access PatternCodeReturns
Get specific serverMcpAdapter::instance()->get_server('server-id')McpServer or null
Get all serversMcpAdapter::instance()->get_servers()McpServer[]
Check if initializedInternal flag, no public APIbool

Sources: includes/Core/McpAdapter.php236-247