Skip to content

Commit 9157545

Browse files
committed
Improve MCP server shutdown.
Fixes #287
1 parent 95c8b10 commit 9157545

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44

55
- Fix "approve and remember" tool call when checking files outside workspace.
6+
- Improve MCP server shutdown. #287
67

78
## 0.98.2
89

src/eca/features/tools/mcp.clj

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,18 @@
430430
resource (.readResource ^McpSyncClient mcp-client (McpSchema$ReadResourceRequest. uri))]
431431
{:contents (mapv ->resource-content (.contents resource))}))
432432

433-
(defn shutdown! [db*]
433+
(defn shutdown!
434+
"Shutdown MCP servers in parallel waiting max 5s in total."
435+
[db*]
434436
(try
435-
(doseq [[_name {:keys [client]}] (:mcp-clients @db*)]
436-
(.closeGracefully ^McpSyncClient client))
437+
(let [clients (vals (:mcp-clients @db*))
438+
futures (doall
439+
(pmap (fn [{:keys [^McpSyncClient client]}]
440+
(future
441+
(try (.closeGracefully client)
442+
(catch Exception _ nil))))
443+
clients))]
444+
(doseq [f futures]
445+
(try (deref f 5000 nil) (catch Exception _ nil))))
437446
(catch Exception _ nil))
438447
(swap! db* assoc :mcp-clients {}))

0 commit comments

Comments
 (0)