basis 0.12.0

The basis SDK: workspace discovery, run lifecycle, one event stream, and the two seams. No protocol, no transport, no TTY.
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
//! The `.mcp.json` format.
//!
//! One object, `mcpServers`, keyed by name — the name is the map key rather
//! than a field, which is the one place this format and mentra's
//! [`McpServerConfig`] disagree.
//!
//! An entry names its transport with `type`, or omits it and lets its shape
//! say: `command` means stdio, `url` means a remote server. Both or neither is
//! a mistake worth reporting rather than guessing at, because either guess
//! silently starts something the operator did not ask for.

use std::{
    collections::{BTreeMap, HashMap},
    path::Path,
};

use mentra::{
    McpServerConfig, McpSseServerConfig, McpStreamableHttpConfigError,
    McpStreamableHttpServerConfig,
};
use serde::Deserialize;

use crate::expand::expand;

use super::{ConfiguredServer, McpError, McpServer};

/// The whole file.
#[derive(Debug, Deserialize)]
struct McpFile {
    /// Optional so that its absence can be reported. A missing `mcpServers`
    /// is almost always a misspelled one, and defaulting to empty would turn
    /// that into a workspace whose servers quietly never start.
    #[serde(rename = "mcpServers")]
    mcp_servers: Option<BTreeMap<String, RawServer>>,
}

/// One entry, before it is known which transport it describes.
///
/// Unknown fields are tolerated: these files are shared with other agents, and
/// rejecting a key basis has no opinion about would make a working file
/// unreadable for no gain.
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
struct RawServer {
    #[serde(rename = "type")]
    transport: Option<String>,
    command: Option<String>,
    #[serde(default)]
    args: Vec<String>,
    #[serde(default)]
    env: HashMap<String, String>,
    cwd: Option<String>,
    url: Option<String>,
    #[serde(default)]
    headers: BTreeMap<String, String>,
}

/// Which transport an entry asks for, once the question is settled.
enum Transport {
    Stdio,
    Sse,
    Http,
}

/// Reads `text` as the file at `path`.
pub(super) fn parse(path: &Path, text: &str) -> Result<Vec<ConfiguredServer>, McpError> {
    parse_with(path, text, &|name| std::env::var(name).ok())
}

/// The same, against an explicit environment, so the rules are testable
/// without mutating the process's own.
fn parse_with(
    path: &Path,
    text: &str,
    lookup: &dyn Fn(&str) -> Option<String>,
) -> Result<Vec<ConfiguredServer>, McpError> {
    let file: McpFile = serde_json::from_str(text).map_err(|source| McpError::Parse {
        path: path.to_path_buf(),
        // serde's own message quotes the value it choked on, which in this
        // file is as likely as not a credential. Location and kind only.
        problem: match source.classify() {
            serde_json::error::Category::Syntax => "a syntax error",
            serde_json::error::Category::Data => "a value of the wrong type",
            serde_json::error::Category::Eof => "an unexpected end of input",
            serde_json::error::Category::Io => "a read error",
        },
        line: source.line(),
        column: source.column(),
    })?;

    let Some(entries) = file.mcp_servers else {
        return Err(McpError::NoServers {
            path: path.to_path_buf(),
        });
    };

    let origin = path.display().to_string();

    entries
        .into_iter()
        .map(|(name, raw)| raw.into_server(&origin, name, lookup))
        .collect()
}

/// mentra's refusal, restated where it would echo a value.
///
/// `PlaintextCredentials` embeds the whole URL, whose query string may hold
/// an expanded credential — and it suggests `allow_plaintext_credentials`, a
/// knob this file deliberately does not offer (see the module docs on
/// transports). Every other variant already names fields without their
/// values.
fn refused(error: &McpStreamableHttpConfigError) -> String {
    match error {
        McpStreamableHttpConfigError::PlaintextCredentials { .. } => {
            "has headers that would travel over plaintext `http` to a \
             non-loopback host; use `https` or a loopback address"
                .to_string()
        }
        other => format!("is not a valid Streamable HTTP configuration: {other}"),
    }
}

