Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
//! Types that describes server and client capabilities

use serde::{Deserialize, Serialize};
use std::collections::HashMap;

/// Represents the capabilities that a client may support.
///
/// See the [schema](https://github.com/modelcontextprotocol/specification/blob/main/schema/) for details
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ClientCapabilities {
    /// Gets or sets the client's roots capability, which are entry points for resource navigation.
    ///
    /// > **Note:** When `roots` is `Some`, the client indicates that it can respond to
    /// > server requests for listing root URIs. Root URIs serve as entry points for resource navigation in the protocol.
    /// >
    /// > The server can use `RequestRoots` to request the list of
    /// > available roots from the client, which will trigger the client's `RootsHandler`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub roots: Option<RootsCapability>,

    /// Gets or sets the client's sampling capability, which indicates whether the client
    /// supports issuing requests to an LLM on behalf of the server.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sampling: Option<SamplingCapability>,

    /// Gets or sets the client's elicitation capability, which indicates whether the client
    /// supports elicitation of additional information from the user on behalf of the server.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub elicitation: Option<ElicitationCapability>,

    /// Present if the client supports task-augmented requests.
    #[cfg(feature = "tasks")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tasks: Option<ClientTasksCapability>,

    /// Gets or sets experimental, non-standard capabilities that the client supports.
    ///
    /// > **Note:** The `experimental` map allows clients to advertise support for features that are not yet
    /// > standardized in the Model Context Protocol specification. This extension mechanism enables
    /// > future protocol enhancements while maintaining backward compatibility.
    /// >
    /// > Values in this map are implementation-specific and should be coordinated between client
    /// > and server implementations. Servers should not assume the presence of any experimental capability
    /// > without checking for it first.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub experimental: Option<HashMap<String, serde_json::Value>>,
}

/// Represents a client capability that enables root resource discovery in the Model Context Protocol.
///
/// > **Note:** When present in [`ClientCapabilities`], it indicates that the client supports listing
/// > root URIs that serve as entry points for resource navigation.
/// >
/// > The roots capability establishes a mechanism for servers to discover and access the hierarchical
/// > structure of resources provided by a client. Root URIs represent top-level entry points from which
/// > servers can navigate to access specific resources.
///
/// See the [schema](https://github.com/modelcontextprotocol/specification/blob/main/schema/) for details
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct RootsCapability {
    /// Indicates whether the client supports notifications for changes to the roots list.
    ///
    /// > **Note:** When set to `true`, the client can notify servers when roots are added,
    /// > removed, or modified, allowing servers to refresh their roots cache accordingly.
    /// > This enables servers to stay synchronized with client-side changes to available roots.
    #[serde(default, rename = "listChanged")]
    pub list_changed: bool,
}

/// Represents the capability for a client to generate text or other content using an AI model.
///
/// > **Note:** This capability enables the MCP client to respond to sampling requests from an MCP server.
/// >
/// > When this capability is enabled, an MCP server can request the client to generate content
/// > using an AI model. The client must set a `SamplingHandler` to process these requests.
///
/// See the [schema](https://github.com/modelcontextprotocol/specification/blob/main/schema/) for details
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct SamplingCapability {
    /// Indicates whether the client supports context inclusion via `includeContext` parameter.
    #[serde(skip_serializing_if = "Option::is_none")]
    context: Option<SamplingContextCapability>,

    /// Indicates whether the client supports tool use via `tools` and `toolChoice` parameters.
    #[serde(skip_serializing_if = "Option::is_none")]
    tools: Option<SamplingToolsCapability>,
}

/// Represents the sampling context capability.
///
/// See the [schema](https://github.com/modelcontextprotocol/specification/blob/main/schema/) for details
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct SamplingContextCapability {
    // Currently empty in the spec, but may be extended in the future
}

/// Represents the sampling tools capability.
///
/// See the [schema](https://github.com/modelcontextprotocol/specification/blob/main/schema/) for details
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct SamplingToolsCapability {
    // Currently empty in the spec, but may be extended in the future
}

/// Represents the capability for a client to provide server-requested additional information during interactions.
///
/// > **Note:** This capability enables the MCP client to respond to elicitation requests from an MCP server.
/// >
/// > When this capability is enabled, an MCP server can request the client to provide additional information
/// > during interactions.
///
/// See the [schema](https://github.com/modelcontextprotocol/specification/blob/main/schema/) for details
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct ElicitationCapability {
    /// Indicates whether the client supports `form` mode elicitation.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub form: Option<ElicitationFormCapability>,

    /// Indicates whether the client supports `url` mode elicitation.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub url: Option<ElicitationUrlCapability>,
}

