'mcp-adapter-default-server', 'namespace' => 'mcp', ); $settings = get_option(AIZEN_OPTION_SETTINGS, array()); return wp_parse_args(is_array($settings) ? $settings : array(), $defaults); } /** * The full MCP HTTP endpoint for the default mcp-adapter server. * * @return string */ public function get_endpoint_url(): string { $settings = $this->get_settings(); return trailingslashit(rest_url($settings['namespace'] . '/' . $settings['server_slug'])); } /** * @return bool Whether WordPress core Abilities API is present (6.9+). */ public function has_abilities_api(): bool { return function_exists('wp_register_ability') && function_exists('wp_get_abilities'); } /** * @return bool Whether the WordPress/mcp-adapter plugin is active. */ public function has_mcp_adapter(): bool { return is_plugin_active('mcp-adapter/mcp-adapter.php'); ///return class_exists('WP\MCP\Core\McpAdapter'); } /** * @return bool Whether WordPress Application Passwords are available on * this site (core feature since WP 5.6, but can be * disabled by a filter/host, and requires HTTPS by default). */ public function has_application_passwords(): bool { return function_exists('wp_is_application_passwords_available') && wp_is_application_passwords_available(); } /** * @return bool Whether the site is being served over HTTPS, required by * core for Application Passwords outside local environments. */ public function is_https(): bool { return is_ssl(); } /** * @return string Direct link to the current user's "Application Passwords" * section of their profile screen. */ public function get_application_password_url(): string { return admin_url('profile.php#application-passwords-section'); } /** * Builds the JSON snippet for the HTTP/proxy MCP client configuration * (Claude Desktop, Cursor, VS Code, Claude Code, etc.) using the * official @automattic/mcp-wordpress-remote proxy, authenticated with an * Application Password. * * @param string $server_key Key to use inside "mcpServers". * @return string Pretty-printed JSON. */ public function get_client_config_json(string $server_key = 'mywordpress', string $authcode = ''): string { $config = array( 'mcpServers' => array( $server_key => array( 'command' => 'npx', 'args' => array('-y', 'mcp-remote', '' . $this->get_endpoint_url() . '', '--header', 'Authorization: Basic ' . $authcode), // 'env' => array( // 'WP_API_URL' => $this->get_endpoint_url(), // 'WP_API_USERNAME' => 'your-wp-username', // 'WP_API_PASSWORD' => 'xxxx xxxx xxxx xxxx xxxx xxxx', // ), ), ), ); return wp_json_encode($config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); } /** * Builds the WP-CLI/STDIO config snippet, useful when the MCP client * runs on the same machine as WordPress (local development). * * @return string */ public function get_stdio_config_json(): string { $settings = $this->get_settings(); $config = array( 'mcpServers' => array( 'wordpress-local' => array( 'command' => 'wp', 'args' => array( '--path=/path/to/your/wordpress', 'mcp-adapter', 'serve', '--server=' . $settings['server_slug'], '--user=admin', ), ), ), ); return wp_json_encode($config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); } /** * @return string WP-CLI command to install the MCP Adapter plugin. */ public function get_mcp_adapter_install_command(): string { return 'wp plugin install https://github.com/WordPress/mcp-adapter/releases/latest/download/mcp-adapter.zip --activate'; } }