gemini-bridge 1.0.1__py3-none-any.whl → 1.0.3__py3-none-any.whl

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.
@@ -0,0 +1,645 @@
1
+ Metadata-Version: 2.4
2
+ Name: gemini-bridge
3
+ Version: 1.0.3
4
+ Summary: Lightweight MCP server bridging Claude Code to Google's Gemini AI via official CLI
5
+ Author-email: Shelakh <info@shelakh.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/eLyiN/gemini-bridge
8
+ Project-URL: Repository, https://github.com/eLyiN/gemini-bridge
9
+ Project-URL: Issues, https://github.com/eLyiN/gemini-bridge/issues
10
+ Keywords: mcp,gemini,ai,coding,assistant
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
18
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
19
+ Requires-Python: >=3.10
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: mcp>=1.0.0
23
+ Dynamic: license-file
24
+
25
+ # Gemini Bridge
26
+
27
+ ![CI Status](https://github.com/eLyiN/gemini-bridge/actions/workflows/ci.yml/badge.svg)
28
+ ![PyPI Version](https://img.shields.io/pypi/v/gemini-bridge)
29
+ ![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)
30
+ ![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)
31
+ ![MCP Compatible](https://img.shields.io/badge/MCP-compatible-green.svg)
32
+ ![Gemini CLI](https://img.shields.io/badge/Gemini-CLI-blue.svg)
33
+
34
+ A lightweight MCP (Model Context Protocol) server that enables AI coding assistants to interact with Google's Gemini AI through the official CLI. Works with Claude Code, Cursor, VS Code, and other MCP-compatible clients. Designed for simplicity, reliability, and seamless integration.
35
+
36
+ ## ✨ Features
37
+
38
+ - **Direct Gemini CLI Integration**: Zero API costs using official Gemini CLI
39
+ - **Simple MCP Tools**: Two core functions for basic queries and file analysis
40
+ - **Stateless Operation**: No sessions, caching, or complex state management
41
+ - **Production Ready**: Robust error handling with configurable 60-second timeouts
42
+ - **Minimal Dependencies**: Only requires `mcp>=1.0.0` and Gemini CLI
43
+ - **Easy Deployment**: Support for both uvx and traditional pip installation
44
+ - **Universal MCP Compatibility**: Works with any MCP-compatible AI coding assistant
45
+
46
+ ## 🚀 Quick Start
47
+
48
+ ### Prerequisites
49
+
50
+ 1. **Install Gemini CLI**:
51
+ ```bash
52
+ npm install -g @google/gemini-cli
53
+ ```
54
+
55
+ 2. **Authenticate with Gemini**:
56
+ ```bash
57
+ gemini auth login
58
+ ```
59
+
60
+ 3. **Verify installation**:
61
+ ```bash
62
+ gemini --version
63
+ ```
64
+
65
+ ### Installation
66
+
67
+ **🎯 Recommended: PyPI Installation**
68
+ ```bash
69
+ # Install from PyPI
70
+ pip install gemini-bridge
71
+
72
+ # Add to Claude Code with uvx (recommended)
73
+ claude mcp add gemini-bridge -s user -- uvx gemini-bridge
74
+ ```
75
+
76
+ **Alternative: From Source**
77
+ ```bash
78
+ # Clone the repository
79
+ git clone https://github.com/shelakh/gemini-bridge.git
80
+ cd gemini-bridge
81
+
82
+ # Build and install locally
83
+ uvx --from build pyproject-build
84
+ pip install dist/*.whl
85
+
86
+ # Add to Claude Code
87
+ claude mcp add gemini-bridge -s user -- uvx gemini-bridge
88
+ ```
89
+
90
+ **Development Installation**
91
+ ```bash
92
+ # Clone and install in development mode
93
+ git clone https://github.com/shelakh/gemini-bridge.git
94
+ cd gemini-bridge
95
+ pip install -e .
96
+
97
+ # Add to Claude Code (development)
98
+ claude mcp add gemini-bridge-dev -s user -- python -m src
99
+ ```
100
+
101
+ ## 🌐 Multi-Client Support
102
+
103
+ **Gemini Bridge works with any MCP-compatible AI coding assistant** - the same server supports multiple clients through different configuration methods.
104
+
105
+ ### Supported MCP Clients
106
+ - **Claude Code** ✅ (Default)
107
+ - **Cursor** ✅
108
+ - **VS Code** ✅
109
+ - **Windsurf** ✅
110
+ - **Cline** ✅
111
+ - **Void** ✅
112
+ - **Cherry Studio** ✅
113
+ - **Augment** ✅
114
+ - **Roo Code** ✅
115
+ - **Zencoder** ✅
116
+ - **Any MCP-compatible client** ✅
117
+
118
+ ### Configuration Examples
119
+
120
+ <details>
121
+ <summary><strong>Claude Code</strong> (Default)</summary>
122
+
123
+ ```bash
124
+ # Recommended installation
125
+ claude mcp add gemini-bridge -s user -- uvx gemini-bridge
126
+
127
+ # Development installation
128
+ claude mcp add gemini-bridge-dev -s user -- python -m src
129
+ ```
130
+
131
+ </details>
132
+
133
+ <details>
134
+ <summary><strong>Cursor</strong></summary>
135
+
136
+ **Global Configuration** (`~/.cursor/mcp.json`):
137
+ ```json
138
+ {
139
+ "mcpServers": {
140
+ "gemini-bridge": {
141
+ "command": "uvx",
142
+ "args": ["gemini-bridge"],
143
+ "env": {}
144
+ }
145
+ }
146
+ }
147
+ ```
148
+
149
+ **Project-Specific** (`.cursor/mcp.json` in your project):
150
+ ```json
151
+ {
152
+ "mcpServers": {
153
+ "gemini-bridge": {
154
+ "command": "uvx",
155
+ "args": ["gemini-bridge"],
156
+ "env": {}
157
+ }
158
+ }
159
+ }
160
+ ```
161
+
162
+ Go to: `Settings` → `Cursor Settings` → `MCP` → `Add new global MCP server`
163
+
164
+ </details>
165
+
166
+ <details>
167
+ <summary><strong>VS Code</strong></summary>
168
+
169
+ **Configuration** (`.vscode/mcp.json` in your workspace):
170
+ ```json
171
+ {
172
+ "servers": {
173
+ "gemini-bridge": {
174
+ "type": "stdio",
175
+ "command": "uvx",
176
+ "args": ["gemini-bridge"]
177
+ }
178
+ }
179
+ }
180
+ ```
181
+
182
+ **Alternative: Through Extensions**
183
+ 1. Open Extensions view (Ctrl+Shift+X)
184
+ 2. Search for MCP extensions
185
+ 3. Add custom server with command: `uvx gemini-bridge`
186
+
187
+ </details>
188
+
189
+ <details>
190
+ <summary><strong>Windsurf</strong></summary>
191
+
192
+ Add to your Windsurf MCP configuration:
193
+ ```json
194
+ {
195
+ "mcpServers": {
196
+ "gemini-bridge": {
197
+ "command": "uvx",
198
+ "args": ["gemini-bridge"],
199
+ "env": {}
200
+ }
201
+ }
202
+ }
203
+ ```
204
+
205
+ </details>
206
+
207
+ <details>
208
+ <summary><strong>Cline</strong> (VS Code Extension)</summary>
209
+
210
+ 1. Open Cline and click **MCP Servers** in the top navigation
211
+ 2. Select **Installed** tab → **Advanced MCP Settings**
212
+ 3. Add to `cline_mcp_settings.json`:
213
+
214
+ ```json
215
+ {
216
+ "mcpServers": {
217
+ "gemini-bridge": {
218
+ "command": "uvx",
219
+ "args": ["gemini-bridge"],
220
+ "env": {}
221
+ }
222
+ }
223
+ }
224
+ ```
225
+
226
+ </details>
227
+
228
+ <details>
229
+ <summary><strong>Void</strong></summary>
230
+
231
+ Go to: `Settings` → `MCP` → `Add MCP Server`
232
+
233
+ ```json
234
+ {
235
+ "mcpServers": {
236
+ "gemini-bridge": {
237
+ "command": "uvx",
238
+ "args": ["gemini-bridge"],
239
+ "env": {}
240
+ }
241
+ }
242
+ }
243
+ ```
244
+
245
+ </details>
246
+
247
+ <details>
248
+ <summary><strong>Cherry Studio</strong></summary>
249
+
250
+ 1. Navigate to **Settings → MCP Servers → Add Server**
251
+ 2. Fill in the server details:
252
+ - **Name**: `gemini-bridge`
253
+ - **Type**: `STDIO`
254
+ - **Command**: `uvx`
255
+ - **Arguments**: `["gemini-bridge"]`
256
+ 3. Save the configuration
257
+
258
+ </details>
259
+
260
+ <details>
261
+ <summary><strong>Augment</strong></summary>
262
+
263
+ **Using the UI:**
264
+ 1. Click hamburger menu → **Settings** → **Tools**
265
+ 2. Click **+ Add MCP** button
266
+ 3. Enter command: `uvx gemini-bridge`
267
+ 4. Name: **Gemini Bridge**
268
+
269
+ **Manual Configuration:**
270
+ ```json
271
+ "augment.advanced": {
272
+ "mcpServers": [
273
+ {
274
+ "name": "gemini-bridge",
275
+ "command": "uvx",
276
+ "args": ["gemini-bridge"],
277
+ "env": {}
278
+ }
279
+ ]
280
+ }
281
+ ```
282
+
283
+ </details>
284
+
285
+ <details>
286
+ <summary><strong>Roo Code</strong></summary>
287
+
288
+ 1. Go to **Settings → MCP Servers → Edit Global Config**
289
+ 2. Add to `mcp_settings.json`:
290
+
291
+ ```json
292
+ {
293
+ "mcpServers": {
294
+ "gemini-bridge": {
295
+ "command": "uvx",
296
+ "args": ["gemini-bridge"],
297
+ "env": {}
298
+ }
299
+ }
300
+ }
301
+ ```
302
+
303
+ </details>
304
+
305
+ <details>
306
+ <summary><strong>Zencoder</strong></summary>
307
+
308
+ 1. Go to Zencoder menu (...) → **Tools** → **Add Custom MCP**
309
+ 2. Add configuration:
310
+
311
+ ```json
312
+ {
313
+ "command": "uvx",
314
+ "args": ["gemini-bridge"],
315
+ "env": {}
316
+ }
317
+ ```
318
+
319
+ 3. Hit the **Install** button
320
+
321
+ </details>
322
+
323
+ <details>
324
+ <summary><strong>Alternative Installation Methods</strong></summary>
325
+
326
+ **For pip-based installations:**
327
+ ```json
328
+ {
329
+ "command": "gemini-bridge",
330
+ "args": [],
331
+ "env": {}
332
+ }
333
+ ```
334
+
335
+ **For development/local testing:**
336
+ ```json
337
+ {
338
+ "command": "python",
339
+ "args": ["-m", "src"],
340
+ "env": {},
341
+ "cwd": "/path/to/gemini-bridge"
342
+ }
343
+ ```
344
+
345
+ **For npm-style installation** (if needed):
346
+ ```json
347
+ {
348
+ "command": "npx",
349
+ "args": ["gemini-bridge"],
350
+ "env": {}
351
+ }
352
+ ```
353
+
354
+ </details>
355
+
356
+ ### Universal Usage
357
+
358
+ Once configured with any client, use the same two tools:
359
+
360
+ 1. **Ask general questions**: "What authentication patterns are used in this codebase?"
361
+ 2. **Analyze specific files**: "Review these auth files for security issues"
362
+
363
+ **The server implementation is identical** - only the client configuration differs!
364
+
365
+ ## ⚙️ Configuration
366
+
367
+ ### Timeout Configuration
368
+
369
+ By default, Gemini Bridge uses a 60-second timeout for all CLI operations. For longer queries (large files, complex analysis), you can configure a custom timeout using the `GEMINI_BRIDGE_TIMEOUT` environment variable.
370
+
371
+ **Example configurations:**
372
+
373
+ <details>
374
+ <summary><strong>Claude Code</strong></summary>
375
+
376
+ ```bash
377
+ # Add with custom timeout (120 seconds)
378
+ claude mcp add gemini-bridge -s user --env GEMINI_BRIDGE_TIMEOUT=120 -- uvx gemini-bridge
379
+ ```
380
+
381
+ </details>
382
+
383
+ <details>
384
+ <summary><strong>Manual Configuration (mcp_settings.json)</strong></summary>
385
+
386
+ ```json
387
+ {
388
+ "mcpServers": {
389
+ "gemini-bridge": {
390
+ "command": "uvx",
391
+ "args": ["gemini-bridge"],
392
+ "env": {
393
+ "GEMINI_BRIDGE_TIMEOUT": "120"
394
+ }
395
+ }
396
+ }
397
+ }
398
+ ```
399
+
400
+ </details>
401
+
402
+ **Timeout Options:**
403
+ - **Default**: 60 seconds (if not configured)
404
+ - **Range**: Any positive integer (seconds)
405
+ - **Recommended**: 120-300 seconds for large file analysis
406
+ - **Invalid values**: Fall back to 60 seconds with warning
407
+
408
+ ## 🛠️ Available Tools
409
+
410
+ ### `consult_gemini`
411
+ Direct CLI bridge for simple queries.
412
+
413
+ **Parameters:**
414
+ - `query` (string): The question or prompt to send to Gemini
415
+ - `directory` (string): Working directory for the query (default: current directory)
416
+ - `model` (string, optional): Model to use - "flash" or "pro" (default: "flash")
417
+
418
+ **Example:**
419
+ ```python
420
+ consult_gemini(
421
+ query="Find authentication patterns in this codebase",
422
+ directory="/path/to/project",
423
+ model="flash"
424
+ )
425
+ ```
426
+
427
+ ### `consult_gemini_with_files`
428
+ CLI bridge with file attachments for detailed analysis.
429
+
430
+ **Parameters:**
431
+ - `query` (string): The question or prompt to send to Gemini
432
+ - `directory` (string): Working directory for the query
433
+ - `files` (list): List of file paths relative to the directory
434
+ - `model` (string, optional): Model to use - "flash" or "pro" (default: "flash")
435
+
436
+ **Example:**
437
+ ```python
438
+ consult_gemini_with_files(
439
+ query="Analyze these auth files and suggest improvements",
440
+ directory="/path/to/project",
441
+ files=["src/auth.py", "src/models.py"],
442
+ model="pro"
443
+ )
444
+ ```
445
+
446
+ ## 📋 Usage Examples
447
+
448
+ ### Basic Code Analysis
449
+ ```python
450
+ # Simple research query
451
+ consult_gemini(
452
+ query="What authentication patterns are used in this project?",
453
+ directory="/Users/dev/my-project"
454
+ )
455
+ ```
456
+
457
+ ### Detailed File Review
458
+ ```python
459
+ # Analyze specific files
460
+ consult_gemini_with_files(
461
+ query="Review these files and suggest security improvements",
462
+ directory="/Users/dev/my-project",
463
+ files=["src/auth.py", "src/middleware.py"],
464
+ model="pro"
465
+ )
466
+ ```
467
+
468
+ ### Multi-file Analysis
469
+ ```python
470
+ # Compare multiple implementation files
471
+ consult_gemini_with_files(
472
+ query="Compare these database implementations and recommend the best approach",
473
+ directory="/Users/dev/my-project",
474
+ files=["src/db/postgres.py", "src/db/sqlite.py", "src/db/redis.py"]
475
+ )
476
+ ```
477
+
478
+ ## 🏗️ Architecture
479
+
480
+ ### Core Design
481
+ - **CLI-First**: Direct subprocess calls to `gemini` command
482
+ - **Stateless**: Each tool call is independent with no session state
483
+ - **Fixed Timeout**: 60-second maximum execution time
484
+ - **Simple Error Handling**: Clear error messages with fail-fast approach
485
+
486
+ ### Project Structure
487
+ ```
488
+ gemini-bridge/
489
+ ├── src/
490
+ │ ├── __init__.py # Entry point
491
+ │ ├── __main__.py # Module execution entry point
492
+ │ └── mcp_server.py # Main MCP server implementation
493
+ ├── .github/ # GitHub templates and workflows
494
+ ├── pyproject.toml # Python package configuration
495
+ ├── README.md # This file
496
+ ├── CONTRIBUTING.md # Contribution guidelines
497
+ ├── CODE_OF_CONDUCT.md # Community standards
498
+ ├── SECURITY.md # Security policies
499
+ ├── CHANGELOG.md # Version history
500
+ └── LICENSE # MIT license
501
+ ```
502
+
503
+ ## 🔧 Development
504
+
505
+ ### Local Testing
506
+ ```bash
507
+ # Install in development mode
508
+ pip install -e .
509
+
510
+ # Run directly
511
+ python -m src
512
+
513
+ # Test CLI availability
514
+ gemini --version
515
+ ```
516
+
517
+ ### Integration with Claude Code
518
+ The server automatically integrates with Claude Code when properly configured through the MCP protocol.
519
+
520
+ ## 🔍 Troubleshooting
521
+
522
+ ### CLI Not Available
523
+ ```bash
524
+ # Install Gemini CLI
525
+ npm install -g @google/gemini-cli
526
+
527
+ # Authenticate
528
+ gemini auth login
529
+
530
+ # Test
531
+ gemini --version
532
+ ```
533
+
534
+ ### Connection Issues
535
+ - Verify Gemini CLI is properly authenticated
536
+ - Check network connectivity
537
+ - Ensure Claude Code MCP configuration is correct
538
+ - Check that the `gemini` command is in your PATH
539
+
540
+ ### Timeout Issues 🔥
541
+
542
+ Gemini Bridge now includes comprehensive timeout debugging. If you're experiencing timeout issues:
543
+
544
+ **1. Use the Debug Tool**
545
+ ```python
546
+ # Get detailed diagnostics about your configuration
547
+ get_debug_info()
548
+ ```
549
+
550
+ This will show:
551
+ - Current timeout configuration
552
+ - Gemini CLI status and version
553
+ - Authentication status
554
+ - Environment variables
555
+ - System information
556
+
557
+ **2. Configure Appropriate Timeout**
558
+
559
+ For different operation types, recommended timeouts:
560
+
561
+ - **Default operations**: 60 seconds (default)
562
+ - **Large file analysis**: 240 seconds
563
+ - **Complex multi-file operations**: 300+ seconds
564
+
565
+ **Configuration Examples:**
566
+
567
+ ```bash
568
+ # Claude Code with 4-minute timeout for large operations
569
+ claude mcp add gemini-bridge -s user --env GEMINI_BRIDGE_TIMEOUT=240 -- uvx gemini-bridge
570
+
571
+ # Environment variable (if running manually)
572
+ export GEMINI_BRIDGE_TIMEOUT=240
573
+ ```
574
+
575
+ **3. Common Timeout Scenarios**
576
+
577
+ | Scenario | Recommended Timeout | Reason |
578
+ |----------|-------------------|---------|
579
+ | Single file < 10KB | 60s (default) | Fast processing |
580
+ | Multiple files or large files | 240s | More content to process |
581
+ | Complex code analysis | 300s | Deep reasoning required |
582
+ | Very large files (>100KB) | 300-600s | Processing overhead |
583
+
584
+ **4. Debugging Steps**
585
+
586
+ 1. **Check your configuration**:
587
+ ```bash
588
+ # Run the debug tool to see current timeout
589
+ # Look for "Actual timeout used" in the output
590
+ ```
591
+
592
+ 2. **Monitor logs**: The server now logs detailed timing information
593
+
594
+ 3. **Test with smaller queries**: If large queries timeout, break them into smaller parts
595
+
596
+ 4. **Verify Gemini CLI performance**: Test `gemini` directly with similar queries
597
+
598
+ **5. Advanced Troubleshooting**
599
+
600
+ If timeouts persist even with high timeout values:
601
+
602
+ - **Network issues**: Check your internet connection
603
+ - **Gemini CLI version**: Update with `npm install -g @google/gemini-cli@latest`
604
+ - **Authentication**: Re-authenticate with `gemini auth login`
605
+ - **System resources**: Check if your system is under high load
606
+ - **File encoding**: Ensure files are UTF-8 encoded
607
+ - **MCP client timeout**: Some clients have their own timeout settings
608
+
609
+ ### Common Error Messages
610
+ - **"CLI not available"**: Gemini CLI is not installed or not in PATH
611
+ - **"Authentication required"**: Run `gemini auth login`
612
+ - **"Timeout after X seconds"**: Operation took longer than configured timeout
613
+ - Solution: Increase `GEMINI_BRIDGE_TIMEOUT` environment variable
614
+ - For immediate testing: Use smaller files or simpler queries
615
+ - **"Large content size warning"**: Files total >100KB, may need longer timeout
616
+ - **"Very high timeout configured"**: Timeout >300s, failed operations will wait long
617
+
618
+ ## 🤝 Contributing
619
+
620
+ We welcome contributions from the community! Please read our [Contributing Guidelines](CONTRIBUTING.md) for details on how to get started.
621
+
622
+ ### Quick Contributing Guide
623
+ 1. Fork the repository
624
+ 2. Create a feature branch
625
+ 3. Make your changes
626
+ 4. Add tests if applicable
627
+ 5. Submit a pull request
628
+
629
+ ## 📄 License
630
+
631
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
632
+
633
+ ## 🔄 Version History
634
+
635
+ See [CHANGELOG.md](CHANGELOG.md) for detailed version history.
636
+
637
+ ## 🆘 Support
638
+
639
+ - **Issues**: Report bugs or request features via [GitHub Issues](https://github.com/shelakh/gemini-bridge/issues)
640
+ - **Discussions**: Join the community discussion
641
+ - **Documentation**: Additional docs can be created in the `docs/` directory
642
+
643
+ ---
644
+
645
+ **Focus**: A simple, reliable bridge between Claude Code and Gemini AI through the official CLI.
@@ -0,0 +1,9 @@
1
+ gemini_bridge-1.0.3.dist-info/licenses/LICENSE,sha256=yTz_R8ocWu64Eubxr6vdZCKRS0dB_Pi3RbjUNn4qPxQ,1063
2
+ src/__init__.py,sha256=w8kaouHPnS_Oe6HQHbGRn6lVKRAYJXG8C4GxqPktK0E,190
3
+ src/__main__.py,sha256=12FoIYCXYYKu2_BYX1GS_h9E9qO41Q26B8zedRIDPBs,149
4
+ src/mcp_server.py,sha256=T9GS8pvpCjn6csLdjUbsTPVrqs3Q9LATotIF4_Xkin8,14469
5
+ gemini_bridge-1.0.3.dist-info/METADATA,sha256=vaefL-Mc6YXwVO9-tQJQ8s4DYhqyN0DIMbz0_DOq6UY,16223
6
+ gemini_bridge-1.0.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
+ gemini_bridge-1.0.3.dist-info/entry_points.txt,sha256=ygWf0B23Gygq8mW_GzPx8rxIA19RR_RH4RG2I15lU3E,43
8
+ gemini_bridge-1.0.3.dist-info/top_level.txt,sha256=74rtVfumQlgAPzR5_2CgYN24MB0XARCg0t-gzk6gTrM,4
9
+ gemini_bridge-1.0.3.dist-info/RECORD,,
src/__init__.py CHANGED
@@ -5,5 +5,5 @@ Version 1.0.0 - Production ready, radically simplified.
5
5
 
6
6
  from .mcp_server import main
7
7
 
8
- __version__ = "1.0.1"
8
+ __version__ = "1.0.3"
9
9
  __all__ = ["main"]
src/mcp_server.py CHANGED
@@ -1,18 +1,24 @@
1
1
  #!/usr/bin/env python3
2
2
  """
3
3
  Gemini MCP Server - Simple CLI Bridge
4
- Version 1.0.0
4
+ Version 1.0.2
5
5
  A minimal MCP server to interface with Gemini AI via the gemini CLI.
6
6
  Created by @shelakh/elyin
7
7
  """
8
8
 
9
+ import logging
9
10
  import os
10
11
  import shutil
11
12
  import subprocess
13
+ import sys
12
14
  from typing import List, Optional
13
15
 
14
16
  from mcp.server.fastmcp import FastMCP
15
17
 
18
+ # Configure logging for debugging timeout issues
19
+ logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
20
+ logger = logging.getLogger(__name__)
21
+
16
22
  mcp = FastMCP("gemini-assistant")
17
23
 
18
24
 
@@ -40,6 +46,47 @@ def _normalize_model_name(model: Optional[str]) -> str:
40
46
  return "gemini-2.5-flash"
41
47
 
42
48
 
49
+ def _get_timeout() -> int:
50
+ """
51
+ Get the timeout value from environment variable GEMINI_BRIDGE_TIMEOUT.
52
+ Defaults to 60 seconds if not set or invalid.
53
+
54
+ Returns:
55
+ Timeout value in seconds (positive integer)
56
+ """
57
+ timeout_str = os.getenv("GEMINI_BRIDGE_TIMEOUT")
58
+ logger.debug(
59
+ "Reading timeout from environment: GEMINI_BRIDGE_TIMEOUT=%s", timeout_str
60
+ )
61
+
62
+ if not timeout_str:
63
+ logger.info("GEMINI_BRIDGE_TIMEOUT not set, using default 60 seconds")
64
+ return 60
65
+
66
+ try:
67
+ timeout = int(timeout_str)
68
+ except ValueError:
69
+ logger.warning(
70
+ "Invalid GEMINI_BRIDGE_TIMEOUT value '%s' (must be integer). Using default 60 seconds.",
71
+ timeout_str,
72
+ )
73
+ return 60
74
+
75
+ if timeout <= 0:
76
+ logger.warning(
77
+ "Invalid GEMINI_BRIDGE_TIMEOUT value '%s' (must be positive). Using default 60 seconds.",
78
+ timeout_str,
79
+ )
80
+ return 60
81
+
82
+ logger.info("Using configured timeout: %s seconds", timeout)
83
+ if timeout > 300:
84
+ logger.warning(
85
+ "Large timeout configured (%ss). This may cause long waits for failed operations.",
86
+ timeout,
87
+ )
88
+ return timeout
89
+
43
90
  def execute_gemini_simple(query: str, directory: str = ".", model: Optional[str] = None) -> str:
44
91
  """
45
92
  Execute gemini CLI command for simple queries without file attachments.
@@ -65,25 +112,39 @@ def execute_gemini_simple(query: str, directory: str = ".", model: Optional[str]
65
112
  cmd = ["gemini", "-m", selected_model]
66
113
 
67
114
  # Execute CLI command - simple timeout, no retries
115
+ timeout = _get_timeout()
116
+ logger.info(f"Executing Gemini CLI with timeout: {timeout}s, model: {selected_model}, directory: {directory}")
117
+ logger.debug(f"Query length: {len(query)} characters")
118
+
68
119
  try:
69
120
  result = subprocess.run(
70
121
  cmd,
71
122
  cwd=directory,
72
123
  capture_output=True,
73
124
  text=True,
74
- timeout=60,
125
+ timeout=timeout,
75
126
  input=query
76
127
  )
77
128
 
129
+ logger.debug(f"Gemini CLI completed with return code: {result.returncode}")
130
+
78
131
  if result.returncode == 0:
79
- return result.stdout.strip() if result.stdout.strip() else "No output from Gemini CLI"
132
+ output = result.stdout.strip() if result.stdout.strip() else "No output from Gemini CLI"
133
+ logger.info(f"Gemini CLI successful, output length: {len(output)} characters")
134
+ return output
80
135
  else:
81
- return f"Gemini CLI Error: {result.stderr.strip()}"
136
+ error_msg = f"Gemini CLI Error: {result.stderr.strip()}"
137
+ logger.error(error_msg)
138
+ return error_msg
82
139
 
83
140
  except subprocess.TimeoutExpired:
84
- return "Error: Gemini CLI command timed out after 60 seconds"
141
+ timeout_msg = f"Error: Gemini CLI command timed out after {timeout} seconds. Try increasing GEMINI_BRIDGE_TIMEOUT environment variable for large operations."
142
+ logger.error(timeout_msg)
143
+ return timeout_msg
85
144
  except Exception as e:
86
- return f"Error executing Gemini CLI: {str(e)}"
145
+ error_msg = f"Error executing Gemini CLI: {str(e)}"
146
+ logger.error(error_msg)
147
+ return error_msg
87
148
 
88
149
 
89
150
  def execute_gemini_with_files(query: str, directory: str = ".", files: Optional[List[str]] = None, model: Optional[str] = None) -> str:
@@ -136,25 +197,44 @@ def execute_gemini_with_files(query: str, directory: str = ".", files: Optional[
136
197
  stdin_content = "\n\n".join(file_contents) + "\n\n" + query
137
198
 
138
199
  # Execute CLI command - simple timeout, no retries
200
+ timeout = _get_timeout()
201
+ total_content_size = len(stdin_content)
202
+ logger.info(f"Executing Gemini CLI with files, timeout: {timeout}s, model: {selected_model}, directory: {directory}")
203
+ logger.info(f"File count: {len(files)}, total content size: {total_content_size} characters")
204
+
205
+ # Warn about large content that might timeout
206
+ if total_content_size > 100000: # 100KB threshold
207
+ logger.warning(f"Large content size ({total_content_size} chars). Consider increasing timeout if you experience timeouts.")
208
+
139
209
  try:
140
210
  result = subprocess.run(
141
211
  cmd,
142
212
  cwd=directory,
143
213
  capture_output=True,
144
214
  text=True,
145
- timeout=60,
215
+ timeout=timeout,
146
216
  input=stdin_content
147
217
  )
148
218
 
219
+ logger.debug(f"Gemini CLI completed with return code: {result.returncode}")
220
+
149
221
  if result.returncode == 0:
150
- return result.stdout.strip() if result.stdout.strip() else "No output from Gemini CLI"
222
+ output = result.stdout.strip() if result.stdout.strip() else "No output from Gemini CLI"
223
+ logger.info(f"Gemini CLI successful, output length: {len(output)} characters")
224
+ return output
151
225
  else:
152
- return f"Gemini CLI Error: {result.stderr.strip()}"
226
+ error_msg = f"Gemini CLI Error: {result.stderr.strip()}"
227
+ logger.error(error_msg)
228
+ return error_msg
153
229
 
154
230
  except subprocess.TimeoutExpired:
155
- return "Error: Gemini CLI command timed out after 60 seconds"
231
+ timeout_msg = f"Error: Gemini CLI command timed out after {timeout} seconds with {len(files)} files ({total_content_size} chars). Try increasing GEMINI_BRIDGE_TIMEOUT environment variable (current: {os.getenv('GEMINI_BRIDGE_TIMEOUT', 'not set')})."
232
+ logger.error(timeout_msg)
233
+ return timeout_msg
156
234
  except Exception as e:
157
- return f"Error executing Gemini CLI: {str(e)}"
235
+ error_msg = f"Error executing Gemini CLI: {str(e)}"
236
+ logger.error(error_msg)
237
+ return error_msg
158
238
 
159
239
 
160
240
  @mcp.tool()
@@ -206,9 +286,120 @@ def consult_gemini_with_files(
206
286
  return execute_gemini_with_files(query, directory, files, model)
207
287
 
208
288
 
289
+ @mcp.tool()
290
+ def get_debug_info() -> str:
291
+ """
292
+ Get diagnostic information about the Gemini Bridge configuration.
293
+
294
+ Useful for troubleshooting timeout issues and verifying setup.
295
+
296
+ Returns:
297
+ Formatted debug information including timeout configuration,
298
+ environment variables, and system status
299
+ """
300
+ debug_info = []
301
+ debug_info.append("=== Gemini Bridge Debug Information ===\n")
302
+
303
+ # Timeout configuration
304
+ timeout_env = os.getenv("GEMINI_BRIDGE_TIMEOUT")
305
+ actual_timeout = _get_timeout()
306
+ debug_info.append("Timeout Configuration:")
307
+ debug_info.append(f" GEMINI_BRIDGE_TIMEOUT env var: {timeout_env or 'not set'}")
308
+ debug_info.append(f" Actual timeout used: {actual_timeout} seconds")
309
+
310
+ if actual_timeout == 60 and not timeout_env:
311
+ debug_info.append(" ⚠️ Using default timeout. Set GEMINI_BRIDGE_TIMEOUT=240 for large operations.")
312
+ elif actual_timeout < 120:
313
+ debug_info.append(" ⚠️ Timeout may be too low for large files or complex queries.")
314
+ elif actual_timeout > 300:
315
+ debug_info.append(f" ⚠️ Very high timeout configured. Failed operations will wait {actual_timeout}s.")
316
+ else:
317
+ debug_info.append(" ✓ Timeout looks reasonable for most operations.")
318
+
319
+ debug_info.append("")
320
+
321
+ # Gemini CLI status
322
+ gemini_path = shutil.which("gemini")
323
+ debug_info.append("Gemini CLI Status:")
324
+ debug_info.append(f" CLI available: {'✓ Yes' if gemini_path else '✗ No'}")
325
+ if gemini_path:
326
+ debug_info.append(f" CLI path: {gemini_path}")
327
+ try:
328
+ # Try to get version
329
+ result = subprocess.run(
330
+ ["gemini", "--version"],
331
+ capture_output=True,
332
+ text=True,
333
+ timeout=5
334
+ )
335
+ if result.returncode == 0:
336
+ version = result.stdout.strip()
337
+ debug_info.append(f" CLI version: {version}")
338
+ else:
339
+ debug_info.append(f" CLI version check failed: {result.stderr.strip()}")
340
+ except Exception as e:
341
+ debug_info.append(f" CLI version check error: {str(e)}")
342
+ else:
343
+ debug_info.append(" ✗ Install with: npm install -g @google/gemini-cli")
344
+
345
+ debug_info.append("")
346
+ # Environment details
347
+ debug_info.append("Environment:")
348
+ debug_info.append(f" Python version: {sys.version.split()[0]}")
349
+ debug_info.append(f" Current working directory: {os.getcwd()}")
350
+ debug_info.append(f" PORT: {os.getenv('PORT', '8080')}")
351
+
352
+ # Check authentication status
353
+ try:
354
+ result = subprocess.run(
355
+ ["gemini", "auth", "status"],
356
+ capture_output=True,
357
+ text=True,
358
+ timeout=10,
359
+ cwd="."
360
+ )
361
+ if result.returncode == 0:
362
+ debug_info.append(" Authentication: ✓ Logged in")
363
+ else:
364
+ debug_info.append(" Authentication: ✗ Not logged in - run 'gemini auth login'")
365
+ except Exception as e:
366
+ debug_info.append(f" Authentication status check failed: {str(e)}")
367
+
368
+ debug_info.append("")
369
+
370
+ # Recent environment variables that might affect operation
371
+ relevant_env_vars = [
372
+ "GEMINI_BRIDGE_TIMEOUT", "NODE_PATH", "PATH", "HOME",
373
+ "GOOGLE_APPLICATION_CREDENTIALS", "GOOGLE_CLOUD_PROJECT"
374
+ ]
375
+
376
+ debug_info.append("Relevant Environment Variables:")
377
+ for var in relevant_env_vars:
378
+ value = os.getenv(var)
379
+ if value:
380
+ # Truncate very long values
381
+ display_value = value[:100] + "..." if len(value) > 100 else value
382
+ debug_info.append(f" {var}: {display_value}")
383
+ else:
384
+ debug_info.append(f" {var}: not set")
385
+
386
+ debug_info.append("")
387
+ debug_info.append("=== End Debug Information ===")
388
+
389
+ return "\n".join(debug_info)
390
+
391
+
209
392
  def main():
210
393
  """Entry point for the MCP server."""
211
- mcp.run()
394
+ port = int(os.getenv("PORT", "8080"))
395
+ timeout = _get_timeout() # Log timeout configuration at startup
396
+
397
+ logger.info(f"Starting Gemini Bridge MCP Server on port {port}")
398
+ logger.info(f"Configured timeout: {timeout} seconds")
399
+ logger.info(f"Gemini CLI available: {shutil.which('gemini') is not None}")
400
+
401
+ # Run the MCP server with SSE transport (port is managed by the library)
402
+ mcp.run(transport="sse")
212
403
 
213
404
 
214
405
  if __name__ == "__main__":
@@ -1,262 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: gemini-bridge
3
- Version: 1.0.1
4
- Summary: Lightweight MCP server bridging Claude Code to Google's Gemini AI via official CLI
5
- Author-email: Shelakh <info@shelakh.com>
6
- License-Expression: MIT
7
- Project-URL: Homepage, https://github.com/eLyiN/gemini-bridge
8
- Project-URL: Repository, https://github.com/eLyiN/gemini-bridge
9
- Project-URL: Issues, https://github.com/eLyiN/gemini-bridge/issues
10
- Keywords: mcp,gemini,ai,coding,assistant
11
- Classifier: Development Status :: 5 - Production/Stable
12
- Classifier: Intended Audience :: Developers
13
- Classifier: Programming Language :: Python :: 3
14
- Classifier: Programming Language :: Python :: 3.10
15
- Classifier: Programming Language :: Python :: 3.11
16
- Classifier: Programming Language :: Python :: 3.12
17
- Classifier: Topic :: Software Development :: Libraries :: Python Modules
18
- Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
19
- Requires-Python: >=3.10
20
- Description-Content-Type: text/markdown
21
- License-File: LICENSE
22
- Requires-Dist: mcp>=1.0.0
23
- Dynamic: license-file
24
-
25
- # Gemini Bridge
26
-
27
- ![CI Status](https://github.com/eLyiN/gemini-bridge/actions/workflows/ci.yml/badge.svg)
28
- ![PyPI Version](https://img.shields.io/pypi/v/gemini-bridge)
29
- ![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)
30
- ![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)
31
- ![MCP Compatible](https://img.shields.io/badge/MCP-compatible-green.svg)
32
- A lightweight MCP (Model Context Protocol) server that enables Claude Code to interact with Google's Gemini AI through the official CLI. Designed for simplicity, reliability, and seamless integration.
33
-
34
- ## ✨ Features
35
-
36
- - **Direct Gemini CLI Integration**: Zero API costs using official Gemini CLI
37
- - **Simple MCP Tools**: Two core functions for basic queries and file analysis
38
- - **Stateless Operation**: No sessions, caching, or complex state management
39
- - **Production Ready**: Robust error handling with configurable 60-second timeouts
40
- - **Minimal Dependencies**: Only requires `mcp>=1.0.0` and Gemini CLI
41
- - **Easy Deployment**: Support for both uvx and traditional pip installation
42
-
43
- ## 🚀 Quick Start
44
-
45
- ### Prerequisites
46
-
47
- 1. **Install Gemini CLI**:
48
- ```bash
49
- npm install -g @google/gemini-cli
50
- ```
51
-
52
- 2. **Authenticate with Gemini**:
53
- ```bash
54
- gemini auth login
55
- ```
56
-
57
- 3. **Verify installation**:
58
- ```bash
59
- gemini --version
60
- ```
61
-
62
- ### Installation
63
-
64
- **🎯 Recommended: PyPI Installation**
65
- ```bash
66
- # Install from PyPI
67
- pip install gemini-bridge
68
-
69
- # Add to Claude Code with uvx (recommended)
70
- claude mcp add gemini-bridge -s user -- uvx gemini-bridge
71
- ```
72
-
73
- **Alternative: From Source**
74
- ```bash
75
- # Clone the repository
76
- git clone https://github.com/shelakh/gemini-bridge.git
77
- cd gemini-bridge
78
-
79
- # Build and install locally
80
- uvx --from build pyproject-build
81
- pip install dist/*.whl
82
-
83
- # Add to Claude Code
84
- claude mcp add gemini-bridge -s user -- uvx gemini-bridge
85
- ```
86
-
87
- **Development Installation**
88
- ```bash
89
- # Clone and install in development mode
90
- git clone https://github.com/shelakh/gemini-bridge.git
91
- cd gemini-bridge
92
- pip install -e .
93
-
94
- # Add to Claude Code (development)
95
- claude mcp add gemini-bridge-dev -s user -- python -m src
96
- ```
97
-
98
- ## 🛠️ Available Tools
99
-
100
- ### `consult_gemini`
101
- Direct CLI bridge for simple queries.
102
-
103
- **Parameters:**
104
- - `query` (string): The question or prompt to send to Gemini
105
- - `directory` (string): Working directory for the query (default: current directory)
106
- - `model` (string, optional): Model to use - "flash" or "pro" (default: "flash")
107
-
108
- **Example:**
109
- ```python
110
- consult_gemini(
111
- query="Find authentication patterns in this codebase",
112
- directory="/path/to/project",
113
- model="flash"
114
- )
115
- ```
116
-
117
- ### `consult_gemini_with_files`
118
- CLI bridge with file attachments for detailed analysis.
119
-
120
- **Parameters:**
121
- - `query` (string): The question or prompt to send to Gemini
122
- - `directory` (string): Working directory for the query
123
- - `files` (list): List of file paths relative to the directory
124
- - `model` (string, optional): Model to use - "flash" or "pro" (default: "flash")
125
-
126
- **Example:**
127
- ```python
128
- consult_gemini_with_files(
129
- query="Analyze these auth files and suggest improvements",
130
- directory="/path/to/project",
131
- files=["src/auth.py", "src/models.py"],
132
- model="pro"
133
- )
134
- ```
135
-
136
- ## 📋 Usage Examples
137
-
138
- ### Basic Code Analysis
139
- ```python
140
- # Simple research query
141
- consult_gemini(
142
- query="What authentication patterns are used in this project?",
143
- directory="/Users/dev/my-project"
144
- )
145
- ```
146
-
147
- ### Detailed File Review
148
- ```python
149
- # Analyze specific files
150
- consult_gemini_with_files(
151
- query="Review these files and suggest security improvements",
152
- directory="/Users/dev/my-project",
153
- files=["src/auth.py", "src/middleware.py"],
154
- model="pro"
155
- )
156
- ```
157
-
158
- ### Multi-file Analysis
159
- ```python
160
- # Compare multiple implementation files
161
- consult_gemini_with_files(
162
- query="Compare these database implementations and recommend the best approach",
163
- directory="/Users/dev/my-project",
164
- files=["src/db/postgres.py", "src/db/sqlite.py", "src/db/redis.py"]
165
- )
166
- ```
167
-
168
- ## 🏗️ Architecture
169
-
170
- ### Core Design
171
- - **CLI-First**: Direct subprocess calls to `gemini` command
172
- - **Stateless**: Each tool call is independent with no session state
173
- - **Fixed Timeout**: 60-second maximum execution time
174
- - **Simple Error Handling**: Clear error messages with fail-fast approach
175
-
176
- ### Project Structure
177
- ```
178
- gemini-bridge/
179
- ├── src/
180
- │ ├── __init__.py # Entry point
181
- │ ├── __main__.py # Module execution entry point
182
- │ └── mcp_server.py # Main MCP server implementation
183
- ├── .github/ # GitHub templates and workflows
184
- ├── pyproject.toml # Python package configuration
185
- ├── README.md # This file
186
- ├── CONTRIBUTING.md # Contribution guidelines
187
- ├── CODE_OF_CONDUCT.md # Community standards
188
- ├── SECURITY.md # Security policies
189
- ├── CHANGELOG.md # Version history
190
- └── LICENSE # MIT license
191
- ```
192
-
193
- ## 🔧 Development
194
-
195
- ### Local Testing
196
- ```bash
197
- # Install in development mode
198
- pip install -e .
199
-
200
- # Run directly
201
- python -m src
202
-
203
- # Test CLI availability
204
- gemini --version
205
- ```
206
-
207
- ### Integration with Claude Code
208
- The server automatically integrates with Claude Code when properly configured through the MCP protocol.
209
-
210
- ## 🔍 Troubleshooting
211
-
212
- ### CLI Not Available
213
- ```bash
214
- # Install Gemini CLI
215
- npm install -g @google/gemini-cli
216
-
217
- # Authenticate
218
- gemini auth login
219
-
220
- # Test
221
- gemini --version
222
- ```
223
-
224
- ### Connection Issues
225
- - Verify Gemini CLI is properly authenticated
226
- - Check network connectivity
227
- - Ensure Claude Code MCP configuration is correct
228
- - Check that the `gemini` command is in your PATH
229
-
230
- ### Common Error Messages
231
- - **"CLI not available"**: Gemini CLI is not installed or not in PATH
232
- - **"Authentication required"**: Run `gemini auth login`
233
- - **"Timeout after 60 seconds"**: Query took too long, try breaking it into smaller parts
234
-
235
- ## 🤝 Contributing
236
-
237
- We welcome contributions from the community! Please read our [Contributing Guidelines](CONTRIBUTING.md) for details on how to get started.
238
-
239
- ### Quick Contributing Guide
240
- 1. Fork the repository
241
- 2. Create a feature branch
242
- 3. Make your changes
243
- 4. Add tests if applicable
244
- 5. Submit a pull request
245
-
246
- ## 📄 License
247
-
248
- This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
249
-
250
- ## 🔄 Version History
251
-
252
- See [CHANGELOG.md](CHANGELOG.md) for detailed version history.
253
-
254
- ## 🆘 Support
255
-
256
- - **Issues**: Report bugs or request features via [GitHub Issues](https://github.com/shelakh/gemini-bridge/issues)
257
- - **Discussions**: Join the community discussion
258
- - **Documentation**: Additional docs can be created in the `docs/` directory
259
-
260
- ---
261
-
262
- **Focus**: A simple, reliable bridge between Claude Code and Gemini AI through the official CLI.
@@ -1,9 +0,0 @@
1
- gemini_bridge-1.0.1.dist-info/licenses/LICENSE,sha256=yTz_R8ocWu64Eubxr6vdZCKRS0dB_Pi3RbjUNn4qPxQ,1063
2
- src/__init__.py,sha256=4DkVQMA4JJ2eUEDNpi3sMJh94joDfaG_52p7Dro6cQI,190
3
- src/__main__.py,sha256=12FoIYCXYYKu2_BYX1GS_h9E9qO41Q26B8zedRIDPBs,149
4
- src/mcp_server.py,sha256=SGdrmNMvpCvJseSvvMlBGvDS71RkwWS7yM4JnSPg_Yg,6871
5
- gemini_bridge-1.0.1.dist-info/METADATA,sha256=C6gVIb1Z2OHpAPHA8F2_Ub42E6InC3ROjZTYEfqjONI,7825
6
- gemini_bridge-1.0.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
- gemini_bridge-1.0.1.dist-info/entry_points.txt,sha256=ygWf0B23Gygq8mW_GzPx8rxIA19RR_RH4RG2I15lU3E,43
8
- gemini_bridge-1.0.1.dist-info/top_level.txt,sha256=74rtVfumQlgAPzR5_2CgYN24MB0XARCg0t-gzk6gTrM,4
9
- gemini_bridge-1.0.1.dist-info/RECORD,,