@dgxo/mashadevcli 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +393 -0
  3. package/bundle/builtin/skill-creator/SKILL.md +382 -0
  4. package/bundle/builtin/skill-creator/scripts/init_skill.cjs +239 -0
  5. package/bundle/builtin/skill-creator/scripts/package_skill.cjs +131 -0
  6. package/bundle/builtin/skill-creator/scripts/validate_skill.cjs +131 -0
  7. package/bundle/docs/CONTRIBUTING.md +1 -0
  8. package/bundle/docs/admin/enterprise-controls.md +115 -0
  9. package/bundle/docs/assets/connected_devtools.png +0 -0
  10. package/bundle/docs/assets/gemini-screenshot.png +0 -0
  11. package/bundle/docs/assets/monitoring-dashboard-logs.png +0 -0
  12. package/bundle/docs/assets/monitoring-dashboard-metrics.png +0 -0
  13. package/bundle/docs/assets/monitoring-dashboard-overview.png +0 -0
  14. package/bundle/docs/assets/release_patch.png +0 -0
  15. package/bundle/docs/assets/theme-ansi-light.png +0 -0
  16. package/bundle/docs/assets/theme-ansi.png +0 -0
  17. package/bundle/docs/assets/theme-atom-one.png +0 -0
  18. package/bundle/docs/assets/theme-ayu-light.png +0 -0
  19. package/bundle/docs/assets/theme-ayu.png +0 -0
  20. package/bundle/docs/assets/theme-custom.png +0 -0
  21. package/bundle/docs/assets/theme-default-light.png +0 -0
  22. package/bundle/docs/assets/theme-default.png +0 -0
  23. package/bundle/docs/assets/theme-dracula.png +0 -0
  24. package/bundle/docs/assets/theme-github-light.png +0 -0
  25. package/bundle/docs/assets/theme-github.png +0 -0
  26. package/bundle/docs/assets/theme-google-light.png +0 -0
  27. package/bundle/docs/assets/theme-xcode-light.png +0 -0
  28. package/bundle/docs/changelogs/index.md +867 -0
  29. package/bundle/docs/changelogs/latest.md +208 -0
  30. package/bundle/docs/changelogs/preview.md +187 -0
  31. package/bundle/docs/cli/checkpointing.md +93 -0
  32. package/bundle/docs/cli/cli-reference.md +115 -0
  33. package/bundle/docs/cli/creating-skills.md +80 -0
  34. package/bundle/docs/cli/custom-commands.md +327 -0
  35. package/bundle/docs/cli/enterprise.md +604 -0
  36. package/bundle/docs/cli/gemini-ignore.md +71 -0
  37. package/bundle/docs/cli/gemini-md.md +116 -0
  38. package/bundle/docs/cli/generation-settings.md +210 -0
  39. package/bundle/docs/cli/headless.md +50 -0
  40. package/bundle/docs/cli/model-routing.md +42 -0
  41. package/bundle/docs/cli/model.md +53 -0
  42. package/bundle/docs/cli/plan-mode.md +375 -0
  43. package/bundle/docs/cli/rewind.md +51 -0
  44. package/bundle/docs/cli/sandbox.md +257 -0
  45. package/bundle/docs/cli/session-management.md +184 -0
  46. package/bundle/docs/cli/settings.md +165 -0
  47. package/bundle/docs/cli/skills.md +134 -0
  48. package/bundle/docs/cli/system-prompt.md +125 -0
  49. package/bundle/docs/cli/telemetry.md +922 -0
  50. package/bundle/docs/cli/themes.md +269 -0
  51. package/bundle/docs/cli/token-caching.md +20 -0
  52. package/bundle/docs/cli/trusted-folders.md +126 -0
  53. package/bundle/docs/cli/tutorials/automation.md +283 -0
  54. package/bundle/docs/cli/tutorials/file-management.md +142 -0
  55. package/bundle/docs/cli/tutorials/mcp-setup.md +113 -0
  56. package/bundle/docs/cli/tutorials/memory-management.md +126 -0
  57. package/bundle/docs/cli/tutorials/session-management.md +105 -0
  58. package/bundle/docs/cli/tutorials/shell-commands.md +107 -0
  59. package/bundle/docs/cli/tutorials/skills-getting-started.md +110 -0
  60. package/bundle/docs/cli/tutorials/task-planning.md +93 -0
  61. package/bundle/docs/cli/tutorials/web-tools.md +78 -0
  62. package/bundle/docs/core/index.md +107 -0
  63. package/bundle/docs/core/remote-agents.md +84 -0
  64. package/bundle/docs/core/subagents.md +307 -0
  65. package/bundle/docs/examples/proxy-script.md +83 -0
  66. package/bundle/docs/extensions/best-practices.md +188 -0
  67. package/bundle/docs/extensions/index.md +61 -0
  68. package/bundle/docs/extensions/reference.md +333 -0
  69. package/bundle/docs/extensions/releasing.md +154 -0
  70. package/bundle/docs/extensions/writing-extensions.md +308 -0
  71. package/bundle/docs/get-started/authentication.md +402 -0
  72. package/bundle/docs/get-started/examples.md +139 -0
  73. package/bundle/docs/get-started/gemini-3.md +115 -0
  74. package/bundle/docs/get-started/index.md +82 -0
  75. package/bundle/docs/get-started/installation.md +174 -0
  76. package/bundle/docs/hooks/best-practices.md +709 -0
  77. package/bundle/docs/hooks/index.md +164 -0
  78. package/bundle/docs/hooks/reference.md +330 -0
  79. package/bundle/docs/hooks/writing-hooks.md +474 -0
  80. package/bundle/docs/ide-integration/ide-companion-spec.md +267 -0
  81. package/bundle/docs/ide-integration/index.md +224 -0
  82. package/bundle/docs/index.md +141 -0
  83. package/bundle/docs/integration-tests.md +211 -0
  84. package/bundle/docs/issue-and-pr-automation.md +172 -0
  85. package/bundle/docs/local-development.md +134 -0
  86. package/bundle/docs/mermaid/context.mmd +103 -0
  87. package/bundle/docs/mermaid/render-path.mmd +64 -0
  88. package/bundle/docs/npm.md +62 -0
  89. package/bundle/docs/redirects.json +20 -0
  90. package/bundle/docs/reference/commands.md +526 -0
  91. package/bundle/docs/reference/configuration.md +1786 -0
  92. package/bundle/docs/reference/keyboard-shortcuts.md +164 -0
  93. package/bundle/docs/reference/memport.md +246 -0
  94. package/bundle/docs/reference/policy-engine.md +364 -0
  95. package/bundle/docs/reference/tools.md +106 -0
  96. package/bundle/docs/release-confidence.md +164 -0
  97. package/bundle/docs/releases.md +540 -0
  98. package/bundle/docs/resources/faq.md +175 -0
  99. package/bundle/docs/resources/quota-and-pricing.md +165 -0
  100. package/bundle/docs/resources/tos-privacy.md +102 -0
  101. package/bundle/docs/resources/troubleshooting.md +176 -0
  102. package/bundle/docs/resources/uninstall.md +56 -0
  103. package/bundle/docs/sidebar.json +233 -0
  104. package/bundle/docs/tools/activate-skill.md +43 -0
  105. package/bundle/docs/tools/ask-user.md +95 -0
  106. package/bundle/docs/tools/file-system.md +129 -0
  107. package/bundle/docs/tools/internal-docs.md +46 -0
  108. package/bundle/docs/tools/mcp-server.md +1150 -0
  109. package/bundle/docs/tools/memory.md +35 -0
  110. package/bundle/docs/tools/planning.md +58 -0
  111. package/bundle/docs/tools/shell.md +216 -0
  112. package/bundle/docs/tools/todos.md +35 -0
  113. package/bundle/docs/tools/web-fetch.md +35 -0
  114. package/bundle/docs/tools/web-search.md +32 -0
  115. package/bundle/docs/update/update-guide.md +111 -0
  116. package/bundle/masha.js +563471 -0
  117. package/bundle/node_modules/@dgxo/mashadevcli-devtools/dist/client/main.js +89 -0
  118. package/bundle/node_modules/@dgxo/mashadevcli-devtools/dist/src/_client-assets.d.ts +7 -0
  119. package/bundle/node_modules/@dgxo/mashadevcli-devtools/dist/src/_client-assets.js +9 -0
  120. package/bundle/node_modules/@dgxo/mashadevcli-devtools/dist/src/_client-assets.js.map +1 -0
  121. package/bundle/node_modules/@dgxo/mashadevcli-devtools/dist/src/index.d.ts +48 -0
  122. package/bundle/node_modules/@dgxo/mashadevcli-devtools/dist/src/index.js +299 -0
  123. package/bundle/node_modules/@dgxo/mashadevcli-devtools/dist/src/index.js.map +1 -0
  124. package/bundle/node_modules/@dgxo/mashadevcli-devtools/dist/src/types.d.ts +36 -0
  125. package/bundle/node_modules/@dgxo/mashadevcli-devtools/dist/src/types.js +7 -0
  126. package/bundle/node_modules/@dgxo/mashadevcli-devtools/dist/src/types.js.map +1 -0
  127. package/bundle/node_modules/@dgxo/mashadevcli-devtools/package.json +32 -0
  128. package/bundle/policies/conseca.toml +6 -0
  129. package/bundle/policies/discovered.toml +8 -0
  130. package/bundle/policies/plan.toml +109 -0
  131. package/bundle/policies/read-only.toml +53 -0
  132. package/bundle/policies/write.toml +80 -0
  133. package/bundle/policies/yolo.toml +54 -0
  134. package/bundle/sandbox-macos-permissive-open.sb +27 -0
  135. package/bundle/sandbox-macos-permissive-proxied.sb +37 -0
  136. package/bundle/sandbox-macos-restrictive-open.sb +96 -0
  137. package/bundle/sandbox-macos-restrictive-proxied.sb +98 -0
  138. package/bundle/sandbox-macos-strict-open.sb +131 -0
  139. package/bundle/sandbox-macos-strict-proxied.sb +133 -0
  140. package/package.json +169 -0
