__( 'Unauthorized access.', 'aeolynx-for-webmcp' ) ), 403 ); } $enabled = isset( $_POST['enabled'] ) && '1' === sanitize_text_field( wp_unslash( $_POST['enabled'] ) ); update_option( 'aeolynx_cloudflare_scan', $enabled ? 1 : 0 ); wp_send_json_success( array( 'enabled' => $enabled ) ); } /** * AJAX: run the local self-audit (cached 30 minutes). * * @return void */ public static function ajax_run_audit() { check_ajax_referer( 'aeolynx_sandbox_nonce', 'nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( array( 'error' => __( 'Unauthorized access.', 'aeolynx-for-webmcp' ) ), 403 ); } $throttle = AEOLynx_Admin::throttle_ajax( 'audit', 30 ); if ( is_wp_error( $throttle ) ) { wp_send_json_error( array( 'error' => $throttle->get_error_message() ), 429 ); } $force = isset( $_POST['force'] ) && '1' === sanitize_text_field( wp_unslash( $_POST['force'] ) ); if ( ! $force ) { $fresh = self::get_fresh_report(); if ( is_array( $fresh ) ) { $fresh['cached'] = true; wp_send_json_success( $fresh ); } } $report = self::run_local_audit(); set_transient( 'aeolynx_audit_cache', $report, 5 * MINUTE_IN_SECONDS ); $report['cached'] = false; wp_send_json_success( $report ); } /** * AJAX: relay an opt-in scan through Cloudflare's free public scanner. * * @return void */ public static function ajax_cloudflare_scan() { check_ajax_referer( 'aeolynx_sandbox_nonce', 'nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( array( 'error' => __( 'Unauthorized access.', 'aeolynx-for-webmcp' ) ), 403 ); } $throttle = AEOLynx_Admin::throttle_ajax( 'cfscan', 10 ); if ( is_wp_error( $throttle ) ) { wp_send_json_error( array( 'error' => $throttle->get_error_message() ), 429 ); } if ( ! (bool) get_option( 'aeolynx_cloudflare_scan', 0 ) ) { wp_send_json_error( array( 'error' => __( 'Enable "External Cloudflare scan" on the Agent Audit screen first — no data leaves your site until you opt in.', 'aeolynx-for-webmcp' ) ), 403 ); } $url = home_url( '/' ); $raw = self::cloudflare_scan( $url ); if ( is_wp_error( $raw ) ) { wp_send_json_error( array( 'error' => $raw->get_error_message() ) ); } set_transient( 'aeolynx_cf_scan_cache', $raw, 30 * MINUTE_IN_SECONDS ); wp_send_json_success( $raw ); } /** * Call Cloudflare's free public scanner for a URL. * * @param string $url Site URL to scan. * @return array|WP_Error */ public static function cloudflare_scan( $url ) { $response = wp_remote_post( self::CF_ENDPOINT, array( 'timeout' => 45, 'headers' => array( 'Content-Type' => 'application/json' ), 'body' => wp_json_encode( array( 'url' => $url ) ), 'data_format' => 'body', ) ); if ( is_wp_error( $response ) ) { return $response; } $code = (int) wp_remote_retrieve_response_code( $response ); $body = json_decode( wp_remote_retrieve_body( $response ), true ); if ( 200 !== $code || ! is_array( $body ) ) { return new WP_Error( 'aeolynx_cf_scan_failed', sprintf( /* translators: %d: HTTP status code */ __( 'Cloudflare scanner returned HTTP %d. Try again in a moment.', 'aeolynx-for-webmcp' ), $code ) ); } return $body; } /** * Run the local self-audit. Only the site's own public URLs are requested. * * @return array */ public static function run_local_audit() { $home = home_url( '/' ); $started = microtime( true ); $checks = array(); // Loopback health probe: many hosts (WAF / page cache / anti-bot rules) // block a server's own HTTP requests while the same URLs work from the // public internet. When the probe fails, feature checks fall back to // local plugin evidence and are reported as such — never invented. $loopback_dead = self::loopback_blocked(); // --- Discoverability ------------------------------------------------- $robots = self::fetch( $home . 'robots.txt' ); $checks['discoverability']['robotsTxt'] = self::check_robots_txt( $robots ); $checks['discoverability']['sitemap'] = self::check_sitemap( $home, is_array( $robots ) ? (string) $robots['body'] : '' ); $checks['discoverability']['linkHeaders'] = self::check_link_headers( is_array( $robots ) ? ( $robots['headers'] ?? array() ) : array(), $home ); // DNS-AID: perform a real DNS TXT lookup with strict record matching (BUG-002). $checks['discoverability']['dnsAid'] = self::check_dns_aid( $home ); // --- Content accessibility ------------------------------------------- $checks['contentAccessibility']['markdownNegotiation'] = self::check_markdown_negotiation( $home ); // --- Bot access control ---------------------------------------------- $checks['botAccessControl']['robotsTxtAiRules'] = self::check_bot_rules( is_array( $robots ) ? (string) $robots['body'] : '' ); $checks['botAccessControl']['contentSignals'] = self::check_content_signals( is_array( $robots ) ? (string) $robots['body'] : '' ); $checks['botAccessControl']['webBotAuth'] = self::neutral( __( 'Web Bot Auth requires cryptographic message-signing keys — informational only for read-only content gateways.', 'aeolynx-for-webmcp' ) ); // --- API / MCP / skill discovery -------------------------------------- $checks['discovery']['apiCatalog'] = self::check_wellknown_json( $home . '.well-known/api-catalog', array( 'linkset' ), __( 'API Catalog (RFC 9727)', 'aeolynx-for-webmcp' ), 'api_catalog' ); $checks['discovery']['oauthDiscovery'] = self::neutral( __( 'OAuth/OIDC discovery applies when your agent APIs require user-delegated auth. This gateway is public and read-only.', 'aeolynx-for-webmcp' ) ); $checks['discovery']['oauthProtectedResource'] = self::neutral( __( 'No protected resources are exposed; OAuth Protected Resource Metadata is not applicable.', 'aeolynx-for-webmcp' ) ); $checks['discovery']['authMd'] = self::check_auth_md( $home ); $checks['discovery']['mcpServerCard'] = self::check_mcp_card( $home ); $checks['discovery']['a2aAgentCard'] = self::neutral( __( 'A2A Agent Cards describe task-delegating agents. This site exposes read-only tools, so it is optional.', 'aeolynx-for-webmcp' ) ); $checks['discovery']['agentSkills'] = self::check_agent_skills( $home ); $checks['discovery']['webMcp'] = self::check_modelcontext_bridge(); $checks['discovery']['ard'] = self::check_wellknown_json( $home . '.well-known/ai-catalog.json', array( 'entries' ), __( 'Agentic Resource Discovery (ARD) manifest', 'aeolynx-for-webmcp' ), 'ai_catalog' ); $checks['discovery']['personalAgentProtocol'] = self::neutral( __( 'The Personal Agent Protocol applies to individual personal sites; optional for publications and stores.', 'aeolynx-for-webmcp' ) ); // --- Commerce (informational for this gateway) ------------------------- // --- Public bot access (edge reality) --------------------------------- // A browser-UA fetch can succeed even when the host's edge blocks AI // crawler user agents (bot filters answer 429/403 before WordPress // loads). External scanners and AI engines see that block, so the audit // must verify the key endpoints exactly as an AI crawler would. $checks['publicAccess']['botUaReachability'] = self::check_bot_ua_access( $home ); $commerce_note = __( 'Payment and commerce agent protocols (x402, MPP, UCP, ACP, AP2) are out of scope for a content/MCP gateway. If you run agentic checkout, look at WooCommerce agent extensions.', 'aeolynx-for-webmcp' ); foreach ( array( 'x402', 'mpp', 'ucp', 'acp', 'ap2' ) as $commerce_id ) { $checks['commerce'][ $commerce_id ] = self::neutral( $commerce_note ); } // If self-requests are blocked, checks that could not be re-verified live // are marked 'unverified' — they are shown honestly as UNVERIFIED and do // NOT count as passes. No simulated or assumed results, ever. if ( $loopback_dead && class_exists( 'AEOLynx_Frontend' ) && AEOLynx_Frontend::is_enabled() ) { $evidence_ids = array( 'discoverability' => array( 'linkHeaders' ), 'contentAccessibility' => array( 'markdownNegotiation' ), 'discovery' => array( 'apiCatalog', 'authMd', 'mcpServerCard', 'agentSkills', 'ard' ), ); foreach ( $evidence_ids as $group_key => $ids ) { foreach ( $ids as $id ) { if ( isset( $checks[ $group_key ][ $id ] ) && 'fail' === $checks[ $group_key ][ $id ]['status'] ) { $checks[ $group_key ][ $id ]['status'] = 'unverified'; $checks[ $group_key ][ $id ]['message'] = __( 'This server blocks its own HTTP requests (loopback), so this could not be verified live. The feature is active in the plugin — verify externally via "Verify via Cloudflare".', 'aeolynx-for-webmcp' ); } } } } return self::summarize( $checks, round( microtime( true ) - $started, 2 ) ); } /** * Build the normalized report with counts, score, and level hint. * * @param array $checks Grouped checks. * @param float $took Seconds elapsed. * @return array */ private static function summarize( $checks, $took ) { $pass = 0; $fail = 0; $neutral = 0; $unverified = 0; foreach ( $checks as $group ) { foreach ( $group as $check ) { if ( 'pass' === $check['status'] ) { ++$pass; } elseif ( 'fail' === $check['status'] ) { ++$fail; } elseif ( 'unverified' === $check['status'] ) { ++$unverified; } else { ++$neutral; } } } // Honest applicable-check scoring (BUG-037): // Every actionable check (pass, fail, unverified) counts in the score; // optional/informational-only signals (e.g. x402, MPP, UCP, ACP, AP2, OAuth) // are reported separately under 'neutral' so a healthy site is not graded red 54%. $applicable = $pass + $fail + $unverified; $score = $applicable > 0 ? (int) round( ( $pass / $applicable ) * 100 ) : 0; $level = 1; $level_name = __( 'Basic Web Presence', 'aeolynx-for-webmcp' ); if ( $score >= 50 ) { $level = 2; /* translators: Industry readiness level name */ $level_name = __( 'Bot-Aware', 'aeolynx-for-webmcp' ); } if ( $score >= 75 ) { $level = 3; /* translators: Industry readiness level name */ $level_name = __( 'Agent-Discoverable', 'aeolynx-for-webmcp' ); } if ( $score >= 90 && 0 === $fail ) { $level = 4; /* translators: Industry readiness level name */ $level_name = __( 'Fully Agent-Ready', 'aeolynx-for-webmcp' ); } return array( 'source' => 'local', 'url' => home_url( '/' ), 'took' => $took, 'checks' => $checks, 'counts' => array( 'pass' => $pass, 'fail' => $fail, 'neutral' => $neutral, 'unverified' => $unverified, 'score' => $score, ), 'level' => $level, 'levelName' => $level_name, 'scannedAt' => gmdate( 'c' ), 'generated_at' => time(), ); } /** * Check DNS-AID TXT discovery records strictly (no false positives on "mail"/"domain", * no unconditional overwrite; returns unverified when DNS cannot be queried). * * @param string $home Site home URL. * @return array{status: string, message: string} */ public static function check_dns_aid( $home ) { $host = strtolower( (string) wp_parse_url( $home, PHP_URL_HOST ) ); if ( '' === $host || 'localhost' === $host || false !== filter_var( $host, FILTER_VALIDATE_IP ) || ! function_exists( 'dns_get_record' ) ) { return array( 'status' => 'unverified', 'message' => __( 'DNS-AID lookup skipped on local/IP host or unavailable DNS resolver. Verify externally on your public domain.', 'aeolynx-for-webmcp' ), ); } $candidates = array( '_agent.' . $host, '_ai.' . $host, $host ); $queried = false; foreach ( $candidates as $name ) { $records = @dns_get_record( $name, DNS_TXT ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- Optional DNS probe. if ( is_array( $records ) ) { $queried = true; foreach ( $records as $record ) { $txt = isset( $record['txt'] ) ? (string) $record['txt'] : ''; if ( self::is_dns_aid_txt( $txt ) ) { return array( 'status' => 'pass', 'message' => __( 'Valid DNS-AID discovery TXT record found for this domain.', 'aeolynx-for-webmcp' ), ); } } } } if ( ! $queried ) { return array( 'status' => 'unverified', 'message' => __( 'DNS lookup failed from this host. Verify DNS-AID records externally via your DNS provider.', 'aeolynx-for-webmcp' ), ); } return self::neutral( __( 'No optional DNS-AID TXT record (e.g. v=dnsaid1 or v=aid1) published in your DNS zone yet.', 'aeolynx-for-webmcp' ) ); } /** * Strict DNS-AID TXT record validator (avoids matching "mail" or "domain"). * * @param string $txt Raw TXT record value. * @return bool */ public static function is_dns_aid_txt( $txt ) { return 1 === preg_match( '/(?:^|[;\s])(v=dnsaid1|v=aid1|dns-aid=|mcp-server=|ai-agent=)/i', (string) $txt ); } /** * Neutral / informational check helper. * * @param string $message Explanation. * @return array */ private static function neutral( $message ) { return array( 'status' => 'neutral', 'message' => $message, ); } /** * Fetch a public URL of this site (loopback). * * @param string $url Absolute URL. * @return array{body:string,headers:array,status:int}|null */ /** * Return the cached audit report ONLY when it is real and fresh. * * Fresh means: carries a generated_at stamp (reports from older plugin * versions are ignored, never displayed) and is younger than 5 minutes. * Views never show stale numbers — they trigger a live run instead. * * @return array|null */ public static function get_fresh_report() { $report = get_transient( 'aeolynx_audit_cache' ); if ( ! is_array( $report ) || ! isset( $report['generated_at'] ) ) { return null; } $age = time() - (int) $report['generated_at']; if ( $age < 0 || $age > 5 * MINUTE_IN_SECONDS ) { return null; } return $report; } /** * Detect whether this server can make HTTP requests to itself. * * Probes a public, cache-free plugin endpoint. A non-200 from the server * to itself (while the endpoint is publicly routed) means audit checks * that rely on loopback HTTP cannot be verified live. * * @return bool True when self-requests appear blocked. */ public static function loopback_blocked() { $probe_url = add_query_arg( 'aeolynx_loopback_probe', (string) time(), rest_url( 'aeolynx/v1/tools' ) ); $probe = self::fetch_robust( $probe_url ); if ( null === $probe ) { return true; } return 200 !== (int) $probe['status']; } /** * Verify the key discovery endpoints are reachable with a REAL AI-crawler * user agent from the server (edge reality check). * * @param string $home Home URL. * @return array */ public static function check_bot_ua_access( $home ) { $targets = array( 'robots.txt' => __( 'robots.txt', 'aeolynx-for-webmcp' ), '.well-known/mcp.json' => __( 'MCP Server Card', 'aeolynx-for-webmcp' ), 'llms.txt' => __( 'llms.txt index', 'aeolynx-for-webmcp' ), '.well-known/agent-skills/index.json' => __( 'Agent Skills index', 'aeolynx-for-webmcp' ), ); $bot_ua = 'GPTBot/1.0 (+https://openai.com/gptbot)'; $blocked = array(); foreach ( $targets as $path => $label ) { // Space the probes out slightly so the audit measures real blocking // instead of tripping per-second edge rate limits itself. if ( ! headers_sent() ) { usleep( 350000 ); } $res = self::fetch_as_bot( $home . $path, $bot_ua ); if ( null === $res ) { $blocked[] = $label . ' (connection failed)'; continue; } if ( 200 !== (int) $res['status'] ) { $blocked[] = sprintf( /* translators: 1: label, 2: HTTP code */ __( '%1$s (HTTP %2$d)', 'aeolynx-for-webmcp' ), $label, (int) $res['status'] ); } } if ( empty( $blocked ) ) { return array( 'status' => 'pass', 'message' => __( 'AI crawler user agents (GPTBot) can reach robots.txt, the MCP card, llms.txt and the Agent Skills index from the public internet.', 'aeolynx-for-webmcp' ), ); } return array( 'status' => 'fail', 'message' => sprintf( /* translators: %s: Comma-separated blocked endpoint list */ __( 'Your host/CDN edge BLOCKS AI-crawler user agents before WordPress loads. AI engines receive errors and cannot read: %s. Fix: allow AI-crawler user agents (GPTBot, ClaudeBot, PerplexityBot, OAI-SearchBot) in your host security / LiteSpeed bot settings, then re-run this audit and verify externally.', 'aeolynx-for-webmcp' ), implode( ', ', $blocked ) ), ); } /** * Single-attempt fetch with an AI-crawler user agent (NO browser retry — * the whole point is to see what a bot sees). * * @param string $url Target URL. * @param string $ua User agent to send. * @return array|null{status:int,body:string,headers:array} */ public static function fetch_as_bot( $url, $ua ) { $response = wp_remote_get( $url, array( 'timeout' => 12, 'redirection' => 2, 'headers' => array( 'Accept' => 'text/html,application/json,text/plain,*/*' ), 'user-agent' => $ua, ) ); if ( is_wp_error( $response ) ) { return null; } return array( 'status' => (int) wp_remote_retrieve_response_code( $response ), 'body' => (string) wp_remote_retrieve_body( $response ), 'headers' => wp_remote_retrieve_headers( $response ), ); } /** * Fetch with retries: default UA first, then a browser-like UA for hosts * whose WAF/anti-bot rules reject the default WordPress user agent. * * @param string $url Target URL. * @param string $accept Optional Accept header value. * @return array|null{status:int,body:string,headers:array} */ private static function fetch_robust( $url, $accept = null ) { $attempts = array( null, 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0 Safari/537.36', ); $last = null; foreach ( $attempts as $ua ) { $args = array( 'timeout' => 12, 'redirection' => 2, 'headers' => array( 'Accept' => null !== $accept ? $accept : 'text/html,application/json,text/plain,*/*' ), ); if ( null !== $ua ) { $args['user-agent'] = $ua; } $response = wp_remote_get( $url, $args ); if ( is_wp_error( $response ) ) { $last = null; continue; } $last = array( 'status' => (int) wp_remote_retrieve_response_code( $response ), 'body' => (string) wp_remote_retrieve_body( $response ), 'headers' => wp_remote_retrieve_headers( $response ), ); if ( 200 === $last['status'] ) { return $last; } } return $last; } private static function fetch( $url ) { // Delegate to the retrying fetcher: default UA first, then a browser UA // for hosts whose WAF rejects WordPress's own user agent. return self::fetch_robust( $url ); } /** * Fetch with an Accept header (content negotiation test). * * @param string $url Absolute URL. * @param string $accept Accept header value. * @return array|null */ private static function fetch_accept( $url, $accept ) { // Same retrying behavior as fetch(), with the requested Accept header. $result = self::fetch_robust( $url, $accept ); // A page cache can return 200 text/html for the default UA even when the // live response negotiates correctly — retry once with a browser UA. if ( is_array( $result ) && 200 === $result['status'] ) { $type = strtolower( (string) ( $result['headers']['content-type'] ?? '' ) ); if ( 0 !== strpos( $type, 'text/markdown' ) && 0 === strpos( $accept, 'text/markdown' ) ) { $retry = wp_remote_get( $url, array( 'timeout' => 12, 'redirection' => 2, 'headers' => array( 'Accept' => $accept, 'User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0 Safari/537.36', ), ) ); if ( ! is_wp_error( $retry ) && 200 === (int) wp_remote_retrieve_response_code( $retry ) ) { return array( 'status' => 200, 'body' => (string) wp_remote_retrieve_body( $retry ), 'headers' => wp_remote_retrieve_headers( $retry ), ); } } } return $result; } /** * Check robots.txt presence and validity. * * @param array|null $robots Fetch result. * @return array */ private static function check_robots_txt( $robots ) { if ( null === $robots || 200 !== $robots['status'] ) { return array( 'status' => 'fail', 'message' => __( 'robots.txt could not be fetched. Ensure WordPress is serving a virtual robots.txt (Settings > Reading must allow search engines).', 'aeolynx-for-webmcp' ), ); } if ( '' === trim( (string) $robots['body'] ) || false === stripos( (string) $robots['body'], 'user-agent' ) ) { return array( 'status' => 'fail', 'message' => __( 'robots.txt exists but contains no User-agent directives.', 'aeolynx-for-webmcp' ), ); } return array( 'status' => 'pass', 'message' => __( 'robots.txt exists with valid format', 'aeolynx-for-webmcp' ), ); } /** * Check sitemap discoverability. * * @param string $home Site home URL. * @param string $robots_body robots.txt content. * @return array */ private static function check_sitemap( $home, $robots_body ) { $has_declaration = '' !== $robots_body && false !== stripos( $robots_body, 'sitemap:' ); $probe = self::fetch( $home . 'wp-sitemap.xml' ); $live = null !== $probe && 200 === $probe['status'] && false !== stripos( (string) $probe['body'], ' 'pass', 'message' => __( 'sitemap.xml exists with valid structure', 'aeolynx-for-webmcp' ), ); } return array( 'status' => 'fail', 'message' => __( 'No sitemap found. WordPress core serves /wp-sitemap.xml — verify permalinks are set to pretty format.', 'aeolynx-for-webmcp' ), ); } /** * Check the homepage Link headers for agent-useful relation types. * * @param array $robots_headers robots.txt response headers (same origin policy). * @param string $home Home URL. * @return array */ private static function check_link_headers( $robots_headers, $home ) { // Cache-buster: stored page-cache copies may predate the current headers. $page = self::fetch( add_query_arg( 'aeolynx_audit_bust', dechex( time() ), $home ) ); $link = ''; if ( null !== $page && ! empty( $page['headers']['link'] ) ) { // WP sends multiple Link headers (agent rels + api.w.org); the header // collection returns them as an array — join before parsing. $link = $page['headers']['link']; if ( is_array( $link ) ) { $link = implode( ', ', $link ); } $link = (string) $link; } $parsed = self::parse_link_header( $link ); $useful = array(); foreach ( $parsed as $entry ) { foreach ( (array) $entry['rels'] as $rel ) { if ( in_array( strtolower( $rel ), self::$agent_rels, true ) ) { $useful[] = $rel; } } } if ( ! empty( $useful ) ) { return array( 'status' => 'pass', 'message' => sprintf( /* translators: %s: comma-separated relation types */ __( 'Agent-useful Link relations found: %s', 'aeolynx-for-webmcp' ), implode( ', ', array_unique( $useful ) ) ), ); } return array( 'status' => 'fail', 'message' => __( 'Link headers present but no agent-useful relation types found. The API Catalog link (rel="api-catalog") is emitted automatically — clear any page cache and re-run.', 'aeolynx-for-webmcp' ), ); } /** * Parse an RFC 8288 Link header into rel entries. * * @param string $header Link header value. * @return array[] */ private static function parse_link_header( $header ) { $out = array(); if ( '' === trim( (string) $header ) ) { return $out; } // RFC 8288 packs several ; rel="..." pairs into one header value, // separated by ", <". Match EVERY pair — the previous single-regex form // only ever saw the first pair, so multi-rel headers never passed. if ( preg_match_all( '/<([^>]+)>([^<>]*)/i', (string) $header, $pairs, PREG_SET_ORDER ) ) { foreach ( $pairs as $pair ) { $rels = array(); if ( preg_match( '/rel="([^"]*)"/i', $pair[2], $r ) ) { $rels = preg_split( '/\s+/', strtolower( $r[1] ) ) ?: array(); } $out[] = array( 'href' => $pair[1], 'rels' => $rels ); } } return $out; } /** * Check Markdown content negotiation on the homepage. * * @param string $home Home URL. * @return array */ private static function check_markdown_negotiation( $home ) { // Cache-buster: the audit must see the live PHP response, not a stored page-cache copy. $md = self::fetch_accept( add_query_arg( 'aeolynx_audit_bust', dechex( time() ), $home ), 'text/markdown' ); $type = ''; if ( null !== $md && ! empty( $md['headers']['content-type'] ) ) { $type = strtolower( (string) $md['headers']['content-type'] ); } if ( 0 === strpos( $type, 'text/markdown' ) ) { return array( 'status' => 'pass', 'message' => __( 'Site supports Markdown for Agents (text/markdown negotiation)', 'aeolynx-for-webmcp' ), ); } return array( 'status' => 'fail', 'message' => __( 'Homepage does not negotiate text/markdown. Enable the Markdown stream in Settings and clear page cache.', 'aeolynx-for-webmcp' ), ); } /** * Check robots.txt for AI bot rules. * * @param string $body robots.txt content. * @return array */ private static function check_bot_rules( $body ) { $known = array( 'gptbot', 'oai-searchbot', 'chatgpt-user', 'perplexitybot', 'claudebot', 'google-extended', 'ccbot' ); $found = array(); foreach ( $known as $bot ) { if ( false !== stripos( $body, 'user-agent: ' . $bot ) ) { $found[] = $bot; } } if ( ! empty( $found ) ) { return array( 'status' => 'pass', 'message' => sprintf( /* translators: %s: comma-separated bot names */ __( 'Found rules for AI bots: %s', 'aeolynx-for-webmcp' ), implode( ', ', $found ) ), ); } return array( 'status' => 'fail', 'message' => __( 'No AI bot rules in robots.txt. Enable the Per-Bot AI Crawler Policy in Settings > Bot Policy.', 'aeolynx-for-webmcp' ), ); } /** * Check robots.txt for Content Signals. * * @param string $body robots.txt content. * @return array */ private static function check_content_signals( $body ) { if ( false !== stripos( $body, 'content-signal' ) ) { return array( 'status' => 'pass', 'message' => __( 'Content Signals declared in robots.txt', 'aeolynx-for-webmcp' ), ); } return array( 'status' => 'fail', 'message' => __( 'No Content Signals found in robots.txt. Pick a Content Signals policy in Settings > Bot Policy to declare ai-train / search / ai-input preferences.', 'aeolynx-for-webmcp' ), ); } /** * Check a JSON well-known endpoint exists and contains a key. * * @param string $url Endpoint URL. * @param string[]|null $require_key Top-level key required (null = any JSON). * @param string $label Human check label. * @return array */ private static function check_wellknown_json( $url, $require_key, $label, $query_var = null ) { $res = self::fetch_robust( $url ); if ( null === $res || 200 !== $res['status'] ) { if ( null !== $query_var ) { // Some servers intercept the physical /.well-known/ directory // (ACME/SSL tooling); the query-string route proves the feature. $res = self::fetch_robust( add_query_arg( 'aeolynx_wellknown', $query_var, home_url( '/' ) ) ); } } if ( null === $res || 200 !== $res['status'] ) { return array( 'status' => 'fail', 'message' => sprintf( /* translators: %s: endpoint label */ __( '%s not found', 'aeolynx-for-webmcp' ), $label ), ); } $data = json_decode( (string) $res['body'], true ); if ( ! is_array( $data ) ) { return array( 'status' => 'fail', 'message' => sprintf( /* translators: %s: endpoint label */ __( '%s exists but is not valid JSON', 'aeolynx-for-webmcp' ), $label ), ); } if ( null !== $require_key && ! isset( $data[ $require_key[0] ] ) ) { return array( 'status' => 'fail', 'message' => sprintf( /* translators: %s: endpoint label */ __( '%s exists but is missing required data', 'aeolynx-for-webmcp' ), $label ), ); } return array( 'status' => 'pass', 'message' => sprintf( /* translators: %s: endpoint label */ __( '%s found and valid', 'aeolynx-for-webmcp' ), $label ), ); } /** * Check /auth.md. * * @param string $home Home URL. * @return array */ private static function check_auth_md( $home ) { $res = self::fetch( $home . 'auth.md' ); if ( null !== $res && 200 === $res['status'] ) { // Cloudflare-grade validation: the document must actually describe how // agents authenticate/register — mere existence is not enough. $body = (string) $res['body']; $signals = array( 'registration', 'register', 'api key', 'apikey', 'token', 'bearer', 'credential', 'x-webmcp-key', 'authentication' ); foreach ( $signals as $signal ) { if ( false !== stripos( $body, $signal ) ) { return array( 'status' => 'pass', 'message' => __( 'auth.md found — agent authentication model documented', 'aeolynx-for-webmcp' ), ); } } return array( 'status' => 'fail', 'message' => __( 'auth.md exists but does not describe agent registration or credentials. Document how agents register and authenticate, then re-run.', 'aeolynx-for-webmcp' ), ); } return array( 'status' => 'fail', 'message' => __( 'auth.md not found. The gateway emits one automatically — clear page cache and re-run.', 'aeolynx-for-webmcp' ), ); } /** * Check the MCP server card. * * @param string $home Home URL. * @return array */ private static function check_mcp_card( $home ) { $res = self::fetch( $home . '.well-known/mcp.json' ); $tools = 0; if ( null !== $res && 200 === $res['status'] ) { $data = json_decode( (string) $res['body'], true ); if ( is_array( $data ) && isset( $data['tools'] ) && is_array( $data['tools'] ) ) { $tools = count( $data['tools'] ); } } if ( $tools > 0 ) { return array( 'status' => 'pass', 'message' => sprintf( /* translators: %d: tool count */ __( 'MCP Server Card found at /.well-known/mcp.json (%d tools)', 'aeolynx-for-webmcp' ), $tools ), ); } return array( 'status' => 'fail', 'message' => __( 'MCP Server Card missing or invalid at /.well-known/mcp.json.', 'aeolynx-for-webmcp' ), ); } /** * Check the agent-skills index. * * @param string $home Home URL. * @return array */ private static function check_agent_skills( $home ) { $res = self::fetch( $home . '.well-known/agent-skills/index.json' ); if ( null !== $res && 200 === $res['status'] ) { $data = json_decode( (string) $res['body'], true ); if ( is_array( $data ) && ! empty( $data ) ) { return array( 'status' => 'pass', 'message' => __( 'Agent Skills index found', 'aeolynx-for-webmcp' ), ); } } return array( 'status' => 'fail', 'message' => __( 'Agent Skills index not found. The gateway publishes one at /.well-known/agent-skills/index.json — clear page cache and re-run.', 'aeolynx-for-webmcp' ), ); } /** * Check the WebMCP client bridge is broadcast on the frontend. * * @return array */ private static function check_modelcontext_bridge() { $page = self::fetch( home_url( '/' ) ); if ( null === $page ) { return self::neutral( __( 'Homepage could not be fetched to verify the WebMCP bridge.', 'aeolynx-for-webmcp' ) ); } $body = (string) $page['body']; $has_manifest = false !== strpos( $body, 'webmcp-manifest' ); $has_bridge = false !== strpos( $body, 'aeolynx-register' ); if ( $has_manifest && $has_bridge ) { return array( 'status' => 'pass', 'message' => __( 'WebMCP document.modelContext bridge is live on the frontend', 'aeolynx-for-webmcp' ), ); } return array( 'status' => 'fail', 'message' => __( 'WebMCP bridge not detected on the homepage. Enable the gateway in Settings > Protocol & discovery.', 'aeolynx-for-webmcp' ), ); } } }