/// Represents elicitation form capability.
///
/// See the [schema](https://github.com/modelcontextprotocol/specification/blob/main/schema/) for details
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct ElicitationFormCapability {
    // Currently empty in the spec, but may be extended in the future.
}

/// Represents elicitation URL capability
///
/// See the [schema](https://github.com/modelcontextprotocol/specification/blob/main/schema/) for details
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct ElicitationUrlCapability {
    // Currently empty in the spec, but may be extended in the future.
}

/// Represents the capabilities that a server may support.
///
/// > **Note:** Server capabilities define the features and functionality available when clients connect.
/// > These capabilities are advertised to clients during the initialize handshake.
///
/// See the [schema](https://github.com/modelcontextprotocol/specification/blob/main/schema/) for details
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ServerCapabilities {
    /// Present if the server offers any tools to call.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tools: Option<ToolsCapability>,

    /// Present if the server offers any prompt templates.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub prompts: Option<PromptsCapability>,

    /// Present if the server offers any resources to read.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub resources: Option<ResourcesCapability>,

    /// Present if the server supports sending log messages to the client.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub logging: Option<LoggingCapability>,

    /// Present if the server supports argument autocompletion suggestions.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub completions: Option<CompletionsCapability>,

    /// Present if the server supports task-augmented requests.
    #[cfg(feature = "tasks")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tasks: Option<ServerTasksCapability>,

    /// Indicates experimental, non-standard capabilities that the server supports.
    ///
    /// > **Note:** The `experimental` map allows servers to advertise support for features that are not yet
    /// > standardized in the Model Context Protocol specification. This extension mechanism enables
    /// > future protocol enhancements while maintaining backward compatibility.
    /// >
    /// > Values in this dictionary are implementation-specific and should be coordinated between client
    /// > and server implementations. Clients should not assume the presence of any experimental capability
    /// > without checking for it first.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub experimental: Option<HashMap<String, serde_json::Value>>,
}

/// Represents the tools capability configuration.
///
/// See the [schema](https://github.com/modelcontextprotocol/specification/blob/main/schema/) for details
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct ToolsCapability {
    /// Indicates whether this server supports notifications for changes to the tool list.
    #[serde(default, rename = "listChanged")]
    pub list_changed: bool,
}

/// Represents the prompts capability configuration.
///
/// See the [schema](https://github.com/modelcontextprotocol/specification/blob/main/schema/) for details
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct PromptsCapability {
    /// Indicates whether this server supports notifications for changes to the prompt list.
    #[serde(default, rename = "listChanged")]
    pub list_changed: bool,
}

/// Represents the resources capability configuration.
///
/// See the [schema](https://github.com/modelcontextprotocol/specification/blob/main/schema/) for details
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct ResourcesCapability {
    /// Indicates whether this server supports notifications for changes to the resource list.
    #[serde(default, rename = "listChanged")]
    pub list_changed: bool,

    /// Indicates whether this server supports subscribing to resource updates.
    pub subscribe: bool,
}

/// Represents the logging capability configuration.
///
/// See the [schema](https://github.com/modelcontextprotocol/specification/blob/main/schema/) for details
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct LoggingCapability {
    // Currently empty in the spec, but may be extended in the future
}

/// Represents the completions capability configuration.
///
/// See the [schema](https://github.com/modelcontextprotocol/specification/blob/main/schema/) for details
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct CompletionsCapability {
    // Currently empty in the spec, but may be extended in the future
}

/// Represents task-augmented requests capability configuration for a server.
///
/// See the [schema](https://github.com/modelcontextprotocol/specification/blob/main/schema/) for details
#[cfg(feature = "tasks")]
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct ServerTasksCapability {
    /// Indicates whether this server supports `tasks/cancel`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cancel: Option<TaskCancellationCapability>,

    /// Indicates whether this server supports `tasks/list`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub list: Option<TaskListCapability>,

    /// Specifies which request types can be augmented with tasks.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub requests: Option<ServerTaskRequestsCapability>,
}

/// Represents task-augmented requests capability configuration for a client.
///
/// See the [schema](https://github.com/modelcontextprotocol/specification/blob/main/schema/) for details
#[cfg(feature = "tasks")]
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct ClientTasksCapability {
    /// Indicates whether this client supports `tasks/cancel`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cancel: Option<TaskCancellationCapability>,

    /// Indicates whether this client supports `tasks/list`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub list: Option<TaskListCapability>,

    /// Specifies which request types can be augmented with tasks.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub requests: Option<ClientTaskRequestsCapability>,
}

