Skip to main content

surjection_core/adapters/
antigravity.rs

1//! Antigravity (`antigravity`): SPEC 7.3, 7.4 and 7.5.
2//!
3//! - User scope: `~/.gemini/config/mcp_config.json`.
4//! - Project scope: `<P>/.agents/mcp_config.json`.
5//! - Entries: `mcpServers.<name>` without `type`: `{command, args, env}`
6//!   (stdio) or `{serverUrl, headers}` (Streamable HTTP; `serverUrl` means
7//!   http, SPEC 7.5). No SSE, no `httpUrl`, no `cwd`. `timeoutSeconds` is a
8//!   passthrough field.
9//! - No variable expansion is assumed: values are written literally, so
10//!   `env` delivery is not available and secrets use another mode.
11//!
12//! Assumptions left for Tier C verification (`scripts/verify-clients.md`,
13//! ANT-*): `[verify]` the user file (ANT-1, SPEC 7.3 names
14//! `~/.gemini/config/`; record whether the app reads
15//! `~/.gemini/antigravity/` instead) and the project file (ANT-2), whether
16//! any variable syntax is expanded (ANT-3, `env_ref = None` until then),
17//! that there is no native disable field (ANT-4: an existing `disabled` or
18//! `disabledTools` key is kept as an unmapped field), how a project entry
19//! combines with a same-named user entry and whether a project can hide one
20//! (ANT-5, `ProjectSemantics::Unknown`, `cannot_suppress_in_project`), any
21//! trust prompt (ANT-6), that a `url` key is not read (ANT-7), that any
22//! non-empty name loads (ANT-8), that Windows starts `npx` without `cmd /c`
23//! (ANT-9) and the detection probes (ANT-10).
24
25use crate::adapters::caps::{
26    Caps, FieldSet, ProjectSemantics, Source, TimeUnit, TimeoutField, TransportSet,
27};
28use crate::adapters::detect::Probe;
29use crate::adapters::location::Location;
30use crate::adapters::mapper::{
31    Canonical, EntryMapper, Launch, MapError, RenderedServer, ServerDef, WriteCx, carry_over,
32    check_name, check_transport, drop_empty, existing_entry, read_disabled, read_tools, shape,
33    split_rest, string_field, string_list, string_map, string_map_field, strings, unsupported,
34    write_enabled, write_passthrough, write_tools,
35};
36use crate::adapters::spec::{AdapterSpec, ContainerPath, McpSpec, Tier, exact_names};
37use crate::env::Os;
38use crate::formats::{Format, NativeMap, NativeValue};
39use crate::model::clients::passthrough_of;
40use crate::model::server::{ServerFields, Transport};
41
42pub const ID: &str = "antigravity";
43
44const SERVER_URL: &str = "serverUrl";
45
46const CAPS: Caps = Caps {
47    transports: TransportSet::STDIO_HTTP,
48    env_ref: None,
49    env_ref_fields: FieldSet::NONE,
50    command_ref: None,
51    native_disable: None,
52    project_disable: None,
53    project_semantics: ProjectSemantics::Unknown,
54    precedence: &[Source::Project, Source::User],
55    compat_reads: &[],
56    trust_gate: None,
57    rewrites_file_at_runtime: false,
58    restart_required: false,
59    tool_filter: None,
60    windows_shell_shim: false,
61    timeouts: &[TimeoutField {
62        key: "timeoutSeconds",
63        unit: TimeUnit::Seconds,
64    }],
65    passthrough_allowlist: passthrough_of(ID),
66};
67
68/// Keys the Antigravity mapper models besides passthrough fields.
69const MODELED_KEYS: [&str; 5] = ["command", "args", "env", SERVER_URL, "headers"];
70
71fn is_modeled(key: &str) -> bool {
72    MODELED_KEYS.contains(&key) || CAPS.passthrough_allowlist.contains(&key)
73}
74
75fn valid_name(name: &str) -> bool {
76    !name.is_empty()
77}
78
79/// The `mcpServers.<name>` entry of Antigravity's `mcp_config.json`:
80/// `{command, args, env}` or `{serverUrl, headers}`.
81#[derive(Debug)]
82pub struct AntigravityJson;
83
84impl EntryMapper for AntigravityJson {
85    fn to_native(
86        &self,
87        server: &RenderedServer,
88        cx: &WriteCx<'_>,
89    ) -> Result<NativeValue, MapError> {
90        check_name(valid_name, &server.name)?;
91        check_transport(&CAPS, &server.launch)?;
92        let existing = existing_entry(cx);
93        let keep_empty = |key: &str| existing.is_some_and(|entry| entry.contains_key(key));
94        let mut entry = NativeMap::new();
95        match &server.launch {
96            Launch::Stdio(stdio) => {
97                if !stdio.forward_env.is_empty() {
98                    return unsupported("env_vars");
99                }
100                if stdio.cwd.is_some() {
101                    return unsupported("cwd");
102                }
103                entry.insert("command", stdio.command.as_str().into());
104                entry.insert("args", strings(stdio.args.clone()));
105                if !stdio.env.is_empty() || keep_empty("env") {
106                    entry.insert("env", string_map(&stdio.env));
107                }
108            }
109            Launch::Http(remote) => {
110                if remote.headers_helper.is_some() {
111                    return unsupported("headersHelper");
112                }
113                if remote.bearer_env.is_some() {
114                    return unsupported("bearer_token_env_var");
115                }
116                if !remote.headers_env.is_empty() {
117                    return unsupported("env_http_headers");
118                }
119                entry.insert(SERVER_URL, remote.url.as_str().into());
120                if !remote.headers.is_empty() || keep_empty("headers") {
121                    entry.insert("headers", string_map(&remote.headers));
122                }
123            }
124            Launch::Sse(_) => unreachable!("check_transport rejects SSE for Antigravity"),
125        }
126        write_enabled(&mut entry, &CAPS, server, existing)?;
127        write_tools(&mut entry, &CAPS, &server.tools)?;
128        write_passthrough(&mut entry, &CAPS, server)?;
129        carry_over(&mut entry, existing, is_modeled);
130        Ok(NativeValue::Object(entry))
131    }
132
133    fn from_native(&self, key: &str, value: &NativeValue) -> Result<ServerDef, MapError> {
134        let entry = value.as_object().ok_or_else(|| MapError::UnexpectedShape {
135            field: key.to_owned(),
136            expected: "an object",
137        })?;
138        let fields = match (
139            entry.contains_key("command"),
140            entry.contains_key(SERVER_URL),
141        ) {
142            (true, true) => return shape(SERVER_URL, "absent when `command` is set"),
143            (true, false) => ServerFields {
144                transport: Some(Transport::Stdio),
145                command: string_field(entry, "command")?,
146                args: string_list(entry, "args")?,
147                env: string_map_field(entry, "env")?,
148                ..ServerFields::default()
149            },
150            (false, true) => ServerFields {
151                transport: Some(Transport::Http),
152                url: string_field(entry, SERVER_URL)?,
153                headers: string_map_field(entry, "headers")?,
154                ..ServerFields::default()
155            },
156            (false, false) => {
157                return shape("command", "set (or `serverUrl` for a remote server)");
158            }
159        };
160        let mut def = ServerDef {
161            fields,
162            disabled: read_disabled(entry, &CAPS)?,
163            tools: read_tools(entry, &CAPS)?,
164            ..ServerDef::default()
165        };
166        split_rest(&mut def, entry, &CAPS, is_modeled);
167        Ok(def)
168    }
169
170    fn canonical(&self, value: &NativeValue) -> Canonical {
171        let Some(entry) = value.as_object() else {
172            return Canonical::of(value);
173        };
174        let mut entry = entry.clone();
175        drop_empty(&mut entry, &["args", "env", "headers"]);
176        Canonical::of(&NativeValue::Object(entry))
177    }
178}
179
180static MAPPER: AntigravityJson = AntigravityJson;
181
182pub static SPEC: AdapterSpec = AdapterSpec {
183    id: ID,
184    display_name: "Antigravity",
185    tier: Tier::C,
186    detect: &[
187        Probe::Path(Location::Home(".gemini/config")),
188        Probe::Path(Location::Home(".antigravity")),
189        Probe::Path(Location::AppData("Antigravity")),
190        Probe::Executable("antigravity"),
191    ],
192    mcp: Some(McpSpec {
193        oses: &[Os::Windows, Os::Linux, Os::MacOs],
194        read_only: false,
195        user: &[Location::Home(".gemini/config/mcp_config.json")],
196        user_files: None,
197        user_mirrors: &[],
198        profiles: None,
199        project: &[Location::Project(".agents/mcp_config.json")],
200        project_local: &[],
201        format: Format::Json,
202        skeleton: "",
203        container: ContainerPath(&["mcpServers"]),
204        project_local_container: ContainerPath(&["mcpServers"]),
205        legacy_containers: &[],
206        same_name: exact_names,
207        replaced_by: &[],
208        mapper: &MAPPER,
209        caps: CAPS,
210        sign_in: crate::adapters::sign_in::SignIn::UNKNOWN,
211    }),
212};