fastmcp-console 0.3.0

Rich console output for FastMCP servers
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
//! Centralized configuration for FastMCP console output.
//!
//! `ConsoleConfig` provides a single point of configuration for all aspects
//! of rich console output, supporting both programmatic and environment
//! variable-based configuration.

use crate::detection::DisplayContext;
use std::env;

/// Comprehensive configuration for FastMCP console output
#[derive(Debug, Clone)]
pub struct ConsoleConfig {
    // Display mode
    /// Override display context (None = auto-detect)
    pub context: Option<DisplayContext>,
    /// Force color output even in non-TTY
    pub force_color: Option<bool>,
    /// Force plain text mode (no styling)
    pub force_plain: bool,

    // Theme
    /// Custom color overrides (theme accessed via crate::theme::theme())
    pub custom_colors: Option<CustomColors>,

    // Startup
    /// Show startup banner
    pub show_banner: bool,
    /// Show capabilities list in banner
    pub show_capabilities: bool,
    /// Banner display style
    pub banner_style: BannerStyle,

    // Logging
    /// Log level filter
    pub log_level: Option<log::Level>,
    /// Show timestamps in logs
    pub log_timestamps: bool,
    /// Show target module in logs
    pub log_targets: bool,
    /// Show file and line in logs
    pub log_file_line: bool,

    // Runtime
    /// Show periodic stats
    pub show_stats_periodic: bool,
    /// Stats display interval in seconds
    pub stats_interval_secs: u64,
    /// Show request/response traffic
    pub show_request_traffic: bool,
    /// Traffic logging verbosity
    pub traffic_verbosity: TrafficVerbosity,

    // Errors
    /// Show fix suggestions for errors
    pub show_suggestions: bool,
    /// Show error codes
    pub show_error_codes: bool,
    /// Show backtraces for errors
    pub show_backtrace: bool,

    // Output limits
    /// Maximum rows in tables
    pub max_table_rows: usize,
    /// Maximum depth for JSON display
    pub max_json_depth: usize,
    /// Truncate long strings at this length
    pub truncate_at: usize,
}

/// Style variants for the startup banner
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub enum BannerStyle {
    /// Full banner with logo, info panel, and capabilities
    #[default]
    Full,
    /// Compact banner without logo
    Compact,
    /// Minimal one-line banner
    Minimal,
    /// No banner at all
    None,
}

/// Verbosity levels for traffic logging
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub enum TrafficVerbosity {
    /// No traffic logging
    #[default]
    None,
    /// Summary only (method name, timing)
    Summary,
    /// Include headers/metadata
    Headers,
    /// Full request/response bodies
    Full,
}

/// Custom color overrides
#[derive(Debug, Clone, Default)]
pub struct CustomColors {
    /// Primary brand color override
    pub primary: Option<String>,
    /// Secondary accent color override
    pub secondary: Option<String>,
    /// Success color override
    pub success: Option<String>,
    /// Warning color override
    pub warning: Option<String>,
    /// Error color override
    pub error: Option<String>,
}

impl Default for ConsoleConfig {
    fn default() -> Self {
        Self {
            context: None,
            force_color: None,
            force_plain: false,
            custom_colors: None,
            show_banner: true,
            show_capabilities: true,
            banner_style: BannerStyle::Full,
            log_level: None,
            log_timestamps: true,
            log_targets: true,
            log_file_line: false,
            show_stats_periodic: false,
            stats_interval_secs: 60,
            show_request_traffic: false,
            traffic_verbosity: TrafficVerbosity::None,
            show_suggestions: true,
            show_error_codes: true,
            show_backtrace: false,
            max_table_rows: 100,
            max_json_depth: 5,
            truncate_at: 200,
        }
    }
}

impl ConsoleConfig {
    /// Create config with defaults
    #[must_use]
    pub fn new() -> Self {
        Self::default()
    }

    /// Create config from environment variables
    ///
    /// # Environment Variables
    ///
    /// | Variable | Values | Description |
    /// |----------|--------|-------------|
    /// | `FASTMCP_FORCE_COLOR` | (set) | Force rich output |
    /// | `FASTMCP_PLAIN` | (set) | Force plain output |
    /// | `NO_COLOR` | (set) | Disable colors (standard) |
    /// | `FASTMCP_BANNER` | full/compact/minimal/none | Banner style |
    /// | `FASTMCP_LOG` | trace/debug/info/warn/error | Log level |
    /// | `FASTMCP_LOG_TIMESTAMPS` | 0/1 | Show timestamps |
    /// | `FASTMCP_TRAFFIC` | none/summary/headers/full | Traffic logging |
    /// | `RUST_BACKTRACE` | 1/full | Show backtraces |
    #[must_use]
    pub fn from_env() -> Self {
        Self::from_lookup(|key| env::var(key).ok())
    }

