Skip to content

Commit 4f239ad

Browse files
committed
Bump plumcp
1 parent ac1b74a commit 4f239ad

4 files changed

Lines changed: 21 additions & 47 deletions

File tree

CHANGELOG.md

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

55
- Improve OAuth callback error page to show error code, description, and error URI from the authorization server response.
6+
- Bump plumcp to 0.2.0-beta4, simplify MCP tool call error handling now that HTTP 400/404/500 are returned as JSON-RPC errors.
67

78
## 0.115.0
89

deps-lock.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,24 +1053,24 @@
10531053
"hash": "sha256-RLTLjpPU9rJiwE7Qdx1w3WbnbUXX/HVYIGcaYmVcVDk="
10541054
},
10551055
{
1056-
"mvn-path": "io/github/plumce/plumcp.core-json-cheshire/0.2.0-beta3/plumcp.core-json-cheshire-0.2.0-beta3.jar",
1056+
"mvn-path": "io/github/plumce/plumcp.core-json-cheshire/0.2.0-beta4/plumcp.core-json-cheshire-0.2.0-beta4.jar",
10571057
"mvn-repo": "https://repo.clojars.org/",
1058-
"hash": "sha256-zv+Trbz3BWVF2jWgADInlyjqsDsanbWKVYGOceV+WnM="
1058+
"hash": "sha256-Go75A0bKRlFzzrFYnYqOzZTvZMBIQUC0Up8o5hpKOME="
10591059
},
10601060
{
1061-
"mvn-path": "io/github/plumce/plumcp.core-json-cheshire/0.2.0-beta3/plumcp.core-json-cheshire-0.2.0-beta3.pom",
1061+
"mvn-path": "io/github/plumce/plumcp.core-json-cheshire/0.2.0-beta4/plumcp.core-json-cheshire-0.2.0-beta4.pom",
10621062
"mvn-repo": "https://repo.clojars.org/",
1063-
"hash": "sha256-w6nOMod07L7uKT2Vl+Ici/Oonq3CvGCCrJix3f0y7Cs="
1063+
"hash": "sha256-f9YSqBznPLeapNXmEAG0J0ao9j8lphA+AE074mw3Txw="
10641064
},
10651065
{
1066-
"mvn-path": "io/github/plumce/plumcp.core/0.2.0-beta3/plumcp.core-0.2.0-beta3.jar",
1066+
"mvn-path": "io/github/plumce/plumcp.core/0.2.0-beta4/plumcp.core-0.2.0-beta4.jar",
10671067
"mvn-repo": "https://repo.clojars.org/",
1068-
"hash": "sha256-M/6egOI3jY8hVnave6Cx12P5Hmd6M1J5QuZEszUx2nk="
1068+
"hash": "sha256-veMNSRikNa9wpbP4tq1aIyqbXybFMFjFj1pzmahd/h0="
10691069
},
10701070
{
1071-
"mvn-path": "io/github/plumce/plumcp.core/0.2.0-beta3/plumcp.core-0.2.0-beta3.pom",
1071+
"mvn-path": "io/github/plumce/plumcp.core/0.2.0-beta4/plumcp.core-0.2.0-beta4.pom",
10721072
"mvn-repo": "https://repo.clojars.org/",
1073-
"hash": "sha256-I6gSOKlouC7ZMoJYow4/XZEgwMeZYGLZwtj2oblpVoA="
1073+
"hash": "sha256-pdR9owenFET4Kz09C3GXWEqqvFet96OvKKIqy9bbF0A="
10741074
},
10751075
{
10761076
"mvn-path": "io/methvin/directory-watcher/0.17.3/directory-watcher-0.17.3.jar",

deps.edn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
org.clojure/core.async {:mvn/version "1.8.741"}
44
org.babashka/cli {:mvn/version "0.8.65"}
55
com.github.clojure-lsp/jsonrpc4clj {:mvn/version "1.0.2"}
6-
io.github.plumce/plumcp.core-json-cheshire {:mvn/version "0.2.0-beta3"}
6+
io.github.plumce/plumcp.core-json-cheshire {:mvn/version "0.2.0-beta4"}
77
org.yaml/snakeyaml {:mvn/version "2.4"} ;; used by eca.shared for YAML parsing
88
borkdude/dynaload {:mvn/version "0.3.5"}
99
selmer/selmer {:mvn/version "1.12.69"}

src/eca/features/tools/mcp.clj

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -534,48 +534,28 @@
534534
(swap! db* update :mcp-clients dissoc server-name)
535535
(initialize-server! server-name db* config metrics (constantly nil)))
536536

537-
(def ^:private reinit-poll-interval-ms 100)
538537
(def ^:private tool-call-timeout-ms 120000)
539538

