AmeliaMcpServerRegistrar.php
63 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaBooking\Infrastructure\WP\MCP; |
| 4 | |
| 5 | class AmeliaMcpServerRegistrar |
| 6 | { |
| 7 | /** |
| 8 | * Register the Amelia MCP server via the adapter. |
| 9 | * |
| 10 | * @param mixed $adapter The adapter instance (WP\MCP\Core\McpAdapter). |
| 11 | */ |
| 12 | public static function init($adapter): void |
| 13 | { |
| 14 | $adapter->create_server( |
| 15 | 'amelia-mcp-server', |
| 16 | 'mcp', |
| 17 | 'amelia-mcp-server', |
| 18 | 'Amelia Booking System', |
| 19 | 'Amelia Booking System – appointments, events, services and customers.', |
| 20 | '1.0.0', |
| 21 | array( 'WP\\MCP\\Transport\\HttpTransport' ), |
| 22 | null, |
| 23 | null, |
| 24 | array( |
| 25 | 'amelia/list-services', |
| 26 | 'amelia/list-employees', |
| 27 | 'amelia/list-customers', |
| 28 | 'amelia/list-events', |
| 29 | 'amelia/list-appointments', |
| 30 | 'amelia/add-service', |
| 31 | 'amelia/add-customer', |
| 32 | 'amelia/create-appointment', |
| 33 | 'amelia/create-event', |
| 34 | 'amelia/book-event', |
| 35 | 'amelia/cancel-booking', |
| 36 | 'amelia/check-availability', |
| 37 | ), |
| 38 | array(), |
| 39 | array(), |
| 40 | static function () { |
| 41 | if (is_user_logged_in()) { |
| 42 | return true; |
| 43 | } |
| 44 | |
| 45 | $username = sanitize_text_field($_SERVER['PHP_AUTH_USER'] ?? ''); |
| 46 | $password = sanitize_text_field($_SERVER['PHP_AUTH_PW'] ?? ''); |
| 47 | |
| 48 | if (! $username || ! $password) { |
| 49 | return false; |
| 50 | } |
| 51 | |
| 52 | $user = wp_authenticate_application_password(null, $username, $password); |
| 53 | |
| 54 | if ($user instanceof \WP_User) { |
| 55 | return true; |
| 56 | } |
| 57 | |
| 58 | return false; |
| 59 | } |
| 60 | ); |
| 61 | } |
| 62 | } |
| 63 |