kindly-guard-server 0.11.14

KindlyGuard MCP server - Enterprise-grade security for AI model interactions
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
use anyhow::{Context, Result};
use serde::{Deserialize, Serialize};
use std::env;
use std::fs;
use std::path::{Path, PathBuf};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum IdeType {
    ClaudeDesktop,
    ClaudeCode,
    VsCode,
    Cursor,
    Zed,
    Neovim,
    Unknown,
}

impl IdeType {
    pub fn as_str(&self) -> &str {
        match self {
            Self::ClaudeDesktop => "Claude Desktop",
            Self::ClaudeCode => "Claude Code",
            Self::VsCode => "VS Code",
            Self::Cursor => "Cursor",
            Self::Zed => "Zed",
            Self::Neovim => "Neovim",
            Self::Unknown => "Unknown",
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum ConfigFormat {
    Json,
    JsonLocal,
    Toml,
    Yaml,
}

impl ConfigFormat {
    pub fn extension(&self) -> &str {
        match self {
            Self::Json => "json",
            Self::JsonLocal => "json.local",
            Self::Toml => "toml",
            Self::Yaml => "yaml",
        }
    }
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ConfigLocation {
    pub path: PathBuf,
    pub format: ConfigFormat,
    pub exists: bool,
    pub ide: IdeType,
}

impl ConfigLocation {
    fn new(path: PathBuf, format: ConfigFormat, ide: IdeType) -> Self {
        let exists = path.exists();
        Self {
            path,
            format,
            exists,
            ide,
        }
    }
}

pub struct McpDetector {
    platform: Platform,
}

#[derive(Debug, Clone, Copy)]
enum Platform {
    Windows,
    MacOs,
    Linux,
}

impl McpDetector {
    pub fn new() -> Self {
        let platform = if cfg!(target_os = "windows") {
            Platform::Windows
        } else if cfg!(target_os = "macos") {
            Platform::MacOs
        } else {
            Platform::Linux
        };

        Self { platform }
    }

    /// Detect all possible MCP configuration locations
    pub fn detect_all(&self) -> Result<Vec<ConfigLocation>> {
        let mut locations = Vec::new();

        // Claude Desktop configs
        locations.extend(self.get_claude_desktop_configs()?);

        // Claude Code configs
        locations.extend(self.get_claude_code_configs()?);

        // VS Code configs
        locations.extend(self.get_vscode_configs()?);

        // Cursor configs
        locations.extend(self.get_cursor_configs()?);

        // Zed configs
        locations.extend(self.get_zed_configs()?);

        // Neovim configs
        locations.extend(self.get_neovim_configs()?);

        // Global MCP configs
        locations.extend(self.get_global_mcp_configs()?);

        Ok(locations)
    }

    /// Detect which IDE/terminal is currently running
    pub fn detect_active_ide(&self) -> Result<IdeType> {
        // Check environment variables first
        if env::var("CLAUDE_CODE").is_ok() {
            return Ok(IdeType::ClaudeCode);
        }

        if env::var("CLAUDE_DESKTOP").is_ok() {
            return Ok(IdeType::ClaudeDesktop);
        }

        if env::var("VSCODE_PID").is_ok() {
            return Ok(IdeType::VsCode);
        }

        if env::var("CURSOR_PID").is_ok() {
            return Ok(IdeType::Cursor);
        }

        if env::var("NVIM").is_ok() || env::var("NVIM_LISTEN_ADDRESS").is_ok() {
            return Ok(IdeType::Neovim);
        }

        // Check running processes
        match self.platform {
            Platform::Windows => self.detect_windows_processes(),
            Platform::MacOs => self.detect_macos_processes(),
            Platform::Linux => self.detect_linux_processes(),
        }
    }

    /// Get configuration location for a specific IDE
    pub fn get_config_location(&self, ide: IdeType) -> Result<ConfigLocation> {
        let path = self.get_config_path(ide)?;
        let format = ConfigFormat::Json; // Default to JSON for now
        Ok(ConfigLocation::new(path, format, ide))
    }

    /// Get configuration path for a specific IDE
    pub fn get_config_path(&self, ide: IdeType) -> Result<PathBuf> {
        match ide {
            IdeType::ClaudeDesktop => self.get_claude_desktop_config_path(),
            IdeType::ClaudeCode => self.get_claude_code_config_path(),
            IdeType::VsCode => self.get_vscode_config_path(),
            IdeType::Cursor => self.get_cursor_config_path(),
            IdeType::Zed => self.get_zed_config_path(),
            IdeType::Neovim => self.get_neovim_config_path(),
            IdeType::Unknown => Err(anyhow::anyhow!("Cannot get config path for unknown IDE")),
        }
    }

    /// Detect Claude-specific configurations
    pub fn detect_claude_configs(&self) -> Result<Vec<ConfigLocation>> {
        let mut configs = Vec::new();
        configs.extend(self.get_claude_desktop_configs()?);
        configs.extend(self.get_claude_code_configs()?);
        Ok(configs)
    }

    // Platform-specific home directory helpers
    fn get_home_dir(&self) -> Result<PathBuf> {
        match self.platform {
            Platform::Windows => env::var("USERPROFILE")
                .or_else(|_| {
                    env::var("HOMEDRIVE").and_then(|drive| {
                        env::var("HOMEPATH").map(|path| format!("{}{}", drive, path))
                    })
                })
                .map(PathBuf::from)
                .context("Failed to get Windows home directory"),
            Platform::MacOs | Platform::Linux => env::var("HOME")
                .map(PathBuf::from)
                .context("Failed to get Unix home directory"),
        }
    }

    fn get_config_dir(&self) -> Result<PathBuf> {
        match self.platform {
            Platform::Windows => env::var("APPDATA")
                .map(PathBuf::from)
                .context("Failed to get Windows config directory"),
            Platform::MacOs => {
                let home = self.get_home_dir()?;
                Ok(home.join("Library").join("Application Support"))
            },
            Platform::Linux => env::var("XDG_CONFIG_HOME")
                .map(PathBuf::from)
                .or_else(|_| self.get_home_dir().map(|home| home.join(".config")))
                .context("Failed to get Linux config directory"),
        }
    }

    // Claude Desktop configurations
    fn get_claude_desktop_configs(&self) -> Result<Vec<ConfigLocation>> {
        let mut configs = Vec::new();

        match self.platform {
            Platform::Windows => {
                let appdata = env::var("APPDATA").map(PathBuf::from)?;
                configs.push(ConfigLocation::new(
                    appdata.join("Claude").join("claude_desktop_config.json"),
                    ConfigFormat::Json,
                    IdeType::ClaudeDesktop,
                ));
            },
            Platform::MacOs => {
                let home = self.get_home_dir()?;
                configs.push(ConfigLocation::new(
                    home.join("Library")
                        .join("Application Support")
                        .join("Claude")
                        .join("claude_desktop_config.json"),
                    ConfigFormat::Json,
                    IdeType::ClaudeDesktop,
                ));
            },
            Platform::Linux => {
                let config = self.get_config_dir()?;
                configs.push(ConfigLocation::new(
                    config.join("claude").join("claude_desktop_config.json"),
                    ConfigFormat::Json,
                    IdeType::ClaudeDesktop,
                ));
            },
        }

        Ok(configs)
    }

    // Claude Code configurations
    fn get_claude_code_configs(&self) -> Result<Vec<ConfigLocation>> {
        let mut configs = Vec::new();
        let home = self.get_home_dir()?;

        // Primary config location
        configs.push(ConfigLocation::new(
            home.join(".mcp.json"),
            ConfigFormat::Json,
            IdeType::ClaudeCode,
        ));

        // Local override
        configs.push(ConfigLocation::new(
            home.join(".mcp.json.local"),
            ConfigFormat::JsonLocal,
            IdeType::ClaudeCode,
        ));

        // Alternative locations
        match self.platform {
            Platform::Windows => {
                let appdata = env::var("APPDATA").map(PathBuf::from)?;
                configs.push(ConfigLocation::new(
                    appdata.join("claude-code").join("mcp.json"),
                    ConfigFormat::Json,
                    IdeType::ClaudeCode,
                ));
            },
            Platform::MacOs => {
                configs.push(ConfigLocation::new(
                    home.join("Library")
                        .join("Application Support")
                        .join("claude-code")
                        .join("mcp.json"),
                    ConfigFormat::Json,
                    IdeType::ClaudeCode,
                ));
            },
            Platform::Linux => {
                let config = self.get_config_dir()?;
                configs.push(ConfigLocation::new(
                    config.join("claude-code").join("mcp.json"),
                    ConfigFormat::Json,
                    IdeType::ClaudeCode,
                ));
            },
        }

        Ok(configs)
    }

    // VS Code configurations
    fn get_vscode_configs(&self) -> Result<Vec<ConfigLocation>> {
        let mut configs = Vec::new();

        match self.platform {
            Platform::Windows => {
                let appdata = env::var("APPDATA").map(PathBuf::from)?;
                configs.push(ConfigLocation::new(
                    appdata.join("Code").join("User").join("mcp.json"),
                    ConfigFormat::Json,
                    IdeType::VsCode,
                ));
            },
            Platform::MacOs => {
                let home = self.get_home_dir()?;
                configs.push(ConfigLocation::new(
                    home.join("Library")
                        .join("Application Support")
                        .join("Code")
                        .join("User")
                        .join("mcp.json"),
                    ConfigFormat::Json,
                    IdeType::VsCode,
                ));
            },
            Platform::Linux => {
                let config = self.get_config_dir()?;
                configs.push(ConfigLocation::new(
                    config.join("Code").join("User").join("mcp.json"),
                    ConfigFormat::Json,
                    IdeType::VsCode,
                ));
            },
        }

        Ok(configs)
    }

    // Cursor configurations
    fn get_cursor_configs(&self) -> Result<Vec<ConfigLocation>> {
        let mut configs = Vec::new();

        match self.platform {
            Platform::Windows => {
                let appdata = env::var("APPDATA").map(PathBuf::from)?;
                configs.push(ConfigLocation::new(
                    appdata.join("Cursor").join("User").join("mcp.json"),
                    ConfigFormat::Json,
                    IdeType::Cursor,
                ));
            },
            Platform::MacOs => {
                let home = self.get_home_dir()?;
                configs.push(ConfigLocation::new(
                    home.join("Library")
                        .join("Application Support")
                        .join("Cursor")
                        .join("User")
                        .join("mcp.json"),
                    ConfigFormat::Json,
                    IdeType::Cursor,
                ));
            },
            Platform::Linux => {
                let config = self.get_config_dir()?;
                configs.push(ConfigLocation::new(
                    config.join("Cursor").join("User").join("mcp.json"),
                    ConfigFormat::Json,
                    IdeType::Cursor,
                ));
            },
        }

        Ok(configs)
    }

    // Zed configurations
    fn get_zed_configs(&self) -> Result<Vec<ConfigLocation>> {
        let mut configs = Vec::new();

        match self.platform {
            Platform::Windows => {
                let appdata = env::var("APPDATA").map(PathBuf::from)?;
                configs.push(ConfigLocation::new(
                    appdata.join("Zed").join("mcp.json"),
                    ConfigFormat::Json,
                    IdeType::Zed,
                ));
            },
            Platform::MacOs => {
                let home = self.get_home_dir()?;
                configs.push(ConfigLocation::new(
                    home.join("Library")
                        .join("Application Support")
                        .join("Zed")
                        .join("mcp.json"),
                    ConfigFormat::Json,
                    IdeType::Zed,
                ));
            },
            Platform::Linux => {
                let config_home = env::var("XDG_CONFIG_HOME")
                    .map(PathBuf::from)
                    .unwrap_or_else(|_| {
                        let home = self.get_home_dir().unwrap_or_default();
                        home.join(".config")
                    });
                configs.push(ConfigLocation::new(
                    config_home.join("zed").join("mcp.json"),
                    ConfigFormat::Json,
                    IdeType::Zed,
                ));
            },
        }

        Ok(configs)
    }

    // Neovim configurations
    fn get_neovim_configs(&self) -> Result<Vec<ConfigLocation>> {
        let mut configs = Vec::new();
        let home = self.get_home_dir()?;

        // Standard Neovim config locations
        configs.push(ConfigLocation::new(
            home.join(".config").join("nvim").join("mcp.json"),
            ConfigFormat::Json,
            IdeType::Neovim,
        ));

        configs.push(ConfigLocation::new(
            home.join(".config").join("nvim").join("mcp.toml"),
            ConfigFormat::Toml,
            IdeType::Neovim,
        ));

        // Legacy location
        configs.push(ConfigLocation::new(
            home.join(".nvim").join("mcp.json"),
            ConfigFormat::Json,
            IdeType::Neovim,
        ));

        Ok(configs)
    }

    // Global MCP configurations
    fn get_global_mcp_configs(&self) -> Result<Vec<ConfigLocation>> {
        let mut configs = Vec::new();
        let home = self.get_home_dir()?;

        // Global config in home directory
        configs.push(ConfigLocation::new(
            home.join(".mcp").join("config.json"),
            ConfigFormat::Json,
            IdeType::Unknown,
        ));

        configs.push(ConfigLocation::new(
            home.join(".mcp").join("config.toml"),
            ConfigFormat::Toml,
            IdeType::Unknown,
        ));

        configs.push(ConfigLocation::new(
            home.join(".mcp").join("config.yaml"),
            ConfigFormat::Yaml,
            IdeType::Unknown,
        ));

        // System-wide configs
        match self.platform {
            Platform::Windows => {
                let programdata = env::var("PROGRAMDATA")
                    .map(PathBuf::from)
                    .unwrap_or_else(|_| PathBuf::from("C:\\ProgramData"));
                configs.push(ConfigLocation::new(
                    programdata.join("mcp").join("config.json"),
                    ConfigFormat::Json,
                    IdeType::Unknown,
                ));
            },
            Platform::MacOs | Platform::Linux => {
                configs.push(ConfigLocation::new(
                    PathBuf::from("/etc/mcp/config.json"),
                    ConfigFormat::Json,
                    IdeType::Unknown,
                ));
                configs.push(ConfigLocation::new(
                    PathBuf::from("/etc/mcp/config.toml"),
                    ConfigFormat::Toml,
                    IdeType::Unknown,
                ));
            },
        }

        Ok(configs)
    }

    // Process detection methods
    fn detect_windows_processes(&self) -> Result<IdeType> {
        use std::process::Command;

        let output = Command::new("tasklist")
            .output()
            .context("Failed to run tasklist")?;

        let processes = String::from_utf8_lossy(&output.stdout);

        if processes.contains("Claude.exe") || processes.contains("claude.exe") {
            return Ok(IdeType::ClaudeDesktop);
        }

        if processes.contains("ClaudeCode.exe") || processes.contains("claude-code.exe") {
            return Ok(IdeType::ClaudeCode);
        }

        if processes.contains("Code.exe") {
            return Ok(IdeType::VsCode);
        }

        if processes.contains("Cursor.exe") {
            return Ok(IdeType::Cursor);
        }

        if processes.contains("nvim.exe") || processes.contains("nvim-qt.exe") {
            return Ok(IdeType::Neovim);
        }

        Ok(IdeType::Unknown)
    }

    fn detect_macos_processes(&self) -> Result<IdeType> {
        use std::process::Command;

        let output = Command::new("ps")
            .args(&["-ax"])
            .output()
            .context("Failed to run ps")?;

        let processes = String::from_utf8_lossy(&output.stdout);

        if processes.contains("Claude.app") || processes.contains("Claude Desktop") {
            return Ok(IdeType::ClaudeDesktop);
        }

        if processes.contains("Claude Code") || processes.contains("claude-code") {
            return Ok(IdeType::ClaudeCode);
        }

        if processes.contains("Visual Studio Code.app") || processes.contains("Code Helper") {
            return Ok(IdeType::VsCode);
        }

        if processes.contains("Cursor.app") || processes.contains("Cursor Helper") {
            return Ok(IdeType::Cursor);
        }

        if processes.contains("nvim") {
            return Ok(IdeType::Neovim);
        }

        Ok(IdeType::Unknown)
    }

    fn detect_linux_processes(&self) -> Result<IdeType> {
        use std::process::Command;

        let output = Command::new("ps")
            .args(&["aux"])
            .output()
            .context("Failed to run ps")?;

        let processes = String::from_utf8_lossy(&output.stdout);

        if processes.contains("claude-desktop") || processes.contains("Claude") {
            return Ok(IdeType::ClaudeDesktop);
        }

        if processes.contains("claude-code") {
            return Ok(IdeType::ClaudeCode);
        }

        if processes.contains("code") && !processes.contains("claude-code") {
            return Ok(IdeType::VsCode);
        }

        if processes.contains("cursor") {
            return Ok(IdeType::Cursor);
        }

        if processes.contains("nvim") {
            return Ok(IdeType::Neovim);
        }

        Ok(IdeType::Unknown)
    }

    // Helper methods to get primary config paths
    fn get_claude_desktop_config_path(&self) -> Result<PathBuf> {
        match self.platform {
            Platform::Windows => {
                let appdata = env::var("APPDATA").map(PathBuf::from)?;
                Ok(appdata.join("Claude").join("claude_desktop_config.json"))
            },
            Platform::MacOs => {
                let home = self.get_home_dir()?;
                Ok(home
                    .join("Library")
                    .join("Application Support")
                    .join("Claude")
                    .join("claude_desktop_config.json"))
            },
            Platform::Linux => {
                let config = self.get_config_dir()?;
                Ok(config.join("claude").join("claude_desktop_config.json"))
            },
        }
    }

    fn get_claude_code_config_path(&self) -> Result<PathBuf> {
        let home = self.get_home_dir()?;
        Ok(home.join(".mcp.json"))
    }

    fn get_vscode_config_path(&self) -> Result<PathBuf> {
        match self.platform {
            Platform::Windows => {
                let appdata = env::var("APPDATA").map(PathBuf::from)?;
                Ok(appdata.join("Code").join("User").join("mcp.json"))
            },
            Platform::MacOs => {
                let home = self.get_home_dir()?;
                Ok(home
                    .join("Library")
                    .join("Application Support")
                    .join("Code")
                    .join("User")
                    .join("mcp.json"))
            },
            Platform::Linux => {
                let config = self.get_config_dir()?;
                Ok(config.join("Code").join("User").join("mcp.json"))
            },
        }
    }

    fn get_cursor_config_path(&self) -> Result<PathBuf> {
        match self.platform {
            Platform::Windows => {
                let appdata = env::var("APPDATA").map(PathBuf::from)?;
                Ok(appdata.join("Cursor").join("User").join("mcp.json"))
            },
            Platform::MacOs => {
                let home = self.get_home_dir()?;
                Ok(home
                    .join("Library")
                    .join("Application Support")
                    .join("Cursor")
                    .join("User")
                    .join("mcp.json"))
            },
            Platform::Linux => {
                let config = self.get_config_dir()?;
                Ok(config.join("Cursor").join("User").join("mcp.json"))
            },
        }
    }

    fn get_zed_config_path(&self) -> Result<PathBuf> {
        match self.platform {
            Platform::Windows => {
                let appdata = env::var("APPDATA").map(PathBuf::from)?;
                Ok(appdata.join("Zed").join("mcp.json"))
            },
            Platform::MacOs => {
                let home = self.get_home_dir()?;
                Ok(home
                    .join("Library")
                    .join("Application Support")
                    .join("Zed")
                    .join("mcp.json"))
            },
            Platform::Linux => {
                let config_home = env::var("XDG_CONFIG_HOME")
                    .map(PathBuf::from)
                    .unwrap_or_else(|_| {
                        let home = self.get_home_dir().unwrap_or_default();
                        home.join(".config")
                    });
                Ok(config_home.join("zed").join("mcp.json"))
            },
        }
    }

    fn get_neovim_config_path(&self) -> Result<PathBuf> {
        let home = self.get_home_dir()?;
        Ok(home.join(".config").join("nvim").join("mcp.json"))
    }

    /// Check if a specific MCP server is configured
    pub fn is_server_configured(&self, server_name: &str) -> Result<bool> {
        let configs = self.detect_claude_configs()?;

        for config in configs.iter().filter(|c| c.exists) {
            if self.check_server_in_config(&config.path, server_name)? {
                return Ok(true);
            }
        }

        Ok(false)
    }

    fn check_server_in_config(&self, path: &Path, server_name: &str) -> Result<bool> {
        let content = fs::read_to_string(path)?;

        // Basic check - could be enhanced with proper JSON/TOML parsing
        Ok(content.contains(server_name))
    }

    /// Get a summary of MCP configuration status
    pub fn get_status_summary(&self) -> Result<String> {
        let active_ide = self.detect_active_ide()?;
        let all_configs = self.detect_all()?;
        let existing_configs: Vec<_> = all_configs.iter().filter(|c| c.exists).collect();

        let mut summary = format!("MCP Configuration Status\n");
        summary.push_str(&format!("========================\n"));
        summary.push_str(&format!("Active IDE: {}\n", active_ide.as_str()));
        summary.push_str(&format!("Platform: {:?}\n", self.platform));
        summary.push_str(&format!(
            "Total config locations checked: {}\n",
            all_configs.len()
        ));
        summary.push_str(&format!(
            "Existing configurations: {}\n\n",
            existing_configs.len()
        ));

        if !existing_configs.is_empty() {
            summary.push_str("Found configurations:\n");
            for config in existing_configs {
                summary.push_str(&format!(
                    "  - {} ({:?}): {}\n",
                    config.ide.as_str(),
                    config.format,
                    config.path.display()
                ));
            }
        }

        Ok(summary)
    }
}

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

    #[test]
    fn test_detector_creation() {
        let detector = McpDetector::new();
        assert!(matches!(
            detector.platform,
            Platform::Windows | Platform::MacOs | Platform::Linux
        ));
    }

    #[test]
    fn test_config_format_extensions() {
        assert_eq!(ConfigFormat::Json.extension(), "json");
        assert_eq!(ConfigFormat::JsonLocal.extension(), "json.local");
        assert_eq!(ConfigFormat::Toml.extension(), "toml");
        assert_eq!(ConfigFormat::Yaml.extension(), "yaml");
    }

    #[test]
    fn test_ide_type_strings() {
        assert_eq!(IdeType::ClaudeDesktop.as_str(), "Claude Desktop");
        assert_eq!(IdeType::ClaudeCode.as_str(), "Claude Code");
        assert_eq!(IdeType::VsCode.as_str(), "VS Code");
        assert_eq!(IdeType::Cursor.as_str(), "Cursor");
        assert_eq!(IdeType::Neovim.as_str(), "Neovim");
        assert_eq!(IdeType::Unknown.as_str(), "Unknown");
    }
}