|
326 | 326 | (logger/warn logger-tag (format "Could not list %s: %s" kind (format-jsonrpc-error jsonrpc-error))) |
327 | 327 | [])) |
328 | 328 |
|
329 | | -(defn ^:private list-server-tools [client] |
| 329 | +(defn ^:private on-list-timeout [kind] |
| 330 | + (fn [_id _timeout-value] |
| 331 | + (logger/warn logger-tag (format "Timeout waiting server response listing %s" kind)) |
| 332 | + [])) |
| 333 | + |
| 334 | +(defn ^:private list-options [kind timeout-ms] |
| 335 | + {:on-error (on-list-error kind) |
| 336 | + :timeout-millis timeout-ms |
| 337 | + :timeout-value ::list-timeout |
| 338 | + :on-timeout (on-list-timeout kind)}) |
| 339 | + |
| 340 | +(defn ^:private list-server-tools [client timeout-ms] |
330 | 341 | (if (get-in (pmc/get-initialize-result client) [:capabilities :tools]) |
331 | | - (or (some->> (pmc/list-tools client {:on-error (on-list-error "tools")}) |
| 342 | + (or (some->> (pmc/list-tools client (list-options "tools" timeout-ms)) |
332 | 343 | (mapv tool->internal)) |
333 | 344 | []) |
334 | 345 | [])) |
335 | 346 |
|
336 | | -(defn ^:private list-server-prompts [client] |
| 347 | +(defn ^:private list-server-prompts [client timeout-ms] |
337 | 348 | (if (get-in (pmc/get-initialize-result client) [:capabilities :prompts]) |
338 | | - (or (pmc/list-prompts client {:on-error (on-list-error "prompts")}) |
| 349 | + (or (pmc/list-prompts client (list-options "prompts" timeout-ms)) |
339 | 350 | []) |
340 | 351 | [])) |
341 | 352 |
|
342 | | -(defn ^:private list-server-resources [client] |
| 353 | +(defn ^:private list-server-resources [client timeout-ms] |
343 | 354 | (if (get-in (pmc/get-initialize-result client) [:capabilities :resources]) |
344 | | - (or (pmc/list-resources client {:on-error (on-list-error "resources")}) |
| 355 | + (or (pmc/list-resources client (list-options "resources" timeout-ms)) |
345 | 356 | []) |
346 | 357 | [])) |
347 | 358 |
|
|
453 | 464 | server-config |
454 | 465 | {:on-server-updated on-server-updated}) |
455 | 466 | (let [init-timeout (:mcpTimeoutSeconds config) |
| 467 | + list-timeout-ms (* 1000 init-timeout) |
456 | 468 | pending-tools-refresh* (atom nil) |
457 | 469 | on-tools-change (fn [tools] |
458 | 470 | (let [tools (mapv tool->internal tools)] |
|
479 | 491 | http-client (assoc :http-client http-client))) |
480 | 492 | (swap! db* assoc-in [:mcp-clients name :version] version) |
481 | 493 | (swap! db* assoc-in [:mcp-clients name :instructions] (:instructions init-result)) |
482 | | - (swap! db* assoc-in [:mcp-clients name :tools] (list-server-tools client)) |
483 | | - (swap! db* assoc-in [:mcp-clients name :prompts] (list-server-prompts client)) |
484 | | - (swap! db* assoc-in [:mcp-clients name :resources] (list-server-resources client)) |
| 494 | + (swap! db* assoc-in [:mcp-clients name :tools] (list-server-tools client list-timeout-ms)) |
| 495 | + (swap! db* assoc-in [:mcp-clients name :prompts] (list-server-prompts client list-timeout-ms)) |
| 496 | + (swap! db* assoc-in [:mcp-clients name :resources] (list-server-resources client list-timeout-ms)) |
485 | 497 | (if (and needs-reinit?* @needs-reinit?*) |
486 | 498 | (do (try (pp/stop-client-transport! transport false) (catch Exception _)) |
487 | 499 | (if (< attempt max-init-retries) |
|
0 commit comments