gemini-bridge 1.0.2__py3-none-any.whl → 1.0.4__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gemini-bridge
3
- Version: 1.0.2
3
+ Version: 1.0.4
4
4
  Summary: Lightweight MCP server bridging Claude Code to Google's Gemini AI via official CLI
5
5
  Author-email: Shelakh <info@shelakh.com>
6
6
  License-Expression: MIT
@@ -537,10 +537,83 @@ gemini --version
537
537
  - Ensure Claude Code MCP configuration is correct
538
538
  - Check that the `gemini` command is in your PATH
539
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
+
540
609
  ### Common Error Messages
541
610
  - **"CLI not available"**: Gemini CLI is not installed or not in PATH
542
611
  - **"Authentication required"**: Run `gemini auth login`
543
- - **"Timeout after 60 seconds"**: Query took too long, try breaking it into smaller parts
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
544
617
 
545
618
  ## 🤝 Contributing
546
619
 
@@ -0,0 +1,9 @@
1
+ gemini_bridge-1.0.4.dist-info/licenses/LICENSE,sha256=yTz_R8ocWu64Eubxr6vdZCKRS0dB_Pi3RbjUNn4qPxQ,1063
2
+ src/__init__.py,sha256=U_gAa2Z0ljR0Mn193WDvGATLlzB_UPNkyRDPU7OLPVw,190
3
+ src/__main__.py,sha256=12FoIYCXYYKu2_BYX1GS_h9E9qO41Q26B8zedRIDPBs,149
4
+ src/mcp_server.py,sha256=jioHBNwa1zLExONL1p60a1JWht_K2y7zRPQ_nN1eF4s,14557
5
+ gemini_bridge-1.0.4.dist-info/METADATA,sha256=wUJmFg56YQDH5ZmF9L-tqCuUQIV58-PNVOj2wpfFV7Y,16223
6
+ gemini_bridge-1.0.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
+ gemini_bridge-1.0.4.dist-info/entry_points.txt,sha256=ygWf0B23Gygq8mW_GzPx8rxIA19RR_RH4RG2I15lU3E,43
8
+ gemini_bridge-1.0.4.dist-info/top_level.txt,sha256=74rtVfumQlgAPzR5_2CgYN24MB0XARCg0t-gzk6gTrM,4
9
+ gemini_bridge-1.0.4.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.2"
8
+ __version__ = "1.0.4"
9
9
  __all__ = ["main"]
src/mcp_server.py CHANGED
@@ -10,11 +10,17 @@ import logging
10
10
  import os
11
11
  import shutil
12
12
  import subprocess
13
+ import sys
13
14
  from typing import List, Optional
14
15
 
15
16
  from mcp.server.fastmcp import FastMCP
16
17
 
17
- mcp = FastMCP("gemini-assistant")
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
+
22
+ # FastMCP instance with correct port configuration
23
+ mcp = FastMCP("gemini-assistant", port=int(os.getenv("PORT", "8080")))
18
24
 
19
25
 
20
26
  def _normalize_model_name(model: Optional[str]) -> str:
@@ -50,19 +56,37 @@ def _get_timeout() -> int:
50
56
  Timeout value in seconds (positive integer)
