|
5 | 5 | [mcp-toolkit.impl.common :refer [user-callback]] |
6 | 6 | [promesa.core :as p])) |
7 | 7 |
|
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] |
9 | 19 | (json-rpc/call-remote-method context {:method "logging/setLevel" |
10 | 20 | :params {:level level}})) |
11 | 21 |
|
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] |
14 | 36 | (json-rpc/call-remote-method context {:method "completion/complete" |
15 | 37 | :params {:ref {:type "ref/prompt" |
16 | 38 | :name prompt-name} |
17 | 39 | :argument {:name param-name |
18 | 40 | :value param-value}}})) |
19 | 41 |
|
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] |
22 | 56 | (json-rpc/call-remote-method context {:method "completion/complete" |
23 | 57 | :params {:ref {:type "ref/resource" |
24 | 58 | :uri uri-template} |
25 | 59 | :argument {:name param-name |
26 | 60 | :value param-value}}})) |
27 | 61 |
|
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] |
29 | 74 | (let [{:keys [session]} context |
30 | 75 | {:keys [server-capabilities]} @session] |
31 | 76 | (when (contains? server-capabilities :prompts) |
|
34 | 79 | (swap! session assoc :server-prompt-by-name (mc/index-by :name prompts)) |
35 | 80 | ((user-callback :on-server-prompt-list-updated) context))))))) |
36 | 81 |
|
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] |
38 | 94 | (json-rpc/call-remote-method context {:method "prompts/get" |
39 | 95 | :params {:name prompt-name |
40 | 96 | :arguments arguments}})) |
41 | 97 |
|
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] |
43 | 110 | (let [{:keys [session]} context |
44 | 111 | {:keys [server-capabilities]} @session] |
45 | 112 | (when (contains? server-capabilities :resources) |
|
48 | 115 | (swap! session assoc :server-resource-by-uri (mc/index-by :uri resources)) |
49 | 116 | ((user-callback :on-server-resource-list-updated) context))))))) |
50 | 117 |
|
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] |
52 | 129 | (json-rpc/call-remote-method context {:method "resources/read" |
53 | 130 | :params {:uri resource-uri}})) |
54 | 131 |
|
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] |
56 | 142 | (json-rpc/call-remote-method context {:method "resources/templates/list"})) |
57 | 143 |
|
| 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) |
58 | 147 |
|
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] |
60 | 155 | (json-rpc/call-remote-method context {:method "resources/subscribe" |
61 | 156 | :params {:uri resource-uri}})) |
62 | 157 |
|
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] |
64 | 169 | (json-rpc/call-remote-method context {:method "resources/unsubscribe" |
65 | 170 | :params {:uri resource-uri}})) |
66 | 171 |
|
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] |
68 | 184 | (let [{:keys [session]} context |
69 | 185 | {:keys [server-capabilities]} @session] |
70 | 186 | (when (contains? server-capabilities :prompts) |
|
73 | 189 | (swap! session assoc :server-tool-by-name (mc/index-by :name tools)) |
74 | 190 | ((user-callback :on-server-tool-list-updated) context))))))) |
75 | 191 |
|
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] |
77 | 204 | (json-rpc/call-remote-method context {:method "tools/call" |
78 | 205 | :params {:name tool-name |
79 | 206 | :arguments arguments}})) |
80 | 207 |
|
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] |
82 | 219 | (json-rpc/send-message context (json-rpc/notification "cancelled" |
83 | 220 | {:requestId request-id}))) |
84 | 221 |
|
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] |
86 | 232 | (json-rpc/send-message context (json-rpc/notification "roots/list_changed"))) |
87 | 233 |
|
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] |
89 | 246 | (let [{:keys [session]} context |
90 | 247 | {:keys [client-info |
91 | 248 | client-capabilities |
|
0 commit comments