Skip to content

Commit b59b1f2

Browse files
committed
Support disable tools
1 parent 99b636e commit b59b1f2

File tree

6 files changed

+44
-22
lines changed

6 files changed

+44
-22
lines changed

docs/configuration.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,11 @@ interface Config {
131131
anthropicApiKey?: string;
132132
rules: [{path: string;}];
133133
nativeTools: {
134-
{[key: string] {enabled: boolean}}
134+
filesystem: {enabled: boolean};
135+
shell: {enabled: boolean;
136+
excludeCommands: string[]};
135137
};
138+
disabledTools: string[],
136139
toolCall?: {
137140
manualApproval?: boolean,
138141
};
@@ -174,9 +177,10 @@ interface Config {
174177
"openaiApiKey" : null,
175178
"anthropicApiKey" : null,
176179
"rules" : [],
177-
"nativeTools": {"filesystem": {"enabled": true}
178-
"shell": {"enabled": true
180+
"nativeTools": {"filesystem": {"enabled": true},
181+
"shell": {"enabled": true,
179182
"excludeCommands": []}},
183+
"disabledTools": [],
180184
"toolCall": {
181185
"manualApproval": false,
182186
},

docs/protocol.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,11 @@ interface ServerTool {
843843
* The server tool parameters.
844844
*/
845845
parameters: any;
846+
847+
/**
848+
* Whther this tool is disabled.
849+
*/
850+
disabled?: boolean;
846851
}
847852
```
848853

src/eca/config.clj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
:nativeTools {:filesystem {:enabled true}
2323
:shell {:enabled true
2424
:excludeCommands []}}
25+
:disabledTools []
2526
:mcpTimeoutSeconds 60
2627
:mcpServers {}
2728
:ollama {:host "http://localhost"

src/eca/features/tools.clj

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@
88
[eca.features.tools.shell :as f.tools.shell]
99
[eca.features.tools.util :as tools.util]
1010
[eca.logger :as logger]
11-
[eca.messenger :as messenger])
11+
[eca.messenger :as messenger]
12+
[eca.shared :refer [assoc-some]])
1213
(:import
1314
[java.util Map]))
1415

1516
(set! *warn-on-reflection* true)
1617

1718
(def ^:private logger-tag "[TOOLS]")
1819

19-
(defn native-definitions [db config]
20+
(defn ^:private native-definitions [db config]
2021
(into
2122
{}
2223
(map (fn [[name tool]]
@@ -38,9 +39,13 @@
3839
"Returns all available tools, including both native ECA tools
3940
(like filesystem and shell tools) and tools provided by MCP servers."
4041
[db config]
41-
(concat
42-
(mapv #(assoc % :origin :native) (native-tools db config))
43-
(mapv #(assoc % :origin :mcp) (f.mcp/all-tools db))))
42+
(let [disabled-tools (set (get-in config [:disabledTools] []))]
43+
(filterv
44+
(fn [tool]
45+
(not (contains? disabled-tools (:name tool))))
46+
(concat
47+
(mapv #(assoc % :origin :native) (native-tools db config))
48+
(mapv #(assoc % :origin :mcp) (f.mcp/all-tools db))))))
4449

4550
(defn call-tool! [^String name ^Map arguments db config]
4651
(logger/info logger-tag (format "Calling tool '%s' with args '%s'" name arguments))
@@ -49,12 +54,17 @@
4954
(f.mcp/call-tool! name arguments db)))
5055

5156
(defn init-servers! [db* messenger config]
52-
(messenger/tool-server-updated messenger {:type :native
53-
:name "ECA"
54-
:status "running"
55-
:tools (native-tools @db* config)})
56-
(f.mcp/initialize-servers-async!
57-
{:on-server-updated (fn [server]
58-
(messenger/tool-server-updated messenger (assoc server :type :mcp)))}
59-
db*
60-
config))
57+
(let [disabled-tools (set (get-in config [:disabledTools] []))
58+
with-tool-status (fn [tool]
59+
(assoc-some tool :disabled (contains? disabled-tools (:name tool))))]
60+
(messenger/tool-server-updated messenger {:type :native
61+
:name "ECA"
62+
:status "running"
63+
:tools (mapv with-tool-status (native-tools @db* config))})
64+
(f.mcp/initialize-servers-async!
65+
{:on-server-updated (fn [server]
66+
(messenger/tool-server-updated messenger (-> server
67+
(assoc :type :mcp)
68+
(update :tools #(mapv with-tool-status %)))))}
69+
db*
70+
config)))

src/eca/handlers.clj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,25 @@
3636
{}
3737
ollama-models))))
3838

39-
(defn initialize [{:keys [db* messenger config]} params]
39+
(defn initialize [{:keys [db* config]} params]
4040
(logger/logging-task
4141
:eca/initialize
4242
(swap! db* assoc
4343
:client-info (:client-info params)
4444
:workspace-folders (:workspace-folders params)
4545
:client-capabilities (:capabilities params)
4646
:chat-behavior (or (-> params :initialization-options :chat-behavior) (:chat-behavior @db*)))
47-
(future
48-
(f.tools/init-servers! db* messenger config))
4947
(initialize-extra-models! db* config)
5048
{:models (keys (:models @db*))
5149
:chat-default-model (f.chat/default-model @db* config)
5250
:chat-behaviors (:chat-behaviors @db*)
5351
:chat-default-behavior (:chat-default-behavior @db*)
5452
:chat-welcome-message (:welcomeMessage (:chat config))}))
5553

54+
(defn initialized [{:keys [db* messenger config]}]
55+
(future
56+
(f.tools/init-servers! db* messenger config)))
57+
5658
(defn shutdown [{:keys [db*]}]
5759
(logger/logging-task
5860
:eca/shutdown

src/eca/server.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
(liveness-probe/start! parent-process-id log-wrapper-fn #(exit server)))
3535
(handlers/initialize (with-config components) params))
3636

37-
(defmethod lsp.server/receive-notification "initialized" [_ _components _params]
38-
(logger/info logger-tag "Initialized!"))
37+
(defmethod lsp.server/receive-notification "initialized" [_ components _params]
38+
(handlers/initialized (with-config components)))
3939

4040
(defmethod lsp.server/receive-request "shutdown" [_ components _params]
4141
(handlers/shutdown (with-config components)))

0 commit comments

Comments
 (0)