gemini-as-mcp 1.0.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 (83) hide show
  1. package/LICENSE +28 -0
  2. package/README.md +303 -0
  3. package/dist/constants.d.ts +74 -0
  4. package/dist/constants.d.ts.map +1 -0
  5. package/dist/constants.js +73 -0
  6. package/dist/constants.js.map +1 -0
  7. package/dist/index.d.ts +3 -0
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/index.js +187 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/tools/ask-gemini.tool.d.ts +3 -0
  12. package/dist/tools/ask-gemini.tool.d.ts.map +1 -0
  13. package/dist/tools/ask-gemini.tool.js +36 -0
  14. package/dist/tools/ask-gemini.tool.js.map +1 -0
  15. package/dist/tools/brainstorm.tool.d.ts +3 -0
  16. package/dist/tools/brainstorm.tool.d.ts.map +1 -0
  17. package/dist/tools/brainstorm.tool.js +136 -0
  18. package/dist/tools/brainstorm.tool.js.map +1 -0
  19. package/dist/tools/codebase-tools.d.ts +4 -0
  20. package/dist/tools/codebase-tools.d.ts.map +1 -0
  21. package/dist/tools/codebase-tools.js +104 -0
  22. package/dist/tools/codebase-tools.js.map +1 -0
  23. package/dist/tools/fetch-chunk.tool.d.ts +3 -0
  24. package/dist/tools/fetch-chunk.tool.d.ts.map +1 -0
  25. package/dist/tools/fetch-chunk.tool.js +62 -0
  26. package/dist/tools/fetch-chunk.tool.js.map +1 -0
  27. package/dist/tools/index.d.ts +2 -0
  28. package/dist/tools/index.d.ts.map +1 -0
  29. package/dist/tools/index.js +12 -0
  30. package/dist/tools/index.js.map +1 -0
  31. package/dist/tools/registry.d.ts +25 -0
  32. package/dist/tools/registry.d.ts.map +1 -0
  33. package/dist/tools/registry.js +80 -0
  34. package/dist/tools/registry.js.map +1 -0
  35. package/dist/tools/simple-tools.d.ts +4 -0
  36. package/dist/tools/simple-tools.d.ts.map +1 -0
  37. package/dist/tools/simple-tools.js +32 -0
  38. package/dist/tools/simple-tools.js.map +1 -0
  39. package/dist/tools/test-tool.example.d.ts +13 -0
  40. package/dist/tools/test-tool.example.d.ts.map +1 -0
  41. package/dist/tools/test-tool.example.js +32 -0
  42. package/dist/tools/test-tool.example.js.map +1 -0
  43. package/dist/tools/timeout-test.tool.d.ts +3 -0
  44. package/dist/tools/timeout-test.tool.d.ts.map +1 -0
  45. package/dist/tools/timeout-test.tool.js +32 -0
  46. package/dist/tools/timeout-test.tool.js.map +1 -0
  47. package/dist/tools/web-tools.d.ts +4 -0
  48. package/dist/tools/web-tools.d.ts.map +1 -0
  49. package/dist/tools/web-tools.js +78 -0
  50. package/dist/tools/web-tools.js.map +1 -0
  51. package/dist/utils/changeModeChunker.d.ts +11 -0
  52. package/dist/utils/changeModeChunker.d.ts.map +1 -0
  53. package/dist/utils/changeModeChunker.js +89 -0
  54. package/dist/utils/changeModeChunker.js.map +1 -0
  55. package/dist/utils/changeModeParser.d.ts +15 -0
  56. package/dist/utils/changeModeParser.d.ts.map +1 -0
  57. package/dist/utils/changeModeParser.js +67 -0
  58. package/dist/utils/changeModeParser.js.map +1 -0
  59. package/dist/utils/changeModeTranslator.d.ts +8 -0
  60. package/dist/utils/changeModeTranslator.d.ts.map +1 -0
  61. package/dist/utils/changeModeTranslator.js +70 -0
  62. package/dist/utils/changeModeTranslator.js.map +1 -0
  63. package/dist/utils/chunkCache.d.ts +22 -0
  64. package/dist/utils/chunkCache.d.ts.map +1 -0
  65. package/dist/utils/chunkCache.js +161 -0
  66. package/dist/utils/chunkCache.js.map +1 -0
  67. package/dist/utils/commandExecutor.d.ts +2 -0
  68. package/dist/utils/commandExecutor.d.ts.map +1 -0
  69. package/dist/utils/commandExecutor.js +74 -0
  70. package/dist/utils/commandExecutor.js.map +1 -0
  71. package/dist/utils/geminiExecutor.d.ts +3 -0
  72. package/dist/utils/geminiExecutor.d.ts.map +1 -0
  73. package/dist/utils/geminiExecutor.js +170 -0
  74. package/dist/utils/geminiExecutor.js.map +1 -0
  75. package/dist/utils/logger.d.ts +13 -0
  76. package/dist/utils/logger.d.ts.map +1 -0
  77. package/dist/utils/logger.js +42 -0
  78. package/dist/utils/logger.js.map +1 -0
  79. package/dist/utils/timeoutManager.d.ts +2 -0
  80. package/dist/utils/timeoutManager.d.ts.map +1 -0
  81. package/dist/utils/timeoutManager.js +2 -0
  82. package/dist/utils/timeoutManager.js.map +1 -0
  83. package/package.json +70 -0
