|
| 1 | +(ns eca.features.tools.mcp-test |
| 2 | + (:require |
| 3 | + [clojure.test :refer [deftest is testing]] |
| 4 | + [eca.features.tools.mcp :as mcp])) |
| 5 | + |
| 6 | +(deftest all-tools-test |
| 7 | + (testing "empty db" |
| 8 | + (is (= [] |
| 9 | + (mcp/all-tools {})))) |
| 10 | + |
| 11 | + (testing "db with no mcp-clients" |
| 12 | + (is (= [] |
| 13 | + (mcp/all-tools {:some-other-key "value"})))) |
| 14 | + |
| 15 | + (testing "db with empty mcp-clients" |
| 16 | + (is (= [] |
| 17 | + (mcp/all-tools {:mcp-clients {}})))) |
| 18 | + |
| 19 | + (testing "db with mcp-clients but no tools" |
| 20 | + (is (= [] |
| 21 | + (mcp/all-tools {:mcp-clients {"server1" {}}})))) |
| 22 | + |
| 23 | + (testing "db with single server with tools" |
| 24 | + (let [tools [{:name "tool1" :description "desc1"} |
| 25 | + {:name "tool2" :description "desc2"}]] |
| 26 | + (is (= tools |
| 27 | + (mcp/all-tools {:mcp-clients {"server1" {:tools tools}}}))))) |
| 28 | + |
| 29 | + (testing "db with multiple servers with tools" |
| 30 | + (let [tools1 [{:name "tool1" :description "desc1"}] |
| 31 | + tools2 [{:name "tool2" :description "desc2"} |
| 32 | + {:name "tool3" :description "desc3"}]] |
| 33 | + (is (= (concat tools1 tools2) |
| 34 | + (mcp/all-tools {:mcp-clients {"server1" {:tools tools1} |
| 35 | + "server2" {:tools tools2}}})))))) |
| 36 | + |
| 37 | +(deftest all-prompts-test |
| 38 | + (testing "empty db" |
| 39 | + (is (= [] |
| 40 | + (mcp/all-prompts {})))) |
| 41 | + |
| 42 | + (testing "db with no mcp-clients" |
| 43 | + (is (= [] |
| 44 | + (mcp/all-prompts {:some-other-key "value"})))) |
| 45 | + |
| 46 | + (testing "db with empty mcp-clients" |
| 47 | + (is (= [] |
| 48 | + (mcp/all-prompts {:mcp-clients {}})))) |
| 49 | + |
| 50 | + (testing "db with mcp-clients but no prompts" |
| 51 | + (is (= [] |
| 52 | + (mcp/all-prompts {:mcp-clients {"server1" {}}})))) |
| 53 | + |
| 54 | + (testing "db with single server with prompts" |
| 55 | + (let [prompts [{:name "prompt1" :description "desc1"} |
| 56 | + {:name "prompt2" :description "desc2"}] |
| 57 | + expected (mapv #(assoc % :server "server1") prompts)] |
| 58 | + (is (= expected |
| 59 | + (mcp/all-prompts {:mcp-clients {"server1" {:prompts prompts}}}))))) |
| 60 | + |
| 61 | + (testing "db with multiple servers with prompts" |
| 62 | + (let [prompts1 [{:name "prompt1" :description "desc1"}] |
| 63 | + prompts2 [{:name "prompt2" :description "desc2"} |
| 64 | + {:name "prompt3" :description "desc3"}] |
| 65 | + expected (concat |
| 66 | + (mapv #(assoc % :server "server1") prompts1) |
| 67 | + (mapv #(assoc % :server "server2") prompts2))] |
| 68 | + (is (= expected |
| 69 | + (mcp/all-prompts {:mcp-clients {"server1" {:prompts prompts1} |
| 70 | + "server2" {:prompts prompts2}}})))))) |
| 71 | + |
| 72 | +(deftest all-resources-test |
| 73 | + (testing "empty db" |
| 74 | + (is (= [] |
| 75 | + (mcp/all-resources {})))) |
| 76 | + |
| 77 | + (testing "db with no mcp-clients" |
| 78 | + (is (= [] |
| 79 | + (mcp/all-resources {:some-other-key "value"})))) |
| 80 | + |
| 81 | + (testing "db with empty mcp-clients" |
| 82 | + (is (= [] |
| 83 | + (mcp/all-resources {:mcp-clients {}})))) |
| 84 | + |
| 85 | + (testing "db with mcp-clients but no resources" |
| 86 | + (is (= [] |
| 87 | + (mcp/all-resources {:mcp-clients {"server1" {}}})))) |
| 88 | + |
| 89 | + (testing "db with single server with resources" |
| 90 | + (let [resources [{:uri "file://test1" :name "resource1"} |
| 91 | + {:uri "file://test2" :name "resource2"}] |
| 92 | + expected (mapv #(assoc % :server "server1") resources)] |
| 93 | + (is (= expected |
| 94 | + (mcp/all-resources {:mcp-clients {"server1" {:resources resources}}}))))) |
| 95 | + |
| 96 | + (testing "db with multiple servers with resources" |
| 97 | + (let [resources1 [{:uri "file://test1" :name "resource1"}] |
| 98 | + resources2 [{:uri "file://test2" :name "resource2"} |
| 99 | + {:uri "file://test3" :name "resource3"}] |
| 100 | + expected (concat |
| 101 | + (mapv #(assoc % :server "server1") resources1) |
| 102 | + (mapv #(assoc % :server "server2") resources2))] |
| 103 | + (is (= expected |
| 104 | + (mcp/all-resources {:mcp-clients {"server1" {:resources resources1} |
| 105 | + "server2" {:resources resources2}}})))))) |
| 106 | + |
| 107 | +(deftest shutdown!-test |
| 108 | + (testing "shutdown with no clients" |
| 109 | + (let [db* (atom {})] |
| 110 | + (mcp/shutdown! db*) |
| 111 | + (is (= {:mcp-clients {}} @db*)))) |
| 112 | + |
| 113 | + (testing "shutdown with empty mcp-clients" |
| 114 | + (let [db* (atom {:mcp-clients {}})] |
| 115 | + (mcp/shutdown! db*) |
| 116 | + (is (= {:mcp-clients {}} @db*)))) |
| 117 | + |
| 118 | + (testing "shutdown preserves other db data" |
| 119 | + (let [db* (atom {:mcp-clients {} |
| 120 | + :workspace-folders [] |
| 121 | + :other-key "value"})] |
| 122 | + (mcp/shutdown! db*) |
| 123 | + (is (= {:mcp-clients {} |
| 124 | + :workspace-folders [] |
| 125 | + :other-key "value"} @db*))))) |
0 commit comments