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
//! Layering a global MCP server list with per-consumer overrides (#7452).
//!
//! Why: the owner requirement behind #7451 is that an MCP connector is
//! configurable per assistant AS WELL AS globally. Both trusty-agents and
//! trusty-code need the same answer to "given the shared file and this
//! assistant's own entries, what does this assistant actually connect to",
//! and two independent implementations of that precedence would drift the way
//! the four config shapes did.
//!
//! What: [`resolve`] applies a list of [`McpServerOverride`]s to a global
//! list. Precedence is WHOLESALE, never a field merge: an override that names
//! a server replaces it entirely. A partial merge would make an override's
//! meaning depend on which fields the global entry happened to set, so
//! removing a global `env` key would be impossible to express.
//!
//! Test: `crates/trusty-mcp/tests/mcp_config.rs` — `resolve_set_replaces_wholesale`,
//! `resolve_disable_removes_global_entry`, `resolve_set_reenables_disabled_global`,
//! `resolve_orders_global_first_then_new_additions`.
use BTreeMap;
use McpServerConfig;
/// One change a consumer's own tier makes to the global list.
///
/// Why: the two operations every consumer needs — "use this instead" and
/// "do not use this at all". Disabling deserves its own variant rather than a
/// `Set` carrying `enabled = false`, because an assistant that merely wants a
/// globally configured server switched off should not have to restate the
/// server's entire transport to say so.
/// What: `Set` supplies a complete replacement (or an addition, when the name
/// is not in the global list); `Disable` removes the global entry by name. A
/// `Set` carrying `enabled = false` is the third answer and not a synonym for
/// either: the entry stays in the output, disabled, so a consumer can still
/// see what it is choosing not to connect to.
/// Test: `resolve_set_replaces_wholesale`, `resolve_disable_removes_global_entry`,
/// `resolve_set_with_enabled_false_stays_disabled_in_output`.
/// The effective server list for one consumer.
///
/// Why: one deterministic answer, so an assistant's connector list does not
/// depend on map iteration order or on which crate computed it.
/// What: overrides are folded left to right, so a later override for the same
/// name wins over an earlier one — including a `Set` after a `Disable`, which
/// is how a consumer re-enables something the global tier turned off. The
/// result is then, in order:
///
/// 1. every global server whose name no override disabled, each replaced
/// wholesale by its `Set` override when one exists (the global entry's
/// POSITION is kept, so overriding a server does not move it);
/// 2. every `Set` naming a server absent from the global list, in the order
/// those overrides first appeared.
///
/// A global list carrying a duplicate name keeps only its first occurrence —
/// [`McpConfigFile`](super::McpConfigFile) rejects such a file, so this is the
/// defensive branch for a list assembled in memory.
/// Test: `resolve_set_replaces_wholesale`, `resolve_disable_removes_global_entry`,
/// `resolve_set_reenables_disabled_global`,
/// `resolve_orders_global_first_then_new_additions`,
/// `resolve_later_override_wins_over_earlier`,
/// `resolve_drops_duplicate_global_names`.