VOOZH about

URL: https://deepwiki.com/WordPress/mcp-adapter/8.3-server-creation-and-configuration

⇱ Server Creation and Configuration | WordPress/mcp-adapter | DeepWiki


Loading...
Menu

Server Creation and Configuration

This reference guide documents the create_server method and its parameters for creating custom MCP servers. It covers server identity configuration, transport setup, error handling, observability, ability registration, and permission callbacks.

For transport implementation details, see HTTP Transport and STDIO Transport. For error handler implementation, see Error Handling. For observability handler implementation, see Observability System. For creating abilities to register with servers, see Creating Abilities.

The create_server Method

The McpAdapter::create_server() method creates and registers a new MCP server instance with the adapter. Each server has a unique identifier, REST API endpoint, and independent configuration for transports, error handling, observability, and permissions.

Method Signature


Sources: includes/Core/McpAdapter.php89-107

Parameters Reference

ParameterTypeRequiredDescription
$server_idstringYesUnique identifier for the server. Used for server lookup and CLI commands.
$server_route_namespacestringYesREST API namespace (e.g., 'my-plugin' for /wp-json/my-plugin/...).
$server_routestringYesREST API route segment (e.g., 'mcp' for /.../mcp).
$server_namestringYesHuman-readable server name displayed to clients.
$server_descriptionstringYesServer description shown during initialization.
$server_versionstringYesServer version following semver format (e.g., '1.0.0').
$mcp_transportsarrayYesArray of transport class names implementing McpTransportInterface.
$error_handler?stringYesClass name implementing McpErrorHandlerInterface. null defaults to NullMcpErrorHandler.
$observability_handler?stringNoClass name implementing McpObservabilityHandlerInterface. null defaults to NullMcpObservabilityHandler.
$toolsarrayNoArray of ability names to register as tools (e.g., ['my-plugin/my-ability']).
$resourcesarrayNoArray of ability names to register as resources.
$promptsarrayNoArray of ability names to register as prompts.
$transport_permission_callback?callableNoCustom authentication callback for transport-level access. null defaults to is_user_logged_in().

Return Value

Returns McpAdapter instance on success for method chaining, or WP_Error on failure with error codes:

  • invalid_error_handler - Error handler class doesn't exist or doesn't implement required interface
  • invalid_observability_handler - Observability handler class doesn't exist or doesn't implement required interface
  • invalid_timing - Method called outside mcp_adapter_init action
  • duplicate_server_id - Server with this ID already exists

Sources: includes/Core/McpAdapter.php105-227

Server Configuration Process

Timing Requirements

Server creation must occur during the mcp_adapter_init action hook. The adapter validates this timing and returns a WP_Error if called at the wrong time.


Initialization Lifecycle: Server Creation Hook

Sources: includes/Core/McpAdapter.php76-86 includes/Core/McpAdapter.php164-174

Correct Hook Usage


Sources: README.md454-472

Parameter Details

Server Identity Configuration

The first six parameters define the server's identity and REST API endpoint.


Server Identity to Endpoint Mapping

ComponentPurposeValidation
server_idUnique identifier for get_server() and CLI commandsMust be unique across all servers
server_route_namespaceREST API namespace segmentWordPress REST API validation
server_routeREST API route segmentWordPress REST API validation
server_nameDisplay name for MCP clientsShown in initialize response
server_descriptionServer descriptionShown in initialize response
server_versionSemantic versionShown in initialize response

Duplicate ID Prevention:

The adapter validates server ID uniqueness and triggers _doing_it_wrong() if a duplicate is detected.

Sources: includes/Core/McpAdapter.php176-191 includes/Core/McpAdapter.php194-208

Transport Configuration

The $mcp_transports parameter is an array of transport class names. Multiple transports can be configured simultaneously.


Transport Configuration Pattern

Built-in Transports:

Transport ClassProtocolUse Case
\WP\MCP\Transport\HttpTransportHTTP + JSON-RPC 2.0AI clients, remote connections (MCP 2025-06-18 compliant)

Example: Single Transport


Example: Custom Transport

For custom transport implementation, see Custom Transports.

Sources: README.md462-464 includes/Core/McpServer.php70-77

Error Handler Configuration

The $error_handler parameter specifies the class name for error handling. If null, defaults to NullMcpErrorHandler.


Error Handler Validation and Defaults

Validation Rules:

  1. Class must exist (includes/Core/McpAdapter.php114-123)
  2. Class must implement McpErrorHandlerInterface (includes/Core/McpAdapter.php125-134)

