Skip to content
OVEX TECH
Education & E-Learning

Extend Gemini CLI with MCP Servers and Extensions

Extend Gemini CLI with MCP Servers and Extensions

Extend Gemini CLI with MCP Servers and Extensions

This tutorial will guide you through enhancing the capabilities of the Gemini CLI by integrating with external services and APIs using Model Context Protocol (MCP) servers and extensions. You’ll learn how to add MCP servers to your project for specific services like Context7, enabling Gemini to access and utilize their functionalities. Additionally, you’ll discover how to install and leverage Gemini CLI extensions, which can bundle MCP servers, markdown files, and custom commands for a more integrated experience with services like Firebase.

Understanding MCP Servers

By default, AI coding agents like Gemini can only interact with your local codebase. However, to enable interaction with external services and APIs, such as Superbase or Firebase, you can utilize MCP servers. MCP stands for Model Context Protocol, a protocol developed by Anthropic. It acts as a bridge, allowing AI clients like the Gemini CLI to interact with external services and data sources.

When you add an MCP server, it exposes a set of tools that Gemini can trigger. These tools are essentially functions that execute code, send requests to the external service, and return the response to Gemini. For instance, a Firebase MCP server might offer a tool like Firebase list projects, which retrieves all your Firebase projects. Gemini doesn’t directly interact with Firebase; instead, it calls these exposed tools provided by the MCP server.

Adding the Context7 MCP Server

This section demonstrates how to add the Context7 MCP server, which provides access to up-to-date documentation for various frameworks and libraries like Next.js, Nuxt, React, Vue, and Tailwind CSS. This is particularly useful for ensuring that Gemini uses the latest official guidance when implementing features or working with new frameworks, preventing the use of outdated information from its training data.

  1. Sign up for Context7 and get an API Key:

    Visit context7.com and sign up for a free account. Navigate to your dashboard and find the Create API key button. Click it, give your API key a name, and then copy the generated key. It’s recommended to paste this key into a temporary location like Notepad for safekeeping.

  2. Locate the Gemini CLI Installation Guide:

    Go to the Context7 MCP server’s GitHub repository. You can usually find a link to this from the Context7 website or by searching online. Scroll down the repository page to find installation options for various clients, including the Gemini CLI.

  3. Copy the Gemini CLI Configuration Snippet:

    Expand the Gemini CLI section in the installation guide. You will see a code snippet for adding the server. Choose the remote server option if available. Highlight and copy the code snippet, typically excluding the surrounding curly braces.

  4. Configure settings.json:

    Open your project’s settings.json file in VS Code. Inside the main settings object, paste the copied snippet. This registers the Context7 MCP server for your current project. You can add multiple MCP servers here.

    Note: MCP servers can also be configured globally in your global Gemini CLI settings file using the same MCP servers property, but for this tutorial, we’re configuring it per project.

  5. Securely Add the API Key:

    The configuration snippet will include a placeholder for your API key. To avoid committing sensitive information to version control, create a .env file in the root of your project. Inside this file, define an environment variable, for example, CONTEXT7_API_KEY, and set its value to the API key you copied earlier.

    In your settings.json file, replace the direct API key value with a reference to your environment variable using the syntax: "${CONTEXT7_API_KEY}".

  6. Restart Gemini CLI and Verify:

    Quit your current Gemini CLI session by typing quit in the terminal. Start a new session by typing gemini and pressing Enter. This ensures that Gemini recognizes the new configuration. To verify the server was added, run the gemini mcp command. This should list the newly added Context7 server and its available tools, such as get library id and get library docs.

  7. Use Context7 for Documentation Queries:

    When interacting with Gemini, you can now ask it to use Context7 for documentation. For example, prompt Gemini to check if your vestconfig.ts is set up correctly for a Nuxt app. Gemini will automatically identify the need to use the Context7 MCP server and may ask for your permission to run its tools. Grant permission, and Gemini will use the official documentation to verify your configuration.

Gemini CLI Extensions

Gemini CLI extensions are packages that can bundle MCP server configurations, markdown files, and custom commands. They offer a more integrated way to add functionality to Gemini.

Installing the Firebase Extension

This example shows how to install the Firebase extension, which includes an MCP server setup, context files, and custom commands for interacting with a Firebase backend.

  1. Find the Extension Install Command:

    Navigate to the Gemini CLI extensions page (usually linked from the main Gemini CLI website). Search for the Firebase extension. On its page, you’ll find an installation command, typically starting with gemini extensions install followed by the extension’s URL.

  2. Install the Extension:

    Copy the installation command. In your terminal, outside of any active Gemini chat session, paste the command and press Enter. You may need to confirm the installation by pressing Enter again on a default ‘yes’ value.

    Note: Extensions are generally installed globally in your user’s Gemini directory.

  3. Verify Installation:

    After installation, the Gemini CLI will be extended with the Firebase MCP server and any associated custom commands. You can confirm this by starting a new Gemini session and typing a forward slash (/) followed by firebase. This should reveal available commands like firebase:deploy, firebase:init, and firebase:consult.

These extensions simplify the process of integrating complex services by pre-configuring necessary MCP servers and providing convenient custom commands.

Conclusion

By integrating MCP servers and extensions, you can significantly expand the Gemini CLI’s ability to interact with external services, access up-to-date documentation, and streamline your development workflow.


Source: Gemini CLI Tutorial #9 – MCP Servers & Extensions (YouTube)

Leave a Reply

Your email address will not be published. Required fields are marked *

Written by

John Digweed

1,377 articles

Life-long learner.