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