540539
(defn ^:private tool-call-error [msg]
541540
{:error true
542541
:contents [{:type :text :text msg}]})
543542

544543
(defn ^:private do-call-tool
545-
"Execute a tool call. When needs-reinit?* is provided (HTTP transport), runs
546-
pmc/call-tool in a future and polls for transport errors (404/5xx) so we can
547-
short-circuit instead of blocking until plumcp's internal timeout — the error
548-
is set in a virtual thread that pmc/call-tool never joins."
549-
[mcp-client name arguments needs-reinit?*]
544+
"Execute a tool call. Delegates timeout handling to plumcp via :timeout-millis.
545+
HTTP 400/404/500 errors are returned as JSON-RPC error responses by plumcp,
546+
so no polling loop is needed."
547+
[mcp-client name arguments]
550548
(locking mcp-client
551-
(when needs-reinit?*
552-
(reset! needs-reinit?* false))
553549
(let [error-msg* (atom nil)
554-
call-opts {:on-error (fn [_id jsonrpc-error]
550+
call-opts {:timeout-millis tool-call-timeout-ms
551+
:on-error (fn [_id jsonrpc-error]
555552
(let [msg (or (:message jsonrpc-error) "Unknown JSON-RPC error")]
556553
(logger/warn logger-tag "Error calling tool:" msg)
557554
(reset! error-msg* msg))
558555
nil)}
559-
call-future (future (pmc/call-tool mcp-client name arguments call-opts))
560556
result (try
561-
(if needs-reinit?*
562-
(loop [elapsed (long 0)]
563-
(cond
564-
(realized? call-future)
565-
(deref call-future)
566-
567-
@needs-reinit?*
568-
(do (future-cancel call-future) ::connection-lost)
569-
570-
(>= elapsed (long tool-call-timeout-ms))
571-
(do (future-cancel call-future) ::timeout)
572-
573-
:else
574-
(do (Thread/sleep (long reinit-poll-interval-ms))
575-
(recur (+ elapsed (long reinit-poll-interval-ms))))))
576-
(deref call-future))
557+
(pmc/call-tool mcp-client name arguments call-opts)
577558
(catch Exception e
578-
(future-cancel call-future)
579559
(if (transient-transport-error? e)
580560
(do (logger/warn logger-tag (format "Transient transport error, retrying tool call: %s" (.getMessage e)))
581561
::retry)
@@ -585,12 +565,6 @@
585565
(= ::retry result)
586566
nil
587567

588-
(= ::timeout result)
589-
(tool-call-error (format "MCP tool call timed out after %ds" (/ tool-call-timeout-ms 1000)))
590-
591-
(= ::connection-lost result)
592-
(tool-call-error "MCP server connection lost during tool call")
593-
594568
(::error-msg result)
595569
(tool-call-error (format "MCP server error: %s" (::error-msg result)))
596570

@@ -604,8 +578,7 @@
604578
(defn ^:private reinit-and-call-tool! [server-name mcp-client db* config metrics name arguments]
605579
(reinitialize-server! server-name mcp-client db* config metrics)
606580
(if-let [new-client (get-in @db* [:mcp-clients server-name :client])]
607-
(let [new-needs-reinit?* (get-in @db* [:mcp-clients server-name :needs-reinit?*])]
608-
(do-call-tool new-client name arguments new-needs-reinit?*))
581+
(do-call-tool new-client name arguments)
609582
(tool-call-error (format "Failed to re-initialize MCP server '%s'" server-name))))
610583

611584
(defn call-tool! [name arguments {:keys [db db* config metrics]}]
@@ -618,13 +591,13 @@
618591
(if (and needs-reinit?* @needs-reinit?* db* config metrics)
619592
;; Already flagged (e.g. GET stream 5xx) — reinit before attempting the call
620593
(reinit-and-call-tool! server-name mcp-client db* config metrics name arguments)
621-
(let [result (do-call-tool mcp-client name arguments needs-reinit?*)]
594+
(let [result (do-call-tool mcp-client name arguments)]
622595
(cond
623596
;; nil = transient transport error, retry once
624597
(nil? result)
625-
(do-call-tool mcp-client name arguments needs-reinit?*)
598+
(do-call-tool mcp-client name arguments)
626599

627-
;; Flagged during the call (e.g. POST 404) — reinit and retry
600+
;; Flagged during the call (e.g. GET stream 404/5xx) — reinit and retry
628601
(and (:error result) needs-reinit?* @needs-reinit?* db* config metrics)
629602
(reinit-and-call-tool! server-name mcp-client db* config metrics name arguments)
630603

0 commit comments

Comments
 (0)