'2.0', 'id' => 1, 'method' => 'initialize', 'params' => array( 'protocolVersion' => '2025-06-18', 'capabilities' => (object) array(), 'clientInfo' => array( 'name' => 'AJACO-Scanner', 'version' => AJACO_VERSION, ), ), ) ); $path = (string) wp_parse_url( $endpoint, PHP_URL_PATH ); $res = $this->http_post_json( $endpoint, 'POST ' . $path . ' (initialize)', $evidence, (string) $body ); if ( '' !== $res['error'] && 0 === $res['code'] ) { return $this->unable( 'Could not reach ' . $path . ' — ' . $res['error'], $evidence ); } $details = array( 'endpoint' => $endpoint, 'status' => $res['code'], 'detected' => (bool) $server, 'adapter' => function_exists( 'Ajaco\\mcp_adapter_active' ) && \Ajaco\mcp_adapter_active(), ); if ( 404 === $res['code'] || 405 === $res['code'] || 410 === $res['code'] ) { $evidence[] = Evidence::parse( 'Interpret response', 'negative', 'HTTP ' . $res['code'] . ' — nothing speaks MCP at this route.' ); return $this->fail( 'No MCP server on this site — agents can read it but cannot act on it', $evidence, $details ); } if ( in_array( $res['code'], array( 401, 403 ), true ) ) { $evidence[] = Evidence::parse( 'Interpret response', 'positive', 'HTTP ' . $res['code'] . ' — an MCP server is present and requires authentication (WordPress Application Passwords), as the adapter is designed to.' ); return $this->pass( 'MCP server present at ' . $path . ' (authentication required — see /auth.md)', $evidence, $details ); } $json = json_decode( $res['body'], true ); $result = is_array( $json ) && isset( $json['result'] ) && is_array( $json['result'] ) ? $json['result'] : null; if ( null !== $result && ( isset( $result['protocolVersion'] ) || isset( $result['serverInfo'] ) ) ) { $name = isset( $result['serverInfo']['name'] ) ? (string) $result['serverInfo']['name'] : 'MCP server'; $evidence[] = Evidence::parse( 'Interpret response', 'positive', 'Valid initialize result from "' . $name . '" (protocol ' . ( isset( $result['protocolVersion'] ) ? $result['protocolVersion'] : '?' ) . ').' ); $details['serverName'] = $name; return $this->pass( 'MCP server "' . $name . '" answered initialize at ' . $path, $evidence, $details ); } $evidence[] = Evidence::parse( 'Interpret response', 'negative', 'HTTP ' . $res['code'] . ' but no JSON-RPC initialize result in the body.' ); return $this->fail( $path . ' answered HTTP ' . $res['code'] . ' but did not return an MCP initialize result', $evidence, $details ); } /** * POST a JSON body (JSON-RPC) and record a fetch evidence step. * * @param string $url Absolute URL. * @param string $label Evidence label. * @param array $evidence Evidence array, by reference. * @param string $body JSON body. * @return array{code: int, body: string, headers: array, error: string} */ private function http_post_json( string $url, string $label, array &$evidence, string $body ): array { $response = wp_remote_post( $url, array( 'timeout' => 10, 'redirection' => 2, 'user-agent' => 'AJACO-Scanner/' . AJACO_VERSION . ' (+' . home_url( '/' ) . ')', 'sslverify' => apply_filters( 'ajaco_scan_sslverify', false ), 'headers' => array( 'Content-Type' => 'application/json', 'Accept' => 'application/json, text/event-stream', ), 'body' => $body, ) ); $evidence[] = Evidence::fetch( $label, $url, $response ); if ( is_wp_error( $response ) ) { return array( 'code' => 0, 'body' => '', 'headers' => array(), 'error' => $response->get_error_message(), ); } $headers = array(); $raw = wp_remote_retrieve_headers( $response ); if ( is_object( $raw ) && method_exists( $raw, 'getAll' ) ) { foreach ( $raw->getAll() as $name => $value ) { $headers[ strtolower( (string) $name ) ] = is_array( $value ) ? implode( ', ', $value ) : (string) $value; } } return array( 'code' => (int) wp_remote_retrieve_response_code( $response ), 'body' => (string) wp_remote_retrieve_body( $response ), 'headers' => $headers, 'error' => '', ); } }