Skip to main content

MCP Gemini Client

Credit to and started from- medium.com/@fruitful2007/building-an-mcp-client-101-lets-build-one-for-a-gemini-chat-agent

pypi.org/project/gemini-tool-agent

A (potentially, lol) powerful MCP (Model Context Protocol) client that uses Google's Gemini AI models for intelligent tool usage and conversation handling.

  • Tested working nicely with Claude Desktop as an MCP Server currently.

Based on untested AI gen code by a non-coder use at own risk.

Features

  • Multiple Gemini Models: Support for various Gemini models (2.0-flash, 2.5-pro, 1.5-pro, etc.)
  • Flexible Package Support: Works with gemini-tool-agent, google-generativeai, or google-genai packages
  • Runtime Model Switching: Change models during conversation
  • Server Configuration Management: Store and manage MCP server configurations
  • Intelligent Tool Usage: AI-powered tool discovery and execution
  • Async/await Support: Efficient concurrent operations
  • Comprehensive Error Handling: Robust error recovery and logging
  • Type Hints: Modern Python practices with full type safety

alt text

alt text

Using "adk web" from agents directory- alter the agent.py paths to your own for simple Gemini mcp use for now until I get a better setup. full_mcp_agent-README.md alt text

alt text

google agent framework report text

Installation

📋 Easy Installation Instructions Here's the correct way to set it up with Claude- maybe, You may need to install this if not working properly:

  • cd /gemini-mcp-client && uv add google-generativeai

Doesn't throw an error and works great for chat, not sure about Gemini MCP use. Just edit in your paths and use this config in Claude Desktop:

{
  "mcpServers": {
    "gemini-ai": {
      "command": "uv",
      "args": [
        "--directory",
        "/home/ty/Repositories/ai_workspace/gemini-mcp-client",
        "run",
        "python",
        "servers/gemini_mcp_server.py"
      ],
      "env": {
        "GEMINI_API_KEY": "your_gemini_api_key_here"
      }
    },
    "echo-server": {
      "command": "uv",
      "args": [
        "--directory",
        "/home/ty/Repositories/ai_workspace/gemini-mcp-client",
        "run",
        "python",
        "examples/echo_server.py"
      ]
    }
  }
}

alt text

Installation outside of Claude if someone wants to try it and maybe develop a Standalone UI for Gemini with MCP Tools!:

  • possibly hallucinatory

This project uses uv for dependency management. Make sure you have uv installed.

Setting up the environment

# Create and activate virtual environment
uv venv --python 3.12 --seed
source .venv/bin/activate


