db_query = AcrossAI_Abilities_Query::instance(); } /** * Register REST routes owned by this controller. * * @since 0.1.0 * @return void */ public function register_routes(): void { register_rest_route( AcrossAI_Abilities_Rest_Controller::REST_NAMESPACE, '/abilities/exposures/(?Ptools|resources|prompts)', array( array( 'methods' => \WP_REST_Server::READABLE, 'callback' => array( $this, 'get_exposures' ), 'permission_callback' => array( AcrossAI_Abilities_Rest_Controller::instance(), 'check_permission' ), 'args' => array( 'type' => array( 'type' => 'string', 'required' => true, 'enum' => array( 'tools', 'resources', 'prompts' ), 'sanitize_callback' => 'sanitize_key', ), ), ), ) ); } /** * Handle GET /abilities/exposures/{type}. * * Maps URL type (tools/resources/prompts) to mcp_type (tool/resource/prompt). * * @since 0.1.0 * @param \WP_REST_Request $request REST request. * @return \WP_REST_Response|\WP_Error */ public function get_exposures( \WP_REST_Request $request ) { $type = sanitize_key( (string) $request->get_param( 'type' ) ); // Map plural URL segment to mcp_type singular value. $type_map = array( 'tools' => 'tool', 'resources' => 'resource', 'prompts' => 'prompt', ); if ( ! isset( $type_map[ $type ] ) ) { return new \WP_Error( 'rest_invalid_param', __( 'Invalid exposure type.', 'acrossai-abilities-manager' ), array( 'status' => 400 ) ); } $mcp_type = $type_map[ $type ]; $rows = $this->db_query->by_mcp_type( $mcp_type, true ); return rest_ensure_response( AcrossAI_Abilities_Formatter::format_exposure_collection( $rows ) ); } }