LiamKhoaLe commited on
Commit
53093c0
·
1 Parent(s): 032cbb2

Upd mcp server configs

Browse files
Files changed (1) hide show
  1. app.py +26 -7
app.py CHANGED
@@ -200,12 +200,13 @@ global_mcp_session = None
200
  global_mcp_stdio_ctx = None # Store stdio context to keep it alive
201
  global_mcp_lock = threading.Lock() # Lock for thread-safe session access
202
  # MCP server configuration via environment variables
203
- # Gemini MCP server: mcp-server (PyPI package)
204
- # Install with: pip install mcp-server
205
- # Example: MCP_SERVER_COMMAND="python" MCP_SERVER_ARGS="-m mcp_server"
206
- # Or use npx for Node.js version: MCP_SERVER_COMMAND="npx" MCP_SERVER_ARGS="-y @modelcontextprotocol/server-gemini"
207
- MCP_SERVER_COMMAND = os.environ.get("MCP_SERVER_COMMAND", "python")
208
- MCP_SERVER_ARGS = os.environ.get("MCP_SERVER_ARGS", "-m mcp_server").split() if os.environ.get("MCP_SERVER_ARGS") else ["-m", "mcp_server"]
 
209
 
210
  async def get_mcp_session():
211
  """Get or create MCP client session with proper context management"""
@@ -238,10 +239,28 @@ async def get_mcp_session():
238
 
239
  # Create new session using correct MCP SDK pattern
240
  try:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241
  logger.info(f"Creating MCP client session with command: {MCP_SERVER_COMMAND} {MCP_SERVER_ARGS}")
242
  server_params = StdioServerParameters(
243
  command=MCP_SERVER_COMMAND,
244
- args=MCP_SERVER_ARGS
 
245
  )
246
 
247
  # Correct MCP SDK usage: stdio_client is an async context manager
 
200
  global_mcp_stdio_ctx = None # Store stdio context to keep it alive
201
  global_mcp_lock = threading.Lock() # Lock for thread-safe session access
202
  # MCP server configuration via environment variables
203
+ # Gemini MCP server: Use Node.js version via npx (recommended)
204
+ # No installation needed - npx will download automatically
205
+ # Example: MCP_SERVER_COMMAND="npx" MCP_SERVER_ARGS="-y @modelcontextprotocol/server-gemini"
206
+ # Or use Python version if available: MCP_SERVER_COMMAND="python" MCP_SERVER_ARGS="-m mcp_server_gemini"
207
+ # Make sure GEMINI_API_KEY is set in environment variables
208
+ MCP_SERVER_COMMAND = os.environ.get("MCP_SERVER_COMMAND", "npx")
209
+ MCP_SERVER_ARGS = os.environ.get("MCP_SERVER_ARGS", "-y @modelcontextprotocol/server-gemini").split() if os.environ.get("MCP_SERVER_ARGS") else ["-y", "@modelcontextprotocol/server-gemini"]
210
 
211
  async def get_mcp_session():
212
  """Get or create MCP client session with proper context management"""
 
239
 
240
  # Create new session using correct MCP SDK pattern
241
  try:
242
+ # Prepare environment variables for MCP server
243
+ mcp_env = os.environ.copy()
244
+ if GEMINI_API_KEY:
245
+ mcp_env["GEMINI_API_KEY"] = GEMINI_API_KEY
246
+ else:
247
+ logger.warning("GEMINI_API_KEY not set in environment. Gemini MCP features may not work.")
248
+
249
+ # Add other Gemini MCP configuration if set
250
+ if os.environ.get("GEMINI_MODEL"):
251
+ mcp_env["GEMINI_MODEL"] = os.environ.get("GEMINI_MODEL")
252
+ if os.environ.get("GEMINI_TIMEOUT"):
253
+ mcp_env["GEMINI_TIMEOUT"] = os.environ.get("GEMINI_TIMEOUT")
254
+ if os.environ.get("GEMINI_MAX_OUTPUT_TOKENS"):
255
+ mcp_env["GEMINI_MAX_OUTPUT_TOKENS"] = os.environ.get("GEMINI_MAX_OUTPUT_TOKENS")
256
+ if os.environ.get("GEMINI_TEMPERATURE"):
257
+ mcp_env["GEMINI_TEMPERATURE"] = os.environ.get("GEMINI_TEMPERATURE")
258
+
259
  logger.info(f"Creating MCP client session with command: {MCP_SERVER_COMMAND} {MCP_SERVER_ARGS}")
260
  server_params = StdioServerParameters(
261
  command=MCP_SERVER_COMMAND,
262
+ args=MCP_SERVER_ARGS,
263
+ env=mcp_env
264
  )
265
 
266
  # Correct MCP SDK usage: stdio_client is an async context manager