Skip to content

Commit aa58203

Browse files
committed
Added docstrings with the help of Claude. There might be some minor mistakes here and there, will need a full review before a non-alpha release.
1 parent 2231670 commit aa58203

File tree

4 files changed

+424
-43
lines changed

4 files changed

+424
-43
lines changed

deps.edn

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,11 @@
1515

1616
;; clojure -M:outdated --upgrade
1717
:outdated {:extra-deps {com.github.liquidz/antq {:mvn/version "2.11.1276"}}
18-
:main-opts ["-m" "antq.core"]}}}
18+
:main-opts ["-m" "antq.core"]}
19+
20+
;; Starts a nREPL server on port 7888 so that the Clojure-MCP tool can work on that codebase
21+
;; clojure -M:nrepl
22+
:nrepl {:extra-paths ["test"]
23+
:extra-deps {nrepl/nrepl {:mvn/version "1.3.1"}}
24+
:jvm-opts ["-Djdk.attach.allowAttachSelf"]
25+
:main-opts ["-m" "nrepl.cmdline" "--port" "7888"]}}}

src/mcp_toolkit/client.cljc

Lines changed: 174 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,72 @@
55
[mcp-toolkit.impl.common :refer [user-callback]]
66
[promesa.core :as p]))
77

8-
(defn request-set-logging-level [context level]
8+
(defn request-set-logging-level
9+
"Sets the logging level on the MCP server.
10+
(see https://modelcontextprotocol.io/specification/2025-06-18/server/utilities/logging#log-levels)
11+
12+
Args:
13+
context - The client session context
14+
level - Logging level, accepted values are \"debug\", \"info\", \"notice\", \"warning\", \"error\", \"critical\", \"alert\" and \"emergency\"
15+
16+
Returns:
17+
A promise that resolves when the server acknowledges the level change."
18+
[context level]
919
(json-rpc/call-remote-method context {:method "logging/setLevel"
1020
:params {:level level}}))
1121

12-
(defn request-complete-prompt-param [context prompt-name
13-
param-name param-value]
22+
(defn request-complete-prompt-param
23+
"Requests autocompletion for a prompt parameter from the MCP server.
24+
(see https://modelcontextprotocol.io/specification/2025-06-18/server/utilities/completion#data-types)
25+
26+
Args:
27+
context - The client session context
28+
prompt-name - Name of the prompt to complete
29+
param-name - Name of the parameter to complete
30+
param-value - Current partial value of the parameter
31+
32+
Returns:
33+
A promise that resolves to completion suggestions from the server."
34+
[context prompt-name
35+
param-name param-value]
1436
(json-rpc/call-remote-method context {:method "completion/complete"
1537
:params {:ref {:type "ref/prompt"
1638
:name prompt-name}
1739
:argument {:name param-name
1840
:value param-value}}}))
1941

20-
(defn request-complete-resource-uri [context uri-template
21-
param-name param-value]
42+
(defn request-complete-resource-uri
43+
"Requests autocompletion for a resource URI parameter from the MCP server.
44+
(see https://modelcontextprotocol.io/specification/2025-06-18/server/utilities/completion#data-types)
45+
46+
Args:
47+
context - The client session context
48+
uri-template - URI template to complete
49+
param-name - Name of the parameter to complete
50+
param-value - Current partial value of the parameter
51+
52+
Returns:
53+
A promise that resolves to completion suggestions from the server."
54+
[context uri-template
55+
param-name param-value]
2256
(json-rpc/call-remote-method context {:method "completion/complete"
2357
:params {:ref {:type "ref/resource"
2458
:uri uri-template}
2559
:argument {:name param-name
2660
:value param-value}}}))
2761

28-
(defn request-prompt-list [context]
62+
(defn request-prompt-list
63+
"Requests the list of available prompts from the MCP server.
64+
Updates the session's server-prompt-by-name index and calls the
65+
on-server-prompt-list-updated callback.
66+
(see https://modelcontextprotocol.io/specification/2025-06-18/server/prompts#listing-prompts)
67+
68+
Args:
69+
context - The client session context
70+
71+
Returns:
72+
A promise that resolves when prompts are fetched and stored."
73+
[context]
2974
(let [{:keys [session]} context
3075
{:keys [server-capabilities]} @session]
3176
(when (contains? server-capabilities :prompts)
@@ -34,12 +79,34 @@
3479
(swap! session assoc :server-prompt-by-name (mc/index-by :name prompts))
3580
((user-callback :on-server-prompt-list-updated) context)))))))
3681

37-
(defn request-prompt [context prompt-name arguments]
82+
(defn request-prompt
83+
"Requests a specific prompt from the MCP server with given arguments.
84+
(see https://modelcontextprotocol.io/specification/2025-06-18/server/prompts#getting-a-prompt)
85+
86+
Args:
87+
context - The client session context
88+
prompt-name - Name of the prompt to retrieve
89+
arguments - Map of arguments to pass to the prompt
90+
91+
Returns:
92+
A promise that resolves to the prompt response from the server."
93+
[context prompt-name arguments]
3894
(json-rpc/call-remote-method context {:method "prompts/get"
3995
:params {:name prompt-name
4096
:arguments arguments}}))
4197

42-
(defn request-resource-list [context]
98+
(defn request-resource-list
99+
"Requests the list of available resources from the MCP server.
100+
Updates the session's server-resource-by-uri index and calls the
101+
on-server-resource-list-updated callback.
102+
(see https://modelcontextprotocol.io/specification/2025-06-18/server/resources#listing-resources)
103+
104+
Args:
105+
context - The client session context
106+
107+
Returns:
108+
A promise that resolves when the resource descriptions are fetched and stored."
109+
[context]
43110
(let [{:keys [session]} context
44111
{:keys [server-capabilities]} @session]
45112
(when (contains? server-capabilities :resources)
@@ -48,23 +115,72 @@
48115
(swap! session assoc :server-resource-by-uri (mc/index-by :uri resources))
49116
((user-callback :on-server-resource-list-updated) context)))))))
50117

51-
(defn request-resource [context resource-uri]
118+
(defn request-resource
119+
"Requests a specific resource from the MCP server by URI.
120+
(see https://modelcontextprotocol.io/specification/2025-06-18/server/resources#reading-resources)
121+
122+
Args:
123+
context - The client session context
124+
resource-uri - URI of the resource to retrieve
125+
126+
Returns:
127+
A promise that resolves to the resource content from the server."
128+
[context resource-uri]
52129
(json-rpc/call-remote-method context {:method "resources/read"
53130
:params {:uri resource-uri}}))
54131

55-
(defn request-resource-template-list [context]
132+
(defn request-resource-template-list
133+
"Requests the list of available resource templates from the MCP server.
134+
(see https://modelcontextprotocol.io/specification/2025-06-18/server/resources#resource-templates)
135+
136+
Args:
137+
context - The client session context
138+
139+
Returns:
140+
A promise that resolves to the list of resource templates."
141+
[context]
56142
(json-rpc/call-remote-method context {:method "resources/templates/list"}))
57143

144+
(defn request-subscribe-resource
145+
"Subscribes to changes for a specific resource on the MCP server.
146+
(see https://modelcontextprotocol.io/specification/2025-06-18/server/resources#subscriptions)
58147
59-
(defn request-subscribe-resource [context resource-uri]
148+
Args:
149+
context - The client session context
150+
resource-uri - URI of the resource to subscribe to
151+
152+
Returns:
153+
A promise that resolves when subscription is confirmed."
154+
[context resource-uri]
60155
(json-rpc/call-remote-method context {:method "resources/subscribe"
61156
:params {:uri resource-uri}}))
62157

63-
(defn request-unsubscribe-resource [context resource-uri]
158+
(defn request-unsubscribe-resource
159+
"Unsubscribes from changes for a specific resource on the MCP server.
160+
(see https://modelcontextprotocol.io/specification/2025-06-18/server/resources#subscriptions)
161+
162+
Args:
163+
context - The client session context
164+
resource-uri - URI of the resource to unsubscribe from
165+
166+
Returns:
167+
A promise that resolves when unsubscription is confirmed."
168+
[context resource-uri]
64169
(json-rpc/call-remote-method context {:method "resources/unsubscribe"
65170
:params {:uri resource-uri}}))
66171

67-
(defn request-tool-list [context]
172+
(defn request-tool-list
173+
"Requests the list of available tools from the MCP server.
174+
Updates the session's server-tool-by-name index and triggers the
175+
on-server-tool-list-updated callback.
176+
(see https://modelcontextprotocol.io/specification/2025-06-18/server/tools#listing-tools)
177+
178+
Args:
179+
context - The client session context
180+
181+
Returns:
182+
A promise that resolves when the tool descriptions are fetched and stored."
183+
[context]
68184
(let [{:keys [session]} context
69185
{:keys [server-capabilities]} @session]
70186
(when (contains? server-capabilities :prompts)
@@ -73,19 +189,60 @@
73189
(swap! session assoc :server-tool-by-name (mc/index-by :name tools))
74190
((user-callback :on-server-tool-list-updated) context)))))))
75191

76-
(defn request-tool-invocation [context tool-name arguments]
192+
(defn request-tool-invocation
193+
"Invokes a specific tool on the MCP server with given arguments.
194+
(see https://modelcontextprotocol.io/specification/2025-06-18/server/tools#calling-tools)
195+
196+
Args:
197+
context - The client session context
198+
tool-name - Name of the tool to invoke
199+
arguments - Map of arguments to pass to the tool
200+
201+
Returns:
202+
A promise that resolves to the tool execution result."
203+
[context tool-name arguments]
77204
(json-rpc/call-remote-method context {:method "tools/call"
78205
:params {:name tool-name
79206
:arguments arguments}}))
80207

81-
(defn notify-cancel-request [context request-id]
208+
(defn notify-cancel-request
209+
"Sends a cancellation notification for a specific request to the MCP server.
210+
(see https://modelcontextprotocol.io/specification/2025-06-18/basic/utilities/cancellation#cancellation-flow)
211+
212+
Args:
213+
context - The client session context
214+
request-id - ID of the request to cancel
215+
216+
Returns:
217+
nil"
218+
[context request-id]
82219
(json-rpc/send-message context (json-rpc/notification "cancelled"
83220
{:requestId request-id})))
84221

85-
(defn notify-root-list-updated [context]
222+
(defn notify-root-list-updated
223+
"Notifies the MCP server that the client's root list has been updated.
224+
(see https://modelcontextprotocol.io/specification/2025-06-18/client/roots#root-list-changes)
225+
226+
Args:
227+
context - The client session context
228+
229+
Returns:
230+
nil"
231+
[context]
86232
(json-rpc/send-message context (json-rpc/notification "roots/list_changed")))
87233

88-
(defn send-first-handshake-message [context]
234+
(defn send-first-handshake-message
235+
"Sends the initial handshake message to establish the MCP connection.
236+
Initializes the session with server capabilities and triggers the on-initialized callback
237+
upon receiving the server's response.
238+
(see https://modelcontextprotocol.io/specification/2025-06-18/architecture#capability-negotiation)
239+
240+
Args:
241+
context - The client session context
242+
243+
Returns:
244+
nil"
245+
[context]
89246
(let [{:keys [session]} context
90247
{:keys [client-info
91248
client-capabilities

0 commit comments

Comments
 (0)