impl RawServer {
    fn into_server(
        self,
        origin: &str,
        name: String,
        lookup: &dyn Fn(&str) -> Option<String>,
    ) -> Result<ConfiguredServer, McpError> {
        let invalid = |reason: String| McpError::Invalid {
            origin: origin.to_string(),
            name: name.clone(),
            reason,
        };

        // Expansion failures name the field rather than quoting it. `env` and
        // `headers` are where credentials live, so the field's *name* is the
        // most an error may say about it — see [`McpError`].
        let expanded = |field: &str, raw: &str| -> Result<String, McpError> {
            expand(raw, lookup)
                .map_err(|reason| invalid(format!("has a `{field}` value that {reason}")))
        };

        if name.trim().is_empty() {
            return Err(invalid("has an empty name".to_string()));
        }
        if let Err(reason) = McpServer::validate_name(&name) {
            return Err(invalid(reason.to_string()));
        }

        let (transport, inferred) = self.transport(origin, &name)?;
        // Only the SSE choice is worth diagnosing later: it is the one a
        // failed connect may want to blame on the bare-`url` rule.
        let sse_inferred = matches!(transport, Transport::Sse) && inferred;

        let server = match transport {
            Transport::Stdio => {
                let command = self
                    .command
                    .as_deref()
                    .filter(|command| !command.trim().is_empty())
                    .ok_or_else(|| invalid("has no `command` to run".to_string()))?;

                Ok(McpServer::Stdio(McpServerConfig {
                    command: expanded("command", command)?,
                    args: self
                        .args
                        .iter()
                        .enumerate()
                        .map(|(index, arg)| expanded(&format!("args[{index}]"), arg))
                        .collect::<Result<_, _>>()?,
                    env: self
                        .env
                        .iter()
                        .map(|(key, value)| {
                            Ok((key.clone(), expanded(&format!("env.{key}"), value)?))
                        })
                        .collect::<Result<_, McpError>>()?,
                    cwd: self
                        .cwd
                        .as_deref()
                        .map(|cwd| expanded("cwd", cwd))
                        .transpose()?,
                    name,
                }))
            }
            Transport::Sse => {
                let (url, headers) = self.remote_parts(&invalid, &expanded)?;

                let config = headers.into_iter().fold(
                    McpSseServerConfig::new(name.clone(), url),
                    |config, (key, value)| config.with_header(key, value),
                );

                Ok(McpServer::Sse(config))
            }
            Transport::Http => {
                let (url, headers) = self.remote_parts(&invalid, &expanded)?;

                let config = headers.into_iter().fold(
                    McpStreamableHttpServerConfig::new(name.clone(), url),
                    |config, (key, value)| config.with_header(key, value),
                );

                // Checked here, where a refused entry fails the workspace
                // open loudly, rather than at connect — where a failure is a
                // stderr warning an ACP client never sees.
                config
                    .validate()
                    .map_err(|error| invalid(refused(&error)))?;

                Ok(McpServer::Http(config))
            }
        }?;

        Ok(ConfiguredServer {
            server,
            sse_inferred,
        })
    }

    /// The pieces both remote transports read the same way: a non-empty
    /// `url`, and every header, all `${VAR}`-expanded, in file order.
    fn remote_parts(
        &self,
        invalid: &dyn Fn(String) -> McpError,
        expanded: &dyn Fn(&str, &str) -> Result<String, McpError>,
    ) -> Result<(String, Vec<(String, String)>), McpError> {
        let url = self
            .url
            .as_deref()
            .filter(|url| !url.trim().is_empty())
            .ok_or_else(|| invalid("has no `url` to reach".to_string()))?;
        let url = expanded("url", url)?;

        let headers = self
            .headers
            .iter()
            .map(|(key, value)| Ok((key.clone(), expanded(&format!("headers.{key}"), value)?)))
            .collect::<Result<Vec<_>, McpError>>()?;

        Ok((url, headers))
    }

