assets
3 weeks ago
abilities.php
3 weeks ago
manager.php
3 weeks ago
rest-proxy.php
3 weeks ago
server.php
3 weeks ago
service.php
3 weeks ago
server.php
51 lines
| 1 | <?php |
| 2 | namespace ElementsKit_Lite\Mcp; |
| 3 | |
| 4 | defined( 'ABSPATH' ) || exit; |
| 5 | |
| 6 | /** |
| 7 | * Registers the ElementsKit MCP server with the WordPress MCP adapter. |
| 8 | * |
| 9 | * This exposes the ElementsKit abilities as MCP tools at /wp-json/elementskit/mcp |
| 10 | * for external MCP clients. It is entirely optional: when the MCP adapter library |
| 11 | * (WP\MCP\Core\McpAdapter) is not installed the hook simply never fires and the |
| 12 | * abilities + REST proxy continue to work on their own. |
| 13 | * |
| 14 | * @since 3.10.x |
| 15 | */ |
| 16 | class Server { |
| 17 | |
| 18 | public function hooks() { |
| 19 | add_action( 'mcp_adapter_init', [ $this, 'register_server' ] ); |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * @param mixed $adapter The MCP adapter instance passed by mcp_adapter_init. |
| 24 | */ |
| 25 | public function register_server( $adapter ) { |
| 26 | if ( ! class_exists( '\WP\MCP\Core\McpAdapter' ) || ! $adapter instanceof \WP\MCP\Core\McpAdapter ) { |
| 27 | return; |
| 28 | } |
| 29 | |
| 30 | $result = $adapter->create_server( |
| 31 | 'elementskit-mcp-server', |
| 32 | 'elementskit', |
| 33 | 'mcp', |
| 34 | 'ElementsKit MCP', |
| 35 | __( 'Read and modify ElementsKit widgets and templates for Elementor.', 'elementskit-lite' ), |
| 36 | 'v1.0.0', |
| 37 | [ \WP\MCP\Transport\HttpTransport::class ], |
| 38 | \WP\MCP\Infrastructure\ErrorHandling\ErrorLogMcpErrorHandler::class, |
| 39 | \WP\MCP\Infrastructure\Observability\NullMcpObservabilityHandler::class, |
| 40 | Abilities::ability_ids(), |
| 41 | [], |
| 42 | [] |
| 43 | ); |
| 44 | |
| 45 | if ( is_wp_error( $result ) ) { |
| 46 | // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log |
| 47 | error_log( sprintf( '[ElementsKit MCP] Server registration failed: %s', $result->get_error_message() ) ); |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 |