Skip to main content

Gemma MCP Client

A Python package that combines Google's Gemma language model with MCP (Model Control Protocol) server integration, enabling powerful function calling capabilities across both local functions and remote MCP tools.

Features

  • Seamless integration with Google's Gemma language model
  • Support for both local Python functions and remote MCP tools
  • Automatic tool discovery and registration from MCP servers
  • Python-style function calling syntax
  • Proper resource management with async context managers
  • Support for multiple MCP servers
  • Easy testing through test server support

Installation

pip install gemma-mcp

Requirements

  • Python 3.10+
  • google-genai: Google Generative AI Python SDK
  • FastMCP MCP utilities

Usage

Basic Usage

from gemma_mcp import GemmaMCPClient

# a standard MCP configuration
mcp_config = {
    "mcpServers": {
        "weather": {
            "url": "https://weather-api.example.com/mcp"
        },
        "assistant": {
            "command": "python",
            "args": ["./assistant_server.py"]
        }
    }
}

# Initialize client with MCP support
async with GemmaMCPClient(mcp_config=mcp_config).managed() as client:
    # Chat with automatic function execution
    response = await client.chat(
        "What's the weather like in London?",
        execute_functions=True
    )
    print(response)

Adding Local Functions

You can add local functions in three ways:

  1. Using a callable:
async def my_function(param1: str, param2: int = 0):
    """Function description."""
    return {"result": param1 + str(param2)}

client.add_function(my_function)
  1. Using a dictionary:
function_def = {
    "name": "my_function",
    "description": "Function description",
    "parameters": {
        "type": "object",
        "properties": {
            "param1": {"type": "string"},
            "param2": {"type": "integer", "default": 0}
        },
        "required": ["param1"]
    }
}
client.add_function(function_def)
  1. Using a FunctionDefinition object:
from gemma_mcp import FunctionDefinition

function_def = FunctionDefinition(
    name="my_function",
    description="Function description",
    parameters={
        "type": "object",
        "properties": {
            "param1": {"type": "string"},
            "param2": {"type": "integer", "default": 0}
        },
        "required": ["param1"]
    },
    required=["param1"]
)
client.add_function(function_def)

MCP Server Configuration

The MCP configuration supports multiple server types:

  1. servers with SSE transport:
mcp_config = {
    "mcpServers": {
        "server_name": {
            "url": "https://server-url/mcp"
        }
    }
}
  1. servers with STDIO transport:
mcp_config = {
    "mcpServers": {
        "server_name": {
            "command": "python",
            "args": ["./server.py"]
        }
    }
}

Testing

The package includes support for testing with in-memory MCP servers:

from fastmcp import FastMCP
from gemma_mcp import GemmaMCPClient

# Create test server
mcp = FastMCP("Test Server")

# Initialize client with test server
client = GemmaMCPClient()
client.mcp_client.add_test_server(mcp)

# Use the client as normal
async with client.managed():
    response = await client.chat("Test message", execute_functions=True)

API Reference

GemmaMCPClient

The main client class that handles both Gemma model interactions and MCP tool integration.

Parameters

  • api_key (str, optional): Gemini API key. If not provided, will look for GEMINI_API_KEY env var
  • model (str): Model to use, defaults to "gemma-3-27b-it"
  • temperature (float): Generation temperature, defaults to 0.7
  • system_prompt (str, optional): Custom system prompt
  • mcp_config (dict, optional): MCP configuration dictionary

Methods

  • add_function(function): Add a function definition
  • chat(message, execute_functions=False): Send a message and get response
  • initialize(): Initialize the client and all components
  • cleanup(): Clean up all resources

FunctionDefinition

A dataclass for representing function definitions.

Parameters

  • name (str): Function name
  • description (str): Function description
  • parameters (dict): Function parameters schema
  • required (list): List of required parameters
  • callable (callable, optional): The actual callable function

License

MIT License

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Metadata

Release files for gemma-mcp 0.1.1

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

Source distribution (sdist)

Source distribution for gemma-mcp 0.1.1
File Size Uploaded
gemma_mcp-0.1.1.tar.gz 10.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gemma-mcp 0.1.1
File Interpreter ABI Platform
gemma_mcp-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 18.4 kB

Release files / gemma_mcp-0.1.1.tar.gz

Download URL gemma_mcp-0.1.1.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
53f7c260a65606afdbb6a9700766afe754a965be441430c99a33d23b27f4b09a
BLAKE2b-256 checksum
How to use checksums
fb16144a2583cc06ec9772b085cd426bf066821bfa6ddaed3560e7dcf21fda96
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.5

Release files / gemma_mcp-0.1.1-py3-none-any.whl

Download URL gemma_mcp-0.1.1-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
850e98bbce955848a956e19fab3117924a366be03ca540b7e1a143c3ef650a1e
BLAKE2b-256 checksum
How to use checksums
658b43d78531566140a3da2168cf1896d436f8df7cf4d703d5d292899c21937c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.5

Release history Release notifications | RSS feed

This release

0.1.1 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