*/ public static function forUser(User $user, Workspace $workspace): array { $tokens = AccessToken::query() ->where('user_id', $user->id) ->where('workspace_id', $workspace->id) ->connectedMcpOAuth() ->with(['client', 'user.currentWorkspace', 'workspace', 'refreshToken']) ->get(); return $tokens ->filter(fn (AccessToken $token): bool => $token->isListedMcpConnection($user, $workspace)) ->groupBy('client_id') ->map(function (Collection $group): array { /** @var AccessToken $token */ $token = $group->first(); return [ 'client_id' => $token->client_id, 'name' => $token->client->name, 'can_disconnect' => true, 'last_used_at' => $group->max('last_used_at'), ]; }) ->sortByDesc(fn (array $client): mixed => $client['last_used_at'] ?? 0) ->values() ->all(); } }