Workshop: Gemini CLI with Model Context Protocol (MCP) and ML Certifications

GDG Roma

Workshop: Gemini CLI with Model Context Protocol (MCP) and ML CertificationsThis workshop offers a practical exploration...

Aug 21, 4:30 – 6:00 PM (UTC)

19 RSVP'd

Key Themes

Build with AICloudGemini

About this event

Workshop: Gemini CLI with Model Context Protocol (MCP) and ML Certifications

This workshop offers a practical exploration of the Gemini Command-Line Interface (CLI) and its integration with the Google Cloud Platform (GCP). The session is designed for professionals and enthusiasts seeking to leverage generative AI within their development workflows. The Model Context Protocol (MCP) is an open standard that enables AI models to interact with external tools and systems.

Participants will gain a foundational understanding of how to configure and operate this powerful, no-cost tool for seamless interaction with the Gemini API. The curriculum includes practical exercises on executing prompts, analyzing code, and automating routine development tasks, all from within a command-line environment.

This event is a pilot program, and we expect collaboration from participants to be instrumental in improving the workshop for future iterations. The content is structured to be functionally similar to other command-line AI tools, with a dedicated focus on the unique capabilities of the Gemini API.

Gemini Command-Line Interface

The Gemini Command-Line Interface (CLI) embeds the capabilities of Google's Gemini models directly within the terminal, thereby providing a deeply integrated artificial intelligence assistant.

How to use this Guide:

First read the summary (what we talked about yesterday) and then go deeper with these links: For further information, the official documentation (https://github.com/google-gemini/gemini-cli) and a hands-on lab are available for review: https://codelabs.developers.google.com/gemini-cli-hands-on

Installation and Prerequisites

A prerequisite for installation is a Node.js environment, version 20 or greater. The installation process is uncomplicated and is executed via the Node Package Manager (npm). To ensure you have the latest version of npm, you can run:

npm install -g npm

Install the Gemini CLI with the subsequent command:

npm install -g @google/gemini-cli

Authentication and Access

Upon first execution, the Gemini CLI provides an easy authentication method.

OAuth Authentication (Recommended for Individuals)

The primary method is to log in using a Google Account (OAuth). This option is particularly advantageous for individual developers as it provides access to a generous free tier, including substantial daily and per-minute request quotas with powerful models like Gemini 2.5 Pro. This method is also suitable for users who possess a Gemini Code Assist License. Due to the provided quota limits, this option is effectively free for a significant range of use cases.

Advanced Agent Capabilities

The Gemini CLI operates not as a simple chat interface, but as an interactive agent capable of reasoning and execution. It is equipped with a suite of built-in tools for file system operations, shell command execution, and web-based searches. This functionality enables the performance of complex, multi-step tasks directly within the context of a given project. The paradigm shifts from a simple query-response model to one where the artificial intelligence is assigned an objective and autonomously utilizes its available resources to accomplish it.

To inspect the available built-in functions, you can use the /tools command. This command lists all the capabilities the agent can decide to use, such as ReadFile, WriteFile, GoogleSearch, and Shell. This transparency allows you to understand the potential actions the agent might take to fulfill your requests. Learn more about built-in tools.

/tools

Extensibility through the Model Context Protocol (MCP)

A feature that you cannot use in Gemini WEB I is its implementation of the Model Context Protocol (MCP). MCP is an open standard that facilitates the connection of the CLI to external servers, thereby furnishing it with an array of powerful, customized tools. This can be conceptualized as an application programming interface (API) for the language model itself. By establishing a connection to an MCP server, the Gemini CLI can be augmented with new capabilities, such as interacting with specific databases, querying proprietary APIs, or accessing specialized knowledge repositories.

GitHub Example

A salient example of this extensibility is the integration with an MCP server such as Context7. Connecting the Gemini CLI to Context7 provides the model with access to current documentation and contextual information for a wide range of coding libraries and frameworks. Consequently, when tasked to prepare code for a specific function using this integration, the CLI leverages the MCP server to retrieve the most relevant and up-to-date information. This process yields more accurate and robust code generation that is cognizant of project-specific dependencies.

Example: Generating Postgres Code with Context7

Here is a practical example of generating a Python script to interact with a PostgreSQL database.

1. Configure the Context7 MCP Server

First, you must configure Gemini CLI to connect to the Context7 server. Open your settings file at ~/.gemini/settings.json and add the context7 server to the mcpServers object:

{
  "mcpServers": {
    "context7": {
      "httpUrl": "https://mcp.context7.com/mcp"
    }
  }
}

2. Provide a Prompt

Now, you can ask Gemini to generate the code. By including @context7, you instruct the agent to use the Context7 server to get the most up-to-date information about the necessary libraries (in this case, psycopg2 for Python).

Prompt: Using @context7, write a Python script that connects to a PostgreSQL database and creates a table named 'employees' with columns for id, name, and role. Also, add documentation explaining how the script works.

3. Review the Output

Gemini will use its WriteFile tool to create a Python script similar to the following, checking and using official documentation:

# db_setup.py
import psycopg2
import os

def create_employees_table():
    """
    Connects to the PostgreSQL database and creates the 'employees' table.

    This script uses database credentials stored in environment variables
    (DB_NAME, DB_USER, DB_PASSWORD, DB_HOST, DB_PORT) to establish a
    connection. It then executes a SQL command to create a new table
    named 'employees' if it does not already exist. The table includes
    an auto-incrementing primary key 'id', a 'name' field, and a 'role' field.
    The connection is properly closed after the operation.
    """
    conn = None
    try:
        # Connect to your postgres DB
        conn = psycopg2.connect(
            dbname=os.environ.get("DB_NAME"),
            user=os.environ.get("DB_USER"),
            password=os.environ.get("DB_PASSWORD"),
            host=os.environ.get("DB_HOST"),
            port=os.environ.get("DB_PORT")
        )
        cur = conn.cursor()

        # SQL command to create a table
        create_table_command = """
        CREATE TABLE IF NOT EXISTS employees (
            id SERIAL PRIMARY KEY,
            name VARCHAR(255) NOT NULL,
            role VARCHAR(255) NOT NULL
        );
        """
        
        cur.execute(create_table_command)
        conn.commit()
        print("Table 'employees' created successfully.")
        
        cur.close()
    except (Exception, psycopg2.DatabaseError) as error:
        print(error)
    finally:
        if conn is not None:
            conn.close()

if __name__ == '__main__':
    create_employees_table()

By leveraging Context7, the agent generates accurate, modern code with appropriate error handling and includes the requested documentation, demonstrating a clear understanding of the PostgreSQL library.

Learn more about Context, Memory, and Conversational Branching

Organizers

  • Antonella Blasetti

    GDG Organizer

  • Juna Salviati

    GDG Organizer

  • Maria Cilione

  • Arnaldo Morena

    dev talent partner

  • Nicola Marziale

    Cloud and Dev Expert

Contact Us