MCPcopy
hub / github.com/coder/mux / cleanupIdleServers

Method cleanupIdleServers

src/node/services/mcpServerManager.ts:677–696  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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,

Callers 2

constructorMethod · 0.95

Calls 2

getLeaseCountMethod · 0.95
stopServersMethod · 0.95

Tested by

no test coverage detected