SystemHandler.php
91 lines
| 1 | <?php |
| 2 | /** |
| 3 | * System method handlers for MCP requests. |
| 4 | * |
| 5 | * @package McpAdapter |
| 6 | */ |
| 7 | |
| 8 | declare( strict_types=1 ); |
| 9 | |
| 10 | namespace WP\MCP\Handlers\System; |
| 11 | |
| 12 | use WP\MCP\Infrastructure\ErrorHandling\McpErrorFactory; |
| 13 | |
| 14 | /** |
| 15 | * Handles system-related MCP methods. |
| 16 | */ |
| 17 | class SystemHandler { |
| 18 | /** |
| 19 | * Handle the ping request. |
| 20 | * |
| 21 | * @param int $request_id The request ID for JSON-RPC. |
| 22 | * |
| 23 | * @return array |
| 24 | */ |
| 25 | public function ping( int $request_id = 0 ): array { |
| 26 | // According to MCP specification, ping returns an empty result. |
| 27 | return array(); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Handle the logging/setLevel request. |
| 32 | * |
| 33 | * @param array $params Request parameters. |
| 34 | * @param int $request_id The request ID for JSON-RPC. |
| 35 | * |
| 36 | * @return array |
| 37 | */ |
| 38 | public function set_logging_level( array $params, int $request_id = 0 ): array { |
| 39 | if ( ! isset( $params['params']['level'] ) && ! isset( $params['level'] ) ) { |
| 40 | return array( 'error' => McpErrorFactory::missing_parameter( $request_id, 'level' )['error'] ); |
| 41 | } |
| 42 | |
| 43 | // @todo: Implement logging level setting logic here. |
| 44 | |
| 45 | return array(); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Handle the completion/complete request. |
| 50 | * |
| 51 | * @param int $request_id The request ID for JSON-RPC. |
| 52 | * |
| 53 | * @return array |
| 54 | */ |
| 55 | public function complete( int $request_id = 0 ): array { |
| 56 | // Implement completion logic here. |
| 57 | |
| 58 | return array(); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Handle the roots/list request. |
| 63 | * |
| 64 | * @param int $request_id The request ID for JSON-RPC. |
| 65 | * |
| 66 | * @return array |
| 67 | */ |
| 68 | public function list_roots( int $request_id = 0 ): array { |
| 69 | // Implement roots listing logic here. |
| 70 | $roots = array(); |
| 71 | |
| 72 | return array( |
| 73 | 'roots' => $roots, |
| 74 | ); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Handle method not found errors. |
| 79 | * |
| 80 | * @param array $params Request parameters. |
| 81 | * @param int $request_id The request ID for JSON-RPC. |
| 82 | * |
| 83 | * @return array |
| 84 | */ |
| 85 | public function method_not_found( array $params, int $request_id = 0 ): array { |
| 86 | $method = $params['method'] ?? 'unknown'; |
| 87 | |
| 88 | return array( 'error' => McpErrorFactory::method_not_found( $request_id, $method )['error'] ); |
| 89 | } |
| 90 | } |
| 91 |