WP_REST_Server::READABLE, 'permission_callback' => '__return_true', ); register_rest_route( McpOAuthConstants::REST_NAMESPACE, '/oauth/discovery/protected-resource', $read_only + array( 'callback' => array( $this, 'protectedResource' ) ) ); register_rest_route( McpOAuthConstants::REST_NAMESPACE, '/oauth/discovery/authorization-server', $read_only + array( 'callback' => array( $this, 'authorizationServer' ) ) ); register_rest_route( McpOAuthConstants::REST_NAMESPACE, '/oauth/.well-known/openid-configuration', $read_only + array( 'callback' => array( $this, 'authorizationServer' ) ) ); register_rest_route( McpOAuthConstants::REST_NAMESPACE, '/oauth/.well-known/oauth-authorization-server', $read_only + array( 'callback' => array( $this, 'authorizationServer' ) ) ); } /** * @return WP_REST_Response */ public function protectedResource(): WP_REST_Response { return self::jsonResponse( McpOAuthDiscovery::protectedResourceMetadata() ); } /** * @return WP_REST_Response */ public function authorizationServer(): WP_REST_Response { return self::jsonResponse( McpOAuthDiscovery::authorizationServerMetadata() ); } /** * @param array $data Document body. * @return WP_REST_Response */ private static function jsonResponse( array $data ): WP_REST_Response { $response = new WP_REST_Response( $data, 200 ); $response->header( 'Access-Control-Allow-Origin', '*' ); $response->header( 'Cache-Control', 'public, max-age=3600' ); return $response; } }