self::SCHEMA, 'name' => substr( $namespace, 0, 170 ) . '/' . $name, 'title' => wp_html_excerpt( wp_strip_all_tags( get_bloginfo( 'name' ) ) ?: 'WooCommerce store', 100, '' ), 'description' => 'Search products, calculate delivery and shop through authorised WooCommerce checkout.', 'version' => WACC_VERSION, 'remotes' => array( array( 'type' => 'streamable-http', 'url' => rest_url( Api::NS . '/mcp' ) ) ), ); } public function routes() { register_rest_route( Api::NS, '/server', array( 'methods' => 'GET', 'permission_callback' => array( Api::class, 'available' ), 'callback' => array( $this, 'respond' ) ) ); } public function respond() { return new \WP_REST_Response( self::document() ); } public function headers() { if ( Api::available() === true && ! is_admin() ) { header( 'Link: <' . esc_url_raw( self::url() ) . '>; rel="alternate"; type="application/json"; title="MCP server connection"', false ); } } /** Convenience path inside the WordPress home; REST URL also works with plain permalinks. */ public function alias() { $uri = isset( $_SERVER['REQUEST_URI'] ) && is_string( $_SERVER['REQUEST_URI'] ) ? sanitize_url( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : ''; $path = wp_parse_url( $uri, PHP_URL_PATH ); if ( $path !== wp_parse_url( home_url( '/mcp-server.json' ), PHP_URL_PATH ) ) { return; } $ready = Api::available(); nocache_headers(); if ( is_wp_error( $ready ) ) { wp_send_json( array( 'error' => 'Agent shopping is unavailable.' ), 503 ); } $method = isset( $_SERVER['REQUEST_METHOD'] ) && is_string( $_SERVER['REQUEST_METHOD'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_METHOD'] ) ) : ''; if ( ! in_array( $method, array( 'GET', 'HEAD' ), true ) ) { header( 'Allow: GET, HEAD' ); wp_send_json( array( 'error' => 'Use GET or HEAD.' ), 405 ); } wp_send_json( self::document(), 200 ); } }