(
serverId: string,
workspaceId: string,
success: boolean,
error?: string,
toolCount?: number
)
| 309 | } |
| 310 | |
| 311 | private async updateServerStatus( |
| 312 | serverId: string, |
| 313 | workspaceId: string, |
| 314 | success: boolean, |
| 315 | error?: string, |
| 316 | toolCount?: number |
| 317 | ): Promise<void> { |
| 318 | try { |
| 319 | const [currentServer] = await db |
| 320 | .select({ statusConfig: mcpServers.statusConfig }) |
| 321 | .from(mcpServers) |
| 322 | .where( |
| 323 | and( |
| 324 | eq(mcpServers.id, serverId), |
| 325 | eq(mcpServers.workspaceId, workspaceId), |
| 326 | isNull(mcpServers.deletedAt) |
| 327 | ) |
| 328 | ) |
| 329 | .limit(1) |
| 330 | |
| 331 | const currentConfig: McpServerStatusConfig = |
| 332 | (currentServer?.statusConfig as McpServerStatusConfig | null) ?? { |
| 333 | consecutiveFailures: 0, |
| 334 | lastSuccessfulDiscovery: null, |
| 335 | } |
| 336 | |
| 337 | const now = new Date() |
| 338 | |
| 339 | if (success) { |
| 340 | await db |
| 341 | .update(mcpServers) |
| 342 | .set({ |
| 343 | connectionStatus: 'connected', |
| 344 | lastConnected: now, |
| 345 | lastError: null, |
| 346 | toolCount: toolCount ?? 0, |
| 347 | lastToolsRefresh: now, |
| 348 | statusConfig: { |
| 349 | consecutiveFailures: 0, |
| 350 | lastSuccessfulDiscovery: now.toISOString(), |
| 351 | }, |
| 352 | updatedAt: now, |
| 353 | }) |
| 354 | .where(eq(mcpServers.id, serverId)) |
| 355 | } else { |
| 356 | const newFailures = currentConfig.consecutiveFailures + 1 |
| 357 | const isErrorState = newFailures >= MCP_CONSTANTS.MAX_CONSECUTIVE_FAILURES |
| 358 | |
| 359 | await db |
| 360 | .update(mcpServers) |
| 361 | .set({ |
| 362 | connectionStatus: isErrorState ? 'error' : 'disconnected', |
| 363 | lastError: error || 'Unknown error', |
| 364 | statusConfig: { |
| 365 | consecutiveFailures: newFailures, |
| 366 | lastSuccessfulDiscovery: currentConfig.lastSuccessfulDiscovery, |
| 367 | }, |
| 368 | updatedAt: now, |
no test coverage detected