Skip to content

Add mcp_adapter_server_config filter to McpServer constructor for all servers #190

@raftaar1191

Description

@raftaar1191

Summary

There is currently no filter that allows modifying the configuration of all MCP servers at construction time. The existing mcp_adapter_default_server_config filter only covers the default server created by DefaultServerFactory.

Problem

When McpServer::__construct() is called — whether for the default server or any custom server created via mcp_adapter_init — there is no way to alter its configuration (server name, route namespace, tools, resources, prompts, etc.) without forking the creation logic.

This makes it impossible for plugins to:

  • Add or remove abilities from any server's tools/resources/prompts list
  • Rename or reroute a server they did not create
  • Apply site-wide rules (e.g. visibility allowlists) across all servers uniformly

Proposed Solution

Add a single filter at the top of McpServer::__construct(), before parameters are assigned to properties:

/**
 * Filters the configuration of any MCP server before it is applied.
 *
 * Fires for ALL servers during construction. Use $config['server_id']
 * to target a specific server or apply changes to all servers.
 *
 * @since 0.6.0
 *
 * @param array  $config {
 *     Server configuration array.
 *
 *     @type string   $server_id              Server identifier.
 *     @type string   $server_route_namespace REST API namespace.
 *     @type string   $server_route           REST API route.
 *     @type string   $server_name            Human-readable server name.
 *     @type string   $server_description     Server description.
 *     @type string   $server_version         Server version.
 *     @type string[] $tools                  Ability names to expose as tools.
 *     @type string[] $resources              Ability names to expose as resources.
 *     @type string[] $prompts                Ability names to expose as prompts.
 * }
 * @param string $server_id The server identifier (for convenience — same as $config['server_id']).
 */
$config = apply_filters( 'mcp_adapter_server_config', $config, $server_id );

The filter fires inside __construct() after parameters are packed into a $config array and before they are unpacked into instance properties. The rest of the constructor continues unchanged.

Location

includes/Core/McpServer.php — top of __construct(), before line 144 where properties are assigned.

Use Case Example

add_filter( 'mcp_adapter_server_config', function( array $config, string $server_id ) {
    // Remove a specific ability from tools on all servers.
    $config['tools'] = array_diff( $config['tools'], array( 'core/get-environment-info' ) );

    // Rename a specific server.
    if ( 'mcp-adapter-default-server' === $server_id ) {
        $config['server_name'] = 'My Custom Server Name';
    }

    return $config;
}, 10, 2 );

Why One Filter Instead of Many

A single filter receiving the full config array is preferred over per-parameter filters (mcp_adapter_server_tools, mcp_adapter_server_name, etc.) because:

  • Single hook to learn and maintain
  • Tools, resources, and prompts are often modified together based on the same logic
  • $server_id as the second parameter allows targeting specific or all servers
  • Consistent shape with the existing mcp_adapter_default_server_config filter

Relationship to mcp_adapter_default_server_config

mcp_adapter_default_server_config fires inside DefaultServerFactory before the default server is constructed — it shapes the config before it reaches McpServer::__construct(). The proposed mcp_adapter_server_config fires inside __construct() itself, covering all servers regardless of how they were created. The two filters are complementary, not redundant.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions