mcplint 0.4.0

MCP Server Testing, Fuzzing, and Security Scanning Platform
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
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
//! MCP (Model Context Protocol) message types
//! Based on MCP Specification 2025-03-26

use serde::{Deserialize, Serialize};
use serde_json::Value;

/// Supported MCP protocol versions
pub const PROTOCOL_VERSION_2024_11_05: &str = "2024-11-05";
pub const PROTOCOL_VERSION_2025_03_26: &str = "2025-03-26";
pub const LATEST_PROTOCOL_VERSION: &str = PROTOCOL_VERSION_2025_03_26;

/// Check if a protocol version is supported
pub fn is_supported_version(version: &str) -> bool {
    matches!(
        version,
        PROTOCOL_VERSION_2024_11_05 | PROTOCOL_VERSION_2025_03_26
    )
}

// ============================================================================
// Common Types
// ============================================================================

/// Implementation info (client or server)
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Implementation {
    pub name: String,
    pub version: String,
}

impl Implementation {
    pub fn new(name: impl Into<String>, version: impl Into<String>) -> Self {
        Self {
            name: name.into(),
            version: version.into(),
        }
    }
}

// ============================================================================
// Initialize
// ============================================================================

/// Initialize request parameters
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct InitializeParams {
    pub protocol_version: String,
    pub capabilities: ClientCapabilities,
    pub client_info: Implementation,
}

impl InitializeParams {
    pub fn new(client_info: Implementation, capabilities: ClientCapabilities) -> Self {
        Self {
            protocol_version: LATEST_PROTOCOL_VERSION.to_string(),
            capabilities,
            client_info,
        }
    }
}

/// Initialize result from server
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct InitializeResult {
    pub protocol_version: String,
    pub capabilities: ServerCapabilities,
    pub server_info: Implementation,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub instructions: Option<String>,
}

// ============================================================================
// Capabilities
// ============================================================================

/// Client capabilities advertised during initialization
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ClientCapabilities {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub roots: Option<RootsCapability>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sampling: Option<SamplingCapability>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub experimental: Option<Value>,
}

/// Server capabilities advertised during initialization
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ServerCapabilities {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub prompts: Option<PromptsCapability>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub resources: Option<ResourcesCapability>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tools: Option<ToolsCapability>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub logging: Option<LoggingCapability>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub completions: Option<CompletionsCapability>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub experimental: Option<Value>,
}

impl ServerCapabilities {
    pub fn has_tools(&self) -> bool {
        self.tools.is_some()
    }

    pub fn has_resources(&self) -> bool {
        self.resources.is_some()
    }

    pub fn has_prompts(&self) -> bool {
        self.prompts.is_some()
    }
}

/// Roots capability (client)
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RootsCapability {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub list_changed: Option<bool>,
}

/// Sampling capability (client)
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct SamplingCapability {}

/// Prompts capability (server)
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PromptsCapability {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub list_changed: Option<bool>,
}

/// Resources capability (server)
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ResourcesCapability {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub subscribe: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub list_changed: Option<bool>,
}

/// Tools capability (server)
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ToolsCapability {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub list_changed: Option<bool>,
}

/// Logging capability (server)
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct LoggingCapability {}

/// Completions capability (server)
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct CompletionsCapability {}

// ============================================================================
// Tools
// ============================================================================

/// Tool definition from server
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Tool {
    pub name: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    pub input_schema: Value,
}

/// Result of tools/list
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ListToolsResult {
    pub tools: Vec<Tool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_cursor: Option<String>,
}

/// Parameters for tools/call
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CallToolParams {
    pub name: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub arguments: Option<Value>,
}

impl CallToolParams {
    pub fn new(name: impl Into<String>) -> Self {
        Self {
            name: name.into(),
            arguments: None,
        }
    }

    pub fn with_arguments(mut self, arguments: Value) -> Self {
        self.arguments = Some(arguments);
        self
    }
}

/// Result of tools/call
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CallToolResult {
    pub content: Vec<Content>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub is_error: Option<bool>,
}

// ============================================================================
// Resources
// ============================================================================

/// Resource definition from server
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Resource {
    pub uri: String,
    pub name: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub mime_type: Option<String>,
}

/// Result of resources/list
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ListResourcesResult {
    pub resources: Vec<Resource>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_cursor: Option<String>,
}

/// Parameters for resources/read
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReadResourceParams {
    pub uri: String,
}

/// Result of resources/read
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ReadResourceResult {
    pub contents: Vec<ResourceContent>,
}

/// Resource content
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ResourceContent {
    pub uri: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub mime_type: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub text: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub blob: Option<String>,
}

// ============================================================================
// Prompts
// ============================================================================

/// Prompt definition from server
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Prompt {
    pub name: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub arguments: Option<Vec<PromptArgument>>,
}

/// Prompt argument definition
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PromptArgument {
    pub name: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub required: Option<bool>,
}

/// Result of prompts/list
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ListPromptsResult {
    pub prompts: Vec<Prompt>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_cursor: Option<String>,
}

/// Parameters for prompts/get
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GetPromptParams {
    pub name: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub arguments: Option<Value>,
}

/// Result of prompts/get
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GetPromptResult {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    pub messages: Vec<PromptMessage>,
}

/// Message in a prompt result
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PromptMessage {
    pub role: Role,
    pub content: Content,
}

// ============================================================================
// Content Types
// ============================================================================

/// Message role
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum Role {
    User,
    Assistant,
}

/// Content in tool results and prompts
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "lowercase")]
pub enum Content {
    Text {
        text: String,
    },
    Image {
        data: String,
        #[serde(rename = "mimeType")]
        mime_type: String,
    },
    Resource {
        resource: ResourceContent,
    },
}

impl Content {
    pub fn text(text: impl Into<String>) -> Self {
        Content::Text { text: text.into() }
    }

    pub fn image(data: String, mime_type: String) -> Self {
        Content::Image { data, mime_type }
    }
}

// ============================================================================
// Pagination
// ============================================================================

/// Common pagination parameters
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct PaginationParams {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cursor: Option<String>,
}

// ============================================================================
// Method Names
// ============================================================================

pub mod methods {
    // Lifecycle
    pub const INITIALIZE: &str = "initialize";
    pub const INITIALIZED: &str = "notifications/initialized";
    pub const PING: &str = "ping";

    // Tools
    pub const TOOLS_LIST: &str = "tools/list";
    pub const TOOLS_CALL: &str = "tools/call";

    // Resources
    pub const RESOURCES_LIST: &str = "resources/list";
    pub const RESOURCES_READ: &str = "resources/read";
    pub const RESOURCES_SUBSCRIBE: &str = "resources/subscribe";
    pub const RESOURCES_UNSUBSCRIBE: &str = "resources/unsubscribe";

    // Prompts
    pub const PROMPTS_LIST: &str = "prompts/list";
    pub const PROMPTS_GET: &str = "prompts/get";

    // Logging
    pub const LOGGING_SET_LEVEL: &str = "logging/setLevel";

    // Notifications
    pub const NOTIFICATION_CANCELLED: &str = "notifications/cancelled";
    pub const NOTIFICATION_PROGRESS: &str = "notifications/progress";
    pub const NOTIFICATION_RESOURCES_UPDATED: &str = "notifications/resources/updated";
    pub const NOTIFICATION_RESOURCES_LIST_CHANGED: &str = "notifications/resources/list_changed";
    pub const NOTIFICATION_TOOLS_LIST_CHANGED: &str = "notifications/tools/list_changed";
    pub const NOTIFICATION_PROMPTS_LIST_CHANGED: &str = "notifications/prompts/list_changed";
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn serialize_initialize_params() {
        let params = InitializeParams::new(
            Implementation::new("test-client", "1.0.0"),
            ClientCapabilities::default(),
        );
        let json = serde_json::to_string(&params).unwrap();
        assert!(json.contains("protocolVersion"));
        assert!(json.contains("2025-03-26"));
        assert!(json.contains("test-client"));
    }

    #[test]
    fn deserialize_initialize_result() {
        let json = r#"{
            "protocolVersion": "2025-03-26",
            "capabilities": {
                "tools": {"listChanged": true},
                "resources": {"subscribe": true}
            },
            "serverInfo": {"name": "test-server", "version": "1.0.0"},
            "instructions": "Test instructions"
        }"#;