/// Represents task cancellation capability configuration.
///
/// See the [schema](https://github.com/modelcontextprotocol/specification/blob/main/schema/) for details
#[cfg(feature = "tasks")]
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct TaskCancellationCapability {
    // Currently empty in the spec, but may be extended in the future
}

/// Represents task list retrieval capability configuration.
///
/// See the [schema](https://github.com/modelcontextprotocol/specification/blob/main/schema/) for details
#[cfg(feature = "tasks")]
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct TaskListCapability {
    // Currently empty in the spec, but may be extended in the future
}

/// Specifies which request types can be augmented with tasks.
///
/// See the [schema](https://github.com/modelcontextprotocol/specification/blob/main/schema/) for details
#[cfg(feature = "tasks")]
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct ServerTaskRequestsCapability {
    /// Specifies task support for tool-related requests.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tools: Option<ToolsTaskCapability>,
}

/// Specifies which request types can be augmented with tasks.
///
/// See the [schema](https://github.com/modelcontextprotocol/specification/blob/main/schema/) for details
#[cfg(feature = "tasks")]
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct ClientTaskRequestsCapability {
    /// Specifies task support for elicitation-related requests.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub elicitation: Option<ElicitationTaskCapability>,

    /// Specifies task support for sampling-related requests.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sampling: Option<SamplingTaskCapability>,
}

/// Specifies task support for tool-related requests.
///
/// See the [schema](https://github.com/modelcontextprotocol/specification/blob/main/schema/) for details
#[cfg(feature = "tasks")]
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct ToolsTaskCapability {
    /// Indicates whether the server supports task-augmented `tools/call` requests.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub call: Option<ToolsCallTaskCapability>,
}

/// Specifies task support for elicitation-related requests.
///
/// See the [schema](https://github.com/modelcontextprotocol/specification/blob/main/schema/) for details
#[cfg(feature = "tasks")]
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct ElicitationTaskCapability {
    /// Indicates whether the client supports task-augmented `elicitation/create` requests.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub create: Option<ElicitationCreateTaskCapability>,
}

/// Specifies task support for sampling-related requests.
///
/// See the [schema](https://github.com/modelcontextprotocol/specification/blob/main/schema/) for details
#[cfg(feature = "tasks")]
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct SamplingTaskCapability {
    /// Indicates whether the client supports task-augmented `sampling/createMessage` requests.
    #[serde(rename = "createMessage", skip_serializing_if = "Option::is_none")]
    pub create: Option<SamplingCreateMessageTaskCapability>,
}

/// Represents task support configuration for `tools/call` requests.
///
/// See the [schema](https://github.com/modelcontextprotocol/specification/blob/main/schema/) for details
#[cfg(feature = "tasks")]
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct ToolsCallTaskCapability {
    // Currently empty in the spec, but may be extended in the future
}

/// Represents task support configuration for `elicitation/create` requests.
///
/// See the [schema](https://github.com/modelcontextprotocol/specification/blob/main/schema/) for details
#[cfg(feature = "tasks")]
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct ElicitationCreateTaskCapability {
    // Currently empty in the spec, but may be extended in the future
}

/// Represents task support configuration for `sampling/createMessage` requests.
///
/// See the [schema](https://github.com/modelcontextprotocol/specification/blob/main/schema/) for details
#[cfg(feature = "tasks")]
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct SamplingCreateMessageTaskCapability {
    // Currently empty in the spec, but may be extended in the future
}

#[cfg(feature = "server")]
impl ToolsCapability {
    /// Specifies whether this server supports notifications for changes to the tools list.
    ///
    /// Default: _false_
    pub fn with_list_changed(mut self) -> Self {
        self.list_changed = true;
        self
    }
}

#[cfg(feature = "server")]
impl ResourcesCapability {
    /// Specifies whether this server supports notifications for changes to the resource list.
    ///
    /// Default: _false_
    pub fn with_list_changed(mut self) -> Self {
        self.list_changed = true;
        self
    }

    /// Specifies whether this server supports subscribing to resource updates.
    ///
    /// Default: _false_
    pub fn with_subscribe(mut self) -> Self {
        self.subscribe = true;
        self
    }
}

#[cfg(feature = "server")]
impl PromptsCapability {
    /// Specifies whether this server supports notifications for changes to the prompts list.
    ///
    /// Default: _false_
    pub fn with_list_changed(mut self) -> Self {
        self.list_changed = true;
        self
    }
}

