Skip to content

Commit 7ab668c

Browse files
author
Lasim
committed
feat(backend): enhance MCP client activity endpoint for team awareness
1 parent 7c48a4a commit 7ab668c

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

services/backend/api-spec.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3638,13 +3638,23 @@
36383638
},
36393639
"/api/users/me/mcp/client-activity": {
36403640
"get": {
3641-
"summary": "Get current user's active MCP clients",
3641+
"summary": "Get current user's active MCP clients for a specific team",
36423642
"tags": [
36433643
"Users",
36443644
"MCP"
36453645
],
3646-
"description": "Returns the current user's active MCP clients (VS Code, Cursor, etc.) based on recent activity. This is a PERSONAL dashboard endpoint - users see ONLY their own clients, not their team members' activity.",
3646+
"description": "Returns the current user's active MCP clients (VS Code, Cursor, etc.) based on recent activity for the specified team. This is a TEAM-AWARE PERSONAL dashboard endpoint - users see ONLY their own clients within the specified team, not their team members' activity. Requires team_id query parameter.",
36473647
"parameters": [
3648+
{
3649+
"schema": {
3650+
"type": "string",
3651+
"minLength": 1
3652+
},
3653+
"in": "query",
3654+
"name": "team_id",
3655+
"required": true,
3656+
"description": "Team ID to filter activity by (required for team-aware filtering)"
3657+
},
36483658
{
36493659
"schema": {
36503660
"type": "integer",

services/backend/api-spec.yaml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2541,14 +2541,23 @@ paths:
25412541
description: Internal Server Error
25422542
/api/users/me/mcp/client-activity:
25432543
get:
2544-
summary: Get current user's active MCP clients
2544+
summary: Get current user's active MCP clients for a specific team
25452545
tags:
25462546
- Users
25472547
- MCP
25482548
description: Returns the current user's active MCP clients (VS Code, Cursor,
2549-
etc.) based on recent activity. This is a PERSONAL dashboard endpoint -
2550-
users see ONLY their own clients, not their team members' activity.
2549+
etc.) based on recent activity for the specified team. This is a
2550+
TEAM-AWARE PERSONAL dashboard endpoint - users see ONLY their own
2551+
clients within the specified team, not their team members' activity.
2552+
Requires team_id query parameter.
25512553
parameters:
2554+
- schema:
2555+
type: string
2556+
minLength: 1
2557+
in: query
2558+
name: team_id
2559+
required: true
2560+
description: Team ID to filter activity by (required for team-aware filtering)
25522561
- schema:
25532562
type: integer
25542563
minimum: 1

services/backend/src/routes/users/getMcpClientActivity.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import { requireAuthenticationAny } from '../../middleware/oauthMiddleware';
88
const QUERY_PARAMS_SCHEMA = {
99
type: 'object',
1010
properties: {
11+
team_id: {
12+
type: 'string',
13+
minLength: 1,
14+
description: 'Team ID to filter activity by (required for team-aware filtering)'
15+
},
1116
limit: {
1217
type: 'integer',
1318
minimum: 1,
@@ -29,6 +34,7 @@ const QUERY_PARAMS_SCHEMA = {
2934
description: 'Show clients active within N minutes (1-1440)'
3035
}
3136
},
37+
required: ['team_id'],
3238
additionalProperties: false
3339
} as const;
3440

@@ -93,6 +99,7 @@ const ERROR_RESPONSE_SCHEMA = {
9399

94100
// TypeScript interfaces
95101
interface QueryParams {
102+
team_id: string;
96103
limit?: number;
97104
offset?: number;
98105
active_within_minutes?: number;
@@ -147,8 +154,8 @@ export default async function getMcpClientActivityRoute(server: FastifyInstance)
147154
preValidation: [requireAuthenticationAny()],
148155
schema: {
149156
tags: ['Users', 'MCP'],
150-
summary: 'Get current user\'s active MCP clients',
151-
description: 'Returns the current user\'s active MCP clients (VS Code, Cursor, etc.) based on recent activity. This is a PERSONAL dashboard endpoint - users see ONLY their own clients, not their team members\' activity.',
157+
summary: 'Get current user\'s active MCP clients for a specific team',
158+
description: 'Returns the current user\'s active MCP clients (VS Code, Cursor, etc.) based on recent activity for the specified team. This is a TEAM-AWARE PERSONAL dashboard endpoint - users see ONLY their own clients within the specified team, not their team members\' activity. Requires team_id query parameter.',
152159
security: [
153160
{ cookieAuth: [] },
154161
{ bearerAuth: [] }
@@ -181,27 +188,29 @@ export default async function getMcpClientActivityRoute(server: FastifyInstance)
181188
const userId = request.user!.id;
182189
const query = request.query as QueryParams;
183190

191+
const teamId = query.team_id;
184192
const limit = query.limit || 20;
185193
const offset = query.offset || 0;
186194
const activeWithinMinutes = query.active_within_minutes || 30;
187195

188196
// Calculate cutoff timestamp (X minutes ago)
189197
const cutoffTime = new Date(Date.now() - activeWithinMinutes * 60 * 1000);
190198

191-
// Get total count for pagination
199+
// Get total count for pagination (team-aware)
192200
const countResult = await db
193201
.select({ count: sql<number>`count(*)` })
194202
.from(mcpClientActivity)
195203
.where(
196204
and(
197205
eq(mcpClientActivity.user_id, userId),
206+
eq(mcpClientActivity.team_id, teamId),
198207
gt(mcpClientActivity.last_activity_at, cutoffTime)
199208
)
200209
);
201210

202211
const total = Number(countResult[0]?.count || 0);
203212

204-
// Get activity records with satellite information
213+
// Get activity records with satellite information (team-aware)
205214
const activityRecords = await db
206215
.select({
207216
id: mcpClientActivity.id,
@@ -219,6 +228,7 @@ export default async function getMcpClientActivityRoute(server: FastifyInstance)
219228
.where(
220229
and(
221230
eq(mcpClientActivity.user_id, userId),
231+
eq(mcpClientActivity.team_id, teamId),
222232
gt(mcpClientActivity.last_activity_at, cutoffTime)
223233
)
224234
)

0 commit comments

Comments
 (0)