51
57
  """
52
58
  timeout_str = os.getenv("GEMINI_BRIDGE_TIMEOUT")
59
+ logger.debug(
60
+ "Reading timeout from environment: GEMINI_BRIDGE_TIMEOUT=%s", timeout_str
61
+ )
62
+
53
63
  if not timeout_str:
64
+ logger.info("GEMINI_BRIDGE_TIMEOUT not set, using default 60 seconds")
54
65
  return 60
55
-
66
+
56
67
  try:
57
68
  timeout = int(timeout_str)
58
- if timeout <= 0:
59
- logging.warning("Invalid GEMINI_BRIDGE_TIMEOUT value '%s' (must be positive). Using default 60 seconds.", timeout_str)
60
- return 60
61
- return timeout
62
69
  except ValueError:
63
- logging.warning("Invalid GEMINI_BRIDGE_TIMEOUT value '%s' (must be integer). Using default 60 seconds.", timeout_str)
70
+ logger.warning(
71
+ "Invalid GEMINI_BRIDGE_TIMEOUT value '%s' (must be integer). Using default 60 seconds.",
72
+ timeout_str,
73
+ )
74
+ return 60
75
+
76
+ if timeout <= 0:
77
+ logger.warning(
78
+ "Invalid GEMINI_BRIDGE_TIMEOUT value '%s' (must be positive). Using default 60 seconds.",
79
+ timeout_str,
80
+ )
64
81
  return 60
65
82
 
83
+ logger.info("Using configured timeout: %s seconds", timeout)
84
+ if timeout > 300:
85
+ logger.warning(
86
+ "Large timeout configured (%ss). This may cause long waits for failed operations.",
87
+ timeout,
88
+ )
89
+ return timeout
66
90
 
67
91
  def execute_gemini_simple(query: str, directory: str = ".", model: Optional[str] = None) -> str:
68
92
  """
