Skip to content

Commit 38b5712

Browse files
committed
Fix error handling of MCP
1 parent 06f34df commit 38b5712

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

src/eca/features/tools/mcp.clj

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,22 @@
107107
(keep (fn [{:keys [client tools]}]
108108
(when (some #(= name (:name %)) tools)
109109
client)))
110-
first)
111-
result (.callTool ^McpSyncClient mcp-client
112-
(McpSchema$CallToolRequest. name arguments))]
113-
(logger/debug logger-tag "ToolCall result: " result)
114-
{:contents (map (fn [content]
115-
(case (.type ^McpSchema$Content content)
116-
"text" {:type :text
117-
:error (.isError result)
118-
:content (.text ^McpSchema$TextContent content)}
119-
nil))
120-
(.content result))}))
110+
first)]
111+
(try
112+
(let [result (.callTool ^McpSyncClient mcp-client
113+
(McpSchema$CallToolRequest. name arguments))]
114+
(logger/debug logger-tag "ToolCall result: " result)
115+
{:contents (map (fn [content]
116+
(case (.type ^McpSchema$Content content)
117+
"text" {:type :text
118+
:error (.isError result)
119+
:content (.text ^McpSchema$TextContent content)}
120+
nil))
121+
(.content result))})
122+
(catch Exception e
123+
{:contents [{:type :text
124+
:error true
125+
:content (.getMessage e)}]}))))
121126

122127
(defn shutdown! [db*]
123128
(doseq [[_name {:keys [_client]}] (:mcp-clients @db*)]

test/eca/features/tools_test.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@
2323
{}))))
2424
(testing "Include enabled native tools"
2525
(is (match?
26-
(m/embeds [{:name "list_directory"
26+
(m/embeds [{:name "eca_list_directory"
2727
:description string?
2828
:parameters some?
2929
:source :native}])
3030
(f.tools/all-tools {} {:nativeTools {:filesystem {:enabled true}}}))))
3131
(testing "Do not include disabled native tools"
3232
(is (match?
33-
(m/embeds [(m/mismatch {:name "list_directory"})])
33+
(m/embeds [(m/mismatch {:name "eca_list_directory"})])
3434
(f.tools/all-tools {} {:nativeTools {:filesystem {:enabled false}}}))))
3535
(testing "Replace special vars description"
3636
(is (match?
37-
(m/embeds [{:name "list_directory"
37+
(m/embeds [{:name "eca_list_directory"
3838
:description (format "Only in %s" (h/file-path "/path/to/project/foo"))
3939
:parameters some?
4040
:source :native}])

0 commit comments

Comments
 (0)