VOOZH about

URL: https://deepwiki.com/WordPress/mcp-adapter/3-architecture

⇱ Architecture | WordPress/mcp-adapter | DeepWiki


Loading...
Menu

Architecture

This page explains the high-level architecture of the MCP Adapter, including its core components, layered design, request processing flow, and security model. For implementation details of specific subsystems, see Core System Components, Request Processing Pipeline, and Security and Permissions.

Three-Tier Architecture

The MCP Adapter follows a three-tier architecture that separates concerns between communication, routing, and business logic:


Sources: includes/Core/McpAdapter.php1-319 includes/Core/McpServer.php includes/Transport/HttpTransport.php includes/Transport/Infrastructure/RequestRouter.php README.md56-146

The three tiers operate as follows:

TierResponsibilityKey Classes
TransportAccept connections, parse JSON-RPC, authenticate, manage sessionsHttpTransport, StdioServerBridge, HttpSessionValidator
RoutingDispatch methods to handlers, extract metadata, coordinate observabilityRequestRouter, HttpRequestHandler, HttpRequestContext
HandlerExecute business logic, validate parameters, interact with abilitiesToolsHandler, ResourcesHandler, PromptsHandler, SystemHandler

Sources: includes/Transport/HttpTransport.php includes/Transport/Infrastructure/RequestRouter.php includes/Handlers/Tools/ToolsHandler.php includes/Handlers/Resources/ResourcesHandler.php includes/Handlers/Prompts/PromptsHandler.php

Core Components

McpAdapter Singleton Registry

The McpAdapter class serves as the central registry for all MCP servers in a WordPress installation. It implements the singleton pattern to ensure a single point of coordination.


Sources: includes/Core/McpAdapter.php25-319

Key responsibilities of McpAdapter:

MethodPurposeHook
instance()Returns singleton instance, sets up initialization hooksrest_api_init (priority 15) or init (priority 20 for CLI)
init()Creates default server, fires mcp_adapter_init actionCalled by WordPress action hooks
create_server()Validates and registers new McpServer instancesMust be called during mcp_adapter_init action
get_server()Retrieves server by IDN/A
get_servers()Returns all registered serversN/A

Sources: includes/Core/McpAdapter.php55-227 mcp-adapter.php55-56

McpServer Instances

Each McpServer represents an independent MCP server with its own configuration, components, and endpoints:


Sources: includes/Core/McpServer.php includes/Core/McpComponentRegistry.php

Each server maintains isolated configuration:

ConfigurationDescriptionDefault
EndpointREST API route for HTTP transport/wp-json/{namespace}/{route}
Transport permissionsCallback for server-wide authenticationis_user_logged_in()
Error handlerCustom error logging/monitoringNullMcpErrorHandler
Observability handlerCustom metrics/event trackingNullMcpObservabilityHandler
ComponentsRegistered tools, resources, promptsEmpty arrays

Sources: includes/Core/McpServer.php includes/Core/McpAdapter.php107-227

Component Registry Pattern

The McpComponentRegistry manages component lookup and validation:


Sources: includes/Core/McpComponentRegistry.php

Multi-Server Architecture

The adapter supports multiple independent MCP servers running simultaneously, each with isolated configuration:


Sources: includes/Core/McpAdapter.php41-247 includes/Servers/DefaultServerFactory.php README.md449-471

Default Server Creation: The default server (mcp-adapter-default-server) is automatically created during mcp_adapter_init unless filtered out via apply_filters('mcp_adapter_create_default_server', true).

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

Request Processing Flow

The complete lifecycle from client request to handler response follows this sequence:

HTTP Transport Flow


Sources: includes/Transport/HttpTransport.php includes/Transport/Infrastructure/HttpRequestHandler.php includes/Transport/Infrastructure/HttpSessionValidator.php includes/Transport/Infrastructure/SessionManager.php includes/Transport/Infrastructure/RequestRouter.php includes/Handlers/Tools/ToolsHandler.php

Key Request Processing Classes

ClassFileResponsibility
HttpTransportincludes/Transport/HttpTransport.phpREST API endpoint registration, request parsing
HttpRequestHandlerincludes/Transport/Infrastructure/HttpRequestHandler.phpCoordinates request processing, permission checks
HttpSessionValidatorincludes/Transport/Infrastructure/HttpSessionValidator.phpSession creation and validation
SessionManagerincludes/Transport/Infrastructure/SessionManager.phpSession state management
RequestRouterincludes/Transport/Infrastructure/RequestRouter.phpMethod-to-handler dispatch, metadata extraction
JsonRpcResponseBuilderincludes/Transport/Infrastructure/JsonRpcResponseBuilder.phpStandardized response formatting