    /// Settles which transport the entry describes, and whether it was the
    /// entry's shape rather than its `type` that settled it.
    fn transport(&self, origin: &str, name: &str) -> Result<(Transport, bool), McpError> {
        let invalid = |reason: String| McpError::Invalid {
            origin: origin.to_string(),
            name: name.to_string(),
            reason,
        };

        match self.transport.as_deref().map(str::trim) {
            Some("stdio") => Ok((Transport::Stdio, false)),
            Some("sse") => Ok((Transport::Sse, false)),
            // Both spellings are in the wild for the same transport.
            Some("http") | Some("streamable-http") => Ok((Transport::Http, false)),
            Some(other) => Err(invalid(format!("names an unknown transport `{other}`"))),
            // The original format had no `type` field at all, so an entry's
            // shape is the older way of saying the same thing.
            None => match (self.command.is_some(), self.url.is_some()) {
                (true, false) => Ok((Transport::Stdio, true)),
                // Deliberately still SSE, never Streamable HTTP: a bare `url`
                // has meant the 2024-11-05 HTTP+SSE transport since before the
                // third one existed, and a file keeps its meaning. A
                // Streamable HTTP server says `type: "http"` — and the
                // inference is recorded, so a failed connect can say what
                // chose SSE.
                (false, true) => Ok((Transport::Sse, true)),
                (true, true) => Err(invalid(
                    "has both `command` and `url`; set `type` to say which is meant".to_string(),
                )),
                (false, false) => Err(invalid("has neither `command` nor `url`".to_string())),
            },
        }
    }
}

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

    fn nothing_set(_: &str) -> Option<String> {
        None
    }

    fn parse_text(text: &str) -> Result<Vec<McpServer>, McpError> {
        parsed(text, &nothing_set)
    }

    /// [`parse_with`] with the inference flags stripped, for the tests that
    /// are about the servers rather than about how their transport was
    /// chosen.
    fn parsed(
        text: &str,
        lookup: &dyn Fn(&str) -> Option<String>,
    ) -> Result<Vec<McpServer>, McpError> {
        parse_with(Path::new("/repo/.mcp.json"), text, lookup).map(|configured| {
            configured
                .into_iter()
                .map(|configured| configured.server)
                .collect()
        })
    }

    #[test]
    fn a_bare_url_records_that_sse_was_inferred() {
        let configured = parse_with(
            Path::new("/repo/.mcp.json"),
            r#"{"mcpServers":{
                "bare":{"url":"https://example.com/sse"},
                "typed":{"type":"sse","url":"https://example.com/sse"}
            }}"#,
            &nothing_set,
        )
        .expect("both parse");

        assert!(
            configured[0].sse_inferred,
            "no `type` named the transport, so the shape rule chose"
        );
        assert!(
            !configured[1].sse_inferred,
            "an explicit `type` is the operator's own choice"
        );
    }

    #[test]
    fn the_documented_shape_becomes_a_stdio_server() {
        let servers = parse_text(
            r#"{
                "mcpServers": {
                    "filesystem": {
                        "command": "npx",
                        "args": ["-y", "@modelcontextprotocol/server-filesystem"],
                        "env": {"ROOT": "/repo"}
                    }
                }
            }"#,
        )
        .expect("a well-formed file");

        assert_eq!(servers.len(), 1);
        let config = servers[0].as_stdio().expect("stdio");
        assert_eq!(config.name, "filesystem", "the map key becomes the name");
        assert_eq!(config.command, "npx");
        assert_eq!(
            config.args,
            vec!["-y", "@modelcontextprotocol/server-filesystem"]
        );
        assert_eq!(config.env.get("ROOT").map(String::as_str), Some("/repo"));
        assert_eq!(config.cwd, None);
    }

    #[test]
    fn an_empty_server_object_is_allowed() {
        let servers = parse_text(r#"{"mcpServers": {}}"#).expect("explicitly empty is a choice");

        assert!(servers.is_empty());
    }

    #[test]
    fn a_missing_mcp_servers_key_is_an_error() {
        let error = parse_text(r#"{"mcpservers": {}}"#).expect_err("a misspelled key is caught");

        assert!(matches!(error, McpError::NoServers { .. }), "{error}");
    }

    #[test]
    fn unknown_keys_are_tolerated() {
        let servers = parse_text(
            r#"{
                "$schema": "https://example.com/mcp.json",
                "mcpServers": {"fs": {"command": "npx", "disabled": false}}
            }"#,
        )
        .expect("these files are shared with other agents");

        assert_eq!(servers.len(), 1);
    }

    #[test]
    fn cwd_is_carried_through() {
        let servers = parse_text(r#"{"mcpServers":{"fs":{"command":"srv","cwd":"/tmp"}}}"#)
            .expect("a well-formed file");

        assert_eq!(
            servers[0].as_stdio().expect("stdio").cwd.as_deref(),
            Some("/tmp")
        );
    }

    #[test]
    fn a_url_without_a_type_is_an_sse_server() {
        let servers = parse_text(r#"{"mcpServers":{"obs":{"url":"https://example.com/sse"}}}"#)
            .expect("shape names the transport");

        let config = servers[0].as_sse().expect("sse");
        assert_eq!(config.name, "obs");
        assert_eq!(config.url, "https://example.com/sse");
    }

    #[test]
    fn an_explicit_sse_type_is_honored() {
        let servers =
            parse_text(r#"{"mcpServers":{"obs":{"type":"sse","url":"https://example.com/sse"}}}"#)
                .expect("an explicit type");

        assert!(servers[0].as_sse().is_some());
    }

    #[test]
    fn sse_headers_are_carried_through() {
        let servers = parse_text(
            r#"{"mcpServers":{"obs":{"url":"https://example.com/sse","headers":{"authorization":"Bearer t"}}}}"#,
        )
        .expect("a well-formed file");

        let config = servers[0].as_sse().expect("sse");
        assert_eq!(
            config
                .headers
                .get("authorization")
                .map(mentra::mcp::SecretString::expose_secret),
            Some("Bearer t")
        );
    }

    #[test]
    fn an_http_type_is_a_streamable_http_server() {
        let servers = parse_text(r#"{"mcpServers":{"api":{"type":"http","url":"https://x/mcp"}}}"#)
            .expect("mentra speaks this transport");

        let config = servers[0].as_http().expect("http");
        assert_eq!(config.name, "api");
        assert_eq!(config.url, "https://x/mcp");
    }

    #[test]
    fn the_streamable_http_alias_names_the_same_transport() {
        let servers = parse_text(
            r#"{"mcpServers":{"api":{"type":"streamable-http","url":"https://x/mcp"}}}"#,
        )
        .expect("both spellings are in the wild");

        assert!(servers[0].as_http().is_some());
    }

    #[test]
    fn http_url_and_headers_are_expanded() {
        let servers = parsed(
            r#"{"mcpServers":{"api":{"type":"http","url":"https://${HOST}/mcp","headers":{"authorization":"Bearer ${API_TOKEN}"}}}}"#,
            &|name| match name {
                "HOST" => Some("example.com".to_string()),
                "API_TOKEN" => Some("secret".to_string()),
                _ => None,
            },
        )
        .expect("both are set");

        let config = servers[0].as_http().expect("http");
        assert_eq!(config.url, "https://example.com/mcp");
        assert_eq!(
            config
                .headers
                .get("authorization")
                .map(mentra::mcp::SecretString::expose_secret),
            Some("Bearer secret")
        );
    }

    #[test]
    fn a_remote_servers_debug_does_not_print_an_expanded_credential() {
        // The parser has already turned `${API_TOKEN}` into the real value by
        // the time this type exists, and `McpConfig` derives Debug around it.
        // The query string matters as much as the headers: mentra types only
        // the headers as `SecretString`, so the URL is basis's to redact.
        let servers = parsed(
            r#"{"mcpServers":{
                "api":{"type":"http","url":"https://x/mcp?key=${API_TOKEN}","headers":{"authorization":"${API_TOKEN}"}},
                "obs":{"type":"sse","url":"https://x/sse?key=${API_TOKEN}","headers":{"authorization":"${API_TOKEN}"}}
            }}"#,
            &|name| (name == "API_TOKEN").then(|| "sk-live-do-not-print-me".to_string()),
        )
        .expect("the token is set");

        for server in &servers {
            let rendered = format!("{server:?}");
            assert!(
                !rendered.contains("sk-live-do-not-print-me"),
                "an expanded credential reached Debug: {rendered}"
            );
            assert!(
                rendered.contains("https://x"),
                "the redaction must not hide where the server is: {rendered}"
            );
        }
    }

    #[test]
    fn plaintext_credentials_to_a_remote_host_fail_at_parse() {
        let error = parse_text(
            r#"{"mcpServers":{"api":{"type":"http","url":"http://example.com/mcp","headers":{"authorization":"Bearer t"}}}}"#,
        )
        .expect_err("a connect-time warning is one an ACP client never sees");

        let rendered = error.to_string();
        assert!(matches!(error, McpError::Invalid { .. }), "{rendered}");
        assert!(rendered.contains("api"), "{rendered}");
        assert!(
            !rendered.contains("example.com") && !rendered.contains("Bearer"),
            "nothing read from the file returns in an error: {rendered}"
        );
    }

    #[test]
    fn loopback_plaintext_http_is_mentras_own_carve_out() {
        let servers = parse_text(
            r#"{"mcpServers":{"local":{"type":"http","url":"http://127.0.0.1:8080/mcp","headers":{"x-env":"dev"}}}}"#,
        )
        .expect("a local dev server needs no ceremony");

        assert!(servers[0].as_http().is_some());
    }

    #[test]
    fn a_malformed_http_url_fails_at_parse() {
        let error = parse_text(r#"{"mcpServers":{"api":{"type":"http","url":"not a url"}}}"#)
            .expect_err("validation happens at the boundary, not mid-handshake");

        assert!(matches!(error, McpError::Invalid { .. }), "{error}");
    }

    #[test]
    fn an_unknown_transport_is_an_error() {
        let error = parse_text(r#"{"mcpServers":{"x":{"type":"carrier-pigeon","url":"u"}}}"#)
            .expect_err("unknown transports are errors");

        assert!(matches!(error, McpError::Invalid { .. }), "{error}");
    }

    #[test]
    fn an_entry_with_neither_command_nor_url_is_an_error() {
        let error = parse_text(r#"{"mcpServers":{"x":{"args":["-y"]}}}"#)
            .expect_err("nothing to connect to");

        assert!(matches!(error, McpError::Invalid { .. }), "{error}");
    }

    #[test]
    fn an_entry_with_both_command_and_url_is_an_error() {
        let error = parse_text(r#"{"mcpServers":{"x":{"command":"srv","url":"https://x"}}}"#)
            .expect_err("ambiguous rather than guessed at");

        assert!(matches!(error, McpError::Invalid { .. }), "{error}");
    }

    #[test]
    fn an_empty_command_is_an_error() {
        let error = parse_text(r#"{"mcpServers":{"x":{"type":"stdio","command":"  "}}}"#)
            .expect_err("nothing to spawn");

        assert!(matches!(error, McpError::Invalid { .. }), "{error}");
    }

    #[test]
    fn an_empty_name_is_an_error() {
        let error = parse_text(r#"{"mcpServers":{"":{"command":"srv"}}}"#)
            .expect_err("the name namespaces the tools");

        assert!(matches!(error, McpError::Invalid { .. }), "{error}");
    }

    #[test]
    fn a_name_containing_a_double_underscore_is_an_error() {
        let error = parse_text(r#"{"mcpServers":{"evil__foo":{"command":"srv"}}}"#)
            .expect_err("mentra's tool-name split would parse this as server `evil`");

        assert!(matches!(error, McpError::Invalid { .. }), "{error}");
        assert!(error.to_string().contains("tool-name encoding"), "{error}");
    }

    #[test]
    fn environment_placeholders_are_expanded() {
        let servers = parsed(
            r#"{"mcpServers":{"gh":{"command":"srv","args":["--org","${ORG}"],"env":{"TOKEN":"${GH_TOKEN}"}}}}"#,
            &|name| match name {
                "ORG" => Some("oops-rs".to_string()),
                "GH_TOKEN" => Some("secret".to_string()),
                _ => None,
            },
        )
        .expect("both are set");

        let config = servers[0].as_stdio().expect("stdio");
        assert_eq!(config.args, vec!["--org", "oops-rs"]);
        assert_eq!(config.env.get("TOKEN").map(String::as_str), Some("secret"));
    }

    #[test]
    fn an_unset_placeholder_names_the_server_and_the_field() {
        let error =
            parse_text(r#"{"mcpServers":{"gh":{"command":"srv","env":{"T":"${GH_TOKEN}"}}}}"#)
                .expect_err("an unset variable is an error");

        let rendered = error.to_string();
        assert!(rendered.contains("gh"), "{rendered}");
        assert!(rendered.contains("env.T"), "{rendered}");
        assert!(rendered.contains("GH_TOKEN"), "{rendered}");
    }

    #[test]
    fn no_error_repeats_a_value_from_the_file() {
        // These files are gitignored because `env` and `headers` hold
        // credentials, and these messages travel to clients and logs.
        const SECRET: &str = "sk-live-do-not-print-me";

        let broken = [
            format!(r#"{{"mcpServers":{{"a":{{"command":"srv","env":{{"T":"{SECRET}${{"}}}}}}}}"#),
            format!(r#"{{"mcpServers":{{"b":{{"command":"srv","args":["{SECRET}${{NOPE}}"]}}}}}}"#),
            format!(
                r#"{{"mcpServers":{{"c":{{"url":"https://x/sse","headers":{{"authorization":"{SECRET}${{}}"}}}}}}}}"#
            ),
            // serde's own message would quote this one.
            format!(r#"{{"mcpServers":{{"d":{{"command":"srv","env":"{SECRET}"}}}}}}"#),
        ];

        for text in broken {
            let error = parse_text(&text).expect_err("each of these fails");

            assert!(
                !error.to_string().contains(SECRET),
                "a value leaked into: {error}"
            );
        }
    }

    #[test]
    fn servers_come_back_in_a_stable_order() {
        let servers = parse_text(
            r#"{"mcpServers":{"zeta":{"command":"z"},"alpha":{"command":"a"},"mid":{"command":"m"}}}"#,
        )
        .expect("a well-formed file");

        let names: Vec<&str> = servers.iter().map(McpServer::name).collect();
        assert_eq!(
            names,
            vec!["alpha", "mid", "zeta"],
            "registration order must not depend on hashing"
        );
    }
}