package/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ MIT License (Non-Commercial)
2
+
3
+ Original work Copyright (c) 2025 jamubc
4
+ Modified work Copyright (c) 2025 baljinnyamday
5
+
6
+ This project is a fork of gemini-mcp-tool (https://github.com/jamubc/gemini-mcp-tool)
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software for non-commercial purposes only, including without limitation
11
+ the rights to use, copy, modify, merge, publish, and distribute copies of the
12
+ Software, and to permit persons to whom the Software is furnished to do so,
13
+ subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in all
16
+ copies or substantial portions of the Software.
17
+
18
+ Commercial use of this software is prohibited without prior written permission
19
+ from the copyright holder. For commercial licensing, please contact the
20
+ copyright holder directly.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,303 @@
1
+
2
+ # Gemini as MCP
3
+
4
+ <div align="center">
5
+
6
+ [![GitHub Release](https://img.shields.io/github/v/release/baljinnyamday/gemini-as-mcp?logo=github&label=GitHub)](https://github.com/baljinnyamday/gemini-as-mcp/releases)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
8
+ [![Open Source](https://img.shields.io/badge/Open%20Source-ā¤ļø-red.svg)](https://github.com/baljinnyamday/gemini-as-mcp)
9
+
10
+ </div>
11
+
12
+ ## TLDR: [![Claude](https://img.shields.io/badge/Claude-D97757?logo=claude&logoColor=fff)](#) + [![Google Gemini](https://img.shields.io/badge/Google%20Gemini-886FBF?logo=googlegemini&logoColor=fff)](#)
13
+
14
+ **Goal**: Supercharge Claude Code with Gemini's 2M+ token context and built-in tools for:
15
+ - šŸ” **Web Search** - Get latest docs, APIs, tutorials (via `google_web_search`)
16
+ - 🌐 **URL Fetching** - Process documentation, blogs, articles (via `web_fetch`)
17
+ - šŸ“‚ **Large Codebase Analysis** - Analyze entire projects that exceed Claude's context
18
+ - āœ… **Implementation Verification** - Check if features/patterns exist in your code
19
+ - šŸ› ļø **Code Execution** - Safely run and test code in sandbox mode
20
+
21
+ ## Prerequisites
22
+
23
+ Before using this tool, ensure you have:
24
+
25
+ 1. **[Node.js](https://nodejs.org/)** (v16.0.0 or higher)
26
+ 2. **[Google Gemini CLI](https://github.com/google-gemini/gemini-cli)** installed and configured
27
+
28
+
29
+ ### One-Line Setup
30
+
31
+ ```bash
32
+ claude mcp add gemini-cli -- npx -y gemini-as-mcp
33
+ ```
34
+
35
+ ### Verify Installation
36
+
37
+ Type `/mcp` inside Claude Code to verify the gemini-cli MCP is active.
38
+
39
+ ---
40
+
41
+ ### Alternative: Import from Claude Desktop
42
+
43
+ If you already have it configured in Claude Desktop:
44
+
45
+ 1. Add to your Claude Desktop config:
46
+ ```json
47
+ "gemini-cli": {
48
+ "command": "npx",
49
+ "args": ["-y", "gemini-as-mcp"]
50
+ }
51
+ ```
52
+
53
+ 2. Import to Claude Code:
54
+ ```bash
55
+ claude mcp add-from-claude-desktop
56
+ ```
57
+
58
+ ## Configuration
59
+
60
+ Register the MCP server with your MCP client:
61
+
62
+ ### For NPX Usage (Recommended)
63
+
64
+ Add this configuration to your Claude Desktop config file:
65
+
66
+ ```json
67
+ {
68
+ "mcpServers": {
69
+ "gemini-cli": {
70
+ "command": "npx",
71
+ "args": ["-y", "gemini-as-mcp"]
72
+ }
73
+ }
74
+ }
75
+ ```
76
+
77
+ ### For Global Installation
78
+
79
+ If you installed globally, use this configuration instead:
80
+
81
+ ```json
82
+ {
83
+ "mcpServers": {
84
+ "gemini-cli": {
85
+ "command": "gemini-as-mcp"
86
+ }
87
+ }
88
+ }
89
+ ```
90
+
91
+ **Configuration File Locations:**
92
+
93
+ - **Claude Desktop**:
94
+ - **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
95
+ - **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
96
+ - **Linux**: `~/.config/claude/claude_desktop_config.json`
97
+
98
+ After updating the configuration, restart your terminal session.
99
+
100
+ ## šŸš€ Available Tools
101
+
102
+ This MCP server provides specialized tools that leverage Gemini's capabilities. Claude Code can use these tools naturally through conversation.
103
+
104
+ ### 1. šŸ” `web-search` - Search the Web via Gemini
105
+
106
+ Search the web and get AI-processed summaries with citations. Perfect for getting current information beyond Claude's knowledge cutoff.
107
+
108
+ **Use Cases:**
109
+ - Latest package versions and breaking changes
110
+ - Current API documentation
111
+ - Recent tutorials and best practices
112
+ - Technology news and updates
113
+
114
+ **Example Prompts for Claude:**
115
+ ```
116
+ "Search the web for React 19 breaking changes"
117
+ "Find the latest Next.js App Router documentation"
118
+ "What are the new features in TypeScript 5.5?"
119
+ ```
120
+
121
+ **Parameters:**
122
+ - `query` (required): Your search query
123
+ - `model` (optional): Model to use (default: `gemini-2.5-pro`)
124
+
125
+ ---
126
+
127
+ ### 2. 🌐 `web-fetch` - Fetch and Process URLs
128
+
129
+ Fetch content from URLs and have Gemini process it according to your instructions. Handles 1-20 URLs per request.
130
+
131
+ **Use Cases:**
132
+ - Fetching and summarizing documentation
133
+ - Comparing multiple API references
134
+ - Extracting code examples from blogs
135
+ - Analyzing articles and tutorials
136
+
137
+ **Example Prompts for Claude:**
138
+ ```
139
+ "Fetch https://nextjs.org/docs/app and explain the new routing system"
140
+ "Compare the APIs at [url1] and [url2]"
141
+ "Extract all code examples from https://example.com/tutorial"
142
+ ```
143
+
144
+ **Parameters:**
145
+ - `urls` (required): Single URL or array of URLs
146
+ - `instruction` (required): What to do with the content
147
+ - `model` (optional): Model to use (default: `gemini-2.5-pro`)
148
+
149
+ ---
150
+
151
+ ### 3. šŸ“‚ `analyze-codebase` - Large Codebase Analysis
152
+
153
+ Analyze entire codebases using Gemini's 2M+ token context window. Perfect for projects that exceed Claude's context limits.
154
+
155
+ **Use Cases:**
156
+ - Understanding project architecture
157
+ - Finding patterns across codebase
158
+ - Analyzing all API endpoints
159
+ - Reviewing entire feature implementations
160
+
161
+ **Example Prompts for Claude:**
162
+ ```
163
+ "Analyze @src/ and explain the authentication flow"
164
+ "Review @./ and summarize the project structure"
165
+ "Find all API endpoints in @backend/ and @routes/"
166
+ ```
167
+
168
+ **Parameters:**
169
+ - `paths` (required): File/directory paths with `@` syntax
170
+ - `question` (required): What you want to know
171
+ - `model` (optional): Model to use (default: `gemini-2.5-pro`)
172
+
173
+ **@ Syntax Examples:**
174
+ - `@src/` - Entire src directory
175
+ - `@package.json` - Single file
176
+ - `@./` - Current directory and subdirectories
177
+ - `@src/ @tests/` - Multiple directories
178
+
179
+ ---
180
+
181
+ ### 4. āœ… `verify-implementation` - Check Feature Implementation
182
+
183
+ Verify if specific features, patterns, or security measures are implemented in your codebase. Returns detailed findings with file paths.
184
+
185
+ **Use Cases:**
186
+ - Check if authentication is implemented
187
+ - Verify error handling exists
188
+ - Find security measures
189
+ - Locate specific patterns (e.g., WebSocket usage)
190
+
191
+ **Example Prompts for Claude:**
192
+ ```
193
+ "Check if JWT authentication is implemented in @src/"
194
+ "Verify rate limiting exists in @api/ @middleware/"
195
+ "Is Redis caching implemented? Check @services/"
196
+ "Find all WebSocket connections in @src/"
197
+ ```
198
+
199
+ **Parameters:**
200
+ - `paths` (required): Directories to search with `@` syntax
201
+ - `feature` (required): Feature/pattern to check for
202
+ - `details` (optional): Specific aspects to verify
203
+ - `model` (optional): Model to use (default: `gemini-2.5-pro`)
204
+
205
+ ---
206
+
207
+ ### 5. šŸ› ļø `ask-gemini` - General Purpose Gemini Query
208
+
209
+ The most flexible tool - automatically uses Gemini's built-in tools (`web_search`, `web_fetch`, file analysis) as needed.
210
+
211
+ **Capabilities:**
212
+ - File/directory analysis via `@` syntax
213
+ - Automatic web search for current info
214
+ - Automatic URL fetching
215
+ - Code execution in sandbox mode
216
+ - Structured code edits (changeMode)
217
+
218
+ **Example Prompts for Claude:**
219
+ ```
220
+ "Ask Gemini to analyze @src/auth.js and suggest improvements"
221
+ "Use Gemini to search for the latest React hooks best practices"
222
+ "Have Gemini explain this codebase @./"
223
+ ```
224
+
225
+ **Parameters:**
226
+ - `prompt` (required): Your request (supports @syntax, URLs, search queries)
227
+ - `model` (optional): Model to use (default: `gemini-2.5-pro`)
228
+ - `sandbox` (optional): Run in sandbox mode (default: false)
229
+ - `changeMode` (optional): Return structured edits (default: false)
230
+
231
+ ---
232
+
233
+ ## šŸ’” Usage Tips
234
+
235
+ ### When to Use Each Tool
236
+
237
+ **Use `web-search` when:**
238
+ - You need current information (latest docs, packages, APIs)
239
+ - You want AI-processed summaries with citations
240
+ - Claude's knowledge cutoff is limiting
241
+
242
+ **Use `web-fetch` when:**
243
+ - You have specific URLs to analyze
244
+ - You need to compare documentation
245
+ - You want to extract information from web pages
246
+
247
+ **Use `analyze-codebase` when:**
248
+ - Your codebase exceeds Claude's context
249
+ - You need to understand entire project structure
250
+ - You're looking for patterns across many files
251
+
252
+ **Use `verify-implementation` when:**
253
+ - You need to check if features exist
254
+ - You're auditing security measures
255
+ - You want to find specific patterns
256
+
257
+ **Use `ask-gemini` when:**
258
+ - You want Gemini to decide which tools to use
259
+ - You have a complex multi-part request
260
+ - You need flexibility
261
+
262
+ ---
263
+
264
+ ## šŸ“ Example Workflows
265
+
266
+ ### Workflow 1: Learning a New Library
267
+ ```
268
+ 1. Claude: "Search the web for Drizzle ORM latest version"
269
+ 2. Claude: "Fetch https://orm.drizzle.team/docs and explain core concepts"
270
+ 3. Claude: "Analyze @src/db/ and suggest how to integrate Drizzle"
271
+ ```
272
+
273
+ ### Workflow 2: Codebase Audit
274
+ ```
275
+ 1. Claude: "Verify if authentication is implemented in @src/"
276
+ 2. Claude: "Check if error handling exists in @api/"
277
+ 3. Claude: "Analyze @src/ for security vulnerabilities"
278
+ ```
279
+
280
+ ### Workflow 3: Feature Implementation
281
+ ```
282
+ 1. Claude: "Search the web for Next.js 14 server actions best practices"
283
+ 2. Claude: "Verify if server actions are used in @app/"
284
+ 3. Claude: "Analyze @app/ and suggest where to add server actions"
285
+ ```
286
+
287
+ ## Attribution
288
+
289
+ This project is a fork of [gemini-mcp-tool](https://github.com/jamubc/gemini-mcp-tool) by jamubc. The original project provided the foundation for integrating Google's Gemini CLI with the Model Context Protocol. This fork maintains the core functionality while diverging in direction and implementation to explore new capabilities and use cases.
290
+
291
+ This is a simple Model Context Protocol (MCP) server that allows AI assistants to interact with the [Gemini CLI](https://github.com/google-gemini/gemini-cli). It enables the AI to leverage the power of Gemini's massive token window for large analysis, especially with large files and codebases using the `@` syntax for direction.
292
+
293
+ - Ask gemini natural questions, through claude or Brainstorm new ideas in a party of 3!
294
+
295
+ ## Contributing
296
+
297
+ Contributions are welcome! Please see our [Contributing Guidelines](CONTRIBUTING.md) for details on how to submit pull requests, report issues, and contribute to the project.
298
+
299
+ ## License
300
+
301
+ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
302
+
303
+ **Disclaimer:** This is an unofficial, third-party tool and is not affiliated with, endorsed, or sponsored by Google.
@@ -0,0 +1,74 @@
1
+ export declare const LOG_PREFIX = "[GMCPT]";
2
+ export declare const ERROR_MESSAGES: {
3
+ readonly QUOTA_EXCEEDED: "Quota exceeded for quota metric 'Gemini 2.5 Pro Requests'";
4
+ readonly QUOTA_EXCEEDED_SHORT: "āš ļø Gemini 2.5 Pro daily quota exceeded. Please retry with model: 'gemini-2.5-flash'";
5
+ readonly TOOL_NOT_FOUND: "not found in registry";
6
+ readonly NO_PROMPT_PROVIDED: "Please provide a prompt for analysis. Use @ syntax to include files (e.g., '@largefile.js explain what this does') or ask general questions";
7
+ };
8
+ export declare const STATUS_MESSAGES: {
9
+ readonly QUOTA_SWITCHING: "🚫 Gemini 2.5 Pro quota exceeded, switching to Flash model...";
10
+ readonly FLASH_RETRY: "⚔ Retrying with Gemini 2.5 Flash...";
11
+ readonly FLASH_SUCCESS: "āœ… Flash model completed successfully";
12
+ readonly SANDBOX_EXECUTING: "šŸ”’ Executing Gemini CLI command in sandbox mode...";
13
+ readonly GEMINI_RESPONSE: "Gemini response:";
14
+ readonly PROCESSING_START: "šŸ” Starting analysis (may take 5-15 minutes for large codebases)";
15
+ readonly PROCESSING_CONTINUE: "ā³ Still processing... Gemini is working on your request";
16
+ readonly PROCESSING_COMPLETE: "āœ… Analysis completed successfully";
17
+ };
18
+ export declare const MODELS: {
19
+ readonly PRO: "gemini-2.5-pro";
20
+ readonly FLASH: "gemini-2.5-flash";
21
+ };
22
+ export declare const PROTOCOL: {
23
+ readonly ROLES: {
24
+ readonly USER: "user";
25
+ readonly ASSISTANT: "assistant";
26
+ };
27
+ readonly CONTENT_TYPES: {
28
+ readonly TEXT: "text";
29
+ };
30
+ readonly STATUS: {
31
+ readonly SUCCESS: "success";
32
+ readonly ERROR: "error";
33
+ readonly FAILED: "failed";
34
+ readonly REPORT: "report";
35
+ };
36
+ readonly NOTIFICATIONS: {
37
+ readonly PROGRESS: "notifications/progress";
38
+ };
39
+ readonly KEEPALIVE_INTERVAL: 25000;
40
+ };
41
+ export declare const CLI: {
42
+ readonly COMMANDS: {
43
+ readonly GEMINI: "gemini";
44
+ readonly ECHO: "echo";
45
+ };
46
+ readonly FLAGS: {
47
+ readonly MODEL: "-m";
48
+ readonly SANDBOX: "-s";
49
+ readonly PROMPT: "-p";
50
+ readonly HELP: "-help";
51
+ };
52
+ readonly DEFAULTS: {
53
+ readonly MODEL: "default";
54
+ readonly BOOLEAN_TRUE: "true";
55
+ readonly BOOLEAN_FALSE: "false";
56
+ };
57
+ };
58
+ export interface ToolArguments {
59
+ prompt?: string;
60
+ model?: string;
61
+ sandbox?: boolean | string;
62
+ changeMode?: boolean | string;
63
+ chunkIndex?: number | string;
64
+ chunkCacheKey?: string;
65
+ message?: string;
66
+ methodology?: string;
67
+ domain?: string;
68
+ constraints?: string;
69
+ existingContext?: string;
70
+ ideaCount?: number;
71
+ includeAnalysis?: boolean;
72
+ [key: string]: string | boolean | number | undefined;
73
+ }
74
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,UAAU,YAAY,CAAC;AAGpC,eAAO,MAAM,cAAc;;;;;CAKjB,CAAC;AAGX,eAAO,MAAM,eAAe;;;;;;;;;CAUlB,CAAC;AAGX,eAAO,MAAM,MAAM;;;CAGT,CAAC;AAGX,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;CAuBX,CAAC;AAIX,eAAO,MAAM,GAAG;;;;;;;;;;;;;;;;CAmBN,CAAC;AAIX,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAC3B,UAAU,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAC9B,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IAGjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;CACtD"}
@@ -0,0 +1,73 @@
1
+ // Logging
2
+ export const LOG_PREFIX = "[GMCPT]";
3
+ // Error messages
4
+ export const ERROR_MESSAGES = {
5
+ QUOTA_EXCEEDED: "Quota exceeded for quota metric 'Gemini 2.5 Pro Requests'",
6
+ QUOTA_EXCEEDED_SHORT: "āš ļø Gemini 2.5 Pro daily quota exceeded. Please retry with model: 'gemini-2.5-flash'",
7
+ TOOL_NOT_FOUND: "not found in registry",
8
+ NO_PROMPT_PROVIDED: "Please provide a prompt for analysis. Use @ syntax to include files (e.g., '@largefile.js explain what this does') or ask general questions",
9
+ };
10
+ // Status messages
11
+ export const STATUS_MESSAGES = {
12
+ QUOTA_SWITCHING: "🚫 Gemini 2.5 Pro quota exceeded, switching to Flash model...",
13
+ FLASH_RETRY: "⚔ Retrying with Gemini 2.5 Flash...",
14
+ FLASH_SUCCESS: "āœ… Flash model completed successfully",
15
+ SANDBOX_EXECUTING: "šŸ”’ Executing Gemini CLI command in sandbox mode...",
16
+ GEMINI_RESPONSE: "Gemini response:",
17
+ // Timeout prevention messages
18
+ PROCESSING_START: "šŸ” Starting analysis (may take 5-15 minutes for large codebases)",
19
+ PROCESSING_CONTINUE: "ā³ Still processing... Gemini is working on your request",
20
+ PROCESSING_COMPLETE: "āœ… Analysis completed successfully",
21
+ };
22
+ // Models
23
+ export const MODELS = {
24
+ PRO: "gemini-2.5-pro",
25
+ FLASH: "gemini-2.5-flash",
26
+ };
27
+ // MCP Protocol Constants
28
+ export const PROTOCOL = {
29
+ // Message roles
30
+ ROLES: {
31
+ USER: "user",
32
+ ASSISTANT: "assistant",
33
+ },
34
+ // Content types
35
+ CONTENT_TYPES: {
36
+ TEXT: "text",
37
+ },
38
+ // Status codes
39
+ STATUS: {
40
+ SUCCESS: "success",
41
+ ERROR: "error",
42
+ FAILED: "failed",
43
+ REPORT: "report",
44
+ },
45
+ // Notification methods
46
+ NOTIFICATIONS: {
47
+ PROGRESS: "notifications/progress",
48
+ },
49
+ // Timeout prevention
50
+ KEEPALIVE_INTERVAL: 25000, // 25 seconds
51
+ };
52
+ // CLI Constants
53
+ export const CLI = {
54
+ // Command names
55
+ COMMANDS: {
56
+ GEMINI: "gemini",
57
+ ECHO: "echo",
58
+ },
59
+ // Command flags
60
+ FLAGS: {
61
+ MODEL: "-m",
62
+ SANDBOX: "-s",
63
+ PROMPT: "-p",
64
+ HELP: "-help",
65
+ },
66
+ // Default values
67
+ DEFAULTS: {
68
+ MODEL: "default", // Fallback model used when no specific model is provided
69
+ BOOLEAN_TRUE: "true",
70
+ BOOLEAN_FALSE: "false",
71
+ },
72
+ };
73
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,UAAU;AACV,MAAM,CAAC,MAAM,UAAU,GAAG,SAAS,CAAC;AAEpC,iBAAiB;AACjB,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,cAAc,EAAE,2DAA2D;IAC3E,oBAAoB,EAAE,qFAAqF;IAC3G,cAAc,EAAE,uBAAuB;IACvC,kBAAkB,EAAE,6IAA6I;CACzJ,CAAC;AAEX,kBAAkB;AAClB,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,eAAe,EAAE,+DAA+D;IAChF,WAAW,EAAE,qCAAqC;IAClD,aAAa,EAAE,sCAAsC;IACrD,iBAAiB,EAAE,oDAAoD;IACvE,eAAe,EAAE,kBAAkB;IACnC,8BAA8B;IAC9B,gBAAgB,EAAE,kEAAkE;IACpF,mBAAmB,EAAE,yDAAyD;IAC9E,mBAAmB,EAAE,mCAAmC;CAChD,CAAC;AAEX,SAAS;AACT,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,GAAG,EAAE,gBAAgB;IACrB,KAAK,EAAE,kBAAkB;CACjB,CAAC;AAEX,yBAAyB;AACzB,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,gBAAgB;IAChB,KAAK,EAAE;QACL,IAAI,EAAE,MAAM;QACZ,SAAS,EAAE,WAAW;KACvB;IACD,gBAAgB;IAChB,aAAa,EAAE;QACb,IAAI,EAAE,MAAM;KACb;IACD,eAAe;IACf,MAAM,EAAE;QACN,OAAO,EAAE,SAAS;QAClB,KAAK,EAAE,OAAO;QACd,MAAM,EAAE,QAAQ;QAChB,MAAM,EAAE,QAAQ;KACjB;IACD,uBAAuB;IACvB,aAAa,EAAE;QACb,QAAQ,EAAE,wBAAwB;KACnC;IACD,qBAAqB;IACrB,kBAAkB,EAAE,KAAK,EAAE,aAAa;CAChC,CAAC;AAGX,gBAAgB;AAChB,MAAM,CAAC,MAAM,GAAG,GAAG;IACjB,gBAAgB;IAChB,QAAQ,EAAE;QACR,MAAM,EAAE,QAAQ;QAChB,IAAI,EAAE,MAAM;KACb;IACD,gBAAgB;IAChB,KAAK,EAAE;QACL,KAAK,EAAE,IAAI;QACX,OAAO,EAAE,IAAI;QACb,MAAM,EAAE,IAAI;QACZ,IAAI,EAAE,OAAO;KACd;IACD,iBAAiB;IACjB,QAAQ,EAAE;QACR,KAAK,EAAE,SAAS,EAAE,yDAAyD;QAC3E,YAAY,EAAE,MAAM;QACpB,aAAa,EAAE,OAAO;KACvB;CACO,CAAC"}
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/dist/index.js ADDED
@@ -0,0 +1,187 @@
1
+ #!/usr/bin/env node
2
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
3
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
+ import { CallToolRequestSchema, ListToolsRequestSchema, ListPromptsRequestSchema, GetPromptRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
5
+ import { Logger } from "./utils/logger.js";
6
+ import { PROTOCOL } from "./constants.js";
7
+ import { getToolDefinitions, getPromptDefinitions, executeTool, toolExists, getPromptMessage } from "./tools/index.js";
8
+ const server = new Server({
9
+ name: "gemini-as-mcp",
10
+ version: "1.0.0",
11
+ }, {
12
+ capabilities: {
13
+ tools: {},
14
+ prompts: {},
15
+ logging: {},
16
+ },
17
+ });
18
+ let isProcessing = false;
19
+ let currentOperationName = "";
20
+ let latestOutput = "";
21
+ async function sendNotification(method, params) {
22
+ try {
23
+ await server.notification({ method, params });
24
+ }
25
+ catch (error) {
26
+ Logger.error("notification failed: ", error);
27
+ }
28
+ }
29
+ /**
30
+ * @param progressToken The progress token provided by the client
31
+ * @param progress The current progress value
32
+ * @param total Optional total value
33
+ * @param message Optional status message
34
+ */
35
+ async function sendProgressNotification(progressToken, progress, total, message) {
36
+ if (!progressToken)
37
+ return; // Only send if client requested progress
38
+ try {
39
+ const params = {
40
+ progressToken,
41
+ progress
42
+ };
43
+ if (total !== undefined)
44
+ params.total = total; // future cache progress
45
+ if (message)
46
+ params.message = message;
47
+ await server.notification({
48
+ method: PROTOCOL.NOTIFICATIONS.PROGRESS,
49
+ params
50
+ });
51
+ }
52
+ catch (error) {
53
+ Logger.error("Failed to send progress notification:", error);
54
+ }
55
+ }
56
+ function startProgressUpdates(operationName, progressToken) {
57
+ isProcessing = true;
58
+ currentOperationName = operationName;
59
+ latestOutput = ""; // Reset latest output
60
+ const progressMessages = [
61
+ `🧠 ${operationName} - Gemini is analyzing your request...`,
62
+ `šŸ“Š ${operationName} - Processing files and generating insights...`,
63
+ `✨ ${operationName} - Creating structured response for your review...`,
64
+ `ā±ļø ${operationName} - Large analysis in progress (this is normal for big requests)...`,
65
+ `šŸ” ${operationName} - Still working... Gemini takes time for quality results...`,
66
+ ];
67
+ let messageIndex = 0;
68
+ let progress = 0;
69
+ // Send immediate acknowledgment if progress requested
70
+ if (progressToken) {
71
+ sendProgressNotification(progressToken, 0, undefined, // No total - indeterminate progress
72
+ `šŸ” Starting ${operationName}`);
73
+ }
74
+ // Keep client alive with periodic updates
75
+ const progressInterval = setInterval(async () => {
76
+ if (isProcessing && progressToken) {
77
+ // Simply increment progress value
78
+ progress += 1;
79
+ // Include latest output if available
80
+ const baseMessage = progressMessages[messageIndex % progressMessages.length];
81
+ const outputPreview = latestOutput.slice(-150).trim(); // Last 150 chars
82
+ const message = outputPreview
83
+ ? `${baseMessage}\nšŸ“ Output: ...${outputPreview}`
84
+ : baseMessage;
85
+ await sendProgressNotification(progressToken, progress, undefined, // No total - indeterminate progress
86
+ message);
87
+ messageIndex++;
88
+ }
89
+ else if (!isProcessing) {
90
+ clearInterval(progressInterval);
91
+ }
92
+ }, PROTOCOL.KEEPALIVE_INTERVAL); // Every 25 seconds
93
+ return { interval: progressInterval, progressToken };
94
+ }
95
+ function stopProgressUpdates(progressData, success = true) {
96
+ const operationName = currentOperationName; // Store before clearing
97
+ isProcessing = false;
98
+ currentOperationName = "";
99
+ clearInterval(progressData.interval);
100
+ // Send final progress notification if client requested progress
101
+ if (progressData.progressToken) {
102
+ sendProgressNotification(progressData.progressToken, 100, 100, success ? `āœ… ${operationName} completed successfully` : `āŒ ${operationName} failed`);
103
+ }
104
+ }
105
+ // tools/list
106
+ server.setRequestHandler(ListToolsRequestSchema, async (request) => {
107
+ return { tools: getToolDefinitions() };
108
+ });
109
+ // tools/get
110
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
111
+ const toolName = request.params.name;
112
+ if (toolExists(toolName)) {
113
+ // Check if client requested progress updates
114
+ const progressToken = request.params._meta?.progressToken;
115
+ // Start progress updates if client requested them
116
+ const progressData = startProgressUpdates(toolName, progressToken);
117
+ try {
118
+ // Get prompt and other parameters from arguments with proper typing
119
+ const args = request.params.arguments || {};
120
+ Logger.toolInvocation(toolName, request.params.arguments);
121
+ // Execute the tool using the unified registry with progress callback
122
+ const result = await executeTool(toolName, args, (newOutput) => {
123
+ latestOutput = newOutput;
124
+ });
125
+ // Stop progress updates
126
+ stopProgressUpdates(progressData, true);
127
+ return {
128
+ content: [
129
+ {
130
+ type: "text",
131
+ text: result,
132
+ },
133
+ ],
134
+ isError: false,
135
+ };
136
+ }
137
+ catch (error) {
138
+ // Stop progress updates on error
139
+ stopProgressUpdates(progressData, false);
140
+ Logger.error(`Error in tool '${toolName}':`, error);
141
+ const errorMessage = error instanceof Error ? error.message : String(error);
142
+ return {
143
+ content: [
144
+ {
145
+ type: "text",
146
+ text: `Error executing ${toolName}: ${errorMessage}`,
147
+ },
148
+ ],
149
+ isError: true,
150
+ };
151
+ }
152
+ }
153
+ else {
154
+ throw new Error(`Unknown tool: ${request.params.name}`);
155
+ }
156
+ });
157
+ // prompts/list
158
+ server.setRequestHandler(ListPromptsRequestSchema, async (request) => {
159
+ return { prompts: getPromptDefinitions() };
160
+ });
161
+ // prompts/get
162
+ server.setRequestHandler(GetPromptRequestSchema, async (request) => {
163
+ const promptName = request.params.name;
164
+ const args = request.params.arguments || {};
165
+ const promptMessage = getPromptMessage(promptName, args);
166
+ if (!promptMessage) {
167
+ throw new Error(`Unknown prompt: ${promptName}`);
168
+ }
169
+ return {
170
+ messages: [{
171
+ role: "user",
172
+ content: {
173
+ type: "text",
174
+ text: promptMessage
175
+ }
176
+ }]
177
+ };
178
+ });
179
+ // Start the server
180
+ async function main() {
181
+ Logger.debug("init gemini-mcp-tool");
182
+ const transport = new StdioServerTransport();
183
+ await server.connect(transport);
184
+ Logger.debug("gemini-mcp-tool listening on stdio");
185
+ }
186
+ main().catch((error) => { Logger.error("Fatal error:", error); process.exit(1); });
187
+ //# sourceMappingURL=index.js.map