Built-in Error Handlers:

Handler ClassBehaviorUse Case
NullMcpErrorHandlerSilent (no logging)Production, high-traffic sites
ErrorLogMcpErrorHandlerLogs to error_log()Development, debugging

Example Configuration:


Sources: includes/Core/McpAdapter.php108-134

Observability Handler Configuration

The $observability_handler parameter specifies the class name for metrics and event tracking. If null, defaults to NullMcpObservabilityHandler.


Observability Handler Validation and Defaults

Validation Rules:

  1. Class must exist (includes/Core/McpAdapter.php142-151)
  2. Class must implement McpObservabilityHandlerInterface (includes/Core/McpAdapter.php153-162)

Built-in Observability Handlers:

Handler ClassBehaviorOverheadUse Case
NullMcpObservabilityHandlerNo-opZeroProduction default
ErrorLogMcpObservabilityHandlerLogs eventsMinimalDevelopment debugging

Example Configuration:


Sources: includes/Core/McpAdapter.php136-162 README.md466-467

Component Registration

The $tools, $resources, and $prompts parameters specify which WordPress abilities to expose through the server.


Ability Registration Flow

Registration Rules:

  1. Abilities must be registered via wp_register_ability() before server creation
  2. Each ability name is a string in format 'namespace/ability-name'
  3. Empty arrays are valid (server with no tools/resources/prompts)
  4. Abilities are validated during server initialization

Example: Mixed Component Types


Sources: includes/Core/McpAdapter.php100-102 includes/Core/McpAdapter.php194-208 README.md468

Transport Permission Callback

The $transport_permission_callback parameter provides custom authentication at the transport layer, before any MCP request processing.


Transport Permission Flow

Permission Layers:

LayerTimingDefault BehaviorCustom Configuration
TransportBefore request routingis_user_logged_in()$transport_permission_callback parameter
AbilityDuring handler executionDefined in wp_register_ability()N/A (set per ability)

Example: API Key Authentication


Example: IP Whitelist


For detailed transport permission patterns, see Transport Permissions.

Sources: includes/Core/McpAdapter.php103 includes/Core/McpAdapter.php207 README.md34

Validation and Error Handling

The create_server method performs comprehensive validation and returns WP_Error objects for invalid configurations.

Validation Sequence


Server Creation Validation Flow

Error Code Reference

Error CodeTrigger ConditionResolution
invalid_error_handlerError handler class doesn't exist or doesn't implement McpErrorHandlerInterfaceVerify class name and interface implementation
invalid_observability_handlerObservability handler class doesn't exist or doesn't implement McpObservabilityHandlerInterfaceVerify class name and interface implementation
invalid_timingcreate_server() called outside mcp_adapter_init actionMove call inside add_action('mcp_adapter_init', ...)
duplicate_server_idServer with same $server_id already registeredUse unique server ID or retrieve existing server with get_server()

Sources: includes/Core/McpAdapter.php108-191

Error Handling Example


Sources: includes/Core/McpAdapter.php105-227

Default Server Creation

The adapter automatically creates a default server unless disabled via filter. This server exposes all registered WordPress abilities.


Default Server Creation Flow

Default Server Configuration

ParameterValue
Server IDmcp-adapter-default-server
Namespacemcp
Routemcp-adapter-default-server
Endpoint/wp-json/mcp/mcp-adapter-default-server
TransportsHttpTransport
Error HandlerErrorLogMcpErrorHandler
ObservabilityNullMcpObservabilityHandler
Built-in Toolsmcp-adapter-discover-abilities, mcp-adapter-get-ability-info, mcp-adapter-execute-ability
Permissionis_user_logged_in()

Disabling Default Server


Default Abilities

The default server includes three core abilities:

AbilityPurposeTool Name
DiscoverAbilitiesAbilityList all registered WordPress abilitiesmcp-adapter-discover-abilities
GetAbilityInfoAbilityGet detailed information about an abilitymcp-adapter-get-ability-info
ExecuteAbilityAbilityExecute any registered abilitymcp-adapter-execute-ability

Sources: includes/Core/McpAdapter.php254-265 includes/Core/McpAdapter.php272-292 includes/Servers/DefaultServerFactory.php1-60

Complete Configuration Examples

Minimal Server


Production Server


Development Server


Multi-Transport Server


Sources: README.md449-472 includes/Core/McpAdapter.php89-227