Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions App/Controllers/ServerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,8 @@ actor MCPConnectionManager {
self.transport = NetworkTransport(
connection: connection,
logger: nil,
heartbeatConfig: .init(enabled: false),
reconnectionConfig: .disabled,
bufferConfig: .unlimited
)

Expand Down Expand Up @@ -627,6 +629,7 @@ actor ServerNetworkManager {
private var connections: [UUID: MCPConnectionManager] = [:]
private var connectionTasks: [UUID: Task<Void, Never>] = [:]
private var pendingConnections: [UUID: String] = [:]
private var removedConnections: Set<UUID> = []

typealias ConnectionApprovalHandler = @Sendable (UUID, MCP.Client.Info) async -> Bool
private var connectionApprovalHandler: ConnectionApprovalHandler?
Expand Down Expand Up @@ -764,11 +767,20 @@ actor ServerNetworkManager {
connections.removeAll()
connectionTasks.removeAll()
pendingConnections.removeAll()
removedConnections.removeAll()

await discoveryManager?.stop()
}

func removeConnection(_ id: UUID) async {
// Guard against redundant removal — calling stop() on an already-stopped
// connection can trigger a double-resume in the SDK's transport continuation.
guard !removedConnections.contains(id) else {
log.debug("Connection \(id) already removed, skipping")
return
}
removedConnections.insert(id)

log.debug("Removing connection: \(id)")

if let connectionManager = connections[id] {
Expand Down