@@ -0,0 +1,1150 @@
1
+ # MCP servers with the Gemini CLI
2
+
3
+ This document provides a guide to configuring and using Model Context Protocol
4
+ (MCP) servers with the Gemini CLI.
5
+
6
+ ## What is an MCP server?
7
+
8
+ An MCP server is an application that exposes tools and resources to the Gemini
9
+ CLI through the Model Context Protocol, allowing it to interact with external
10
+ systems and data sources. MCP servers act as a bridge between the Gemini model
11
+ and your local environment or other services like APIs.
12
+
13
+ An MCP server enables the Gemini CLI to:
14
+
15
+ - **Discover tools:** List available tools, their descriptions, and parameters
16
+ through standardized schema definitions.
17
+ - **Execute tools:** Call specific tools with defined arguments and receive
18
+ structured responses.
19
+ - **Access resources:** Read data from specific resources that the server
20
+ exposes (files, API payloads, reports, etc.).
21
+
22
+ With an MCP server, you can extend the Gemini CLI's capabilities to perform
23
+ actions beyond its built-in features, such as interacting with databases, APIs,
24
+ custom scripts, or specialized workflows.
25
+
26
+ ## Core integration architecture
27
+
28
+ The Gemini CLI integrates with MCP servers through a sophisticated discovery and
29
+ execution system built into the core package (`packages/core/src/tools/`):
30
+
31
+ ### Discovery Layer (`mcp-client.ts`)
32
+
33
+ The discovery process is orchestrated by `discoverMcpTools()`, which:
34
+
35
+ 1. **Iterates through configured servers** from your `settings.json`
36
+ `mcpServers` configuration
37
+ 2. **Establishes connections** using appropriate transport mechanisms (Stdio,
38
+ SSE, or Streamable HTTP)
39
+ 3. **Fetches tool definitions** from each server using the MCP protocol
40
+ 4. **Sanitizes and validates** tool schemas for compatibility with the Gemini
41
+ API
42
+ 5. **Registers tools** in the global tool registry with conflict resolution
43
+ 6. **Fetches and registers resources** if the server exposes any
44
+
45
+ ### Execution layer (`mcp-tool.ts`)
46
+
47
+ Each discovered MCP tool is wrapped in a `DiscoveredMCPTool` instance that:
48
+
49
+ - **Handles confirmation logic** based on server trust settings and user
50
+ preferences
51
+ - **Manages tool execution** by calling the MCP server with proper parameters
52
+ - **Processes responses** for both the LLM context and user display
53
+ - **Maintains connection state** and handles timeouts
54
+
55
+ ### Transport mechanisms
56
+
57
+ The Gemini CLI supports three MCP transport types:
58
+
59
+ - **Stdio Transport:** Spawns a subprocess and communicates via stdin/stdout
60
+ - **SSE Transport:** Connects to Server-Sent Events endpoints
61
+ - **Streamable HTTP Transport:** Uses HTTP streaming for communication
62
+
63
+ ## Working with MCP resources
64
+
65
+ Some MCP servers expose contextual “resources” in addition to the tools and
66
+ prompts. Gemini CLI discovers these automatically and gives you the possibility
67
+ to reference them in the chat.
68
+
69
+ ### Discovery and listing
70
+
71
+ - When discovery runs, the CLI fetches each server’s `resources/list` results.
72
+ - The `/mcp` command displays a Resources section alongside Tools and Prompts
73
+ for every connected server.
74
+
75
+ This returns a concise, plain-text list of URIs plus metadata.
76
+
77
+ ### Referencing resources in a conversation
78
+
79
+ You can use the same `@` syntax already known for referencing local files:
80
+
81
+ ```
82
+ @server://resource/path
83
+ ```
84
+
85
+ Resource URIs appear in the completion menu together with filesystem paths. When
86
+ you submit the message, the CLI calls `resources/read` and injects the content
87
+ in the conversation.
88
+
89
+ ## How to set up your MCP server
90
+
91
+ The Gemini CLI uses the `mcpServers` configuration in your `settings.json` file
92
+ to locate and connect to MCP servers. This configuration supports multiple
93
+ servers with different transport mechanisms.
94
+
95
+ ### Configure the MCP server in settings.json
96
+
97
+ You can configure MCP servers in your `settings.json` file in two main ways:
98
+ through the top-level `mcpServers` object for specific server definitions, and
99
+ through the `mcp` object for global settings that control server discovery and
100
+ execution.
101
+
102
+ #### Global MCP settings (`mcp`)
103
+
104
+ The `mcp` object in your `settings.json` lets you define global rules for all
105
+ MCP servers.
106
+
107
+ - **`mcp.serverCommand`** (string): A global command to start an MCP server.
108
+ - **`mcp.allowed`** (array of strings): A list of MCP server names to allow. If
109
+ this is set, only servers from this list (matching the keys in the
110
+ `mcpServers` object) will be connected to.
111
+ - **`mcp.excluded`** (array of strings): A list of MCP server names to exclude.
112
+ Servers in this list will not be connected to.
113
+
114
+ **Example:**
115
+
116
+ ```json
117
+ {
118
+ "mcp": {
119
+ "allowed": ["my-trusted-server"],
120
+ "excluded": ["experimental-server"]
121
+ }
122
+ }
123
+ ```
124
+
125
+ #### Server-specific configuration (`mcpServers`)
126
+
127
+ The `mcpServers` object is where you define each individual MCP server you want
128
+ the CLI to connect to.
129
+
130
+ ### Configuration structure
131
+
132
+ Add an `mcpServers` object to your `settings.json` file:
133
+
134
+ ```json
135
+ { ...file contains other config objects
136
+ "mcpServers": {
137
+ "serverName": {
138
+ "command": "path/to/server",
139
+ "args": ["--arg1", "value1"],
140
+ "env": {
141
+ "API_KEY": "$MY_API_TOKEN"
142
+ },
143
+ "cwd": "./server-directory",
144
+ "timeout": 30000,
145
+ "trust": false
146
+ }
147
+ }
148
+ }
149
+ ```
150
+
151
+ ### Configuration properties
152
+
153
+ Each server configuration supports the following properties:
154
+
155
+ #### Required (one of the following)
156
+
157
+ - **`command`** (string): Path to the executable for Stdio transport
158
+ - **`url`** (string): SSE endpoint URL (e.g., `"http://localhost:8080/sse"`)
159
+ - **`httpUrl`** (string): HTTP streaming endpoint URL
160
+
161
+ #### Optional
162
+
163
+ - **`args`** (string[]): Command-line arguments for Stdio transport
164
+ - **`headers`** (object): Custom HTTP headers when using `url` or `httpUrl`
165
+ - **`env`** (object): Environment variables for the server process. Values can
166
+ reference environment variables using `$VAR_NAME` or `${VAR_NAME}` syntax (all
167
+ platforms), or `%VAR_NAME%` (Windows only).
168
+ - **`cwd`** (string): Working directory for Stdio transport
169
+ - **`timeout`** (number): Request timeout in milliseconds (default: 600,000ms =
170
+ 10 minutes)
171
+ - **`trust`** (boolean): When `true`, bypasses all tool call confirmations for
172
+ this server (default: `false`)
173
+ - **`includeTools`** (string[]): List of tool names to include from this MCP
174
+ server. When specified, only the tools listed here will be available from this
175
+ server (allowlist behavior). If not specified, all tools from the server are
176
+ enabled by default.
177
+ - **`excludeTools`** (string[]): List of tool names to exclude from this MCP
178
+ server. Tools listed here will not be available to the model, even if they are
179
+ exposed by the server. **Note:** `excludeTools` takes precedence over
180
+ `includeTools` - if a tool is in both lists, it will be excluded.
181
+ - **`targetAudience`** (string): The OAuth Client ID allowlisted on the
182
+ IAP-protected application you are trying to access. Used with
183
+ `authProviderType: 'service_account_impersonation'`.
184
+ - **`targetServiceAccount`** (string): The email address of the Google Cloud
185
+ Service Account to impersonate. Used with
186
+ `authProviderType: 'service_account_impersonation'`.
187
+
188
+ ### Environment variable expansion
189
+
190
+ Gemini CLI automatically expands environment variables in the `env` block of
191
+ your MCP server configuration. This allows you to securely reference variables
192
+ defined in your shell or environment without hardcoding sensitive information
193
+ directly in your `settings.json` file.
194
+
195
+ The expansion utility supports:
196
+
197
+ - **POSIX/Bash syntax:** `$VARIABLE_NAME` or `${VARIABLE_NAME}` (supported on
198
+ all platforms)
199
+ - **Windows syntax:** `%VARIABLE_NAME%` (supported only when running on Windows)
200
+
201
+ If a variable is not defined in the current environment, it resolves to an empty
202
+ string.
203
+
204
+ **Example:**
205
+
206
+ ```json
207
+ "env": {
208
+ "API_KEY": "$MY_EXTERNAL_TOKEN",
209
+ "LOG_LEVEL": "$LOG_LEVEL",
210
+ "TEMP_DIR": "%TEMP%"
211
+ }
212
+ ```
213
+
214
+ ### Security and environment sanitization
215
+
216
+ To protect your credentials, Gemini CLI performs environment sanitization when
217
+ spawning MCP server processes.
218
+
219
+ #### Automatic redaction
220
+
221
+ By default, the CLI redacts sensitive environment variables from the base
222
+ environment (inherited from the host process) to prevent unintended exposure to
223
+ third-party MCP servers. This includes:
224
+
225
+ - Core project keys: `GEMINI_API_KEY`, `GOOGLE_API_KEY`, etc.
226
+ - Variables matching sensitive patterns: `*TOKEN*`, `*SECRET*`, `*PASSWORD*`,
227
+ `*KEY*`, `*AUTH*`, `*CREDENTIAL*`.
228
+ - Certificates and private key patterns.
229
+
230
+ #### Explicit overrides
231
+
232
+ If an environment variable must be passed to an MCP server, you must explicitly
233
+ state it in the `env` property of the server configuration in `settings.json`.
234
+ Explicitly defined variables (including those from extensions) are trusted and
235
+ are **not** subjected to the automatic redaction process.
236
+
237
+ This follows the security principle that if a variable is explicitly configured
238
+ by the user for a specific server, it constitutes informed consent to share that
239
+ specific data with that server.
240
+
241
+ > **Note:** Even when explicitly defined, you should avoid hardcoding secrets.
242
+ > Instead, use environment variable expansion (e.g., `"MY_KEY": "$MY_KEY"`) to
243
+ > securely pull the value from your host environment at runtime.
244
+
245
+ ### OAuth support for remote MCP servers
246
+
247
+ The Gemini CLI supports OAuth 2.0 authentication for remote MCP servers using
248
+ SSE or HTTP transports. This enables secure access to MCP servers that require
249
+ authentication.
250
+
251
+ #### Automatic OAuth discovery
252
+
253
+ For servers that support OAuth discovery, you can omit the OAuth configuration
254
+ and let the CLI discover it automatically:
255
+
256
+ ```json
257
+ {
258
+ "mcpServers": {
259
+ "discoveredServer": {
260
+ "url": "https://api.example.com/sse"
261
+ }
262
+ }
263
+ }
264
+ ```
265
+
266
+ The CLI will automatically:
267
+
268
+ - Detect when a server requires OAuth authentication (401 responses)
269
+ - Discover OAuth endpoints from server metadata
270
+ - Perform dynamic client registration if supported
271
+ - Handle the OAuth flow and token management
272
+
273
+ #### Authentication flow
274
+
275
+ When connecting to an OAuth-enabled server:
276
+
277
+ 1. **Initial connection attempt** fails with 401 Unauthorized
278
+ 2. **OAuth discovery** finds authorization and token endpoints
279
+ 3. **Browser opens** for user authentication (requires local browser access)
280
+ 4. **Authorization code** is exchanged for access tokens
281
+ 5. **Tokens are stored** securely for future use
282
+ 6. **Connection retry** succeeds with valid tokens
283
+
284
+ #### Browser redirect requirements
285
+
286
+ **Important:** OAuth authentication requires that your local machine can:
287
+
288
+ - Open a web browser for authentication
289
+ - Receive redirects on `http://localhost:7777/oauth/callback`
290
+
291
+ This feature will not work in:
292
+
293
+ - Headless environments without browser access
294
+ - Remote SSH sessions without X11 forwarding
295
+ - Containerized environments without browser support
296
+
297
+ #### Managing OAuth authentication
298
+
299
+ Use the `/mcp auth` command to manage OAuth authentication:
300
+
301
+ ```bash
302
+ # List servers requiring authentication
303
+ /mcp auth
304
+
305
+ # Authenticate with a specific server
306
+ /mcp auth serverName
307
+
308
+ # Re-authenticate if tokens expire
309
+ /mcp auth serverName
310
+ ```
311
+
312
+ #### OAuth configuration properties
313
+
314
+ - **`enabled`** (boolean): Enable OAuth for this server
315
+ - **`clientId`** (string): OAuth client identifier (optional with dynamic
316
+ registration)
317
+ - **`clientSecret`** (string): OAuth client secret (optional for public clients)
318
+ - **`authorizationUrl`** (string): OAuth authorization endpoint (auto-discovered
319
+ if omitted)
320
+ - **`tokenUrl`** (string): OAuth token endpoint (auto-discovered if omitted)
321
+ - **`scopes`** (string[]): Required OAuth scopes
322
+ - **`redirectUri`** (string): Custom redirect URI (defaults to
323
+ `http://localhost:7777/oauth/callback`)
324
+ - **`tokenParamName`** (string): Query parameter name for tokens in SSE URLs
325
+ - **`audiences`** (string[]): Audiences the token is valid for
326
+
327
+ #### Token management
328
+
329
+ OAuth tokens are automatically:
330
+
331
+ - **Stored securely** in `~/.gemini/mcp-oauth-tokens.json`
332
+ - **Refreshed** when expired (if refresh tokens are available)
333
+ - **Validated** before each connection attempt
334
+ - **Cleaned up** when invalid or expired
335
+
336
+ #### Authentication provider type
337
+
338
+ You can specify the authentication provider type using the `authProviderType`
339
+ property:
340
+
341
+ - **`authProviderType`** (string): Specifies the authentication provider. Can be
342
+ one of the following:
343
+ - **`dynamic_discovery`** (default): The CLI will automatically discover the
344
+ OAuth configuration from the server.
345
+ - **`google_credentials`**: The CLI will use the Google Application Default
346
+ Credentials (ADC) to authenticate with the server. When using this provider,
347
+ you must specify the required scopes.
348
+ - **`service_account_impersonation`**: The CLI will impersonate a Google Cloud
349
+ Service Account to authenticate with the server. This is useful for
350
+ accessing IAP-protected services (this was specifically designed for Cloud
351
+ Run services).
352
+
353
+ #### Google credentials
354
+
355
+ ```json
356
+ {
357
+ "mcpServers": {
358
+ "googleCloudServer": {
359
+ "httpUrl": "https://my-gcp-service.run.app/mcp",
360
+ "authProviderType": "google_credentials",
361
+ "oauth": {
362
+ "scopes": ["https://www.googleapis.com/auth/userinfo.email"]
363
+ }
364
+ }
365
+ }
366
+ }
367
+ ```
368
+
369
+ #### Service account impersonation
370
+
371
+ To authenticate with a server using Service Account Impersonation, you must set
372
+ the `authProviderType` to `service_account_impersonation` and provide the
373
+ following properties:
374
+
375
+ - **`targetAudience`** (string): The OAuth Client ID allowslisted on the
376
+ IAP-protected application you are trying to access.
377
+ - **`targetServiceAccount`** (string): The email address of the Google Cloud
378
+ Service Account to impersonate.
379
+
380
+ The CLI will use your local Application Default Credentials (ADC) to generate an
381
+ OIDC ID token for the specified service account and audience. This token will
382
+ then be used to authenticate with the MCP server.
383
+
384
+ #### Setup instructions
385
+
386
+ 1. **[Create](https://cloud.google.com/iap/docs/oauth-client-creation) or use an
387
+ existing OAuth 2.0 client ID.** To use an existing OAuth 2.0 client ID,
388
+ follow the steps in
389
+ [How to share OAuth Clients](https://cloud.google.com/iap/docs/sharing-oauth-clients).
390
+ 2. **Add the OAuth ID to the allowlist for
391
+ [programmatic access](https://cloud.google.com/iap/docs/sharing-oauth-clients#programmatic_access)
392
+ for the application.** Since Cloud Run is not yet a supported resource type
393
+ in gcloud iap, you must allowlist the Client ID on the project.
394
+ 3. **Create a service account.**
395
+ [Documentation](https://cloud.google.com/iam/docs/service-accounts-create#creating),
396
+ [Cloud Console Link](https://console.cloud.google.com/iam-admin/serviceaccounts)
397
+ 4. **Add both the service account and users to the IAP Policy** in the
398
+ "Security" tab of the Cloud Run service itself or via gcloud.
399
+ 5. **Grant all users and groups** who will access the MCP Server the necessary
400
+ permissions to
401
+ [impersonate the service account](https://cloud.google.com/docs/authentication/use-service-account-impersonation)
402
+ (i.e., `roles/iam.serviceAccountTokenCreator`).
403
+ 6. **[Enable](https://console.cloud.google.com/apis/library/iamcredentials.googleapis.com)
404
+ the IAM Credentials API** for your project.
405
+
406
+ ### Example configurations
407
+
408
+ #### Python MCP server (stdio)
409
+
410
+ ```json
411
+ {
412
+ "mcpServers": {
413
+ "pythonTools": {
414
+ "command": "python",
415
+ "args": ["-m", "my_mcp_server", "--port", "8080"],
416
+ "cwd": "./mcp-servers/python",
417
+ "env": {
418
+ "DATABASE_URL": "$DB_CONNECTION_STRING",
419
+ "API_KEY": "${EXTERNAL_API_KEY}"
420
+ },
421
+ "timeout": 15000
422
+ }
423
+ }
424
+ }
425
+ ```
426
+
427
+ #### Node.js MCP server (stdio)
428
+
429
+ ```json
430
+ {
431
+ "mcpServers": {
432
+ "nodeServer": {
433
+ "command": "node",
434
+ "args": ["dist/server.js", "--verbose"],
435
+ "cwd": "./mcp-servers/node",
436
+ "trust": true
437
+ }
438
+ }
439
+ }
440
+ ```
441
+
442
+ #### Docker-based MCP server
443
+
444
+ ```json
445
+ {
446
+ "mcpServers": {
447
+ "dockerizedServer": {
448
+ "command": "docker",
449
+ "args": [
450
+ "run",
451
+ "-i",
452
+ "--rm",
453
+ "-e",
454
+ "API_KEY",
455
+ "-v",
456
+ "${PWD}:/workspace",
457
+ "my-mcp-server:latest"
458
+ ],
459
+ "env": {
460
+ "API_KEY": "$EXTERNAL_SERVICE_TOKEN"
461
+ }
462
+ }
463
+ }
464
+ }
465
+ ```
466
+
467
+ #### HTTP-based MCP server
468
+
469
+ ```json
470
+ {
471
+ "mcpServers": {
472
+ "httpServer": {
473
+ "httpUrl": "http://localhost:3000/mcp",
474
+ "timeout": 5000
475
+ }
476
+ }
477
+ }
478
+ ```
479
+
480
+ #### HTTP-based MCP Server with custom headers
481
+
482
+ ```json
483
+ {
484
+ "mcpServers": {
485
+ "httpServerWithAuth": {
486
+ "httpUrl": "http://localhost:3000/mcp",
487
+ "headers": {
488
+ "Authorization": "Bearer your-api-token",
489
+ "X-Custom-Header": "custom-value",
490
+ "Content-Type": "application/json"
491
+ },
492
+ "timeout": 5000
493
+ }
494
+ }
495
+ }
496
+ ```
497
+
498
+ #### MCP server with tool filtering
499
+
500
+ ```json
501
+ {
502
+ "mcpServers": {
503
+ "filteredServer": {
504
+ "command": "python",
505
+ "args": ["-m", "my_mcp_server"],
506
+ "includeTools": ["safe_tool", "file_reader", "data_processor"],
507
+ // "excludeTools": ["dangerous_tool", "file_deleter"],
508
+ "timeout": 30000
509
+ }
510
+ }
511
+ }
512
+ ```
513
+
514
+ ### SSE MCP server with SA impersonation
515
+
516
+ ```json
517
+ {
518
+ "mcpServers": {
519
+ "myIapProtectedServer": {
520
+ "url": "https://my-iap-service.run.app/sse",
521
+ "authProviderType": "service_account_impersonation",
522
+ "targetAudience": "YOUR_IAP_CLIENT_ID.apps.googleusercontent.com",
523
+ "targetServiceAccount": "your-sa@your-project.iam.gserviceaccount.com"
524
+ }
525
+ }
526
+ }
527
+ ```
528
+
529
+ ## Discovery process deep dive
530
+
531
+ When the Gemini CLI starts, it performs MCP server discovery through the
532
+ following detailed process:
533
+
534
+ ### 1. Server iteration and connection
535
+
536
+ For each configured server in `mcpServers`:
537
+
538
+ 1. **Status tracking begins:** Server status is set to `CONNECTING`
539
+ 2. **Transport selection:** Based on configuration properties:
540
+ - `httpUrl` → `StreamableHTTPClientTransport`
541
+ - `url` → `SSEClientTransport`
542
+ - `command` → `StdioClientTransport`
543
+ 3. **Connection establishment:** The MCP client attempts to connect with the
544
+ configured timeout
545
+ 4. **Error handling:** Connection failures are logged and the server status is
546
+ set to `DISCONNECTED`
547
+
548
+ ### 2. Tool discovery
549
+
550
+ Upon successful connection:
551
+
552
+ 1. **Tool listing:** The client calls the MCP server's tool listing endpoint
553
+ 2. **Schema validation:** Each tool's function declaration is validated
554
+ 3. **Tool filtering:** Tools are filtered based on `includeTools` and
555
+ `excludeTools` configuration
556
+ 4. **Name sanitization:** Tool names are cleaned to meet Gemini API
557
+ requirements:
558
+ - Invalid characters (non-alphanumeric, underscore, dot, hyphen) are replaced
559
+ with underscores
560
+ - Names longer than 63 characters are truncated with middle replacement
561
+ (`___`)
562
+
563
+ ### 3. Conflict resolution
564
+
565
+ When multiple servers expose tools with the same name:
566
+
567
+ 1. **First registration wins:** The first server to register a tool name gets
568
+ the unprefixed name
569
+ 2. **Automatic prefixing:** Subsequent servers get prefixed names:
570
+ `serverName__toolName`
571
+ 3. **Registry tracking:** The tool registry maintains mappings between server
572
+ names and their tools
573
+
574
+ ### 4. Schema processing
575
+
576
+ Tool parameter schemas undergo sanitization for Gemini API compatibility:
577
+
578
+ - **`$schema` properties** are removed
579
+ - **`additionalProperties`** are stripped
580
+ - **`anyOf` with `default`** have their default values removed (Vertex AI
581
+ compatibility)
582
+ - **Recursive processing** applies to nested schemas
583
+
584
+ ### 5. Connection management
585
+
586
+ After discovery:
587
+
588
+ - **Persistent connections:** Servers that successfully register tools maintain
589
+ their connections
590
+ - **Cleanup:** Servers that provide no usable tools have their connections
591
+ closed
592
+ - **Status updates:** Final server statuses are set to `CONNECTED` or
593
+ `DISCONNECTED`
594
+
595
+ ## Tool execution flow
596
+
597
+ When the Gemini model decides to use an MCP tool, the following execution flow
598
+ occurs:
599
+
600
+ ### 1. Tool invocation
601
+
602
+ The model generates a `FunctionCall` with:
603
+
604
+ - **Tool name:** The registered name (potentially prefixed)
605
+ - **Arguments:** JSON object matching the tool's parameter schema
606
+
607
+ ### 2. Confirmation process
608
+
609
+ Each `DiscoveredMCPTool` implements sophisticated confirmation logic:
610
+
611
+ #### Trust-based bypass
612
+
613
+ ```typescript
614
+ if (this.trust) {
615
+ return false; // No confirmation needed
616
+ }
617
+ ```
618
+
619
+ #### Dynamic allow-listing
620
+
621
+ The system maintains internal allow-lists for:
622
+
623
+ - **Server-level:** `serverName` → All tools from this server are trusted
624
+ - **Tool-level:** `serverName.toolName` → This specific tool is trusted
625
+
626
+ #### User choice handling
627
+
628
+ When confirmation is required, users can choose:
629
+
630
+ - **Proceed once:** Execute this time only
631
+ - **Always allow this tool:** Add to tool-level allow-list
632
+ - **Always allow this server:** Add to server-level allow-list
633
+ - **Cancel:** Abort execution
634
+
635
+ ### 3. Execution
636
+
637
+ Upon confirmation (or trust bypass):
638
+
639
+ 1. **Parameter preparation:** Arguments are validated against the tool's schema
640
+ 2. **MCP call:** The underlying `CallableTool` invokes the server with:
641
+
642
+ ```typescript
643
+ const functionCalls = [
644
+ {
645
+ name: this.serverToolName, // Original server tool name
646
+ args: params,
647
+ },
648
+ ];
649
+ ```
650
+
651
+ 3. **Response processing:** Results are formatted for both LLM context and user
652
+ display
653
+
654
+ ### 4. Response handling
655
+
656
+ The execution result contains:
657
+
658
+ - **`llmContent`:** Raw response parts for the language model's context
659
+ - **`returnDisplay`:** Formatted output for user display (often JSON in markdown
660
+ code blocks)
661
+
662
+ ## How to interact with your MCP server
663
+
664
+ ### Using the `/mcp` command
665
+
666
+ The `/mcp` command provides comprehensive information about your MCP server
667
+ setup:
668
+
669
+ ```bash
670
+ /mcp
671
+ ```
672
+
673
+ This displays:
674
+
675
+ - **Server list:** All configured MCP servers
676
+ - **Connection status:** `CONNECTED`, `CONNECTING`, or `DISCONNECTED`
677
+ - **Server details:** Configuration summary (excluding sensitive data)
678
+ - **Available tools:** List of tools from each server with descriptions
679
+ - **Discovery state:** Overall discovery process status
680
+
681
+ ### Example `/mcp` output
682
+
683
+ ```
684
+ MCP Servers Status:
685
+
686
+ 📡 pythonTools (CONNECTED)
687
+ Command: python -m my_mcp_server --port 8080
688
+ Working Directory: ./mcp-servers/python
689
+ Timeout: 15000ms
690
+ Tools: calculate_sum, file_analyzer, data_processor
691
+
692
+ 🔌 nodeServer (DISCONNECTED)
693
+ Command: node dist/server.js --verbose
694
+ Error: Connection refused
695
+
696
+ 🐳 dockerizedServer (CONNECTED)
697
+ Command: docker run -i --rm -e API_KEY my-mcp-server:latest
698
+ Tools: docker__deploy, docker__status
699
+
700
+ Discovery State: COMPLETED
701
+ ```
702
+
703
+ ### Tool usage
704
+
705
+ Once discovered, MCP tools are available to the Gemini model like built-in
706
+ tools. The model will automatically:
707
+
708
+ 1. **Select appropriate tools** based on your requests
709
+ 2. **Present confirmation dialogs** (unless the server is trusted)
710
+ 3. **Execute tools** with proper parameters
711
+ 4. **Display results** in a user-friendly format
712
+
713
+ ## Status monitoring and troubleshooting
714
+
715
+ ### Connection states
716
+
717
+ The MCP integration tracks several states:
718
+
719
+ #### Server status (`MCPServerStatus`)
720
+
721
+ - **`DISCONNECTED`:** Server is not connected or has errors
722
+ - **`CONNECTING`:** Connection attempt in progress
723
+ - **`CONNECTED`:** Server is connected and ready
724
+
725
+ #### Discovery state (`MCPDiscoveryState`)
726
+
727
+ - **`NOT_STARTED`:** Discovery hasn't begun
728
+ - **`IN_PROGRESS`:** Currently discovering servers
729
+ - **`COMPLETED`:** Discovery finished (with or without errors)
730
+
731
+ ### Common issues and solutions
732
+
733
+ #### Server won't connect
734
+
735
+ **Symptoms:** Server shows `DISCONNECTED` status
736
+
737
+ **Troubleshooting:**
738
+
739
+ 1. **Check configuration:** Verify `command`, `args`, and `cwd` are correct
740
+ 2. **Test manually:** Run the server command directly to ensure it works
741
+ 3. **Check dependencies:** Ensure all required packages are installed
742
+ 4. **Review logs:** Look for error messages in the CLI output
743
+ 5. **Verify permissions:** Ensure the CLI can execute the server command
744
+
745
+ #### No tools discovered
746
+
747
+ **Symptoms:** Server connects but no tools are available
748
+
749
+ **Troubleshooting:**
750
+
751
+ 1. **Verify tool registration:** Ensure your server actually registers tools
752
+ 2. **Check MCP protocol:** Confirm your server implements the MCP tool listing
753
+ correctly
754
+ 3. **Review server logs:** Check stderr output for server-side errors
755
+ 4. **Test tool listing:** Manually test your server's tool discovery endpoint
756
+
757
+ #### Tools not executing
758
+
759
+ **Symptoms:** Tools are discovered but fail during execution
760
+
761
+ **Troubleshooting:**
762
+
763
+ 1. **Parameter validation:** Ensure your tool accepts the expected parameters
764
+ 2. **Schema compatibility:** Verify your input schemas are valid JSON Schema
765
+ 3. **Error handling:** Check if your tool is throwing unhandled exceptions
766
+ 4. **Timeout issues:** Consider increasing the `timeout` setting
767
+
768
+ #### Sandbox compatibility
769
+
770
+ **Symptoms:** MCP servers fail when sandboxing is enabled
771
+
772
+ **Solutions:**
773
+
774
+ 1. **Docker-based servers:** Use Docker containers that include all dependencies
775
+ 2. **Path accessibility:** Ensure server executables are available in the
776
+ sandbox
777
+ 3. **Network access:** Configure sandbox to allow necessary network connections
778
+ 4. **Environment variables:** Verify required environment variables are passed
779
+ through
780
+
781
+ ### Debugging tips
782
+
783
+ 1. **Enable debug mode:** Run the CLI with `--debug` for verbose output (use F12
784
+ to open debug console in interactive mode)
785
+ 2. **Check stderr:** MCP server stderr is captured and logged (INFO messages
786
+ filtered)
787
+ 3. **Test isolation:** Test your MCP server independently before integrating
788
+ 4. **Incremental setup:** Start with simple tools before adding complex
789
+ functionality
790
+ 5. **Use `/mcp` frequently:** Monitor server status during development
791
+
792
+ ## Important notes
793
+
794
+ ### Security considerations
795
+
796
+ - **Trust settings:** The `trust` option bypasses all confirmation dialogs. Use
797
+ cautiously and only for servers you completely control
798
+ - **Access tokens:** Be security-aware when configuring environment variables
799
+ containing API keys or tokens. See
800
+ [Security and environment sanitization](#security-and-environment-sanitization)
801
+ for details on how Gemini CLI protects your credentials.
802
+ - **Sandbox compatibility:** When using sandboxing, ensure MCP servers are
803
+ available within the sandbox environment
804
+ - **Private data:** Using broadly scoped personal access tokens can lead to
805
+ information leakage between repositories.
806
+
807
+ ### Performance and resource management
808
+
809
+ - **Connection persistence:** The CLI maintains persistent connections to
810
+ servers that successfully register tools
811
+ - **Automatic cleanup:** Connections to servers providing no tools are
812
+ automatically closed
813
+ - **Timeout management:** Configure appropriate timeouts based on your server's
814
+ response characteristics
815
+ - **Resource monitoring:** MCP servers run as separate processes and consume
816
+ system resources
817
+
818
+ ### Schema compatibility
819
+
820
+ - **Property stripping:** The system automatically removes certain schema
821
+ properties (`$schema`, `additionalProperties`) for Gemini API compatibility
822
+ - **Name sanitization:** Tool names are automatically sanitized to meet API
823
+ requirements
824
+ - **Conflict resolution:** Tool name conflicts between servers are resolved
825
+ through automatic prefixing
826
+
827
+ This comprehensive integration makes MCP servers a powerful way to extend the
828
+ Gemini CLI's capabilities while maintaining security, reliability, and ease of
829
+ use.
830
+
831
+ ## Returning rich content from tools
832
+
833
+ MCP tools are not limited to returning simple text. You can return rich,
834
+ multi-part content, including text, images, audio, and other binary data in a
835
+ single tool response. This allows you to build powerful tools that can provide
836
+ diverse information to the model in a single turn.
837
+
838
+ All data returned from the tool is processed and sent to the model as context
839
+ for its next generation, enabling it to reason about or summarize the provided
840
+ information.
841
+
842
+ ### How it works
843
+
844
+ To return rich content, your tool's response must adhere to the MCP
845
+ specification for a
846
+ [`CallToolResult`](https://modelcontextprotocol.io/specification/2025-06-18/server/tools#tool-result).
847
+ The `content` field of the result should be an array of `ContentBlock` objects.
848
+ The Gemini CLI will correctly process this array, separating text from binary
849
+ data and packaging it for the model.
850
+
851
+ You can mix and match different content block types in the `content` array. The
852
+ supported block types include:
853
+
854
+ - `text`
855
+ - `image`
856
+ - `audio`
857
+ - `resource` (embedded content)
858
+ - `resource_link`
859
+
860
+ ### Example: Returning text and an image
861
+
862
+ Here is an example of a valid JSON response from an MCP tool that returns both a
863
+ text description and an image:
864
+
865
+ ```json
866
+ {
867
+ "content": [
868
+ {
869
+ "type": "text",
870
+ "text": "Here is the logo you requested."
871
+ },
872
+ {
873
+ "type": "image",
874
+ "data": "BASE64_ENCODED_IMAGE_DATA_HERE",
875
+ "mimeType": "image/png"
876
+ },
877
+ {
878
+ "type": "text",
879
+ "text": "The logo was created in 2025."
880
+ }
881
+ ]
882
+ }
883
+ ```
884
+
885
+ When the Gemini CLI receives this response, it will:
886
+
887
+ 1. Extract all the text and combine it into a single `functionResponse` part
888
+ for the model.
889
+ 2. Present the image data as a separate `inlineData` part.
890
+ 3. Provide a clean, user-friendly summary in the CLI, indicating that both text
891
+ and an image were received.
892
+
893
+ This enables you to build sophisticated tools that can provide rich, multi-modal
894
+ context to the Gemini model.
895
+
896
+ ## MCP prompts as slash commands
897
+
898
+ In addition to tools, MCP servers can expose predefined prompts that can be
899
+ executed as slash commands within the Gemini CLI. This allows you to create
900
+ shortcuts for common or complex queries that can be easily invoked by name.
901
+
902
+ ### Defining prompts on the server
903
+
904
+ Here's a small example of a stdio MCP server that defines prompts:
905
+
906
+ ```ts
907
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
908
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
909
+ import { z } from 'zod';
910
+
911
+ const server = new McpServer({
912
+ name: 'prompt-server',
913
+ version: '1.0.0',
914
+ });
915
+
916
+ server.registerPrompt(
917
+ 'poem-writer',
918
+ {
919
+ title: 'Poem Writer',
920
+ description: 'Write a nice haiku',
921
+ argsSchema: { title: z.string(), mood: z.string().optional() },
922
+ },
923
+ ({ title, mood }) => ({
924
+ messages: [
925
+ {
926
+ role: 'user',
927
+ content: {
928
+ type: 'text',
929
+ text: `Write a haiku${mood ? ` with the mood ${mood}` : ''} called ${title}. Note that a haiku is 5 syllables followed by 7 syllables followed by 5 syllables `,
930
+ },
931
+ },
932
+ ],
933
+ }),
934
+ );
935
+
936
+ const transport = new StdioServerTransport();
937
+ await server.connect(transport);
938
+ ```
939
+
940
+ This can be included in `settings.json` under `mcpServers` with:
941
+
942
+ ```json
943
+ {
944
+ "mcpServers": {
945
+ "nodeServer": {
946
+ "command": "node",
947
+ "args": ["filename.ts"]
948
+ }
949
+ }
950
+ }
951
+ ```
952
+
953
+ ### Invoking prompts
954
+
955
+ Once a prompt is discovered, you can invoke it using its name as a slash
956
+ command. The CLI will automatically handle parsing arguments.
957
+
958
+ ```bash
959
+ /poem-writer --title="Gemini CLI" --mood="reverent"
960
+ ```
961
+
962
+ or, using positional arguments:
963
+
964
+ ```bash
965
+ /poem-writer "Gemini CLI" reverent
966
+ ```
967
+
968
+ When you run this command, the Gemini CLI executes the `prompts/get` method on
969
+ the MCP server with the provided arguments. The server is responsible for
970
+ substituting the arguments into the prompt template and returning the final
971
+ prompt text. The CLI then sends this prompt to the model for execution. This
972
+ provides a convenient way to automate and share common workflows.
973
+
974
+ ## Managing MCP servers with `gemini mcp`
975
+
976
+ While you can always configure MCP servers by manually editing your
977
+ `settings.json` file, the Gemini CLI provides a convenient set of commands to
978
+ manage your server configurations programmatically. These commands streamline
979
+ the process of adding, listing, and removing MCP servers without needing to
980
+ directly edit JSON files.
981
+
982
+ ### Adding a server (`gemini mcp add`)
983
+
984
+ The `add` command configures a new MCP server in your `settings.json`. Based on
985
+ the scope (`-s, --scope`), it will be added to either the user config
986
+ `~/.gemini/settings.json` or the project config `.gemini/settings.json` file.
987
+
988
+ **Command:**
989
+
990
+ ```bash
991
+ gemini mcp add [options] <name> <commandOrUrl> [args...]
992
+ ```
993
+
994
+ - `<name>`: A unique name for the server.
995
+ - `<commandOrUrl>`: The command to execute (for `stdio`) or the URL (for
996
+ `http`/`sse`).
997
+ - `[args...]`: Optional arguments for a `stdio` command.
998
+
999
+ **Options (flags):**
1000
+
1001
+ - `-s, --scope`: Configuration scope (user or project). [default: "project"]
1002
+ - `-t, --transport`: Transport type (stdio, sse, http). [default: "stdio"]
1003
+ - `-e, --env`: Set environment variables (e.g. -e KEY=value).
1004
+ - `-H, --header`: Set HTTP headers for SSE and HTTP transports (e.g. -H
1005
+ "X-Api-Key: abc123" -H "Authorization: Bearer abc123").
1006
+ - `--timeout`: Set connection timeout in milliseconds.
1007
+ - `--trust`: Trust the server (bypass all tool call confirmation prompts).
1008
+ - `--description`: Set the description for the server.
1009
+ - `--include-tools`: A comma-separated list of tools to include.
1010
+ - `--exclude-tools`: A comma-separated list of tools to exclude.
1011
+
1012
+ #### Adding an stdio server
1013
+
1014
+ This is the default transport for running local servers.
1015
+
1016
+ ```bash
1017
+ # Basic syntax
1018
+ gemini mcp add [options] <name> <command> [args...]
1019
+
1020
+ # Example: Adding a local server
1021
+ gemini mcp add -e API_KEY=123 -e DEBUG=true my-stdio-server /path/to/server arg1 arg2 arg3
1022
+
1023
+ # Example: Adding a local python server
1024
+ gemini mcp add python-server python server.py -- --server-arg my-value
1025
+ ```
1026
+
1027
+ #### Adding an HTTP server
1028
+
1029
+ This transport is for servers that use the streamable HTTP transport.
1030
+
1031
+ ```bash
1032
+ # Basic syntax
1033
+ gemini mcp add --transport http <name> <url>
1034
+
1035
+ # Example: Adding an HTTP server
1036
+ gemini mcp add --transport http http-server https://api.example.com/mcp/
1037
+
1038
+ # Example: Adding an HTTP server with an authentication header
1039
+ gemini mcp add --transport http --header "Authorization: Bearer abc123" secure-http https://api.example.com/mcp/
1040
+ ```
1041
+
1042
+ #### Adding an SSE server
1043
+
1044
+ This transport is for servers that use Server-Sent Events (SSE).
1045
+
1046
+ ```bash
1047
+ # Basic syntax
1048
+ gemini mcp add --transport sse <name> <url>
1049
+
1050
+ # Example: Adding an SSE server
1051
+ gemini mcp add --transport sse sse-server https://api.example.com/sse/
1052
+
1053
+ # Example: Adding an SSE server with an authentication header
1054
+ gemini mcp add --transport sse --header "Authorization: Bearer abc123" secure-sse https://api.example.com/sse/
1055
+ ```
1056
+
1057
+ ### Listing servers (`gemini mcp list`)
1058
+
1059
+ To view all MCP servers currently configured, use the `list` command. It
1060
+ displays each server's name, configuration details, and connection status. This
1061
+ command has no flags.
1062
+
1063
+ **Command:**
1064
+
1065
+ ```bash
1066
+ gemini mcp list
1067
+ ```
1068
+
1069
+ > **Note on Trust:** For security, `stdio` MCP servers (those using the
1070
+ > `command` property) are only tested and displayed as "Connected" if the
1071
+ > current folder is trusted. If the folder is untrusted, they will show as
1072
+ > "Disconnected". Use `gemini trust` to trust the current folder.
1073
+
1074
+ **Example output:**
1075
+
1076
+ ```sh
1077
+ ✓ stdio-server: command: python3 server.py (stdio) - Connected
1078
+ ✓ http-server: https://api.example.com/mcp (http) - Connected
1079
+ ✗ sse-server: https://api.example.com/sse (sse) - Disconnected
1080
+ ```
1081
+
1082
+ ## Troubleshooting and Diagnostics
1083
+
1084
+ To minimize noise during startup, MCP connection errors for background servers
1085
+ are "silent by default." If issues are detected during startup, a single
1086
+ informational hint will be shown: _"MCP issues detected. Run /mcp list for
1087
+ status."_
1088
+
1089
+ Detailed, actionable diagnostics for a specific server are automatically
1090
+ re-enabled when:
1091
+
1092
+ 1. You run an interactive command like `/mcp list`, `/mcp auth`, etc.
1093
+ 2. The model attempts to execute a tool from that server.
1094
+ 3. You invoke an MCP prompt from that server.
1095
+
1096
+ You can also use `gemini mcp list` from your shell to see connection errors for
1097
+ all configured servers.
1098
+
1099
+ ### Removing a server (`gemini mcp remove`)
1100
+
1101
+ To delete a server from your configuration, use the `remove` command with the
1102
+ server's name.
1103
+
1104
+ **Command:**
1105
+
1106
+ ```bash
1107
+ gemini mcp remove <name>
1108
+ ```
1109
+
1110
+ **Options (flags):**
1111
+
1112
+ - `-s, --scope`: Configuration scope (user or project). [default: "project"]
1113
+
1114
+ **Example:**
1115
+
1116
+ ```bash
1117
+ gemini mcp remove my-server
1118
+ ```
1119
+
1120
+ This will find and delete the "my-server" entry from the `mcpServers` object in
1121
+ the appropriate `settings.json` file based on the scope (`-s, --scope`).
1122
+
1123
+ ### Enabling/disabling a server (`gemini mcp enable`, `gemini mcp disable`)
1124
+
1125
+ Temporarily disable an MCP server without removing its configuration, or
1126
+ re-enable a previously disabled server.
1127
+
1128
+ **Commands:**
1129
+
1130
+ ```bash
1131
+ gemini mcp enable <name> [--session]
1132
+ gemini mcp disable <name> [--session]
1133
+ ```
1134
+
1135
+ **Options (flags):**
1136
+
1137
+ - `--session`: Apply change only for this session (not persisted to file).
1138
+
1139
+ Disabled servers appear in `/mcp` status as "Disabled" but won't connect or
1140
+ provide tools. Enablement state is stored in
1141
+ `~/.gemini/mcp-server-enablement.json`.
1142
+
1143
+ The same commands are available as slash commands during an active session:
1144
+ `/mcp enable <name>` and `/mcp disable <name>`.
1145
+
1146
+ ## Instructions
1147
+
1148
+ Gemini CLI supports
1149
+ [MCP server instructions](https://modelcontextprotocol.io/specification/2025-06-18/schema#initializeresult),
1150
+ which will be appended to the system instructions.