Skip to main content
Glama
README.md
# Gemini MCP Server

A streamlined Model Context Protocol (MCP) server that provides Gemini API documentation lookup and ready-to-use code snippets. This server is built using `FastMCP` and is designed to be easily hosted locally or on a remote VM (e.g., Oracle Cloud).

## Features

- **`search_library_docs`**: Retrieves official documentation URLs for various Gemini topics (e.g., caching, function calling, tokens).
- **`get_gemini_code_snippet`**: Provides copy-pasteable Python code snippets for common Gemini tasks (e.g., chat, file upload, list models).
- **Secure Authentication**: Uses a secret token to authenticate requests from your MCP client.

## Prerequisites

- Python 3.10 or higher
- `pip` or `uv` (recommended for faster dependency management)

## Installation

1.  **Clone the repository:**
    ```bash
    git clone https://github.com/SOBANEJAZ/Gemini-MCP-Server.git
    cd Gemini-MCP-Server
    ```

2.  **Install dependencies:**
    ```bash
    pip install -r requirements.txt
    ```

3.  **Configure Environment Variables:**
    Create a `.env` file in the root directory. You can copy the template below:
    ```bash
    cp .env.example .env  # If provided, otherwise create new
    nano .env
    ```

    **Example `.env` content:**
    ```env
    # Security token for the API header (Client -> Server)
    # REPLACE THIS with a strong, random string
    MCP_SECRET=my_super_secret_token_123

    # Server bind address and port
    HOST=0.0.0.0
    PORT=8000
    ```

## Running Locally

To start the server locally:

```bash
python server.py
```

You should see output indicating the server is running:
`Starting Gemini MCP Server on 0.0.0.0:8000...`

## Hosting on a VM (e.g., Oracle Cloud)

1.  **Deploy the code:**
    Clone the repo and install dependencies on your VM as described in the Installation section.

2.  **Firewall Configuration:**
    Ensure your VM's firewall allows ingress traffic on port `8000`.
    - **Oracle Cloud:** Go to your VCN > Security Lists > Ingress Rules. Add a rule for Source CIDR `0.0.0.0/0`, Protocol `TCP`, and Destination Port Range `8000`.
    - **Ubuntu Firewall (if enabled):**
        ```bash
        sudo ufw allow 8000/tcp
        ```

3.  **Run in Background:**
    Use `nohup` to keep the server running after you disconnect:
    ```bash
    nohup python server.py > server.log 2>&1 &
    ```
    *Or use a process manager like `supervisor` or `systemd` for production.*

## MCP Client Configuration (Claude Code/Cursor/Antigravity)

Add the server to your `mcp_config.json`. Choose the option that matches your setup.

### Option A: Local Connection
If the server is running on the *same machine* as your client.

```json
{
  "mcpServers": {
    "Gemini-MCP-Server": {
      "command": "python",
      "args": [
        "/absolute/path/to/gemini-mcp-server/server.py"
      ],
      "env": {
        "MCP_SECRET": "my_super_secret_token_123"
      }
    }
  }
}
```

### Option B: Remote Connection (SSE over HTTP)
If the server is on a VM or different machine. This uses the `mcp-remote` tool (install via `npm install -g mcp-remote` or use `npx`).

```json
{
  "mcpServers": {
    "Gemini-MCP-Server": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-remote",
        "http://<YOUR_VM_IP>:8000/sse",
        "--allow-http",
        "--insecure",
        "--header",
        "API: <YOUR_MCP_SECRET>"
      ]
    }
  }
}
```

### Option C: HTTPS / Smithery Connection
If you are hosting behind a platform that handles SSL termination (like **Smithery**, **Cloudflare**, or an **Nginx** reverse proxy), the `server.py` continues to run on HTTP while the platform handles HTTPS externally.

```json
{
  "mcpServers": {
    "Gemini-MCP-Server": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-remote",
        "https://<YOUR_SECURE_DOMAIN>/sse",
        "--header",
        "API: <YOUR_MCP_SECRET>"
      ]
    }
  }
}
```

**Note:** Replace `<YOUR_VM_IP>` or `<YOUR_SECURE_DOMAIN>` with your server's address, and `<YOUR_MCP_SECRET>` with the secret you set in your `.env` file.