()
| 675 | } |
| 676 | |
| 677 | private cleanupIdleServers(): void { |
| 678 | const now = Date.now(); |
| 679 | for (const [workspaceId, entry] of this.workspaceServers) { |
| 680 | if (entry.instances.size === 0) continue; |
| 681 | |
| 682 | // Never tear down a workspace's MCP servers while a stream is running. |
| 683 | if (this.getLeaseCount(workspaceId) > 0) { |
| 684 | continue; |
| 685 | } |
| 686 | |
| 687 | const idleMs = now - entry.lastActivity; |
| 688 | if (idleMs >= IDLE_TIMEOUT_MS) { |
| 689 | log.info("[MCP] Stopping idle servers", { |
| 690 | workspaceId, |
| 691 | idleMinutes: Math.round(idleMs / 60_000), |
| 692 | }); |
| 693 | void this.stopServers(workspaceId); |
| 694 | } |
| 695 | } |
| 696 | } |
| 697 | |
| 698 | private createWorkspaceStats( |
| 699 | enabledServerCount: number, |
no test coverage detected