    fn from_lookup<F>(lookup: F) -> Self
    where
        F: Fn(&str) -> Option<String>,
    {
        let mut config = Self::default();

        // Display mode
        if lookup("FASTMCP_FORCE_COLOR").is_some() {
            config.force_color = Some(true);
        }
        if lookup("FASTMCP_PLAIN").is_some() || lookup("NO_COLOR").is_some() {
            config.force_plain = true;
        }

        // Banner
        if let Some(val) = lookup("FASTMCP_BANNER") {
            config.banner_style = match val.to_lowercase().as_str() {
                "compact" => BannerStyle::Compact,
                "minimal" => BannerStyle::Minimal,
                "none" | "0" | "false" => BannerStyle::None,
                // "full" and any other value default to Full
                _ => BannerStyle::Full,
            };
            config.show_banner = !matches!(config.banner_style, BannerStyle::None);
        }

        // Logging
        if let Some(level) = lookup("FASTMCP_LOG") {
            config.log_level = match level.to_lowercase().as_str() {
                "trace" => Some(log::Level::Trace),
                "debug" => Some(log::Level::Debug),
                "info" => Some(log::Level::Info),
                "warn" | "warning" => Some(log::Level::Warn),
                "error" => Some(log::Level::Error),
                _ => None,
            };
        }
        if lookup("FASTMCP_LOG_TIMESTAMPS")
            .map(|v| v == "0" || v.to_lowercase() == "false")
            .unwrap_or(false)
        {
            config.log_timestamps = false;
        }

        // Traffic
        if let Some(val) = lookup("FASTMCP_TRAFFIC") {
            config.traffic_verbosity = match val.to_lowercase().as_str() {
                "summary" | "1" => TrafficVerbosity::Summary,
                "headers" | "2" => TrafficVerbosity::Headers,
                "full" | "3" => TrafficVerbosity::Full,
                // "none", "0", and any other value default to None
                _ => TrafficVerbosity::None,
            };
            config.show_request_traffic =
                !matches!(config.traffic_verbosity, TrafficVerbosity::None);
        }

        // Errors
        if lookup("RUST_BACKTRACE").is_some() {
            config.show_backtrace = true;
        }

        config
    }

    // ─────────────────────────────────────────────────
    // Builder Methods
    // ─────────────────────────────────────────────────

    /// Force color output
    #[must_use]
    pub fn force_color(mut self, force: bool) -> Self {
        self.force_color = Some(force);
        self
    }

    /// Enable plain text mode (no styling)
    #[must_use]
    pub fn plain_mode(mut self) -> Self {
        self.force_plain = true;
        self
    }

    /// Set the banner style
    #[must_use]
    pub fn with_banner(mut self, style: BannerStyle) -> Self {
        self.banner_style = style;
        self.show_banner = !matches!(style, BannerStyle::None);
        self
    }

    /// Disable the banner entirely
    #[must_use]
    pub fn without_banner(mut self) -> Self {
        self.show_banner = false;
        self.banner_style = BannerStyle::None;
        self
    }

    /// Set the log level
    #[must_use]
    pub fn with_log_level(mut self, level: log::Level) -> Self {
        self.log_level = Some(level);
        self
    }

    /// Set traffic logging verbosity
    #[must_use]
    pub fn with_traffic(mut self, verbosity: TrafficVerbosity) -> Self {
        self.traffic_verbosity = verbosity;
        self.show_request_traffic = !matches!(verbosity, TrafficVerbosity::None);
        self
    }

    /// Enable periodic stats display
    #[must_use]
    pub fn with_periodic_stats(mut self, interval_secs: u64) -> Self {
        self.show_stats_periodic = true;
        self.stats_interval_secs = interval_secs;
        self
    }

    /// Disable fix suggestions for errors
    #[must_use]
    pub fn without_suggestions(mut self) -> Self {
        self.show_suggestions = false;
        self
    }

    /// Set custom colors
    #[must_use]
    pub fn with_custom_colors(mut self, colors: CustomColors) -> Self {
        self.custom_colors = Some(colors);
        self
    }

