Gemini MCP server

Wraps Google Gemini API with intelligent model fallback, enabling content generation, function calling, stateful chat, and file handling through a consistent tool-based interface.
Back to servers
Setup instructions
Provider
Novakiki
Release date
Apr 07, 2025
Language
TypeScript
Stats
1 star

This MCP Gemini Server provides a bridge between MCP-compatible systems and Google's Gemini models through a standardized tool-based interface. It allows other LLMs like Cline to leverage Gemini's capabilities as a backend workhorse.

Installation Options

Via Smithery

To automatically install Gemini Server for Claude Desktop:

npx -y @smithery/cli install @bsmi021/mcp-gemini-server --client claude

Manual Installation

  1. Install dependencies in the project directory:
npm install
  1. Build the TypeScript project:
npm run build
  1. Configure your MCP client by adding server configuration to its settings file. For Cline/VSCode or Claude Desktop App:
{
  "mcpServers": {
    "gemini-server": {
      "command": "node",
      "args": ["/path/to/mcp-gemini-server/dist/server.js"],
      "env": {
        "GOOGLE_GEMINI_API_KEY": "YOUR_API_KEY",
        "GOOGLE_GEMINI_MODEL": "gemini-1.5-flash"
      },
      "disabled": false,
      "autoApprove": []
    }
  }
}
  1. Restart your MCP client application to load the new server configuration.

Configuration

Configure the server using environment variables passed via the env object:

  • GOOGLE_GEMINI_API_KEY (Required): Your API key from Google AI Studio
  • GOOGLE_GEMINI_MODEL (Optional): Default Gemini model name (e.g., gemini-1.5-flash)

Available Tools

Core Generation

  • gemini_generateContent

    • Generates text content from a prompt
    • Required: prompt (string)
    • Optional: modelName, generationConfig, safetySettings
  • gemini_generateContentStream

    • Generates streaming text content
    • Required: prompt (string)
    • Optional: modelName, generationConfig, safetySettings

Function Calling

  • gemini_functionCall
    • Allows the model to request function execution
    • Required: prompt (string), functionDeclarations (array)
    • Optional: modelName, generationConfig, safetySettings, toolConfig

Stateful Chat

  • gemini_startChat

    • Initiates a new chat session
    • Optional: modelName, history, tools, generationConfig, safetySettings
  • gemini_sendMessage

    • Sends a message in an existing chat session
    • Required: sessionId (string), message (string)
    • Optional: generationConfig, safetySettings, tools, toolConfig
  • gemini_sendFunctionResult

    • Sends function execution results back to a chat session
    • Required: sessionId (string), functionResponses (array)
    • Optional: generationConfig, safetySettings

File Handling (Google AI Studio Key Required)

  • gemini_uploadFile

    • Uploads a file from a local path
    • Required: filePath (string - must be an absolute path)
    • Optional: displayName, mimeType
  • gemini_listFiles

    • Lists previously uploaded files
    • Optional: pageSize, pageToken
  • gemini_getFile

    • Retrieves metadata for a specific file
    • Required: fileName (string - e.g., files/abc123xyz)
  • gemini_deleteFile

    • Deletes an uploaded file
    • Required: fileName (string)

Caching (Google AI Studio Key Required)

  • gemini_createCache

    • Creates cached content for compatible models
    • Required: contents (array)
    • Optional: modelName, displayName, systemInstruction, ttl
  • gemini_listCaches

    • Lists existing cached content
    • Optional: pageSize, pageToken
  • gemini_getCache

    • Retrieves metadata for specific cached content
    • Required: cacheName (string)
  • gemini_updateCache

    • Updates metadata for cached content
    • Required: cacheName (string)
    • Optional: ttl, displayName
  • gemini_deleteCache

    • Deletes cached content
    • Required: cacheName (string)

Usage Examples

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

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

Chat Conversation

Starting a chat:

<use_mcp_tool>
  <server_name>gemini-server</server_name>
  <tool_name>gemini_startChat</tool_name>
  <arguments>
    {}
  </arguments>
</use_mcp_tool>

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

Uploading a File

<use_mcp_tool>
  <server_name>gemini-server</server_name>
  <tool_name>gemini_uploadFile</tool_name>
  <arguments>
    {
      "filePath": "C:\\Users\\YourUser\\Documents\\my_document.txt",
      "displayName": "My Document"
    }
  </arguments>
</use_mcp_tool>

Error Handling

The server returns structured errors using the MCP standard McpError type, containing:

  • code: Error type (e.g., InvalidParams, InternalError)
  • message: Human-readable description
  • details: Additional information from the Gemini SDK

Common error scenarios include:

  • Invalid API key
  • Missing or invalid parameters
  • Safety blocks
  • File/cache not found
  • Rate limits

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","GOOGLE_GEMINI_MODEL":"gemini-1.5-flash"},"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",
                "GOOGLE_GEMINI_MODEL": "gemini-1.5-flash"
            },
            "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",
                "GOOGLE_GEMINI_MODEL": "gemini-1.5-flash"
            },
            "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