Sources: includes/Transport/HttpTransport.php includes/Transport/Infrastructure/

Component Registration Lifecycle

WordPress abilities are automatically converted to MCP components through a hook-based lifecycle:


Sources: includes/Core/McpAdapter.php76-86 includes/Core/McpServer.php includes/Domain/Tools/RegisterAbilityAsMcpTool.php includes/Domain/Resources/RegisterAbilityAsMcpResource.php includes/Domain/Prompts/RegisterAbilityAsMcpPrompt.php

Registration Timing

HookPriorityPurpose
wp_abilities_api_initDefault (10)Plugins register abilities
mcp_adapter_initAfter REST initializationDevelopers create custom servers
rest_api_init15McpAdapter::init() runs, creates default server

Sources: includes/Core/McpAdapter.php55-86

Schema Transformation

The SchemaTransformer automatically converts between WordPress Abilities API schemas and MCP-compatible schemas:


Sources: includes/Domain/SchemaTransformer.php

The transformation occurs in two scenarios:

  1. Tool Registration: Flattened ability input_schema is wrapped into object format for MCP compatibility
  2. Tool Execution: Object-formatted parameters are unwrapped before passing to ability execute_callback

Sources: includes/Domain/Tools/RegisterAbilityAsMcpTool.php includes/Handlers/Tools/ToolsHandler.php

Error Handling Architecture

The error handling system provides centralized error creation and pluggable error handlers:


Sources: includes/Infrastructure/ErrorHandling/McpErrorFactory.php includes/Infrastructure/ErrorHandling/Contracts/McpErrorHandlerInterface.php includes/Infrastructure/ErrorHandling/ErrorLogMcpErrorHandler.php includes/Infrastructure/ErrorHandling/NullMcpErrorHandler.php

Each McpServer can specify its own error handler via the $error_handler parameter in create_server(). If none is provided, NullMcpErrorHandler is used.

Sources: includes/Core/McpAdapter.php107-134

Observability System

The metadata-driven observability architecture enables tracking without coupling handlers to specific monitoring tools:


Sources: includes/Infrastructure/Observability/Contracts/McpObservabilityHandlerInterface.php includes/Infrastructure/Observability/NullMcpObservabilityHandler.php includes/Infrastructure/Observability/ErrorLogMcpObservabilityHandler.php includes/Transport/Infrastructure/RequestRouter.php

Metadata Flow

Handlers attach _metadata to responses containing:

Metadata FieldDescriptionSource
component_type"tool", "resource", or "prompt"Handler logic
component_nameName of executed componentHandler parameter
execution_time_msDuration of executionHandler timing
failure_reasonError category on failureError context

Sources: includes/Handlers/Tools/ToolsHandler.php includes/Handlers/Resources/ResourcesHandler.php includes/Handlers/Prompts/PromptsHandler.php

The RequestRouter extracts this metadata and records events via the server's McpObservabilityHandlerInterface:


Sources: includes/Transport/Infrastructure/RequestRouter.php

Two-Layer Security Model

The MCP Adapter implements security at two distinct layers:


Sources: includes/Transport/Infrastructure/HttpRequestHandler.php includes/Handlers/Tools/ToolsHandler.php includes/Handlers/Resources/ResourcesHandler.php includes/Handlers/Prompts/PromptsHandler.php

Layer 1: Transport Permissions

Server-wide authentication configured via $transport_permission_callback parameter:


Sources: includes/Core/McpAdapter.php107 includes/Transport/Infrastructure/HttpRequestHandler.php

Layer 2: Ability Permissions

Granular permission checks defined in each ability's permission_callback:


Sources: WordPress Abilities API, includes/Handlers/Tools/ToolsHandler.php

Both layers must pass for execution to proceed. See Transport Permissions for implementation patterns and Security and Permissions for detailed security architecture.

Sources: includes/Transport/Infrastructure/HttpRequestHandler.php includes/Handlers/Tools/ToolsHandler.php includes/Handlers/Resources/ResourcesHandler.php includes/Handlers/Prompts/PromptsHandler.php README.md34