This MCP Gemini Server provides a powerful interface to access Google's Gemini AI models through standard MCP tools. The server allows other LLMs like Claude or MCP-compatible systems to leverage Gemini's capabilities.
To install and configure the MCP Gemini Server:
Install Dependencies:
npm install
Build Project:
npm run build
Generate Connection Token: Create a strong, unique token using one of these methods:
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
Or:
openssl rand -hex 32
Configure MCP Client: Add the server configuration to your MCP client's settings file:
{
"mcpServers": {
"gemini-server": {
"command": "node",
"args": ["/path/to/mcp-gemini-server/dist/server.js"],
"env": {
"GOOGLE_GEMINI_API_KEY": "YOUR_API_KEY",
"MCP_SERVER_HOST": "localhost",
"MCP_SERVER_PORT": "8080",
"MCP_CONNECTION_TOKEN": "YOUR_GENERATED_CONNECTION_TOKEN",
"GOOGLE_GEMINI_MODEL": "gemini-1.5-flash",
"ALLOWED_OUTPUT_PATHS": "/var/opt/mcp-gemini-server/outputs,/tmp/mcp-gemini-outputs"
},
"disabled": false,
"autoApprove": []
}
}
}
The server uses environment variables for configuration:
GOOGLE_GEMINI_API_KEY (Required): Your API key from Google AI StudioMCP_SERVER_HOST, MCP_SERVER_PORT, MCP_CONNECTION_TOKEN: Required server settingsGOOGLE_GEMINI_MODEL: Optional default model nameALLOWED_OUTPUT_PATHS: Comma-separated list of allowed output directoriesHere are examples of how to use the MCP Gemini Server:
<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>
<use_mcp_tool>
<server_name>gemini-server</server_name>
<tool_name>gemini_generateContent</tool_name>
<arguments>
{
"modelName": "gemini-1.5-pro",
"prompt": "Explain the concept of recursion in programming.",
"generationConfig": {
"temperature": 0.7,
"maxOutputTokens": 500
}
}
</arguments>
</use_mcp_tool>
Start a chat:
<use_mcp_tool>
<server_name>gemini-server</server_name>
<tool_name>gemini_startChat</tool_name>
<arguments>
{}
</arguments>
</use_mcp_tool>
Send a message (using the returned sessionId):
<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>
<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",
"resolution": "1024x1024",
"numberOfImages": 1,
"negativePrompt": "dystopian, ruins, dark, gloomy"
}
</arguments>
</use_mcp_tool>
<use_mcp_tool>
<server_name>gemini-server</server_name>
<tool_name>gemini_generateContent</tool_name>
<arguments>
{
"prompt": "Please describe this image in detail.",
"urlContext": {
"urls": ["https://example.com/images/photo.jpg"]
}
}
</arguments>
</use_mcp_tool>
<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 summary.",
"urlContext": {
"urls": ["https://www.youtube.com/watch?v=dQw4w9WgXcQ"]
}
}
</arguments>
</use_mcp_tool>
ALLOWED_OUTPUT_PATHS environment variablethinkingConfig parameter to control model reasoning depthTo add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "gemini-server" '{"command":"node","args":["/path/to/mcp-gemini-server/dist/server.js"],"env":{"GOOGLE_GEMINI_API_KEY":"YOUR_API_KEY","MCP_SERVER_HOST":"localhost","MCP_SERVER_PORT":"8080","MCP_CONNECTION_TOKEN":"YOUR_GENERATED_CONNECTION_TOKEN","GOOGLE_GEMINI_MODEL":"gemini-1.5-flash","ALLOWED_OUTPUT_PATHS":"/var/opt/mcp-gemini-server/outputs,/tmp/mcp-gemini-outputs"},"disabled":false,"autoApprove":[]}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:
{
"mcpServers": {
"gemini-server": {
"command": "node",
"args": [
"/path/to/mcp-gemini-server/dist/server.js"
],
"env": {
"GOOGLE_GEMINI_API_KEY": "YOUR_API_KEY",
"MCP_SERVER_HOST": "localhost",
"MCP_SERVER_PORT": "8080",
"MCP_CONNECTION_TOKEN": "YOUR_GENERATED_CONNECTION_TOKEN",
"GOOGLE_GEMINI_MODEL": "gemini-1.5-flash",
"ALLOWED_OUTPUT_PATHS": "/var/opt/mcp-gemini-server/outputs,/tmp/mcp-gemini-outputs"
},
"disabled": false,
"autoApprove": []
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json%APPDATA%\Claude\claude_desktop_config.json~/.config/Claude/claude_desktop_config.json2. Add this to your configuration file:
{
"mcpServers": {
"gemini-server": {
"command": "node",
"args": [
"/path/to/mcp-gemini-server/dist/server.js"
],
"env": {
"GOOGLE_GEMINI_API_KEY": "YOUR_API_KEY",
"MCP_SERVER_HOST": "localhost",
"MCP_SERVER_PORT": "8080",
"MCP_CONNECTION_TOKEN": "YOUR_GENERATED_CONNECTION_TOKEN",
"GOOGLE_GEMINI_MODEL": "gemini-1.5-flash",
"ALLOWED_OUTPUT_PATHS": "/var/opt/mcp-gemini-server/outputs,/tmp/mcp-gemini-outputs"
},
"disabled": false,
"autoApprove": []
}
}
}
3. Restart Claude Desktop for the changes to take effect