#[cfg(feature = "client")]
impl RootsCapability {
    /// Specifies whether this client supports notifications for changes to the roots list.
    ///
    /// Default: _false_
    pub fn with_list_changed(mut self) -> Self {
        self.list_changed = true;
        self
    }
}

#[cfg(feature = "client")]
impl SamplingCapability {
    /// Specifies whether this client supports context inclusion.
    ///
    /// Default: `None`
    pub fn with_context(mut self) -> Self {
        self.context = Some(SamplingContextCapability {});
        self
    }

    /// Specifies whether this client supports the tool use feature.
    ///
    /// Default: `None`
    pub fn with_tools(mut self) -> Self {
        self.tools = Some(SamplingToolsCapability {});
        self
    }
}

#[cfg(feature = "client")]
impl ElicitationCapability {
    /// Specifies whether this client supports `form` elicitation mode.
    ///
    /// Default: `None`
    pub fn with_form(mut self) -> Self {
        self.form = Some(ElicitationFormCapability {});
        self
    }

    /// Specifies whether this client supports `url` elicitation mode.
    ///
    /// Default: `None`
    pub fn with_url(mut self) -> Self {
        self.url = Some(ElicitationUrlCapability {});
        self
    }
}

#[cfg(all(feature = "server", feature = "tasks"))]
impl ServerTasksCapability {
    /// Specifies whether this server supports `tasks/cancel` requests
    pub fn with_cancel(mut self) -> Self {
        self.cancel = Some(TaskCancellationCapability {});
        self
    }

    /// Specifies whether this server supports `tasks/list` requests
    pub fn with_list(mut self) -> Self {
        self.list = Some(TaskListCapability {});
        self
    }

    /// Specifies whether this server supports task-augmented requests
    pub fn with_requests<F>(mut self, config: F) -> Self
    where
        F: FnOnce(ServerTaskRequestsCapability) -> ServerTaskRequestsCapability,
    {
        self.requests = Some(config(Default::default()));
        self
    }

    /// Specifies whether this server supports task-augmented tools-related requests
    pub fn with_tools(self) -> Self {
        self.with_requests(|req| req.with_tools())
    }

    /// Specifies whether this server supports all task-augmented capabilities
    pub fn with_all(self) -> Self {
        self.with_cancel().with_list().with_tools()
    }
}

#[cfg(all(feature = "client", feature = "tasks"))]
impl ClientTasksCapability {
    /// Specifies whether this client supports `tasks/cancel` requests
    pub fn with_cancel(mut self) -> Self {
        self.cancel = Some(TaskCancellationCapability {});
        self
    }

    /// Specifies whether this client supports `tasks/list` requests
    pub fn with_list(mut self) -> Self {
        self.list = Some(TaskListCapability {});
        self
    }

    /// Specifies whether this client supports task-augmented requests
    pub fn with_requests<F>(mut self, config: F) -> Self
    where
        F: FnOnce(ClientTaskRequestsCapability) -> ClientTaskRequestsCapability,
    {
        self.requests = Some(config(Default::default()));
        self
    }

    /// Specifies whether this client supports task-augmented elicitation-related requests
    pub fn with_elicitation(self) -> Self {
        self.with_requests(|req| req.with_elicitation())
    }

    /// Specifies whether this client supports task-augmented sampling-related requests
    pub fn with_sampling(self) -> Self {
        self.with_requests(|req| req.with_sampling())
    }

    /// Specifies whether this client supports all task-augmented capabilities
    pub fn with_all(self) -> Self {
        self.with_cancel()
            .with_list()
            .with_elicitation()
            .with_sampling()
    }
}

#[cfg(all(feature = "server", feature = "tasks"))]
impl ServerTaskRequestsCapability {
    /// Specifies task support for tool-related requests.
    pub fn with_tools(mut self) -> Self {
        self.tools = Some(ToolsTaskCapability {
            call: Some(ToolsCallTaskCapability {}),
        });
        self
    }
}

#[cfg(all(feature = "client", feature = "tasks"))]
impl ClientTaskRequestsCapability {
    /// Specifies task support for elicitation-related requests.
    pub fn with_elicitation(mut self) -> Self {
        self.elicitation = Some(ElicitationTaskCapability {
            create: Some(ElicitationCreateTaskCapability {}),
        });
        self
    }

    /// Specifies task support for sampling-related requests.
    pub fn with_sampling(mut self) -> Self {
        self.sampling = Some(SamplingTaskCapability {
            create: Some(SamplingCreateMessageTaskCapability {}),
        });
        self
    }
}