    /// Set display context explicitly
    #[must_use]
    pub fn with_context(mut self, context: DisplayContext) -> Self {
        self.context = Some(context);
        self
    }

    /// Set maximum table rows
    #[must_use]
    pub fn with_max_table_rows(mut self, max: usize) -> Self {
        self.max_table_rows = max;
        self
    }

    /// Set maximum JSON depth
    #[must_use]
    pub fn with_max_json_depth(mut self, max: usize) -> Self {
        self.max_json_depth = max;
        self
    }

    /// Set truncation length
    #[must_use]
    pub fn with_truncate_at(mut self, len: usize) -> Self {
        self.truncate_at = len;
        self
    }

    // ─────────────────────────────────────────────────
    // Accessor Methods
    // ─────────────────────────────────────────────────

    /// Get the theme (uses global theme singleton)
    #[must_use]
    pub fn theme(&self) -> &'static crate::theme::FastMcpTheme {
        crate::theme::theme()
    }

    // ─────────────────────────────────────────────────
    // Resolution Methods
    // ─────────────────────────────────────────────────

    /// Resolve the display context based on config and environment
    #[must_use]
    pub fn resolve_context(&self) -> DisplayContext {
        if self.force_plain {
            return DisplayContext::new_agent();
        }
        if let Some(true) = self.force_color {
            return DisplayContext::new_human();
        }
        self.context.unwrap_or_else(DisplayContext::detect)
    }

    /// Check if rich output should be used based on resolved context
    #[must_use]
    pub fn should_use_rich(&self) -> bool {
        self.resolve_context().is_human()
    }
}

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

    fn config_from_pairs(pairs: &[(&str, &str)]) -> ConsoleConfig {
        let map: HashMap<&str, &str> = pairs.iter().copied().collect();
        ConsoleConfig::from_lookup(|key| map.get(key).map(|v| (*v).to_string()))
    }

    #[test]
    fn test_default_config() {
        let config = ConsoleConfig::new();
        assert!(config.show_banner);
        assert!(config.show_capabilities);
        assert_eq!(config.banner_style, BannerStyle::Full);
        assert!(config.log_timestamps);
        assert!(!config.force_plain);
        assert_eq!(config.max_table_rows, 100);
    }

    #[test]
    fn test_builder_pattern() {
        let config = ConsoleConfig::new()
            .with_banner(BannerStyle::Compact)
            .with_log_level(log::Level::Debug)
            .with_traffic(TrafficVerbosity::Summary)
            .with_periodic_stats(30);

        assert_eq!(config.banner_style, BannerStyle::Compact);
        assert_eq!(config.log_level, Some(log::Level::Debug));
        assert_eq!(config.traffic_verbosity, TrafficVerbosity::Summary);
        assert!(config.show_stats_periodic);
        assert_eq!(config.stats_interval_secs, 30);
    }

    #[test]
    fn test_plain_mode() {
        let config = ConsoleConfig::new().plain_mode();
        assert!(config.force_plain);
        assert_eq!(config.resolve_context(), DisplayContext::Agent);
    }

    #[test]
    fn test_force_color() {
        let config = ConsoleConfig::new().force_color(true);
        assert_eq!(config.force_color, Some(true));
        assert_eq!(config.resolve_context(), DisplayContext::Human);
    }

    #[test]
    fn test_without_banner() {
        let config = ConsoleConfig::new().without_banner();
        assert!(!config.show_banner);
        assert_eq!(config.banner_style, BannerStyle::None);
    }

    #[test]
    fn test_from_lookup_defaults_when_empty() {
        let config = config_from_pairs(&[]);
        assert_eq!(config.banner_style, BannerStyle::Full);
        assert_eq!(config.log_level, None);
        assert!(config.log_timestamps);
        assert_eq!(config.traffic_verbosity, TrafficVerbosity::None);
        assert!(!config.show_request_traffic);
        assert!(!config.show_backtrace);
    }

    #[test]
    fn test_from_lookup_display_mode_flags() {
        let config = config_from_pairs(&[("FASTMCP_FORCE_COLOR", "1"), ("FASTMCP_PLAIN", "1")]);
        assert_eq!(config.force_color, Some(true));
        assert!(config.force_plain);

        let no_color = config_from_pairs(&[("NO_COLOR", "1")]);
        assert!(no_color.force_plain);
    }

    #[test]
    fn test_from_lookup_banner_variants() {
        let compact = config_from_pairs(&[("FASTMCP_BANNER", "compact")]);
        assert_eq!(compact.banner_style, BannerStyle::Compact);
        assert!(compact.show_banner);

        let minimal = config_from_pairs(&[("FASTMCP_BANNER", "minimal")]);
        assert_eq!(minimal.banner_style, BannerStyle::Minimal);
        assert!(minimal.show_banner);

        let none_false = config_from_pairs(&[("FASTMCP_BANNER", "false")]);
        assert_eq!(none_false.banner_style, BannerStyle::None);
        assert!(!none_false.show_banner);

        let none_zero = config_from_pairs(&[("FASTMCP_BANNER", "0")]);
        assert_eq!(none_zero.banner_style, BannerStyle::None);
        assert!(!none_zero.show_banner);

        let fallback = config_from_pairs(&[("FASTMCP_BANNER", "unknown")]);
        assert_eq!(fallback.banner_style, BannerStyle::Full);
        assert!(fallback.show_banner);
    }

    #[test]
    fn test_from_lookup_log_levels_and_timestamp_toggle() {
        let trace = config_from_pairs(&[("FASTMCP_LOG", "trace")]);
        assert_eq!(trace.log_level, Some(log::Level::Trace));

        let debug = config_from_pairs(&[("FASTMCP_LOG", "debug")]);
        assert_eq!(debug.log_level, Some(log::Level::Debug));

        let warn_alias = config_from_pairs(&[("FASTMCP_LOG", "warning")]);
        assert_eq!(warn_alias.log_level, Some(log::Level::Warn));

        let invalid = config_from_pairs(&[("FASTMCP_LOG", "verbose")]);
        assert_eq!(invalid.log_level, None);

        let timestamps_disabled_zero = config_from_pairs(&[("FASTMCP_LOG_TIMESTAMPS", "0")]);
        assert!(!timestamps_disabled_zero.log_timestamps);

        let timestamps_disabled_false = config_from_pairs(&[("FASTMCP_LOG_TIMESTAMPS", "false")]);
        assert!(!timestamps_disabled_false.log_timestamps);

        let timestamps_enabled = config_from_pairs(&[("FASTMCP_LOG_TIMESTAMPS", "1")]);
        assert!(timestamps_enabled.log_timestamps);
    }

    #[test]
    fn test_from_lookup_traffic_variants_and_backtrace() {
        let summary = config_from_pairs(&[("FASTMCP_TRAFFIC", "summary")]);
        assert_eq!(summary.traffic_verbosity, TrafficVerbosity::Summary);
        assert!(summary.show_request_traffic);

        let headers = config_from_pairs(&[("FASTMCP_TRAFFIC", "2")]);
        assert_eq!(headers.traffic_verbosity, TrafficVerbosity::Headers);
        assert!(headers.show_request_traffic);

        let full = config_from_pairs(&[("FASTMCP_TRAFFIC", "3")]);
        assert_eq!(full.traffic_verbosity, TrafficVerbosity::Full);
        assert!(full.show_request_traffic);

        let none = config_from_pairs(&[("FASTMCP_TRAFFIC", "none")]);
        assert_eq!(none.traffic_verbosity, TrafficVerbosity::None);
        assert!(!none.show_request_traffic);

        let unknown = config_from_pairs(&[("FASTMCP_TRAFFIC", "loud")]);
        assert_eq!(unknown.traffic_verbosity, TrafficVerbosity::None);
        assert!(!unknown.show_request_traffic);

        let backtrace = config_from_pairs(&[("RUST_BACKTRACE", "full")]);
        assert!(backtrace.show_backtrace);
    }

    #[test]
    fn test_additional_builder_methods_and_accessors() {
        let custom = CustomColors {
            primary: Some("#123456".to_string()),
            secondary: None,
            success: Some("#22aa22".to_string()),
            warning: None,
            error: Some("#ff0000".to_string()),
        };

        let config = ConsoleConfig::new()
            .without_suggestions()
            .with_custom_colors(custom.clone())
            .with_context(DisplayContext::new_agent())
            .with_max_table_rows(50)
            .with_max_json_depth(3)
            .with_truncate_at(80);

        assert!(!config.show_suggestions);
        assert!(config.custom_colors.is_some());
        assert_eq!(
            config
                .custom_colors
                .as_ref()
                .and_then(|c| c.primary.as_deref()),
            Some("#123456")
        );
        assert_eq!(config.context, Some(DisplayContext::Agent));
        assert_eq!(config.max_table_rows, 50);
        assert_eq!(config.max_json_depth, 3);
        assert_eq!(config.truncate_at, 80);
        assert!(std::ptr::eq(config.theme(), crate::theme::theme()));
    }

    #[test]
    fn test_context_resolution_and_should_use_rich() {
        let plain = ConsoleConfig::new().plain_mode();
        assert_eq!(plain.resolve_context(), DisplayContext::Agent);
        assert!(!plain.should_use_rich());

        let forced_rich = ConsoleConfig::new().force_color(true);
        assert_eq!(forced_rich.resolve_context(), DisplayContext::Human);
        assert!(forced_rich.should_use_rich());

        let explicit_agent = ConsoleConfig::new().with_context(DisplayContext::new_agent());
        assert_eq!(explicit_agent.resolve_context(), DisplayContext::Agent);
        assert!(!explicit_agent.should_use_rich());

        let explicit_human = ConsoleConfig::new().with_context(DisplayContext::new_human());
        assert_eq!(explicit_human.resolve_context(), DisplayContext::Human);
        assert!(explicit_human.should_use_rich());
    }

    #[test]
    fn test_builder_methods_via_fn_pointers() {
        let set_force_color: fn(ConsoleConfig, bool) -> ConsoleConfig = ConsoleConfig::force_color;
        let set_banner: fn(ConsoleConfig, BannerStyle) -> ConsoleConfig =
            ConsoleConfig::with_banner;
        let set_log: fn(ConsoleConfig, log::Level) -> ConsoleConfig = ConsoleConfig::with_log_level;
        let set_traffic: fn(ConsoleConfig, TrafficVerbosity) -> ConsoleConfig =
            ConsoleConfig::with_traffic;
        let set_stats: fn(ConsoleConfig, u64) -> ConsoleConfig = ConsoleConfig::with_periodic_stats;
        let disable_suggestions: fn(ConsoleConfig) -> ConsoleConfig =
            ConsoleConfig::without_suggestions;
        let set_custom: fn(ConsoleConfig, CustomColors) -> ConsoleConfig =
            ConsoleConfig::with_custom_colors;
        let set_context: fn(ConsoleConfig, DisplayContext) -> ConsoleConfig =
            ConsoleConfig::with_context;
        let set_rows: fn(ConsoleConfig, usize) -> ConsoleConfig =
            ConsoleConfig::with_max_table_rows;
        let set_depth: fn(ConsoleConfig, usize) -> ConsoleConfig =
            ConsoleConfig::with_max_json_depth;
        let set_truncate: fn(ConsoleConfig, usize) -> ConsoleConfig =
            ConsoleConfig::with_truncate_at;

        let custom = CustomColors {
            primary: Some("#111111".to_string()),
            secondary: Some("#222222".to_string()),
            success: None,
            warning: Some("#ffaa00".to_string()),
            error: None,
        };

        let config = set_truncate(
            set_depth(
                set_rows(
                    set_context(
                        set_custom(
                            disable_suggestions(set_stats(
                                set_traffic(
                                    set_log(
                                        set_banner(
                                            set_force_color(ConsoleConfig::new(), false),
                                            BannerStyle::None,
                                        ),
                                        log::Level::Error,
                                    ),
                                    TrafficVerbosity::Headers,
                                ),
                                15,
                            )),
                            custom.clone(),
                        ),
                        DisplayContext::new_human(),
                    ),
                    12,
                ),
                7,
            ),
            42,
        );

        assert_eq!(config.force_color, Some(false));
        assert_eq!(config.banner_style, BannerStyle::None);
        assert!(!config.show_banner);
        assert_eq!(config.log_level, Some(log::Level::Error));
        assert_eq!(config.traffic_verbosity, TrafficVerbosity::Headers);
        assert!(config.show_request_traffic);
        assert!(config.show_stats_periodic);
        assert_eq!(config.stats_interval_secs, 15);
        assert!(!config.show_suggestions);
        assert_eq!(
            config
                .custom_colors
                .as_ref()
                .and_then(|c| c.secondary.as_deref()),
            Some("#222222")
        );
        assert_eq!(config.context, Some(DisplayContext::Human));
        assert_eq!(config.max_table_rows, 12);
        assert_eq!(config.max_json_depth, 7);
        assert_eq!(config.truncate_at, 42);
    }

    #[test]
    fn test_from_env_and_fallback_context_resolution_paths() {
        let _ = ConsoleConfig::from_env();

        let forced_false = ConsoleConfig::new()
            .force_color(false)
            .with_context(DisplayContext::new_agent());
        assert_eq!(forced_false.resolve_context(), DisplayContext::Agent);
        assert!(!forced_false.should_use_rich());

        let explicit_human = ConsoleConfig::new()
            .force_color(false)
            .with_context(DisplayContext::new_human());
        assert_eq!(explicit_human.resolve_context(), DisplayContext::Human);
        assert!(explicit_human.should_use_rich());
    }

    // =========================================================================
    // Additional coverage tests (bd-2ebx)
    // =========================================================================

    #[test]
    fn banner_style_and_traffic_verbosity_defaults() {
        assert_eq!(BannerStyle::default(), BannerStyle::Full);
        assert_eq!(TrafficVerbosity::default(), TrafficVerbosity::None);
    }

    #[test]
    fn console_config_debug_and_clone() {
        let config = ConsoleConfig::new()
            .with_log_level(log::Level::Info)
            .with_max_table_rows(42);
        let debug = format!("{config:?}");
        assert!(debug.contains("ConsoleConfig"));
        assert!(debug.contains("42"));

        let cloned = config.clone();
        assert_eq!(cloned.max_table_rows, 42);
        assert_eq!(cloned.log_level, Some(log::Level::Info));
    }

    #[test]
    fn custom_colors_default_all_none() {
        let colors = CustomColors::default();
        assert!(colors.primary.is_none());
        assert!(colors.secondary.is_none());
        assert!(colors.success.is_none());
        assert!(colors.warning.is_none());
        assert!(colors.error.is_none());

        let debug = format!("{colors:?}");
        assert!(debug.contains("CustomColors"));
    }

    #[test]
    fn from_lookup_banner_none_literal_and_full_explicit() {
        let none = config_from_pairs(&[("FASTMCP_BANNER", "none")]);
        assert_eq!(none.banner_style, BannerStyle::None);
        assert!(!none.show_banner);

        let full = config_from_pairs(&[("FASTMCP_BANNER", "full")]);
        assert_eq!(full.banner_style, BannerStyle::Full);
        assert!(full.show_banner);
    }

    #[test]
    fn from_lookup_remaining_log_levels() {
        let info = config_from_pairs(&[("FASTMCP_LOG", "info")]);
        assert_eq!(info.log_level, Some(log::Level::Info));

        let warn = config_from_pairs(&[("FASTMCP_LOG", "warn")]);
        assert_eq!(warn.log_level, Some(log::Level::Warn));

        let error = config_from_pairs(&[("FASTMCP_LOG", "error")]);
        assert_eq!(error.log_level, Some(log::Level::Error));
    }

    #[test]
    fn from_lookup_traffic_numeric_one() {
        let summary = config_from_pairs(&[("FASTMCP_TRAFFIC", "1")]);
        assert_eq!(summary.traffic_verbosity, TrafficVerbosity::Summary);
        assert!(summary.show_request_traffic);
    }

    #[test]
    fn with_banner_none_clears_show_banner() {
        let config = ConsoleConfig::new().with_banner(BannerStyle::None);
        assert!(!config.show_banner);
        assert_eq!(config.banner_style, BannerStyle::None);
    }

    #[test]
    fn with_traffic_none_clears_show_request_traffic() {
        let config = ConsoleConfig::new()
            .with_traffic(TrafficVerbosity::Full)
            .with_traffic(TrafficVerbosity::None);
        assert!(!config.show_request_traffic);
        assert_eq!(config.traffic_verbosity, TrafficVerbosity::None);
    }

    #[test]
    fn default_fields_full_coverage() {
        let config = ConsoleConfig::default();
        assert!(config.log_targets);
        assert!(!config.log_file_line);
        assert!(config.show_error_codes);
        assert!(!config.show_stats_periodic);
        assert_eq!(config.stats_interval_secs, 60);
        assert_eq!(config.max_json_depth, 5);
        assert_eq!(config.truncate_at, 200);
        assert!(config.show_suggestions);
        assert!(config.custom_colors.is_none());
        assert!(config.context.is_none());
        assert!(config.force_color.is_none());
    }
}