turul_mcp_builders/
protocol_impls.rs1use crate::traits::*;
11use turul_mcp_protocol::completion::{
12 CompleteArgument, CompleteRequest, CompletionContext, CompletionReference,
13};
14use turul_mcp_protocol::notifications::{
15 CancelledNotification, Notification, ProgressNotification, PromptListChangedNotification,
16 ResourceListChangedNotification, ResourceUpdatedNotification, ToolListChangedNotification,
17};
18#[allow(deprecated)]
20use turul_mcp_protocol::roots::Root;
21use turul_mcp_protocol::{Prompt, Resource, Tool, ToolSchema};
22
23#[cfg(feature = "protocol-2025-11-25")]
24use turul_mcp_protocol::elicitation::{ElicitCreateRequest, ElicitationSchema};
25#[cfg(feature = "protocol-2025-11-25")]
26use turul_mcp_protocol::logging::{LoggingLevel, LoggingMessageNotification};
27#[cfg(feature = "protocol-2025-11-25")]
28use turul_mcp_protocol::notifications::{InitializedNotification, RootsListChangedNotification};
29#[cfg(feature = "protocol-2025-11-25")]
30use turul_mcp_protocol::sampling::{CreateMessageParams, ModelPreferences, SamplingMessage};
31#[cfg(feature = "protocol-2025-11-25")]
32use turul_mcp_protocol::tools::ToolExecution;
33
34impl HasResourceMetadata for Resource {
39 fn name(&self) -> &str {
40 &self.name
41 }
42
43 fn title(&self) -> Option<&str> {
44 self.title.as_deref()
45 }
46}
47
48impl HasResourceDescription for Resource {
49 fn description(&self) -> Option<&str> {
50 self.description.as_deref()
51 }
52}
53
54impl HasResourceUri for Resource {
55 fn uri(&self) -> &str {
56 &self.uri
57 }
58}
59
60impl HasResourceMimeType for Resource {
61 fn mime_type(&self) -> Option<&str> {
62 self.mime_type.as_deref()
63 }
64}
65
66impl HasResourceSize for Resource {
67 fn size(&self) -> Option<u64> {
68 self.size
69 }
70}
71
72impl HasResourceAnnotations for Resource {
73 fn annotations(&self) -> Option<&turul_mcp_protocol::meta::Annotations> {
74 self.annotations.as_ref()
75 }
76}
77
78impl HasResourceMeta for Resource {
79 fn resource_meta(&self) -> Option<&std::collections::HashMap<String, serde_json::Value>> {
80 self.meta.as_ref()
81 }
82}
83
84impl HasIcons for Resource {
85 fn icons(&self) -> Option<&Vec<turul_mcp_protocol::icons::Icon>> {
86 self.icons.as_ref()
87 }
88}
89
90impl HasPromptMetadata for Prompt {
97 fn name(&self) -> &str {
98 &self.name
99 }
100
101 fn title(&self) -> Option<&str> {
102 self.title.as_deref()
103 }
104}
105
106impl HasPromptDescription for Prompt {
107 fn description(&self) -> Option<&str> {
108 self.description.as_deref()
109 }
110}
111
112impl HasPromptArguments for Prompt {
113 fn arguments(&self) -> Option<&Vec<turul_mcp_protocol::prompts::PromptArgument>> {
114 self.arguments.as_ref()
115 }
116}
117
118impl HasPromptAnnotations for Prompt {
119 fn annotations(&self) -> Option<&crate::traits::prompt_traits::PromptAnnotations> {
120 None
122 }
123}
124
125impl HasPromptMeta for Prompt {
126 fn prompt_meta(&self) -> Option<&std::collections::HashMap<String, serde_json::Value>> {
127 self.meta.as_ref()
128 }
129}
130
131impl HasIcons for Prompt {
132 fn icons(&self) -> Option<&Vec<turul_mcp_protocol::icons::Icon>> {
133 self.icons.as_ref()
134 }
135}
136
137impl HasBaseMetadata for Tool {
144 fn name(&self) -> &str {
145 &self.name
146 }
147
148 fn title(&self) -> Option<&str> {
149 self.title.as_deref()
150 }
151}
152
153impl HasDescription for Tool {
154 fn description(&self) -> Option<&str> {
155 self.description.as_deref()
156 }
157}
158
159impl HasInputSchema for Tool {
160 fn input_schema(&self) -> &ToolSchema {
161 &self.input_schema
162 }
163}
164
165impl HasOutputSchema for Tool {
166 #[cfg(feature = "protocol-2025-11-25")]
167 fn output_schema(&self) -> Option<&ToolSchema> {
168 self.output_schema.as_ref()
169 }
170
171 #[cfg(feature = "protocol-2026-07-28")]
172 fn output_schema(&self) -> Option<&ToolSchema> {
173 None
174 }
175}
176
177impl HasAnnotations for Tool {
178 fn annotations(&self) -> Option<&turul_mcp_protocol::tools::ToolAnnotations> {
179 self.annotations.as_ref()
180 }
181}
182
183impl HasToolMeta for Tool {
184 fn tool_meta(&self) -> Option<&std::collections::HashMap<String, serde_json::Value>> {
185 self.meta.as_ref()
186 }
187}
188
189impl HasIcons for Tool {
190 fn icons(&self) -> Option<&Vec<turul_mcp_protocol::icons::Icon>> {
191 self.icons.as_ref()
192 }
193}
194
195#[cfg(feature = "protocol-2025-11-25")]
196impl HasExecution for Tool {
197 fn execution(&self) -> Option<ToolExecution> {
198 self.execution.clone()
199 }
200}
201
202#[allow(deprecated)]
209impl HasRootMetadata for Root {
210 fn name(&self) -> Option<&str> {
211 self.name.as_deref()
212 }
213
214 fn uri(&self) -> &str {
215 &self.uri
216 }
217}
218
219#[allow(deprecated)]
220impl HasRootPermissions for Root {
221 }
223
224#[allow(deprecated)]
225impl HasRootFiltering for Root {
226 }
228
229#[allow(deprecated)]
230impl HasRootAnnotations for Root {
231 fn annotations(&self) -> Option<&std::collections::HashMap<String, serde_json::Value>> {
232 self.meta.as_ref()
233 }
234}
235
236#[cfg(feature = "protocol-2025-11-25")]
243impl HasSamplingConfig for CreateMessageParams {
244 fn max_tokens(&self) -> u32 {
245 self.max_tokens
246 }
247
248 fn temperature(&self) -> Option<f64> {
249 self.temperature
250 }
251
252 fn stop_sequences(&self) -> Option<&Vec<String>> {
253 self.stop_sequences.as_ref()
254 }
255}
256
257#[cfg(feature = "protocol-2025-11-25")]
258impl HasSamplingContext for CreateMessageParams {
259 fn messages(&self) -> &[SamplingMessage] {
260 &self.messages
261 }
262
263 fn system_prompt(&self) -> Option<&str> {
264 self.system_prompt.as_deref()
265 }
266
267 fn include_context(&self) -> Option<&str> {
268 self.include_context.as_deref()
269 }
270}
271
272#[cfg(feature = "protocol-2025-11-25")]
273impl HasModelPreferences for CreateMessageParams {
274 fn model_preferences(&self) -> Option<&ModelPreferences> {
275 self.model_preferences.as_ref()
276 }
277
278 fn metadata(&self) -> Option<&serde_json::Value> {
279 self.metadata.as_ref()
280 }
281}
282
283#[cfg(feature = "protocol-2025-11-25")]
284impl HasSamplingTools for CreateMessageParams {
285 fn tools(&self) -> Option<&Vec<turul_mcp_protocol::Tool>> {
286 self.tools.as_ref()
287 }
288}
289
290#[cfg(feature = "protocol-2025-11-25")]
293impl HasSamplingMessageMetadata for SamplingMessage {
294 fn role(&self) -> &turul_mcp_protocol::sampling::Role {
295 &self.role
296 }
297
298 fn content(&self) -> &turul_mcp_protocol::prompts::ContentBlock {
299 &self.content
300 }
301}
302
303#[cfg(feature = "protocol-2025-11-25")]
308impl HasLoggingMetadata for LoggingMessageNotification {
309 fn method(&self) -> &str {
310 &self.method
311 }
312
313 fn logger_name(&self) -> Option<&str> {
314 self.params.logger.as_deref()
315 }
316}
317
318#[cfg(feature = "protocol-2025-11-25")]
319impl HasLogLevel for LoggingMessageNotification {
320 fn level(&self) -> LoggingLevel {
321 self.params.level
322 }
323}
324
325#[cfg(feature = "protocol-2025-11-25")]
326impl HasLogFormat for LoggingMessageNotification {
327 fn data(&self) -> &serde_json::Value {
328 &self.params.data
329 }
330}
331
332#[cfg(feature = "protocol-2025-11-25")]
333impl HasLogTransport for LoggingMessageNotification {
334 }
336
337impl HasCompletionMetadata for CompleteRequest {
344 fn method(&self) -> &str {
345 &self.method
346 }
347
348 fn reference(&self) -> &CompletionReference {
349 &self.params.reference
350 }
351}
352
353impl HasCompletionContext for CompleteRequest {
354 fn argument(&self) -> &CompleteArgument {
355 &self.params.argument
356 }
357
358 fn context(&self) -> Option<&CompletionContext> {
359 self.params.context.as_ref()
360 }
361}
362
363impl HasCompletionHandling for CompleteRequest {
364 }
366
367#[cfg(feature = "protocol-2025-11-25")]
374impl HasElicitationMetadata for ElicitCreateRequest {
375 fn message(&self) -> &str {
376 &self.params.message
377 }
378
379 }
381
382#[cfg(feature = "protocol-2025-11-25")]
383impl HasElicitationSchema for ElicitCreateRequest {
384 fn requested_schema(&self) -> &ElicitationSchema {
385 &self.params.requested_schema
386 }
387}
388
389#[cfg(feature = "protocol-2025-11-25")]
390impl HasElicitationHandling for ElicitCreateRequest {
391 }
393
394impl HasNotificationMetadata for Notification {
402 fn method(&self) -> &str {
403 &self.method
404 }
405}
406
407impl HasNotificationPayload for Notification {
408 fn payload(&self) -> Option<serde_json::Value> {
409 self.params.as_ref().map(|params| {
410 let mut map = serde_json::Map::new();
411
412 for (key, value) in ¶ms.other {
414 map.insert(key.clone(), value.clone());
415 }
416
417 if let Some(meta) = ¶ms.meta
419 && let Ok(meta_value) = serde_json::to_value(meta)
420 {
421 map.insert("_meta".to_string(), meta_value);
422 }
423
424 serde_json::Value::Object(map)
425 })
426 }
427}
428
429impl HasNotificationRules for Notification {}
430
431impl HasNotificationMetadata for ResourceListChangedNotification {
433 fn method(&self) -> &str {
434 &self.method
435 }
436}
437
438impl HasNotificationPayload for ResourceListChangedNotification {
439 fn payload(&self) -> Option<serde_json::Value> {
440 self.params
442 .as_ref()
443 .and_then(|p| serde_json::to_value(p).ok())
444 }
445}
446
447impl HasNotificationRules for ResourceListChangedNotification {}
448
449impl HasNotificationMetadata for ToolListChangedNotification {
451 fn method(&self) -> &str {
452 &self.method
453 }
454}
455
456impl HasNotificationPayload for ToolListChangedNotification {
457 fn payload(&self) -> Option<serde_json::Value> {
458 self.params
460 .as_ref()
461 .and_then(|p| serde_json::to_value(p).ok())
462 }
463}
464
465impl HasNotificationRules for ToolListChangedNotification {}
466
467impl HasNotificationMetadata for PromptListChangedNotification {
469 fn method(&self) -> &str {
470 &self.method
471 }
472}
473
474impl HasNotificationPayload for PromptListChangedNotification {
475 fn payload(&self) -> Option<serde_json::Value> {
476 self.params
478 .as_ref()
479 .and_then(|p| serde_json::to_value(p).ok())
480 }
481}
482
483impl HasNotificationRules for PromptListChangedNotification {}
484
485#[cfg(feature = "protocol-2025-11-25")]
487impl HasNotificationMetadata for RootsListChangedNotification {
488 fn method(&self) -> &str {
489 &self.method
490 }
491}
492
493#[cfg(feature = "protocol-2025-11-25")]
494impl HasNotificationPayload for RootsListChangedNotification {
495 fn payload(&self) -> Option<serde_json::Value> {
496 self.params
498 .as_ref()
499 .and_then(|p| serde_json::to_value(p).ok())
500 }
501}
502
503#[cfg(feature = "protocol-2025-11-25")]
504impl HasNotificationRules for RootsListChangedNotification {}
505
506impl HasNotificationMetadata for ProgressNotification {
508 fn method(&self) -> &str {
509 &self.method
510 }
511}
512
513impl HasNotificationPayload for ProgressNotification {
514 fn payload(&self) -> Option<serde_json::Value> {
515 serde_json::to_value(&self.params).ok()
517 }
518}
519
520impl HasNotificationRules for ProgressNotification {
521 fn priority(&self) -> u32 {
522 2 }
524}
525
526impl HasNotificationMetadata for ResourceUpdatedNotification {
528 fn method(&self) -> &str {
529 &self.method
530 }
531}
532
533impl HasNotificationPayload for ResourceUpdatedNotification {
534 fn payload(&self) -> Option<serde_json::Value> {
535 serde_json::to_value(&self.params).ok()
537 }
538}
539
540impl HasNotificationRules for ResourceUpdatedNotification {}
541
542impl HasNotificationMetadata for CancelledNotification {
544 fn method(&self) -> &str {
545 &self.method
546 }
547}
548
549impl HasNotificationPayload for CancelledNotification {
550 fn payload(&self) -> Option<serde_json::Value> {
551 serde_json::to_value(&self.params).ok()
553 }
554}
555
556impl HasNotificationRules for CancelledNotification {
557 fn priority(&self) -> u32 {
558 3 }
560}
561
562#[cfg(feature = "protocol-2025-11-25")]
564impl HasNotificationMetadata for InitializedNotification {
565 fn method(&self) -> &str {
566 &self.method
567 }
568}
569
570#[cfg(feature = "protocol-2025-11-25")]
571impl HasNotificationPayload for InitializedNotification {
572 fn payload(&self) -> Option<serde_json::Value> {
573 self.params
575 .as_ref()
576 .and_then(|p| serde_json::to_value(p).ok())
577 }
578}
579
580#[cfg(feature = "protocol-2025-11-25")]
581impl HasNotificationRules for InitializedNotification {
582 fn priority(&self) -> u32 {
583 3 }
585}
586
587