| 1 |
<?php |
| 2 |
declare(strict_types=1); |
| 3 |
|
| 4 |
namespace Imagify\MCP; |
| 5 |
|
| 6 |
use Imagify\EventManagement\SubscriberInterface; |
| 7 |
|
| 8 |
/** |
| 9 |
* Customizes the default MCP server configuration for Imagify. |
| 10 |
* |
| 11 |
* Subscribes to the `mcp_adapter_default_server_config` filter and sets |
| 12 |
* the server name and description. All other keys (`server_id`, `route`, |
| 13 |
* `tools`) are left untouched so the adapter keeps its canonical defaults. |
| 14 |
* |
| 15 |
* @since 2.3.0 |
| 16 |
*/ |
| 17 |
class ConfigSubscriber implements SubscriberInterface { |
| 18 |
|
| 19 |
/** |
| 20 |
* Returns the events this subscriber listens to. |
| 21 |
* |
| 22 |
* @return array<string, string> |
| 23 |
*/ |
| 24 |
public static function get_subscribed_events(): array { |
| 25 |
return [ |
| 26 |
// @filter mcp_adapter_default_server_config |
| 27 |
'mcp_adapter_default_server_config' => 'customize_mcp_server', |
| 28 |
]; |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Customizes the MCP server name and description for Imagify. |
| 33 |
* |
| 34 |
* Only `server_name` and `server_description` are overridden. All other |
| 35 |
* keys — including `server_id`, `server_route`, `server_route_namespace`, |
| 36 |
* and `tools` — are preserved so the canonical REST endpoint path and the |
| 37 |
* adapter's built-in tool set remain intact. |
| 38 |
* |
| 39 |
* @param array $config Default server configuration supplied by the adapter. |
| 40 |
* @return array Modified configuration with Imagify name/description. |
| 41 |
*/ |
| 42 |
public function customize_mcp_server( array $config ): array { |
| 43 |
$config['server_name'] = 'imagify-plugin'; |
| 44 |
|
| 45 |
$config['server_description'] = __( |
| 46 |
'Image optimization tools for WordPress powered by Imagify.', |
| 47 |
'imagify' |
| 48 |
); |
| 49 |
|
| 50 |
return $config; |
| 51 |
} |
| 52 |
} |
| 53 |
|