        let result: InitializeResult = serde_json::from_str(json).unwrap();
        assert_eq!(result.protocol_version, "2025-03-26");
        assert!(result.capabilities.has_tools());
        assert!(result.capabilities.has_resources());
        assert_eq!(result.server_info.name, "test-server");
        assert_eq!(result.instructions, Some("Test instructions".to_string()));
    }

    #[test]
    fn deserialize_tool() {
        let json = r#"{
            "name": "read_file",
            "description": "Read a file from disk",
            "inputSchema": {
                "type": "object",
                "properties": {
                    "path": {"type": "string"}
                },
                "required": ["path"]
            }
        }"#;

        let tool: Tool = serde_json::from_str(json).unwrap();
        assert_eq!(tool.name, "read_file");
        assert_eq!(tool.description, Some("Read a file from disk".to_string()));
        assert!(tool.input_schema.is_object());
    }

    #[test]
    fn deserialize_tool_call_result() {
        let json = r#"{
            "content": [
                {"type": "text", "text": "Hello, world!"}
            ],
            "isError": false
        }"#;

        let result: CallToolResult = serde_json::from_str(json).unwrap();
        assert_eq!(result.content.len(), 1);
        assert_eq!(result.is_error, Some(false));
    }

    #[test]
    fn content_variants() {
        let text = Content::text("Hello");
        let json = serde_json::to_string(&text).unwrap();
        assert!(json.contains(r#""type":"text""#));
        assert!(json.contains(r#""text":"Hello""#));
    }

    #[test]
    fn supported_versions() {
        assert!(is_supported_version("2024-11-05"));
        assert!(is_supported_version("2025-03-26"));
        assert!(!is_supported_version("1.0.0"));
    }

    // Implementation tests
    #[test]
    fn implementation_new_with_strings() {
        let impl_info = Implementation::new("mcplint", "1.0.0");
        assert_eq!(impl_info.name, "mcplint");
        assert_eq!(impl_info.version, "1.0.0");
    }

    #[test]
    fn implementation_new_with_string_slices() {
        let name = String::from("test-server");
        let version = String::from("2.1.0");
        let impl_info = Implementation::new(name, version);
        assert_eq!(impl_info.name, "test-server");
        assert_eq!(impl_info.version, "2.1.0");
    }

    #[test]
    fn implementation_serialization() {
        let impl_info = Implementation::new("test", "1.0");
        let json = serde_json::to_string(&impl_info).unwrap();
        assert!(json.contains(r#""name":"test""#));
        assert!(json.contains(r#""version":"1.0""#));
    }

    // InitializeParams tests
    #[test]
    fn initialize_params_new() {
        let client_info = Implementation::new("test-client", "0.1.0");
        let capabilities = ClientCapabilities::default();
        let params = InitializeParams::new(client_info.clone(), capabilities);

        assert_eq!(params.protocol_version, LATEST_PROTOCOL_VERSION);
        assert_eq!(params.client_info.name, "test-client");
        assert_eq!(params.client_info.version, "0.1.0");
    }

    #[test]
    fn initialize_params_with_custom_capabilities() {
        let client_info = Implementation::new("client", "1.0");
        let capabilities = ClientCapabilities {
            roots: Some(RootsCapability {
                list_changed: Some(true),
            }),
            ..ClientCapabilities::default()
        };
        let params = InitializeParams::new(client_info, capabilities);

        assert!(params.capabilities.roots.is_some());
    }

    // ServerCapabilities tests
    #[test]
    fn server_capabilities_has_tools_when_none() {
        let caps = ServerCapabilities::default();
        assert!(!caps.has_tools());
    }

    #[test]
    fn server_capabilities_has_tools_when_some() {
        let caps = ServerCapabilities {
            tools: Some(ToolsCapability::default()),
            ..Default::default()
        };
        assert!(caps.has_tools());
    }

    #[test]
    fn server_capabilities_has_resources_when_none() {
        let caps = ServerCapabilities::default();
        assert!(!caps.has_resources());
    }

    #[test]
    fn server_capabilities_has_resources_when_some() {
        let caps = ServerCapabilities {
            resources: Some(ResourcesCapability::default()),
            ..Default::default()
        };
        assert!(caps.has_resources());
    }

    #[test]
    fn server_capabilities_has_prompts_when_none() {
        let caps = ServerCapabilities::default();
        assert!(!caps.has_prompts());
    }

    #[test]
    fn server_capabilities_has_prompts_when_some() {
        let caps = ServerCapabilities {
            prompts: Some(PromptsCapability::default()),
            ..Default::default()
        };
        assert!(caps.has_prompts());
    }

    // CallToolParams tests
    #[test]
    fn call_tool_params_new() {
        let params = CallToolParams::new("test_tool");
        assert_eq!(params.name, "test_tool");
        assert!(params.arguments.is_none());
    }

    #[test]
    fn call_tool_params_with_arguments() {
        let args = serde_json::json!({"key": "value"});
        let params = CallToolParams::new("test_tool").with_arguments(args.clone());
        assert_eq!(params.name, "test_tool");
        assert_eq!(params.arguments, Some(args));
    }

    #[test]
    fn call_tool_params_chaining() {
        let params = CallToolParams::new("tool").with_arguments(serde_json::json!({"a": 1}));
        assert_eq!(params.name, "tool");
        assert!(params.arguments.is_some());
    }

    // Content tests
    #[test]
    fn content_image_creation() {
        let img = Content::image("base64data".to_string(), "image/png".to_string());
        match img {
            Content::Image { data, mime_type } => {
                assert_eq!(data, "base64data");
                assert_eq!(mime_type, "image/png");
            }
            _ => panic!("Expected Image variant"),
        }
    }

    #[test]
    fn content_text_serialization() {
        let text = Content::text("test text");
        let json = serde_json::to_string(&text).unwrap();
        assert!(json.contains(r#""type":"text""#));
        assert!(json.contains(r#""text":"test text""#));
    }

    #[test]
    fn content_image_serialization() {
        let img = Content::image("data123".to_string(), "image/jpeg".to_string());
        let json = serde_json::to_string(&img).unwrap();
        assert!(json.contains(r#""type":"image""#));
        assert!(json.contains(r#""data":"data123""#));
        assert!(json.contains(r#""mimeType":"image/jpeg""#));
    }

    // Resource tests
    #[test]
    fn resource_serialization() {
        let resource = Resource {
            uri: "file:///test.txt".to_string(),
            name: "test.txt".to_string(),
            description: Some("Test file".to_string()),
            mime_type: Some("text/plain".to_string()),
        };
        let json = serde_json::to_string(&resource).unwrap();
        assert!(json.contains(r#""uri":"file:///test.txt""#));
        assert!(json.contains(r#""name":"test.txt""#));
        assert!(json.contains(r#""description":"Test file""#));
        assert!(json.contains(r#""mimeType":"text/plain""#));
    }

    #[test]
    fn resource_deserialization() {
        let json = r#"{
            "uri": "http://example.com/resource",
            "name": "example",
            "description": "Example resource",
            "mimeType": "application/json"
        }"#;
        let resource: Resource = serde_json::from_str(json).unwrap();
        assert_eq!(resource.uri, "http://example.com/resource");
        assert_eq!(resource.name, "example");
        assert_eq!(resource.description, Some("Example resource".to_string()));
        assert_eq!(resource.mime_type, Some("application/json".to_string()));
    }

    // ReadResourceParams tests
    #[test]
    fn read_resource_params_serialization() {
        let params = ReadResourceParams {
            uri: "file:///data.json".to_string(),
        };
        let json = serde_json::to_string(&params).unwrap();
        assert!(json.contains(r#""uri":"file:///data.json""#));
    }

    // ReadResourceResult tests
    #[test]
    fn read_resource_result_serialization() {
        let result = ReadResourceResult {
            contents: vec![ResourceContent {
                uri: "file:///test".to_string(),
                mime_type: Some("text/plain".to_string()),
                text: Some("content".to_string()),
                blob: None,
            }],
        };
        let json = serde_json::to_string(&result).unwrap();
        assert!(json.contains(r#""contents""#));
    }

    // Prompt tests
    #[test]
    fn prompt_serialization() {
        let prompt = Prompt {
            name: "test_prompt".to_string(),
            description: Some("Test prompt".to_string()),
            arguments: Some(vec![PromptArgument {
                name: "arg1".to_string(),
                description: Some("First argument".to_string()),
                required: Some(true),
            }]),
        };
        let json = serde_json::to_string(&prompt).unwrap();
        assert!(json.contains(r#""name":"test_prompt""#));
        assert!(json.contains(r#""description":"Test prompt""#));
        assert!(json.contains(r#""arguments""#));
    }

    #[test]
    fn prompt_deserialization() {
        let json = r#"{
            "name": "my_prompt",
            "description": "My prompt",
            "arguments": [
                {"name": "input", "required": true}
            ]
        }"#;
        let prompt: Prompt = serde_json::from_str(json).unwrap();
        assert_eq!(prompt.name, "my_prompt");
        assert_eq!(prompt.arguments.as_ref().unwrap().len(), 1);
    }

    // PromptArgument tests
    #[test]
    fn prompt_argument_serialization() {
        let arg = PromptArgument {
            name: "param".to_string(),
            description: Some("Parameter description".to_string()),
            required: Some(false),
        };
        let json = serde_json::to_string(&arg).unwrap();
        assert!(json.contains(r#""name":"param""#));
        assert!(json.contains(r#""required":false"#));
    }

    #[test]
    fn prompt_argument_deserialization() {
        let json = r#"{"name": "arg", "description": "desc", "required": true}"#;
        let arg: PromptArgument = serde_json::from_str(json).unwrap();
        assert_eq!(arg.name, "arg");
        assert_eq!(arg.description, Some("desc".to_string()));
        assert_eq!(arg.required, Some(true));
    }

    // GetPromptParams tests
    #[test]
    fn get_prompt_params_serialization() {
        let params = GetPromptParams {
            name: "prompt1".to_string(),
            arguments: Some(serde_json::json!({"key": "value"})),
        };
        let json = serde_json::to_string(&params).unwrap();
        assert!(json.contains(r#""name":"prompt1""#));
        assert!(json.contains(r#""arguments""#));
    }

    // GetPromptResult tests
    #[test]
    fn get_prompt_result_serialization() {
        let result = GetPromptResult {
            description: Some("Result description".to_string()),
            messages: vec![PromptMessage {
                role: Role::User,
                content: Content::text("Hello"),
            }],
        };
        let json = serde_json::to_string(&result).unwrap();
        assert!(json.contains(r#""description":"Result description""#));
        assert!(json.contains(r#""messages""#));
    }

    // PromptMessage tests
    #[test]
    fn prompt_message_with_user_role() {
        let msg = PromptMessage {
            role: Role::User,
            content: Content::text("User message"),
        };
        let json = serde_json::to_string(&msg).unwrap();
        assert!(json.contains(r#""role":"user""#));
    }

    #[test]
    fn prompt_message_with_assistant_role() {
        let msg = PromptMessage {
            role: Role::Assistant,
            content: Content::text("Assistant message"),
        };
        let json = serde_json::to_string(&msg).unwrap();
        assert!(json.contains(r#""role":"assistant""#));
    }

    // PaginationParams tests
    #[test]
    fn pagination_params_serialization_without_cursor() {
        let params = PaginationParams::default();
        let json = serde_json::to_string(&params).unwrap();
        assert_eq!(json, "{}");
    }

    #[test]
    fn pagination_params_serialization_with_cursor() {
        let params = PaginationParams {
            cursor: Some("cursor123".to_string()),
        };
        let json = serde_json::to_string(&params).unwrap();
        assert!(json.contains(r#""cursor":"cursor123""#));
    }

    // ListToolsResult tests
    #[test]
    fn list_tools_result_with_next_cursor() {
        let result = ListToolsResult {
            tools: vec![],
            next_cursor: Some("next_page".to_string()),
        };
        let json = serde_json::to_string(&result).unwrap();
        assert!(json.contains(r#""next_cursor":"next_page""#));
    }

    #[test]
    fn list_tools_result_without_cursor() {
        let result = ListToolsResult {
            tools: vec![],
            next_cursor: None,
        };
        let json = serde_json::to_string(&result).unwrap();
        assert!(!json.contains("nextCursor"));
    }

    // ListResourcesResult tests
    #[test]
    fn list_resources_result_with_next_cursor() {
        let result = ListResourcesResult {
            resources: vec![],
            next_cursor: Some("page2".to_string()),
        };
        let json = serde_json::to_string(&result).unwrap();
        assert!(json.contains(r#""next_cursor":"page2""#));
    }

    #[test]
    fn list_resources_result_without_cursor() {
        let result = ListResourcesResult {
            resources: vec![],
            next_cursor: None,
        };
        let json = serde_json::to_string(&result).unwrap();
        assert!(!json.contains("nextCursor"));
    }

    // ListPromptsResult tests
    #[test]
    fn list_prompts_result_with_next_cursor() {
        let result = ListPromptsResult {
            prompts: vec![],
            next_cursor: Some("cursor_token".to_string()),
        };
        let json = serde_json::to_string(&result).unwrap();
        assert!(json.contains(r#""next_cursor":"cursor_token""#));
    }

    #[test]
    fn list_prompts_result_without_cursor() {
        let result = ListPromptsResult {
            prompts: vec![],
            next_cursor: None,
        };
        let json = serde_json::to_string(&result).unwrap();
        assert!(!json.contains("nextCursor"));
    }

    // ResourceContent tests
    #[test]
    fn resource_content_with_text() {
        let content = ResourceContent {
            uri: "file:///test.txt".to_string(),
            mime_type: Some("text/plain".to_string()),
            text: Some("File content here".to_string()),
            blob: None,
        };
        let json = serde_json::to_string(&content).unwrap();
        assert!(json.contains(r#""text":"File content here""#));
        assert!(!json.contains(r#""blob""#));
    }

    #[test]
    fn resource_content_with_blob() {
        let content = ResourceContent {
            uri: "file:///image.png".to_string(),
            mime_type: Some("image/png".to_string()),
            text: None,
            blob: Some("base64encodeddata".to_string()),
        };
        let json = serde_json::to_string(&content).unwrap();
        assert!(json.contains(r#""blob":"base64encodeddata""#));
        assert!(!json.contains(r#""text""#));
    }

    // Method constants tests
    #[test]
    fn method_constants_lifecycle() {
        assert_eq!(methods::INITIALIZE, "initialize");
        assert_eq!(methods::INITIALIZED, "notifications/initialized");
        assert_eq!(methods::PING, "ping");
    }

    #[test]
    fn method_constants_tools() {
        assert_eq!(methods::TOOLS_LIST, "tools/list");
        assert_eq!(methods::TOOLS_CALL, "tools/call");
    }

    #[test]
    fn method_constants_resources() {
        assert_eq!(methods::RESOURCES_LIST, "resources/list");
        assert_eq!(methods::RESOURCES_READ, "resources/read");
        assert_eq!(methods::RESOURCES_SUBSCRIBE, "resources/subscribe");
        assert_eq!(methods::RESOURCES_UNSUBSCRIBE, "resources/unsubscribe");
    }

    #[test]
    fn method_constants_prompts() {
        assert_eq!(methods::PROMPTS_LIST, "prompts/list");
        assert_eq!(methods::PROMPTS_GET, "prompts/get");
    }

    #[test]
    fn method_constants_logging() {
        assert_eq!(methods::LOGGING_SET_LEVEL, "logging/setLevel");
    }

    #[test]
    fn method_constants_notifications() {
        assert_eq!(methods::NOTIFICATION_CANCELLED, "notifications/cancelled");
        assert_eq!(methods::NOTIFICATION_PROGRESS, "notifications/progress");
        assert_eq!(
            methods::NOTIFICATION_RESOURCES_UPDATED,
            "notifications/resources/updated"
        );
        assert_eq!(
            methods::NOTIFICATION_RESOURCES_LIST_CHANGED,
            "notifications/resources/list_changed"
        );
        assert_eq!(
            methods::NOTIFICATION_TOOLS_LIST_CHANGED,
            "notifications/tools/list_changed"
        );
        assert_eq!(
            methods::NOTIFICATION_PROMPTS_LIST_CHANGED,
            "notifications/prompts/list_changed"
        );
    }

    // Role tests
    #[test]
    fn role_equality() {
        assert_eq!(Role::User, Role::User);
        assert_eq!(Role::Assistant, Role::Assistant);
        assert_ne!(Role::User, Role::Assistant);
    }

    #[test]
    fn role_serialization() {
        let user_json = serde_json::to_string(&Role::User).unwrap();
        let assistant_json = serde_json::to_string(&Role::Assistant).unwrap();
        assert_eq!(user_json, r#""user""#);
        assert_eq!(assistant_json, r#""assistant""#);
    }
}