```bash
# Install base dependencies- this is wrong it seems.
# uv add .

# maybe
/gemini-mcp-client
uv sync
uv add mcp

# Install a Gemini package (choose one or more):
uv add gemini-tool-agent
# OR
uv add google-generativeai
# OR
uv add google-genai
# OR install all options
uv add all-gemini

Development setup

# Install with development dependencies
uv add --dev ".[dev]"

# Install pre-commit hooks
uv run pre-commit install

Configuration

Create a .env file in the project root:

GEMINI_API_KEY=your_gemini_api_key_here
LOG_LEVEL=INFO

Usage

Model Selection

The client supports multiple Gemini models- not sure if more can be added somehow:

  • gemini-2.0-flash - Fast, efficient model (default)
  • gemini-2.5-pro-preview-03-25 - Advanced model for complex tasks
  • gemini-2.5-flash-preview-04-17 - Balanced speed and capability
  • gemini-1.5-pro - Stable, reliable model
  • gemini-1.5-flash - Fast, lightweight model
  • gemini-1.5-flash-8b - Ultra-lightweight model

Command Line Usage

# Start chat with default model
mcp-gemini-client chat path/to/server.py

# Start chat with specific model
mcp-gemini-client chat server.py --model gemini-2.5-pro-preview-03-25

# Get server information
mcp-gemini-client info server.py

# List available models
mcp-gemini-client models

# Set logging level
mcp-gemini-client chat server.py --log-level DEBUG

Server Management

# List configured servers
mcp-gemini-client servers list

# Add new server interactively
mcp-gemini-client servers add

# Connect to configured server by name
mcp-gemini-client chat echo-server

# Enable/disable servers
mcp-gemini-client servers enable my-server
mcp-gemini-client servers disable my-server

# Export for Claude Desktop
mcp-gemini-client servers export claude_config.json

# Import from Claude Desktop config
mcp-gemini-client servers import existing_config.json

Configuration Management

# Show current configuration
mcp-gemini-client config show

# Set default model
mcp-gemini-client config set default_model gemini-2.5-pro-preview-03-25

# Set other settings
mcp-gemini-client config set log_level DEBUG
mcp-gemini-client config set connection_timeout 60.0

Programmatic Usage

import asyncio
from mcp_gemini_client import MCPClient

async def main():
    # Initialize with specific model
    client = MCPClient(model="gemini-2.5-pro-preview-03-25")

    try:
        # Connect to server
        await client.connect_to_server("examples/echo_server.py")

        # Get server information
        info = await client.get_server_info()
        print(f"Current model: {info['model']}")
        print(f"Available tools: {[tool['name'] for tool in info['tools']]}")

        # Change model during runtime
        client.set_model("gemini-2.0-flash")

        # Interactive conversation
        response = await client.get_response("What tools are available?")
        print(response)

        # Direct tool usage
        result = await client.call_tool_directly("echo", {"message": "Hello!"})
        print(result)

        # Start chat loop
        await client.chat_loop()

    finally:
        await client.close()

asyncio.run(main())

Runtime Model Switching

During an interactive chat session, you can change models:

💬 You: model gemini-2.5-pro-preview-03-25
✅ Model changed to: gemini-2.5-pro-preview-03-25

💬 You: What's the current model?
🤖 Assistant: I'm currently using gemini-2.5-pro-preview-03-25...

Server Configuration

Configuration Files

  • config/servers.json - MCP server configurations
  • config/client.json - Client settings (model, timeouts, etc.)

Example Server Configuration

{
  "my-database": {
    "name": "my-database",
    "description": "Project SQLite database",
    "server_type": "python",
    "command": "uv",
    "args": ["run", "mcp-server-sqlite", "--db-path", "data/project.db"],
    "env": {
      "DB_READONLY": "false"
    },
    "enabled": true,
    "tags": ["database", "sqlite"]
  }
}

Claude Desktop Integration

Export configurations directly for Claude Desktop:

mcp-gemini-client servers export

This creates a claude_desktop_config.json file:

{
  "mcpServers": {
    "my-database": {
      "command": "uv",
      "args": ["run", "mcp-server-sqlite", "--db-path", "data/project.db"],
      "env": {
        "DB_READONLY": "false"
      }
    }
  }
}

Quick Start

# Install and setup
uv add . --optional-dependencies google-generativeai
cp .env.example .env
# Edit .env and add your GEMINI_API_KEY

# List available models
mcp-gemini-client models

# Test with echo server
mcp-gemini-client chat examples/echo_server.py

# Add a server configuration
mcp-gemini-client servers add

# Use configured server
mcp-gemini-client chat my-server

# Export for Claude Desktop
mcp-gemini-client servers export

Examples

Chat with Echo Server

mcp-gemini-client chat examples/echo_server.py

Model Selection Example

# List available models
mcp-gemini-client models

# Use specific model
mcp-gemini-client chat server.py --model gemini-2.5-pro-preview-03-25

Server Configuration Example

from mcp_gemini_client.config import get_config_manager, ServerConfig, ServerType

config_manager = get_config_manager()

# Add a database server
db_server = ServerConfig(
    name="project-db",
    description="Project database server",
    server_type=ServerType.PYTHON,
    command="uv",
    args=["run", "mcp-server-sqlite", "--db-path", "data/project.db"],
    env={"DB_READONLY": "false"},
    tags=["database", "project"]
)

config_manager.add_server(db_server)

# Export for Claude Desktop
config_manager.export_claude_desktop_config("claude_config.json")

Architecture

The client is built with these key components:

  • MCPClient: Main client class handling server connections and conversations
  • GeminiAgent: Wrapper for different Gemini package implementations
  • ConfigManager: Server and client configuration management
  • Async Context Management: Proper resource cleanup and connection handling
  • Model Management: Runtime model selection and switching
  • Error Handling: Comprehensive error recovery and logging
  • Type Safety: Full type hints for better development experience

Development

Code Quality

# Format code
uv run ruff format .

# Check code
uv run ruff check .

# Type checking
uv run pyright

# Run tests
uv run pytest

Testing

# Run all tests
uv run pytest

# Run with coverage
uv run pytest --cov=mcp_gemini_client

# Run specific test
uv run pytest tests/test_client.py::test_model_selection

Documentation

  • Usage Guide: prompts/usage_guide.md
  • Server Configuration: prompts/server_configuration_guide.md
  • Troubleshooting: prompts/troubleshooting.md
  • Best Practices: prompts/best_practices.md

Contributing

  1. Follow the development guidelines in the codebase
  2. Ensure all tests pass
  3. Add type hints to all new code
  4. Write docstrings for public APIs
  5. Keep functions focused and small
  6. Test with multiple Gemini packages

License

MIT License - see LICENSE file for details.

Metadata

Release files for iflow-mcp_angrysky56-gemini-mcp-client 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for iflow-mcp_angrysky56-gemini-mcp-client 0.1.0
File Size Uploaded
iflow_mcp_angrysky56_gemini_mcp_client-0.1.0.tar.gz 19.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for iflow-mcp_angrysky56-gemini-mcp-client 0.1.0
File Interpreter ABI Platform
iflow_mcp_angrysky56_gemini_mcp_client-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 39.2 kB

Release files / iflow_mcp_angrysky56_gemini_mcp_client-0.1.0.tar.gz

Download URL iflow_mcp_angrysky56_gemini_mcp_client-0.1.0.tar.gz
Size 19.5 kB
Tags Source
SHA-256 checksum
How to use checksums
5316240b033dcc1ebd7b48921c3c1fa3c317fcc1e5d68c05fdb94a5dc2bb3975
BLAKE2b-256 checksum
How to use checksums
e17c56ca0d0459aec22de3dfe03ababd9416881ae52400c3186c0f4302669995
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.8

Release files / iflow_mcp_angrysky56_gemini_mcp_client-0.1.0-py3-none-any.whl

Download URL iflow_mcp_angrysky56_gemini_mcp_client-0.1.0-py3-none-any.whl
Size 19.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
59e25ce3661079f3ba21e2612b50770af2b5eba5c596103ab8eeb2be813f3a87
BLAKE2b-256 checksum
How to use checksums
18de6e1d5e536182364d4f416e7fb05de3c804eb062436be7891471ffc394b51
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.8

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page