Skip to content

Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.

Fix 500 on the MCP settings page when a client has never been used (#297)

Paulo Castellano097f30c76539
diff --git a/app/Actions/AccessToken/ListConnectedMcpClients.php b/app/Actions/AccessToken/ListConnectedMcpClients.php
index 0e2922a1b..261669743 100644
--- a/app/Actions/AccessToken/ListConnectedMcpClients.php
+++ b/app/Actions/AccessToken/ListConnectedMcpClients.php
@@ -7,6 +7,7 @@ namespace App\Actions\AccessToken;
use App\Models\AccessToken;
use App\Models\User;
use App\Models\Workspace;
+use Carbon\CarbonInterface;
use Illuminate\Support\Collection;
class ListConnectedMcpClients
@@ -16,7 +17,7 @@ class ListConnectedMcpClients
* OAuth client. Matches API keys: each person only sees what they connected
* for the workspace they are viewing.
*
- * @return list<array{client_id: string, name: string, can_disconnect: bool, last_used_at: mixed}>
+ * @return list<array{client_id: string, name: string, can_disconnect: bool, last_used_at: ?CarbonInterface}>
*/
public static function forUser(User $user, Workspace $workspace): array
{
@@ -41,7 +42,8 @@ class ListConnectedMcpClients
'last_used_at' => $group->max('last_used_at'),
];
})
- ->sortByDesc(fn (array $client): mixed => $client['last_used_at'] ?? 0)
+ // Timestamp, not the date object: never-used clients are null.
+ ->sortByDesc(fn (array $client): int => $client['last_used_at']?->getTimestamp() ?? 0)
->values()
->all();
}
diff --git a/tests/Feature/McpSettingsControllerTest.php b/tests/Feature/McpSettingsControllerTest.php
index d4a8c38df..ca300d353 100644
--- a/tests/Feature/McpSettingsControllerTest.php
+++ b/tests/Feature/McpSettingsControllerTest.php
@@ -313,6 +313,35 @@ it('orders connected mcp clients by last used descending', function (): void {
->where('connectedClients.1.name', 'Older Agent'));
});
+it('orders a never-used client last instead of crashing', function (): void {
+ $used = mcpAccessToken($this->user, mcpOauthClient('Used Agent'), $this->workspace);
+ $neverUsed = mcpAccessToken($this->user, mcpOauthClient('Fresh Agent'), $this->workspace);
+
+ $used->forceFill(['last_used_at' => now()->subHour()])->saveQuietly();
+ $neverUsed->forceFill(['last_used_at' => null])->saveQuietly();
+
+ $this->actingAs($this->user)
+ ->get(route('app.mcp.index'))
+ ->assertOk()
+ ->assertInertia(fn ($page) => $page
+ ->has('connectedClients', 2)
+ ->where('connectedClients.0.name', 'Used Agent')
+ ->where('connectedClients.1.name', 'Fresh Agent'));
+});
+
+it('lists clients that have never been used', function (): void {
+ $first = mcpAccessToken($this->user, mcpOauthClient('First Agent'), $this->workspace);
+ $second = mcpAccessToken($this->user, mcpOauthClient('Second Agent'), $this->workspace);
+
+ $first->forceFill(['last_used_at' => null])->saveQuietly();
+ $second->forceFill(['last_used_at' => null])->saveQuietly();
+
+ $this->actingAs($this->user)
+ ->get(route('app.mcp.index'))
+ ->assertOk()
+ ->assertInertia(fn ($page) => $page->has('connectedClients', 2));
+});
+
it('does not list unbound mcp grants', function (): void {
mcpAccessToken($this->user, mcpOauthClient('Legacy Agent'), workspace: null);