*/ private static array $tools = []; // ── Registration ────────────────────────────────────────────────────── public static function register( string $tool_name, array $meta ): void { $defaults = [ 'tool_name' => $tool_name, 'module' => 'unknown', 'class' => 'read', 'required_scopes' => [], 'destructive' => false, 'admin_sensitive' => false, 'supports_dry_run' => false, 'requires_confirm' => false, 'dependency' => null, 'handler' => null, 'description' => '', 'input_schema' => [], ]; self::$tools[ $tool_name ] = array_merge( $defaults, $meta, [ 'tool_name' => $tool_name ] ); } // ── Lookup ──────────────────────────────────────────────────────────── public static function get( string $tool_name ): ?array { return self::$tools[ $tool_name ] ?? null; } public static function exists( string $tool_name ): bool { return isset( self::$tools[ $tool_name ] ); } public static function get_all(): array { return self::$tools; } /** * Filter to only tools whose dependency is in $active_modules. * Tools with dependency=null are always included. */ public static function get_for_modules( array $active_modules ): array { return array_filter( self::$tools, static function ( array $meta ) use ( $active_modules ): bool { return $meta['dependency'] === null || in_array( $meta['dependency'], $active_modules, true ); } ); } /** * MCP tools/list response format. */ public static function to_mcp_list( array $active_modules ): array { $tools = self::get_for_modules( $active_modules ); return array_values( array_map( static function ( array $meta ): array { return [ 'name' => $meta['tool_name'], 'description' => $meta['description'], 'inputSchema' => [ 'type' => 'object', 'properties' => $meta['input_schema'], ], ]; }, $tools ) ); } }