File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33from __future__ import annotations
44
55import json
6+ import os
67import shutil
78import string
89import subprocess
2324from questionary .question import Question
2425from questionary .styles import merge_styles_default
2526
26- from ucode .agents import copilot , opencode
27+ from ucode .agents import copilot , gemini , opencode
2728from ucode .config_io import restore_file
2829from ucode .databricks import (
2930 build_mcp_service_url ,
@@ -182,6 +183,13 @@ def remove_codex_mcp_server(name: str) -> bool:
182183 return True
183184
184185
186+ def _gemini_cli_env () -> dict [str , str ]:
187+ # Pin GEMINI_CLI_HOME to the same directory the launcher.
188+ env = os .environ .copy ()
189+ env ["GEMINI_CLI_HOME" ] = str (gemini .GEMINI_HOME_DIR )
190+ return env
191+
192+
185193def add_gemini_mcp_server (name : str , url : str ) -> None :
186194 try :
187195 subprocess .run (
@@ -202,6 +210,7 @@ def add_gemini_mcp_server(name: str, url: str) -> None:
202210 capture_output = True ,
203211 text = True ,
204212 timeout = 30 ,
213+ env = _gemini_cli_env (),
205214 )
206215 except subprocess .CalledProcessError as exc :
207216 raise RuntimeError (f"Failed to add MCP server '{ name } ' via gemini CLI." ) from exc
@@ -215,6 +224,7 @@ def remove_gemini_mcp_server(name: str) -> bool:
215224 capture_output = True ,
216225 text = True ,
217226 timeout = 30 ,
227+ env = _gemini_cli_env (),
218228 )
219229 except subprocess .TimeoutExpired as exc :
220230 raise RuntimeError (f"Timed out removing MCP server '{ name } ' via gemini CLI." ) from exc
Original file line number Diff line number Diff line change @@ -94,29 +94,29 @@ def fake_run(args, **kwargs):
9494
9595 mcp .add_gemini_mcp_server ("github" , f"{ WS } /api/2.0/mcp/external/github" )
9696
97- assert calls == [
98- {
99- "args" : [
100- "gemini" ,
101- "mcp" ,
102- "add" ,
103- "github" ,
104- f"{ WS } /api/2.0/mcp/external/github" ,
105- "--type" ,
106- "http" ,
107- "--scope" ,
108- "user" ,
109- "--header" ,
110- "Authorization: Bearer ${OAUTH_TOKEN}" ,
111- ],
112- "kwargs" : {
113- "check" : True ,
114- "capture_output" : True ,
115- "text" : True ,
116- "timeout" : 30 ,
117- },
118- }
97+ assert len (calls ) == 1
98+ call = calls [0 ]
99+ assert call ["args" ] == [
100+ "gemini" ,
101+ "mcp" ,
102+ "add" ,
103+ "github" ,
104+ f"{ WS } /api/2.0/mcp/external/github" ,
105+ "--type" ,
106+ "http" ,
107+ "--scope" ,
108+ "user" ,
109+ "--header" ,
110+ "Authorization: Bearer ${OAUTH_TOKEN}" ,
119111 ]
112+ kwargs = call ["kwargs" ]
113+ assert kwargs ["check" ] is True
114+ assert kwargs ["capture_output" ] is True
115+ assert kwargs ["text" ] is True
116+ assert kwargs ["timeout" ] == 30
117+ # GEMINI_CLI_HOME must point at the launcher's home so `gemini mcp
118+ # add` writes the same settings.json the ucode session reads from.
119+ assert kwargs ["env" ]["GEMINI_CLI_HOME" ] == str (mcp .gemini .GEMINI_HOME_DIR )
120120
121121
122122class TestRemoveClaudeMcpServer :
You can’t perform that action at this time.
0 commit comments