Skip to content

Commit 99b636e

Browse files
committed
include eca server with tools
1 parent 9f118d2 commit 99b636e

File tree

4 files changed

+36
-19
lines changed

4 files changed

+36
-19
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- Include eca as a server with tools.
6+
57
## 0.8.1
68

79
- Make generic tool server updates for eca native tools.

docs/protocol.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,13 +787,21 @@ _Response:_
787787
type ToolServerUpdatedParams = EcaServerUpdatedParams | MCPServerUpdatedParams;
788788

789789
interface EcaServerUpdatedParams {
790+
type: 'native';
791+
792+
name: 'ECA';
793+
794+
status: 'running';
795+
790796
/**
791797
* The built-in tools supported by eca.
792798
*/
793799
tools: ServerTool[];
794800
}
795801

796802
interface MCPServerUpdatedParams {
803+
type: 'mcp';
804+
797805
/**
798806
* The server name.
799807
*/

src/eca/features/tools.clj

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
[eca.features.tools.mcp :as f.mcp]
88
[eca.features.tools.shell :as f.tools.shell]
99
[eca.features.tools.util :as tools.util]
10-
[eca.logger :as logger])
10+
[eca.logger :as logger]
11+
[eca.messenger :as messenger])
1112
(:import
1213
[java.util Map]))
1314

@@ -29,21 +30,31 @@
2930
(when (get-in config [:nativeTools :shell :enabled])
3031
f.tools.shell/definitions))))
3132

33+
(defn ^:private native-tools [db config]
34+
(mapv #(select-keys % [:name :description :parameters])
35+
(vals (native-definitions db config))))
36+
3237
(defn all-tools
3338
"Returns all available tools, including both native ECA tools
3439
(like filesystem and shell tools) and tools provided by MCP servers."
3540
[db config]
36-
(let [native-tools (concat
37-
[]
38-
(mapv #(select-keys % [:name :description :parameters])
39-
(vals (native-definitions db config))))
40-
mcp-tools (f.mcp/all-tools db)]
41-
(concat
42-
(mapv #(assoc % :origin :native) native-tools)
43-
(mapv #(assoc % :origin :mcp) mcp-tools))))
41+
(concat
42+
(mapv #(assoc % :origin :native) (native-tools db config))
43+
(mapv #(assoc % :origin :mcp) (f.mcp/all-tools db))))
4444

4545
(defn call-tool! [^String name ^Map arguments db config]
4646
(logger/info logger-tag (format "Calling tool '%s' with args '%s'" name arguments))
4747
(if-let [native-tool-handler (get-in (native-definitions db config) [name :handler])]
4848
(native-tool-handler arguments {:db db :config config})
4949
(f.mcp/call-tool! name arguments db)))
50+
51+
(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))

src/eca/handlers.clj

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
[eca.config :as config]
44
[eca.db :as db]
55
[eca.features.chat :as f.chat]
6+
[eca.features.tools :as f.tools]
67
[eca.features.tools.mcp :as f.mcp]
78
[eca.llm-api :as llm-api]
8-
[eca.logger :as logger]
9-
[eca.messenger :as messenger]))
9+
[eca.logger :as logger]))
1010

1111
(set! *warn-on-reflection* true)
1212

@@ -44,13 +44,9 @@
4444
:workspace-folders (:workspace-folders params)
4545
:client-capabilities (:capabilities params)
4646
:chat-behavior (or (-> params :initialization-options :chat-behavior) (:chat-behavior @db*)))
47-
(initialize-extra-models! db* config)
4847
(future
49-
(f.mcp/initialize-servers-async!
50-
{:on-server-updated (fn [server]
51-
(messenger/tool-server-updated messenger server))}
52-
db*
53-
config))
48+
(f.tools/init-servers! db* messenger config))
49+
(initialize-extra-models! db* config)
5450
{:models (keys (:models @db*))
5551
:chat-default-model (f.chat/default-model @db* config)
5652
:chat-behaviors (:chat-behaviors @db*)
@@ -86,8 +82,8 @@
8682

8783
(defn chat-prompt-stop [{:keys [db* messenger]} params]
8884
(logger/logging-task
89-
:eca/chat-prompt-stop
90-
(f.chat/prompt-stop params db* messenger)))
85+
:eca/chat-prompt-stop
86+
(f.chat/prompt-stop params db* messenger)))
9187

9288
(defn chat-delete [{:keys [db*]} params]
9389
(logger/logging-task

0 commit comments

Comments
 (0)