Gemini Integration
STDIODedicated MCP server wrapping Google's Gemini SDK for model capabilities integration.
Dedicated MCP server wrapping Google's Gemini SDK for model capabilities integration.
This project provides a dedicated MCP (Model Context Protocol) server that wraps the @google/genai
SDK (v0.10.0). It exposes Google's Gemini model capabilities as standard MCP tools, allowing other LLMs (like Claude) or MCP-compatible systems to leverage Gemini's features as a backend workhorse.
This server aims to simplify integration with Gemini models by providing a consistent, tool-based interface managed via the MCP standard. It supports the latest Gemini models including gemini-1.5-pro-latest
, gemini-1.5-flash
, and gemini-2.5-pro
models.
Important Note: This server does not support direct file uploads. Instead, it focuses on URL-based multimedia analysis for images and videos. For text-based content processing, use the standard content generation tools.
This MCP Gemini Server does not support the following file upload operations:
Why File Uploads Are Not Supported:
This server fully supports analyzing multimedia content from publicly accessible URLs:
Image Analysis from URLs:
YouTube Video Analysis:
Web Content Processing:
If you have local files to analyze:
For audio content:
gemini_generateContent
) and streaming (gemini_generateContentStream
) text generation with support for system instructions and cached content.gemini_functionCall
).gemini_startChat
, gemini_sendMessage
, gemini_sendFunctionResult
) with support for system instructions, tools, and cached content.gemini_generateImage
) with control over resolution, number of images, and negative prompts. Also supports the latest Imagen 3.1 model for high-quality dedicated image generation with advanced style controls. Note that Gemini 2.5 models (Flash and Pro) do not currently support image generation.gemini_generateContent
: Enhanced with URL context support for including web content in promptsgemini_generateContentStream
: Streaming generation with URL context integrationgemini_url_analysis
: Specialized tool for advanced URL content analysis with multiple analysis typesmcpConnectToServer
: Establishes a connection to an external MCP server.mcpListServerTools
: Lists available tools on a connected MCP server.mcpCallServerTool
: Calls a function on a connected MCP server, with an option for file output.mcpDisconnectFromServer
: Disconnects from an external MCP server.writeToFile
: Writes content directly to files within allowed directories.Clone/Place Project: Ensure the mcp-gemini-server
project directory is accessible on your system.
Install Dependencies: Navigate to the project directory in your terminal and run:
npm install
Build Project: Compile the TypeScript source code:
npm run build
This command uses the TypeScript compiler (tsc
) and outputs the JavaScript files to the ./dist
directory (as specified by outDir
in tsconfig.json
). The main server entry point will be dist/server.js
.
Generate Connection Token: Create a strong, unique connection token for secure communication between your MCP client and the server. This is a shared secret that you generate and configure on both the server and client sides.
Generate a secure token using one of these methods:
Option A: Using Node.js crypto (Recommended)
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
Option B: Using OpenSSL
openssl rand -hex 32
Option C: Using PowerShell (Windows)
[System.Convert]::ToBase64String([System.Security.Cryptography.RandomNumberGenerator]::GetBytes(32))
Option D: Online Generator (Use with caution) Use a reputable password generator like 1Password or Bitwarden to generate a 64-character random string.
Important Security Notes:
Configure MCP Client: Add the server configuration to your MCP client's settings file (e.g., cline_mcp_settings.json
for Cline/VSCode, or claude_desktop_config.json
for Claude Desktop App). Replace /path/to/mcp-gemini-server
with the actual absolute path on your system, YOUR_API_KEY
with your Google AI Studio key, and YOUR_GENERATED_CONNECTION_TOKEN
with the token you generated in step 4.
{ "mcpServers": { "gemini-server": { // Or your preferred name "command": "node", "args": ["/path/to/mcp-gemini-server/dist/server.js"], // Absolute path to the compiled server entry point "env": { "GOOGLE_GEMINI_API_KEY": "YOUR_API_KEY", "MCP_SERVER_HOST": "localhost", // Required: Server host "MCP_SERVER_PORT": "8080", // Required: Server port "MCP_CONNECTION_TOKEN": "YOUR_GENERATED_CONNECTION_TOKEN", // Required: Use the token from step 4 "GOOGLE_GEMINI_MODEL": "gemini-1.5-flash", // Optional: Set a default model // Optional security configurations removed - file operations no longer supported "ALLOWED_OUTPUT_PATHS": "/var/opt/mcp-gemini-server/outputs,/tmp/mcp-gemini-outputs" // Optional: Comma-separated list of allowed output directories for mcpCallServerTool and writeToFileTool }, "disabled": false, "autoApprove": [] } // ... other servers } }
Important Notes:
args
must be the absolute path to the compiled dist/server.js
fileMCP_SERVER_HOST
, MCP_SERVER_PORT
, and MCP_CONNECTION_TOKEN
are required unless NODE_ENV
is set to test
MCP_CONNECTION_TOKEN
must be the exact same value you generated in step 4npm run build
Restart MCP Client: Restart your MCP client application (e.g., VS Code with Cline extension, Claude Desktop App) to load the new server configuration. The MCP client will manage starting and stopping the server process.
The server uses environment variables for configuration, passed via the env
object in the MCP settings:
GOOGLE_GEMINI_API_KEY
(Required): Your API key obtained from Google AI Studio.GOOGLE_GEMINI_MODEL
(Optional): Specifies a default Gemini model name (e.g., gemini-1.5-flash
, gemini-1.0-pro
). If set, tools that require a model name (like gemini_generateContent
, gemini_startChat
, etc.) will use this default when the modelName
parameter is omitted in the tool call. This simplifies client calls when primarily using one model. If this environment variable is not set, the modelName
parameter becomes required for those tools. See the Google AI documentation for available model names.ALLOWED_OUTPUT_PATHS
(Optional): A comma-separated list of absolute paths to directories where the mcpCallServerTool
(with outputToFile
parameter) and writeToFileTool
are allowed to write files. If not set, file output will be disabled for these tools. This is a security measure to prevent arbitrary file writes.This server provides the following MCP tools. Parameter schemas are defined using Zod for validation and description.
Validation and Error Handling: All parameters are validated using Zod schemas at both the MCP tool level and service layer, providing consistent validation, detailed error messages, and type safety. The server implements comprehensive error mapping to provide clear, actionable error messages.
Retry Logic: API requests automatically use exponential backoff retry for transient errors (network issues, rate limits, timeouts), improving reliability for unstable connections. The retry mechanism includes configurable parameters for maximum attempts, delay times, and jitter to prevent thundering herd effects.
Note on Optional Parameters: Many tools accept complex optional parameters (e.g., generationConfig
, safetySettings
, toolConfig
, history
, functionDeclarations
, contents
). These parameters are typically objects or arrays whose structure mirrors the types defined in the underlying @google/genai
SDK (v0.10.0). For the exact structure and available fields within these complex parameters, please refer to:
1. The corresponding src/tools/*Params.ts
file in this project.
2. The official Google AI JS SDK Documentation.
gemini_generateContent
prompt
(string)modelName
(string) - Name of the model to usegenerationConfig
(object) - Controls generation parameters like temperature, topP, etc.
thinkingConfig
(object) - Controls model reasoning process
thinkingBudget
(number) - Maximum tokens for reasoning (0-24576)reasoningEffort
(string) - Simplified control: "none" (0 tokens), "low" (1K), "medium" (8K), "high" (24K)safetySettings
(array) - Controls content filtering by harm categorysystemInstruction
(string or object) - System instruction to guide model behaviorcachedContentName
(string) - Identifier for cached content to use with this requesturlContext
(object) - Fetch and include web content from URLs
urls
(array) - URLs to fetch and include as context (max 20)fetchOptions
(object) - Configuration for URL fetching
maxContentKb
(number) - Maximum content size per URL in KB (default: 100)timeoutMs
(number) - Fetch timeout per URL in milliseconds (default: 10000)includeMetadata
(boolean) - Include URL metadata in context (default: true)convertToMarkdown
(boolean) - Convert HTML to markdown (default: true)allowedDomains
(array) - Specific domains to allow for this requestuserAgent
(string) - Custom User-Agent header for URL requestsmodelPreferences
(object) - Model selection preferencesgemini_generateContentStream
prompt
(string)modelName
(string) - Name of the model to usegenerationConfig
(object) - Controls generation parameters like temperature, topP, etc.
thinkingConfig
(object) - Controls model reasoning process
thinkingBudget
(number) - Maximum tokens for reasoning (0-24576)reasoningEffort
(string) - Simplified control: "none" (0 tokens), "low" (1K), "medium" (8K), "high" (24K)safetySettings
(array) - Controls content filtering by harm categorysystemInstruction
(string or object) - System instruction to guide model behaviorcachedContentName
(string) - Identifier for cached content to use with this requesturlContext
(object) - Same URL context options as gemini_generateContent
modelPreferences
(object) - Model selection preferencesgemini_functionCall
prompt
(string), functionDeclarations
(array)modelName
(string) - Name of the model to usegenerationConfig
(object) - Controls generation parameterssafetySettings
(array) - Controls content filteringtoolConfig
(object) - Configures tool behavior like temperature and confidence thresholdsgemini_startChat
sessionId
.modelName
(string) - Name of the model to usehistory
(array) - Initial conversation historytools
(array) - Tool definitions including function declarationsgenerationConfig
(object) - Controls generation parameters
thinkingConfig
(object) - Controls model reasoning process
thinkingBudget
(number) - Maximum tokens for reasoning (0-24576)reasoningEffort
(string) - Simplified control: "none" (0 tokens), "low" (1K), "medium" (8K), "high" (24K)safetySettings
(array) - Controls content filteringsystemInstruction
(string or object) - System instruction to guide model behaviorcachedContentName
(string) - Identifier for cached content to use with this sessiongemini_sendMessage
sessionId
(string), message
(string)generationConfig
(object) - Controls generation parameters
thinkingConfig
(object) - Controls model reasoning process
thinkingBudget
(number) - Maximum tokens for reasoning (0-24576)reasoningEffort
(string) - Simplified control: "none" (0 tokens), "low" (1K), "medium" (8K), "high" (24K)safetySettings
(array) - Controls content filteringtools
(array) - Tool definitions including function declarationstoolConfig
(object) - Configures tool behaviorcachedContentName
(string) - Identifier for cached content to use with this messagegemini_sendFunctionResult
sessionId
(string), functionResponse
(string) - The result of the function executionfunctionCall
(object) - Reference to the original function callgemini_routeMessage
message
(string) - The text message to be routed to the most appropriate modelmodels
(array) - Array of model names to consider for routing (e.g., ['gemini-1.5-flash', 'gemini-1.5-pro']). The first model in the list will be used for routing decisions.routingPrompt
(string) - Custom prompt to use for routing decisions. If not provided, a default routing prompt will be used.defaultModel
(string) - Model to fall back to if routing fails. If not provided and routing fails, an error will be thrown.generationConfig
(object) - Generation configuration settings to apply to the selected model's response.
thinkingConfig
(object) - Controls model reasoning process
thinkingBudget
(number) - Maximum tokens for reasoning (0-24576)reasoningEffort
(string) - Simplified control: "none" (0 tokens), "low" (1K), "medium" (8K), "high" (24K)safetySettings
(array) - Safety settings to apply to both routing and final response.systemInstruction
(string or object) - A system instruction to guide the model's behavior after routing.Note: Direct file upload operations are no longer supported by this server. The server now focuses exclusively on URL-based multimedia analysis for images and videos, and text-based content generation.
Alternative Approaches:
gemini_generateContent
or gemini_url_analysis
toolsgemini_createCache
gemini-1.5-flash
).contents
(array), model
(string)displayName
(string) - Human-readable name for the cached contentsystemInstruction
(string or object) - System instruction to apply to the cached contentttl
(string - e.g., '3600s') - Time-to-live for the cached contenttools
(array) - Tool definitions for use with the cached contenttoolConfig
(object) - Configuration for the toolsgemini_listCaches
pageSize
(number), pageToken
(string - Note: pageToken
may not be reliably returned currently).gemini_getCache
cacheName
(string - e.g., cachedContents/abc123xyz
)gemini_updateCache
cacheName
(string), contents
(array)displayName
(string) - Updated display namesystemInstruction
(string or object) - Updated system instructionttl
(string) - Updated time-to-livetools
(array) - Updated tool definitionstoolConfig
(object) - Updated tool configurationgemini_deleteCache
cacheName
(string - e.g., cachedContents/abc123xyz
)gemini_generateImage
prompt
(string - descriptive text prompt for image generation)modelName
(string - defaults to "imagen-3.1-generate-003" for high-quality dedicated image generation or use "gemini-2.0-flash-exp-image-generation" for Gemini models)resolution
(string enum: "512x512", "1024x1024", "1536x1536")numberOfImages
(number - 1-8, default: 1)safetySettings
(array) - Controls content filtering for generated imagesnegativePrompt
(string - features to avoid in the generated image)stylePreset
(string enum: "photographic", "digital-art", "cinematic", "anime", "3d-render", "oil-painting", "watercolor", "pixel-art", "sketch", "comic-book", "neon", "fantasy")seed
(number - integer value for reproducible generation)styleStrength
(number - strength of style preset, 0.0-1.0)Note: Audio transcription via direct file uploads is no longer supported by this server. The server focuses on URL-based multimedia analysis for images and videos.
Alternative Approaches for Audio Content:
gemini_url_analysis
urls
(array) - URLs to analyze (1-20 URLs supported)analysisType
(string enum) - Type of analysis to perform:
summary
- Comprehensive content summarizationcomparison
- Multi-URL content comparisonextraction
- Structured information extractionqa
- Question-based content analysissentiment
- Emotional tone analysisfact-check
- Credibility assessmentcontent-classification
- Topic and type categorizationreadability
- Accessibility and complexity analysisseo-analysis
- Search optimization evaluationquery
(string) - Specific query or instruction for the analysisextractionSchema
(object) - JSON schema for structured data extractionquestions
(array) - List of specific questions to answer (for Q&A analysis)compareBy
(array) - Specific aspects to compare when using comparison analysisoutputFormat
(string enum: "text", "json", "markdown", "structured") - Desired output formatincludeMetadata
(boolean) - Include URL metadata in the analysis (default: true)fetchOptions
(object) - Advanced URL fetching options (same as urlContext fetchOptions)modelName
(string) - Specific Gemini model to use (auto-selected if not specified)mcpConnectToServer
serverId
(string): A unique identifier for this server connection.connectionType
(string enum: "sse" | "stdio"): The transport protocol to use.sseUrl
(string, optional if connectionType
is "stdio"): The URL for SSE connection.stdioCommand
(string, optional if connectionType
is "sse"): The command to run for stdio connection.stdioArgs
(array of strings, optional): Arguments for the stdio command.stdioEnv
(object, optional): Environment variables for the stdio command.connectionId
that must be used in subsequent calls to mcpListServerTools
, mcpCallServerTool
, and mcpDisconnectFromServer
. This connectionId
is generated internally and is different from the serverId
parameter.mcpListServerTools
connectionId
(string): The connection identifier returned by mcpConnectToServer
.mcpCallServerTool
connectionId
(string): The connection identifier returned by mcpConnectToServer
.toolName
(string): The name of the tool to call on the remote server.toolArgs
(object): The arguments to pass to the remote tool.outputToFile
(string): If provided, the tool's output will be written to this file path. The path must be within one of the directories specified in the ALLOWED_OUTPUT_PATHS
environment variable.mcpDisconnectFromServer
connectionId
(string): The connection identifier returned by mcpConnectToServer
.writeToFile
filePath
(string): The absolute path of the file to write to. Must be within one of the directories specified in the ALLOWED_OUTPUT_PATHS
environment variable.content
(string): The content to write to the file.overwrite
(boolean, default: false): If true, overwrite the file if it already exists. Otherwise, an error will be thrown if the file exists.Here are examples of how an MCP client (like Claude) might call these tools using the use_mcp_tool
format:
Example 1: Simple Content Generation (Using Default Model)
<use_mcp_tool> <server_name>gemini-server</server_name> <tool_name>gemini_generateContent</tool_name> <arguments> { "prompt": "Write a short poem about a rubber duck." } </arguments> </use_mcp_tool>
Example 2: Content Generation (Specifying Model & Config)
<use_mcp_tool> <server_name>gemini-server</server_name> <tool_name>gemini_generateContent</tool_name> <arguments> { "modelName": "gemini-1.0-pro", "prompt": "Explain the concept of recursion in programming.", "generationConfig": { "temperature": 0.7, "maxOutputTokens": 500 } } </arguments> </use_mcp_tool>
Example 2b: Content Generation with Thinking Budget Control
<use_mcp_tool> <server_name>gemini-server</server_name> <tool_name>gemini_generateContent</tool_name> <arguments> { "modelName": "gemini-1.5-pro", "prompt": "Solve this complex math problem: Find all values of x where 2sin(x) = x^2-x+1 in the range [0, 2π].", "generationConfig": { "temperature": 0.2, "maxOutputTokens": 1000, "thinkingConfig": { "thinkingBudget": 8192 } } } </arguments> </use_mcp_tool>
Example 2c: Content Generation with Simplified Reasoning Effort
<use_mcp_tool> <server_name>gemini-server</server_name> <tool_name>gemini_generateContent</tool_name> <arguments> { "modelName": "gemini-1.5-pro", "prompt": "Solve this complex math problem: Find all values of x where 2sin(x) = x^2-x+1 in the range [0, 2π].", "generationConfig": { "temperature": 0.2, "maxOutputTokens": 1000, "thinkingConfig": { "reasoningEffort": "high" } } } </arguments> </use_mcp_tool>
Example 3: Starting and Continuing a Chat
Start Chat:
<use_mcp_tool> <server_name>gemini-server</server_name> <tool_name>gemini_startChat</tool_name> <arguments> {} </arguments> </use_mcp_tool>
(Assume response contains sessionId: "some-uuid-123"
)
Send Message:
<use_mcp_tool> <server_name>gemini-server</server_name> <tool_name>gemini_sendMessage</tool_name> <arguments> { "sessionId": "some-uuid-123", "message": "Hello! Can you tell me about the Gemini API?" } </arguments> </use_mcp_tool>
Example 4: Content Generation with System Instructions (Simplified Format)
<use_mcp_tool> <server_name>gemini-server</server_name> <tool_name>gemini_generateContent</tool_name> <arguments> { "modelName": "gemini-2.5-pro-exp", "prompt": "What should I do with my day off?", "systemInstruction": "You are a helpful assistant that provides friendly and detailed advice. You should focus on outdoor activities and wellness." } </arguments> </use_mcp_tool>
Example 5: Content Generation with System Instructions (Object Format)
<use_mcp_tool> <server_name>gemini-server</server_name> <tool_name>gemini_generateContent</tool_name> <arguments> { "modelName": "gemini-1.5-pro-latest", "prompt": "What should I do with my day off?", "systemInstruction": { "parts": [ { "text": "You are a helpful assistant that provides friendly and detailed advice. You should focus on outdoor activities and wellness." } ] } } </arguments> </use_mcp_tool>
Example 6: Using Cached Content with System Instruction
<use_mcp_tool> <server_name>gemini-server</server_name> <tool_name>gemini_generateContent</tool_name> <arguments> { "modelName": "gemini-2.5-pro-exp", "prompt": "Explain how these concepts relate to my product?", "cachedContentName": "cachedContents/abc123xyz", "systemInstruction": "You are a product expert who explains technical concepts in simple terms." } </arguments> </use_mcp_tool>
Example 6: Generating an Image
<use_mcp_tool> <server_name>gemini-server</server_name> <tool_name>gemini_generateImage</tool_name> <arguments> { "prompt": "A futuristic cityscape with flying cars and neon lights", "modelName": "gemini-2.0-flash-exp-image-generation", "resolution": "1024x1024", "numberOfImages": 1, "negativePrompt": "dystopian, ruins, dark, gloomy" } </arguments> </use_mcp_tool>
Example 6b: Generating a High-Quality Image with Imagen 3.1
<use_mcp_tool> <server_name>gemini-server</server_name> <tool_name>gemini_generateImage</tool_name> <arguments> { "prompt": "A futuristic cityscape with flying cars and neon lights", "modelName": "imagen-3.1-generate-003", "resolution": "1024x1024", "numberOfImages": 4, "negativePrompt": "dystopian, ruins, dark, gloomy" } </arguments> </use_mcp_tool>
Example 6c: Using Advanced Style Options
<use_mcp_tool> <server_name>gemini-server</server_name> <tool_name>gemini_generateImage</tool_name> <arguments> { "prompt": "A futuristic cityscape with flying cars and neon lights", "modelName": "imagen-3.1-generate-003", "resolution": "1024x1024", "numberOfImages": 2, "stylePreset": "anime", "styleStrength": 0.8, "seed": 12345 } </arguments> </use_mcp_tool>
Example 7: Message Routing Between Models
<use_mcp_tool> <server_name>gemini-server</server_name> <tool_name>gemini_routeMessage</tool_name> <arguments> { "message": "Can you create a detailed business plan for a sustainable fashion startup?", "models": ["gemini-1.5-pro", "gemini-1.5-flash", "gemini-2.5-pro"], "routingPrompt": "Analyze this message and determine which model would be best suited to handle it. Consider: gemini-1.5-flash for simpler tasks, gemini-1.5-pro for balanced capabilities, and gemini-2.5-pro for complex creative tasks.", "defaultModel": "gemini-1.5-pro", "generationConfig": { "temperature": 0.7, "maxOutputTokens": 1024 } } </arguments> </use_mcp_tool>
The response will be a JSON string containing both the text response and which model was chosen:
{ "text": "# Business Plan for Sustainable Fashion Startup\n\n## Executive Summary\n...", "chosenModel": "gemini-2.5-pro" }
Example 8: Using URL Context with Content Generation
<use_mcp_tool> <server_name>gemini-server</server_name> <tool_name>gemini_generateContent</tool_name> <arguments> { "prompt": "Summarize the main points from these articles and compare their approaches to sustainable technology", "urlContext": { "urls": [ "https://example.com/sustainable-tech-2024", "https://techblog.com/green-innovation" ], "fetchOptions": { "maxContentKb": 150, "includeMetadata": true, "convertToMarkdown": true } }, "modelPreferences": { "preferQuality": true, "taskType": "reasoning" } } </arguments> </use_mcp_tool>
Example 9: Advanced URL Analysis
<use_mcp_tool> <server_name>gemini-server</server_name> <tool_name>gemini_url_analysis</tool_name> <arguments> { "urls": ["https://company.com/about", "https://company.com/products"], "analysisType": "extraction", "extractionSchema": { "companyName": "string", "foundedYear": "number", "numberOfEmployees": "string", "mainProducts": "array", "headquarters": "string", "financialInfo": "object" }, "outputFormat": "json", "query": "Extract comprehensive company information including business details and product offerings" } </arguments> </use_mcp_tool>
Example 10: Multi-URL Content Comparison
<use_mcp_tool> <server_name>gemini-server</server_name> <tool_name>gemini_url_analysis</tool_name> <arguments> { "urls": [ "https://site1.com/pricing", "https://site2.com/pricing", "https://site3.com/pricing" ], "analysisType": "comparison", "compareBy": ["pricing models", "features", "target audience", "value proposition"], "outputFormat": "markdown", "includeMetadata": true } </arguments> </use_mcp_tool>
Example 11: URL Content with Security Restrictions
<use_mcp_tool> <server_name>gemini-server</server_name> <tool_name>gemini_generateContent</tool_name> <arguments> { "prompt": "Analyze the content from these trusted news sources", "urlContext": { "urls": [ "https://reuters.com/article/tech-news", "https://bbc.com/news/technology" ], "fetchOptions": { "allowedDomains": ["reuters.com", "bbc.com"], "maxContentKb": 200, "timeoutMs": 15000, "userAgent": "Research-Bot/1.0" } } } </arguments> </use_mcp_tool>
These examples demonstrate how to analyze images from public URLs using Gemini's native image understanding capabilities. The server processes images by fetching them from URLs and converting them to the format required by the Gemini API. Note that this server does not support direct file uploads - all image analysis must be performed using publicly accessible image URLs.
Example 17: Basic Image Description and Analysis
<use_mcp_tool> <server_name>gemini-server</server_name> <tool_name>gemini_generateContent</tool_name> <arguments> { "prompt": "Please describe this image in detail, including objects, people, colors, setting, and any text you can see.", "urlContext": { "urls": ["https://example.com/images/photo.jpg"], "fetchOptions": { "includeMetadata": true, "timeoutMs": 15000 } } } </arguments> </use_mcp_tool>
Example 18: Object Detection and Identification
<use_mcp_tool> <server_name>gemini-server</server_name> <tool_name>gemini_generateContent</tool_name> <arguments> { "prompt": "Identify and list all objects visible in this image. For each object, describe its location, size relative to other objects, and any notable characteristics.", "urlContext": { "urls": ["https://example.com/images/scene.png"], "fetchOptions": { "includeMetadata": false, "timeoutMs": 20000 } } } </arguments> </use_mcp_tool>
Example 19: Chart and Data Visualization Analysis
<use_mcp_tool> <server_name>gemini-server</server_name> <tool_name>gemini_generateContent</tool_name> <arguments> { "prompt": "Analyze this chart or graph. What type of visualization is it? What are the main data points, trends, and insights? Extract any numerical values, labels, and time periods shown.", "urlContext": { "urls": ["https://example.com/charts/sales-data.png"] }, "modelPreferences": { "preferQuality": true, "taskType": "reasoning" } } </arguments> </use_mcp_tool>
Example 20: Comparative Image Analysis
<use_mcp_tool> <server_name>gemini-server</server_name> <tool_name>gemini_generateContent</tool_name> <arguments> { "prompt": "Compare these two images side by side. Describe the differences and similarities in terms of objects, composition, colors, style, and any other notable aspects.", "urlContext": { "urls": [ "https://example.com/before-renovation.jpg", "https://example.com/after-renovation.jpg" ], "fetchOptions": { "maxContentKb": 200, "includeMetadata": true } } } </arguments> </use_mcp_tool>
Example 21: Text Extraction from Images (OCR)
<use_mcp_tool> <server_name>gemini-server</server_name> <tool_name>gemini_generateContent</tool_name> <arguments> { "prompt": "Extract all text visible in this image. Include any signs, labels, captions, or written content. Maintain the original formatting and structure as much as possible.", "urlContext": { "urls": ["https://example.com/documents/screenshot.png"] } } </arguments> </use_mcp_tool>
Example 22: Technical Diagram or Flowchart Analysis
<use_mcp_tool> <server_name>gemini-server</server_name> <tool_name>gemini_generateContent</tool_name> <arguments> { "prompt": "Analyze this technical diagram, flowchart, or schematic. Explain the system architecture, identify components, describe the relationships and data flow, and interpret any symbols or notations used.", "urlContext": { "urls": ["https://docs.example.com/architecture-diagram.png"], "fetchOptions": { "maxContentKb": 100, "includeMetadata": true } }, "modelPreferences": { "preferQuality": true, "taskType": "reasoning" } } </arguments> </use_mcp_tool>
Example 23: Image Analysis with Specific Questions
<use_mcp_tool> <server_name>gemini-server</server_name> <tool_name>gemini_generateContent</tool_name> <arguments> { "prompt": "Looking at this image, please answer these specific questions: 1) What is the main subject? 2) What colors dominate the scene? 3) Are there any people visible? 4) What appears to be the setting or location? 5) What mood or atmosphere does the image convey?", "urlContext": { "urls": ["https://example.com/images/landscape.jpg"] } } </arguments> </use_mcp_tool>
Example 24: Image Analysis with Security Restrictions
<use_mcp_tool> <server_name>gemini-server</server_name> <tool_name>gemini_generateContent</tool_name> <arguments> { "prompt": "Analyze the composition and design elements in this image, focusing on visual hierarchy, layout principles, and aesthetic choices.", "urlContext": { "urls": ["https://trusted-cdn.example.com/design-mockup.jpg"], "fetchOptions": { "allowedDomains": ["trusted-cdn.example.com", "assets.example.com"], "maxContentKb": 150, "timeoutMs": 25000, "includeMetadata": false } } } </arguments> </use_mcp_tool>
Important Notes for URL-Based Image Analysis:
These examples demonstrate how to analyze YouTube videos using Gemini's video understanding capabilities. The server can process publicly accessible YouTube videos by providing their URLs. Note that only public YouTube videos are supported - private, unlisted, or region-restricted videos cannot be analyzed.
Example 25: Basic YouTube Video Analysis
<use_mcp_tool> <server_name>gemini-server</server_name> <tool_name>gemini_generateContent</tool_name> <arguments> { "prompt": "Please analyze this YouTube video and provide a comprehensive summary including the main topics discussed, key points, and overall theme.", "urlContext": { "urls": ["https://www.youtube.com/watch?v=dQw4w9WgXcQ"], "fetchOptions": { "includeMetadata": true, "timeoutMs": 30000 } } } </arguments> </use_mcp_tool>
Example 26: YouTube Video Content Extraction with Timestamps
<use_mcp_tool> <server_name>gemini-server</server_name> <tool_name>gemini_generateContent</tool_name> <arguments> { "prompt": "Analyze this educational YouTube video and create a detailed outline with key topics and approximate timestamps. Identify the main learning objectives and key concepts covered.", "urlContext": { "urls": ["https://www.youtube.com/watch?v=EXAMPLE_VIDEO_ID"], "fetchOptions": { "maxContentKb": 300, "includeMetadata": true, "timeoutMs": 45000 } }, "modelPreferences": { "preferQuality": true, "taskType": "reasoning" } } </arguments> </use_mcp_tool>
Example 27: YouTube Video Analysis with Specific Questions
<use_mcp_tool> <server_name>gemini-server</server_name> <tool_name>gemini_generateContent</tool_name> <arguments> { "prompt": "Watch this YouTube video and answer these specific questions: 1) What is the main message or thesis? 2) Who is the target audience? 3) What evidence or examples are provided? 4) What are the key takeaways? 5) How is the content structured?", "urlContext": { "urls": ["https://www.youtube.com/watch?v=EXAMPLE_VIDEO_ID"] } } </arguments> </use_mcp_tool>
Example 28: Comparative Analysis of Multiple YouTube Videos
<use_mcp_tool> <server_name>gemini-server</server_name> <tool_name>gemini_generateContent</tool_name> <arguments> { "prompt": "Compare and contrast these YouTube videos. Analyze their different approaches to the topic, presentation styles, key arguments, and conclusions. Identify similarities and differences in their perspectives.", "urlContext": { "urls": [ "https://www.youtube.com/watch?v=VIDEO_ID_1", "https://www.youtube.com/watch?v=VIDEO_ID_2" ], "fetchOptions": { "maxContentKb": 400, "includeMetadata": true, "timeoutMs": 60000 } }, "modelPreferences": { "preferQuality": true, "taskType": "reasoning" } } </arguments> </use_mcp_tool>
Example 29: YouTube Video Technical Analysis
<use_mcp_tool> <server_name>gemini-server</server_name> <tool_name>gemini_generateContent</tool_name> <arguments> { "prompt": "Analyze this technical YouTube tutorial and extract step-by-step instructions, identify required tools or materials, note any code examples or commands shown, and highlight important warnings or best practices mentioned.", "urlContext": { "urls": ["https://www.youtube.com/watch?v=TECH_TUTORIAL_ID"], "fetchOptions": { "includeMetadata": true, "timeoutMs": 40000 } } } </arguments> </use_mcp_tool>
Example 30: YouTube Video Sentiment and Style Analysis
<use_mcp_tool> <server_name>gemini-server</server_name> <tool_name>gemini_url_analysis</tool_name> <arguments> { "urls": ["https://www.youtube.com/watch?v=EXAMPLE_VIDEO_ID"], "analysisType": "sentiment", "outputFormat": "structured", "query": "Analyze the tone, mood, and presentation style of this YouTube video. Assess the speaker's credibility, engagement level, and overall effectiveness of communication." } </arguments> </use_mcp_tool>
Example 31: YouTube Video Educational Content Assessment
<use_mcp_tool> <server_name>gemini-server</server_name> <tool_name>gemini_generateContent</tool_name> <arguments> { "prompt": "Evaluate this educational YouTube video for accuracy, clarity, and pedagogical effectiveness. Identify the teaching methods used, assess how well complex concepts are explained, and suggest improvements if any.", "urlContext": { "urls": ["https://www.youtube.com/watch?v=EDUCATIONAL_VIDEO_ID"], "fetchOptions": { "maxContentKb": 250, "includeMetadata": true } }, "modelPreferences": { "preferQuality": true, "taskType": "reasoning" } } </arguments> </use_mcp_tool>
Example 32: YouTube Video with Domain Security Restrictions
<use_mcp_tool> <server_name>gemini-server</server_name> <tool_name>gemini_generateContent</tool_name> <arguments> { "prompt": "Analyze the content and key messages of this YouTube video, focusing on factual accuracy and source credibility.", "urlContext": { "urls": ["https://www.youtube.com/watch?v=TRUSTED_VIDEO_ID"], "fetchOptions": { "allowedDomains": ["youtube.com", "www.youtube.com"], "maxContentKb": 200, "timeoutMs": 35000, "includeMetadata": true } } } </arguments> </use_mcp_tool>
Important Notes for YouTube Video Analysis:
includeMetadata: true
The MCP Gemini Server supports comprehensive multimedia analysis through URL-based processing, leveraging Google Gemini's advanced vision and video understanding capabilities. Below are the key use cases organized by content type:
Content Understanding:
Comparative Analysis:
Security & Quality:
Educational Content:
Content Creation:
Technical Analysis:
Business Intelligence:
Multi-Modal Analysis:
Workflow Integration:
Security & Performance:
Example 12: Connecting to an External MCP Server (SSE)
<use_mcp_tool> <server_name>gemini-server</server_name> <tool_name>mcpConnectToServer</tool_name> <arguments> { "serverId": "my-external-server", "connectionType": "sse", "sseUrl": "http://localhost:8080/mcp" } </arguments> </use_mcp_tool>
(Assume response contains a unique connection ID like: connectionId: "12345-abcde-67890"
)
Example 13: Calling a Tool on an External MCP Server and Writing Output to File
<use_mcp_tool> <server_name>gemini-server</server_name> <tool_name>mcpCallServerTool</tool_name> <arguments> { "connectionId": "12345-abcde-67890", // Use the connectionId returned by mcpConnectToServer "toolName": "remote_tool_name", "toolArgs": { "param1": "value1" }, "outputToFile": "/var/opt/mcp-gemini-server/outputs/result.json" } </arguments> </use_mcp_tool>
Important: The connectionId
used in MCP client tools must be the connection identifier returned by mcpConnectToServer
, not the original serverId
parameter.
Note: The outputToFile
path must be within one of the directories specified in the ALLOWED_OUTPUT_PATHS
environment variable. For example, if ALLOWED_OUTPUT_PATHS="/path/to/allowed/output,/another/allowed/path"
, then the file path must be a subdirectory of one of these paths.
Example 14: Writing Content Directly to a File
<use_mcp_tool> <server_name>gemini-server</server_name> <tool_name>writeToFile</tool_name> <arguments> { "filePath": "/path/to/allowed/output/my_notes.txt", "content": "This is some important content.", "overwrite": true } </arguments> </use_mcp_tool>
Note: Like with mcpCallServerTool
, the filePath
must be within one of the directories specified in the ALLOWED_OUTPUT_PATHS
environment variable. This is a critical security feature to prevent unauthorized file writes.
mcp-gemini-server
and Gemini SDK's MCP Function CallingThe official Google Gemini API documentation includes examples (such as for function calling with MCP structure) that demonstrate how you can use the client-side Gemini SDK (e.g., in Python or Node.js) to interact with the Gemini API. In such scenarios, particularly for function calling, the client SDK itself can be used to structure requests and handle responses in a manner that aligns with MCP principles.
The mcp-gemini-server
project offers a complementary approach by providing a fully implemented, standalone MCP server. Instead of your client application directly using the Gemini SDK to format MCP-style messages for the Gemini API, your client application (which could be another LLM like Claude, a custom script, or any MCP-compatible system) would:
mcp-gemini-server
.gemini_functionCall
, gemini_generateContent
, etc.This mcp-gemini-server
then internally handles all the necessary interactions with the Google Gemini API, including structuring the requests, managing API keys, and processing responses, abstracting these details away from your MCP client.
mcp-gemini-server
:mcp-gemini-server
.mcp-gemini-server
:
The mcp-gemini-server
also includes tools like mcpConnectToServer
, mcpListServerTools
, and mcpCallServerTool
. These tools allow this server to act as an MCP client to other external MCP servers. This is a distinct capability from how an MCP client would connect to mcp-gemini-server
to utilize Gemini features.
GOOGLE_GEMINI_API_KEY
: Your Google Gemini API key (required)MCP_SERVER_HOST
: Server host address (e.g., "localhost")MCP_SERVER_PORT
: Port for network transports (e.g., "8080")MCP_CONNECTION_TOKEN
: A strong, unique shared secret token that clients must provide when connecting to this server. This is NOT provided by Google or any external service - you must generate it yourself using a cryptographically secure method. See the installation instructions (step 4) for generation methods. This token must be identical on both the server and all connecting clients.GOOGLE_GEMINI_MODEL
: Default model to use (e.g., gemini-1.5-pro-latest
, gemini-1.5-flash
)GOOGLE_GEMINI_DEFAULT_THINKING_BUDGET
: Default thinking budget in tokens (0-24576) for controlling model reasoningGOOGLE_GEMINI_ENABLE_URL_CONTEXT
: Enable URL context features (options: true
, false
; default: false
)GOOGLE_GEMINI_URL_MAX_COUNT
: Maximum URLs per request (default: 20
)GOOGLE_GEMINI_URL_MAX_CONTENT_KB
: Maximum content size per URL in KB (default: 100
)GOOGLE_GEMINI_URL_FETCH_TIMEOUT_MS
: Fetch timeout per URL in milliseconds (default: 10000
)GOOGLE_GEMINI_URL_ALLOWED_DOMAINS
: Comma-separated list or JSON array of allowed domains (default: *
for all domains)GOOGLE_GEMINI_URL_BLOCKLIST
: Comma-separated list or JSON array of blocked domains (default: empty)GOOGLE_GEMINI_URL_CONVERT_TO_MARKDOWN
: Convert HTML content to markdown (options: true
, false
; default: true
)GOOGLE_GEMINI_URL_INCLUDE_METADATA
: Include URL metadata in context (options: true
, false
; default: true
)GOOGLE_GEMINI_URL_ENABLE_CACHING
: Enable URL content caching (options: true
, false
; default: true
)GOOGLE_GEMINI_URL_USER_AGENT
: Custom User-Agent header for URL requests (default: MCP-Gemini-Server/1.0
)ALLOWED_OUTPUT_PATHS
: A comma-separated list of absolute paths to directories where tools like mcpCallServerTool
(with outputToFile parameter) and writeToFileTool
are allowed to write files. Critical security feature to prevent unauthorized file writes. If not set, file output will be disabled for these tools.MCP_CLIENT_ID
: Default client ID used when this server acts as a client to other MCP servers (defaults to "gemini-sdk-client")MCP_TRANSPORT
: Transport to use for MCP server (options: stdio
, sse
, streamable
, http
; default: stdio
)
MCP_LOG_LEVEL
: Log level for MCP operations (options: debug
, info
, warn
, error
; default: info
)MCP_ENABLE_STREAMING
: Enable SSE streaming for HTTP transport (options: true
, false
; default: false
)MCP_SESSION_TIMEOUT
: Session timeout in seconds for HTTP transport (default: 3600
= 1 hour)SESSION_STORE_TYPE
: Session storage backend (memory
or sqlite
; default: memory
)SQLITE_DB_PATH
: Path to SQLite database file when using sqlite store (default: ./data/sessions.db
)GITHUB_API_TOKEN
: Personal Access Token for GitHub API access (required for GitHub code review features). For public repos, token needs 'public_repo' and 'read:user' scopes. For private repos, token needs 'repo' scope.MCP_TRANSPORT_TYPE
: Deprecated - Use MCP_TRANSPORT
insteadMCP_WS_PORT
: Deprecated - Use MCP_SERVER_PORT
insteadENABLE_HEALTH_CHECK
: Enable health check server (options: true
, false
; default: true
)HEALTH_CHECK_PORT
: Port for health check HTTP server (default: 3000
)You can create a .env
file in the root directory with these variables:
# Required API Configuration GOOGLE_GEMINI_API_KEY=your_api_key_here # Required for Production (unless NODE_ENV=test) MCP_SERVER_HOST=localhost MCP_SERVER_PORT=8080 MCP_CONNECTION_TOKEN=your_secure_token_here # Optional API Configuration GOOGLE_GEMINI_MODEL=gemini-1.5-pro-latest GOOGLE_GEMINI_DEFAULT_THINKING_BUDGET=4096 # Security Configuration ALLOWED_OUTPUT_PATHS=/var/opt/mcp-gemini-server/outputs,/tmp/mcp-gemini-outputs # For mcpCallServerTool and writeToFileTool # URL Context Configuration GOOGLE_GEMINI_ENABLE_URL_CONTEXT=true # Enable URL context features GOOGLE_GEMINI_URL_MAX_COUNT=20 # Maximum URLs per request GOOGLE_GEMINI_URL_MAX_CONTENT_KB=100 # Maximum content size per URL in KB GOOGLE_GEMINI_URL_FETCH_TIMEOUT_MS=10000 # Fetch timeout per URL in milliseconds GOOGLE_GEMINI_URL_ALLOWED_DOMAINS=* # Allowed domains (* for all, or comma-separated list) GOOGLE_GEMINI_URL_BLOCKLIST=malicious.com,spam.net # Blocked domains (comma-separated) GOOGLE_GEMINI_URL_CONVERT_TO_MARKDOWN=true # Convert HTML to markdown GOOGLE_GEMINI_URL_INCLUDE_METADATA=true # Include URL metadata in context GOOGLE_GEMINI_URL_ENABLE_CACHING=true # Enable URL content caching GOOGLE_GEMINI_URL_USER_AGENT=MCP-Gemini-Server/1.0 # Custom User-Agent # Server Configuration MCP_CLIENT_ID=gemini-sdk-client # Optional: Default client ID for MCP connections (defaults to "gemini-sdk-client") MCP_TRANSPORT=stdio # Options: stdio, sse, streamable, http (replaced deprecated MCP_TRANSPORT_TYPE) MCP_LOG_LEVEL=info # Optional: Log level for MCP operations (debug, info, warn, error) MCP_ENABLE_STREAMING=true # Enable SSE streaming for HTTP transport MCP_SESSION_TIMEOUT=3600 # Session timeout in seconds for HTTP transport SESSION_STORE_TYPE=memory # Options: memory, sqlite SQLITE_DB_PATH=./data/sessions.db # Path to SQLite database file when using sqlite store ENABLE_HEALTH_CHECK=true HEALTH_CHECK_PORT=3000 # GitHub Integration GITHUB_API_TOKEN=your_github_token_here
This server implements several security measures to protect against common vulnerabilities. Understanding these security features is critical when deploying in production environments.
Path Validation and Isolation
Path Traversal Protection
FileSecurityService
implements robust path traversal protection by:
Symlink Security
Connection Tokens
MCP_CONNECTION_TOKEN
provides basic authentication for clients connecting to this serverAPI Key Security
GOOGLE_GEMINI_API_KEY
grants access to Google Gemini API servicesMulti-Layer URL Validation
Rate Limiting and Resource Protection
Content Security
Transport Options
Port Configuration
File Paths
ALLOWED_OUTPUT_PATHS
Process Isolation
Secrets Management
URL Context Security
GOOGLE_GEMINI_ENABLE_URL_CONTEXT=false
if not requiredGOOGLE_GEMINI_URL_ALLOWED_DOMAINS=*
in productionGOOGLE_GEMINI_URL_BLOCKLIST
GOOGLE_GEMINI_URL_MAX_CONTENT_KB
and GOOGLE_GEMINI_URL_MAX_COUNT
The server provides enhanced error handling using the MCP standard McpError
type when tool execution fails. This object contains:
code
: An ErrorCode
enum value indicating the type of error:
InvalidParams
: Parameter validation errors (wrong type, missing required field, etc.)InvalidRequest
: General request errors, including safety blocks and not found resourcesPermissionDenied
: Authentication or authorization failuresResourceExhausted
: Rate limits, quotas, or resource capacity issuesFailedPrecondition
: Operations that require conditions that aren't metInternalError
: Unexpected server or API errorsmessage
: A human-readable description of the error with specific details.details
: (Optional) An object with more specific information from the Gemini SDK error.The server uses a multi-layered approach to error handling:
GeminiValidationError
: Parameter validation failuresGeminiAuthError
: Authentication issuesGeminiQuotaError
: Rate limiting and quota exhaustionGeminiContentFilterError
: Content safety filteringGeminiNetworkError
: Connection and timeout issuesGeminiModelError
: Model-specific problemsCommon Error Scenarios:
PermissionDenied
- Invalid API key, expired credentials, or unauthorized access.InvalidParams
- Missing required fields, wrong data types, invalid values.InvalidRequest
- Content blocked by safety filters with details indicating SAFETY
as the block reason.InvalidRequest
- Resource not found, with details about the missing resource.ResourceExhausted
- API quota exceeded or rate limits hit, with details about limits.FailedPrecondition
- When attempting File API operations without a valid Google AI Studio key.InvalidParams
- Attempts to access audio files outside the allowed directory with details about the security validation failure.InvalidParams
- For format issues, size limitations, or invalid inputsInternalError
- For processing failures during analysisResourceExhausted
- For resource-intensive operations exceeding limitsThe server includes additional context in error messages to help with troubleshooting, including session IDs for chat-related errors and specific validation details for parameter errors.
Check the message
and details
fields of the returned McpError
for specific troubleshooting information.
This server includes a comprehensive test suite to ensure functionality and compatibility with the Gemini API. The tests are organized into unit tests (for individual components) and integration tests (for end-to-end functionality).
tests/unit/
- Test individual components in isolation with mocked dependenciestests/integration/
- Test end-to-end functionality with real server interactiontests/utils/
- Helper functions and fixtures for testing# Install dependencies first npm install # Run all tests npm run test # Run only unit tests npm run test:unit # Run only integration tests npm run test:integration # Run a specific test file node --test --loader ts-node/esm tests/path/to/test-file.test.ts
Service Mocking: The tests use a combination of direct method replacement and mock interfaces to simulate the Gemini API response. This is particularly important for the @google/genai
SDK (v0.10.0) which has a complex object structure.
Environmental Variables: Tests automatically check for required environment variables and will skip tests that require API keys if they're not available. This allows core functionality to be tested without credentials.
Test Server: Integration tests use a test server fixture that creates an isolated HTTP server instance with the MCP handler configured for testing.
RetryService: The retry mechanism is extensively tested to ensure proper handling of transient errors with exponential backoff, jitter, and configurable retry parameters.
Image Generation: Tests specifically address the complex interactions with the Gemini API for image generation, supporting both Gemini models and the dedicated Imagen 3.1 model.
For running tests that require API access, create a .env.test
file in the project root with the following variables:
# Required for basic API tests GOOGLE_GEMINI_API_KEY=your_api_key_here # Required for router tests GOOGLE_GEMINI_MODEL=gemini-1.5-flash
The test suite will automatically detect available environment variables and skip tests that require missing configuration.
We welcome contributions to improve the MCP Gemini Server! This section provides guidelines for contributing to the project.
Fork and Clone the Repository
git clone https://github.com/yourusername/mcp-gemini-server.git cd mcp-gemini-server
Install Dependencies
npm install
Set Up Environment Variables
Create a .env
file in the project root with the necessary variables as described in the Environment Variables section.
Build and Run
npm run build npm run dev
Create a Feature Branch
git checkout -b feature/your-feature-name
Make Your Changes Implement your feature or fix, following the code style guidelines.
Write Tests Add tests for your changes to ensure functionality and prevent regressions.
Run Tests and Linting
npm run test npm run lint npm run format
Commit Your Changes Use clear, descriptive commit messages that explain the purpose of your changes.
Update Documentation Update the README.md and other documentation to reflect your changes.
Submit a Pull Request
Code Review
The MCP Gemini Server provides powerful code review capabilities leveraging Gemini's models to analyze git diffs and GitHub repositories. These tools help identify potential issues, suggest improvements, and provide comprehensive feedback on code changes.
Review local git changes directly from your command line:
# Using the included CLI script ./scripts/gemini-review.sh # Options ./scripts/gemini-review.sh --focus=security --reasoning=high
The CLI script supports various options:
--focus=FOCUS
: Focus of the review (security, performance, architecture, bugs, general)--model=MODEL
: Model to use (defaults to gemini-flash-2.0 for cost efficiency)--reasoning=LEVEL
: Reasoning effort (none, low, medium, high)--exclude=PATTERN
: Files to exclude using glob patternsReview GitHub repositories, branches, and pull requests using the following tools:
By default, code review tools use the more cost-efficient gemini-flash-2.0
model, which offers a good balance between cost and capability for most code review tasks. For particularly complex code bases or when higher reasoning depth is needed, you can specify more powerful models:
# Using a more powerful model for complex code ./scripts/gemini-review.sh --model=gemini-1.5-pro --reasoning=high
Tests for the GitHub code review functionality can also use the cheaper model:
# Run tests with the default gemini-flash-2.0 model npm run test:unit
The server provides a built-in health check HTTP endpoint that can be used for monitoring and status checks. This is separate from the MCP server transport and runs as a lightweight HTTP server.
When enabled, you can access the health check at:
http://localhost:3000/health
The health check endpoint returns a JSON response with the following information:
{ "status": "running", "uptime": 1234, // Seconds since the server started "transport": "StdioServerTransport", // Current transport type "version": "0.1.0" // Server version }
You can check the health endpoint using curl:
curl http://localhost:3000/health
You can configure the health check using these environment variables:
ENABLE_HEALTH_CHECK
: Set to "false" to disable the health check server (default: "true")HEALTH_CHECK_PORT
: Port number for the health check server (default: 3000)The server supports persistent session storage for HTTP/SSE transports, allowing sessions to survive server restarts and enabling horizontal scaling.
In-Memory Store (Default)
SQLite Store
Enable SQLite session persistence:
export SESSION_STORE_TYPE=sqlite export SQLITE_DB_PATH=./data/sessions.db # Optional, this is the default
The SQLite database file and directory will be created automatically on first use. The database includes:
The server implements graceful shutdown handling for SIGTERM and SIGINT signals. When the server receives a shutdown signal:
This ensures clean termination when the server is run in containerized environments or when stopped manually.
gemini_listCaches
may not reliably return nextPageToken
due to limitations in iterating the SDK's Pager object. A workaround is implemented but has limited reliability.GOOGLE_GEMINI_ENABLE_URL_CONTEXT=true