Gemini AI MCP server

Provides a robust interface to Google's Gemini AI models with specialized tools for content generation, chat functionality, function calling, and file/cache management.
Back to servers
Setup instructions
Provider
Brian W. Smith
Release date
Apr 02, 2025
Language
TypeScript
Stats
32 stars

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.

Installation

To install and configure the MCP Gemini Server:

  1. Install Dependencies:

    npm install
    
  2. Build Project:

    npm run build
    
  3. 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
    
  4. 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": []
        }
      }
    }
    

Configuration

The server uses environment variables for configuration:

  • GOOGLE_GEMINI_API_KEY (Required): Your API key from Google AI Studio
  • MCP_SERVER_HOST, MCP_SERVER_PORT, MCP_CONNECTION_TOKEN: Required server settings
  • GOOGLE_GEMINI_MODEL: Optional default model name
  • ALLOWED_OUTPUT_PATHS: Comma-separated list of allowed output directories

Basic Usage

Here are examples of how to use the MCP Gemini Server:

Simple Content Generation

<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>

Content Generation with Parameters

<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>

Chat Sessions

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>

Image Generation

<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>

URL-Based Image Analysis

<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>

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 summary.",
      "urlContext": {
        "urls": ["https://www.youtube.com/watch?v=dQw4w9WgXcQ"]
      }
    }
  </arguments>
</use_mcp_tool>

Important Notes

  • This server does not support direct file uploads; use URL-based multimedia analysis instead
  • For image analysis, use publicly accessible image URLs
  • For video analysis, use publicly accessible YouTube videos
  • The Caching API is only compatible with Google AI Studio API keys
  • Always use absolute paths for the ALLOWED_OUTPUT_PATHS environment variable
  • Some tools support the thinkingConfig parameter to control model reasoning depth

How to install this MCP server

For Claude Code

To 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.

For Cursor

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.

Adding an MCP server to Cursor globally

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": []
        }
    }
}

Adding an MCP server to a project

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.

How to use the MCP server

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.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. 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

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later