@@ -90,6 +114,9 @@ def execute_gemini_simple(query: str, directory: str = ".", model: Optional[str]
90
114
 
91
115
  # Execute CLI command - simple timeout, no retries
92
116
  timeout = _get_timeout()
117
+ logger.info(f"Executing Gemini CLI with timeout: {timeout}s, model: {selected_model}, directory: {directory}")
118
+ logger.debug(f"Query length: {len(query)} characters")
119
+
93
120
  try:
94
121
  result = subprocess.run(
95
122
  cmd,
@@ -100,15 +127,25 @@ def execute_gemini_simple(query: str, directory: str = ".", model: Optional[str]
100
127
  input=query
101
128
  )
102
129
 
130
+ logger.debug(f"Gemini CLI completed with return code: {result.returncode}")
131
+
103
132
  if result.returncode == 0:
104
- return result.stdout.strip() if result.stdout.strip() else "No output from Gemini CLI"
133
+ output = result.stdout.strip() if result.stdout.strip() else "No output from Gemini CLI"
134
+ logger.info(f"Gemini CLI successful, output length: {len(output)} characters")
135
+ return output
105
136
  else:
106
- return f"Gemini CLI Error: {result.stderr.strip()}"
137
+ error_msg = f"Gemini CLI Error: {result.stderr.strip()}"
138
+ logger.error(error_msg)
139
+ return error_msg
107
140
 
108
141
  except subprocess.TimeoutExpired:
109
- return f"Error: Gemini CLI command timed out after {timeout} seconds"
142
+ timeout_msg = f"Error: Gemini CLI command timed out after {timeout} seconds. Try increasing GEMINI_BRIDGE_TIMEOUT environment variable for large operations."
143
+ logger.error(timeout_msg)
144
+ return timeout_msg
110
145
  except Exception as e:
111
- return f"Error executing Gemini CLI: {str(e)}"
146
+ error_msg = f"Error executing Gemini CLI: {str(e)}"
147
+ logger.error(error_msg)
148
+ return error_msg
112
149
 
113
150
 
114
151
  def execute_gemini_with_files(query: str, directory: str = ".", files: Optional[List[str]] = None, model: Optional[str] = None) -> str:
@@ -162,6 +199,14 @@ def execute_gemini_with_files(query: str, directory: str = ".", files: Optional[
162
199
 
163
200
  # Execute CLI command - simple timeout, no retries
164
201
  timeout = _get_timeout()
202
+ total_content_size = len(stdin_content)
203
+ logger.info(f"Executing Gemini CLI with files, timeout: {timeout}s, model: {selected_model}, directory: {directory}")
204
+ logger.info(f"File count: {len(files)}, total content size: {total_content_size} characters")
205
+
206
+ # Warn about large content that might timeout
207
+ if total_content_size > 100000: # 100KB threshold
208
+ logger.warning(f"Large content size ({total_content_size} chars). Consider increasing timeout if you experience timeouts.")
209
+
165
210
  try:
166
211
  result = subprocess.run(
167
212
  cmd,
@@ -172,15 +217,25 @@ def execute_gemini_with_files(query: str, directory: str = ".", files: Optional[
172
217
  input=stdin_content
173
218
  )
174
219
 
220
+ logger.debug(f"Gemini CLI completed with return code: {result.returncode}")
221
+
175
222
  if result.returncode == 0:
176
- return result.stdout.strip() if result.stdout.strip() else "No output from Gemini CLI"
223
+ output = result.stdout.strip() if result.stdout.strip() else "No output from Gemini CLI"
224
+ logger.info(f"Gemini CLI successful, output length: {len(output)} characters")
225
+ return output
177
226
  else:
178
- return f"Gemini CLI Error: {result.stderr.strip()}"
227
+ error_msg = f"Gemini CLI Error: {result.stderr.strip()}"
228
+ logger.error(error_msg)
229
+ return error_msg
179
230
 
180
231
  except subprocess.TimeoutExpired:
181
- return f"Error: Gemini CLI command timed out after {timeout} seconds"
232
+ 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')})."
233
+ logger.error(timeout_msg)
234
+ return timeout_msg
182
235
  except Exception as e:
183
- return f"Error executing Gemini CLI: {str(e)}"
236
+ error_msg = f"Error executing Gemini CLI: {str(e)}"
237
+ logger.error(error_msg)
238
+ return error_msg
184
239
 
185
240
 
186
241
  @mcp.tool()
@@ -232,9 +287,120 @@ def consult_gemini_with_files(
232
287
  return execute_gemini_with_files(query, directory, files, model)
233
288
 
234
289
 
290
+ @mcp.tool()
291
+ def get_debug_info() -> str:
292
+ """
293
+ Get diagnostic information about the Gemini Bridge configuration.
294
+
295
+ Useful for troubleshooting timeout issues and verifying setup.
296
+
297
+ Returns:
298
+ Formatted debug information including timeout configuration,
299
+ environment variables, and system status
300
+ """
301
+ debug_info = []
302
+ debug_info.append("=== Gemini Bridge Debug Information ===\n")
303
+
304
+ # Timeout configuration
305
+ timeout_env = os.getenv("GEMINI_BRIDGE_TIMEOUT")
306
+ actual_timeout = _get_timeout()
307
+ debug_info.append("Timeout Configuration:")
308
+ debug_info.append(f" GEMINI_BRIDGE_TIMEOUT env var: {timeout_env or 'not set'}")
309
+ debug_info.append(f" Actual timeout used: {actual_timeout} seconds")
310
+
311
+ if actual_timeout == 60 and not timeout_env:
312
+ debug_info.append(" ⚠️ Using default timeout. Set GEMINI_BRIDGE_TIMEOUT=240 for large operations.")
313
+ elif actual_timeout < 120:
314
+ debug_info.append(" ⚠️ Timeout may be too low for large files or complex queries.")
315
+ elif actual_timeout > 300:
316
+ debug_info.append(f" ⚠️ Very high timeout configured. Failed operations will wait {actual_timeout}s.")
317
+ else:
318
+ debug_info.append(" ✓ Timeout looks reasonable for most operations.")
319
+
320
+ debug_info.append("")
321
+
322
+ # Gemini CLI status
323
+ gemini_path = shutil.which("gemini")
324
+ debug_info.append("Gemini CLI Status:")
325
+ debug_info.append(f" CLI available: {'✓ Yes' if gemini_path else '✗ No'}")
326
+ if gemini_path:
327
+ debug_info.append(f" CLI path: {gemini_path}")
328
+ try:
329
+ # Try to get version
330
+ result = subprocess.run(
331
+ ["gemini", "--version"],
332
+ capture_output=True,
333
+ text=True,
334
+ timeout=5
335
+ )
336
+ if result.returncode == 0:
337
+ version = result.stdout.strip()
338
+ debug_info.append(f" CLI version: {version}")
339
+ else:
340
+ debug_info.append(f" CLI version check failed: {result.stderr.strip()}")
341
+ except Exception as e:
342
+ debug_info.append(f" CLI version check error: {str(e)}")
343
+ else:
344
+ debug_info.append(" ✗ Install with: npm install -g @google/gemini-cli")
345
+
346
+ debug_info.append("")
347
+ # Environment details
348
+ debug_info.append("Environment:")
349
+ debug_info.append(f" Python version: {sys.version.split()[0]}")
350
+ debug_info.append(f" Current working directory: {os.getcwd()}")
351
+ debug_info.append(f" PORT: {os.getenv('PORT', '8080')}")
352
+
353
+ # Check authentication status
354
+ try:
355
+ result = subprocess.run(
356
+ ["gemini", "auth", "status"],
357
+ capture_output=True,
358
+ text=True,
359
+ timeout=10,
360
+ cwd="."
361
+ )
362
+ if result.returncode == 0:
363
+ debug_info.append(" Authentication: ✓ Logged in")
364
+ else:
365
+ debug_info.append(" Authentication: ✗ Not logged in - run 'gemini auth login'")
366
+ except Exception as e:
367
+ debug_info.append(f" Authentication status check failed: {str(e)}")
368
+
369
+ debug_info.append("")
370
+
371
+ # Recent environment variables that might affect operation
372
+ relevant_env_vars = [
373
+ "GEMINI_BRIDGE_TIMEOUT", "NODE_PATH", "PATH", "HOME",
374
+ "GOOGLE_APPLICATION_CREDENTIALS", "GOOGLE_CLOUD_PROJECT"
375
+ ]
376
+
377
+ debug_info.append("Relevant Environment Variables:")
378
+ for var in relevant_env_vars:
379
+ value = os.getenv(var)
380
+ if value:
381
+ # Truncate very long values
382
+ display_value = value[:100] + "..." if len(value) > 100 else value
383
+ debug_info.append(f" {var}: {display_value}")
384
+ else:
385
+ debug_info.append(f" {var}: not set")
386
+
387
+ debug_info.append("")
388
+ debug_info.append("=== End Debug Information ===")
389
+
390
+ return "\n".join(debug_info)
391
+
392
+
235
393
  def main():
236
394
  """Entry point for the MCP server."""
237
- mcp.run()
395
+ port = int(os.getenv("PORT", "8080"))
396
+ timeout = _get_timeout() # Log timeout configuration at startup
397
+
398
+ logger.info(f"Starting Gemini Bridge MCP Server on port {port}")
399
+ logger.info(f"Configured timeout: {timeout} seconds")
400
+ logger.info(f"Gemini CLI available: {shutil.which('gemini') is not None}")
401
+
402
+ # Run the MCP server with SSE transport (port is managed by the library)
403
+ mcp.run(transport="sse")
238
404
 
239
405
 
240
406
  if __name__ == "__main__":
@@ -1,9 +0,0 @@
1
- gemini_bridge-1.0.2.dist-info/licenses/LICENSE,sha256=yTz_R8ocWu64Eubxr6vdZCKRS0dB_Pi3RbjUNn4qPxQ,1063
2
- src/__init__.py,sha256=XwIQ60BQ748HOAFYiRvDP4HWUonSZfGNvNv6-YnuKgc,190
3
- src/__main__.py,sha256=12FoIYCXYYKu2_BYX1GS_h9E9qO41Q26B8zedRIDPBs,149
4
- src/mcp_server.py,sha256=vYykaYMSNtkwOB94VZPvnJ2fuBZkKgnqcoYL12ZM20k,7722
5
- gemini_bridge-1.0.2.dist-info/METADATA,sha256=UF7tWNaTxoCL6unvjkWKnjwp8cFzrz1X6k3dDfWKOu4,13798
6
- gemini_bridge-1.0.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
- gemini_bridge-1.0.2.dist-info/entry_points.txt,sha256=ygWf0B23Gygq8mW_GzPx8rxIA19RR_RH4RG2I15lU3E,43
8
- gemini_bridge-1.0.2.dist-info/top_level.txt,sha256=74rtVfumQlgAPzR5_2CgYN24MB0XARCg0t-gzk6gTrM,4
9
- gemini_bridge-1.0.2.dist-info/RECORD,,