How to build a Gemini CLI extension including MCP and slash commands

Опубликовано: 15 Апрель 2026
на канале: John Capobianco
852
22

👨‍💻 Build Your Own Gemini-CLI Extension from Scratch (Python MCP Tutorial)
Stop just using AI—start building with it! This video is a complete, step-by-step guide on how to create a fully functional, custom extension for the open-source Gemini CLI. We'll use a Subnet Calculator as our example, showing you how to wire a Python application into Gemini's powerful Model Context Protocol (MCP).

If you want to integrate a legacy tool, a custom script, or a specific API into your AI workflow, this is the tutorial for you!

🎬 What You'll Learn & See:
Project Setup (The Foundation):

Creating a dedicated Python venv and managing dependencies with requirements.txt.

Setting up the extension's file structure (including the commands/ directory).

The MCP Server (The Engine):

Writing the core FastMCP Python server using FastMCP and pydantic.

Defining the subnet_calculator function as a tool the AI can understand.

Custom Slash Commands (The User Interface):

Creating multiple .toml files for specialized slash commands (e.g., /subnet:calc, /subnet:hosts, /subnet:next).

Mapping user intent directly to tool execution for a fast, predictable CLI experience.

AI System Instructions (The Brain):

Writing the GEMINI.md file to define the AI's behavior, ensuring it knows when to use a slash command versus when to use the raw tool.

Testing and Deployment:

Running the extension locally and testing all custom commands within the Gemini CLI.

🔑 Key Concepts Covered:
Model Context Protocol (MCP): Understanding how to expose Python tools to the Gemini agent.

Structured Data with Pydantic: Using pydantic to define clear, typed input/output schemas for the AI.

Slash Command Design: Best practices for creating user-friendly, focused commands.

System Prompt Engineering: Using GEMINI.md to control the AI's reasoning and tool usage.

🔗 Resources & Code:
Final Extension Source Code: [Link to your extension's GitHub repository]

Gemini CLI Installation: [Link to the official Gemini CLI documentation]

Required Dependencies: fastmcp, pydantic, python-dotenv, ipaddress

#GeminiCLI #GeminiExtension #MCP #ModelContextProtocol #PythonTutorial #DevOps #Subnetting #AIinDevOps #CodeTutorial

Install and try it yourself:

gemini extensions install https://github.com/automateyournetwor...

Source code:
https://github.com/automateyournetwor...