Skip to content

How to Set Up MCP Servers with Gemini

Configure Model Context Protocol (MCP) servers to extend Gemini CLI with custom tools, data sources, and integrations for advanced workflows.

  1. 1

    Understand MCP Architecture

    MCP (Model Context Protocol) allows Gemini to communicate with external tool servers. Each MCP server exposes tools that Gemini can invoke during conversations to access data or perform actions.

  2. 2

    Create the MCP Configuration File

    Create a .gemini/mcp.json file in your project root. This file defines the MCP servers Gemini should connect to, including their transport type and startup commands.

  3. 3

    Define Server Entries

    Add server entries with a name, command to start the server, and any required arguments. For example: {"servers": {"my-server": {"command": "node", "args": ["server.js"]}}}.

  4. 4

    Implement Your MCP Server

    Build your MCP server using the @modelcontextprotocol/sdk package. Define tools with input schemas and handler functions that return results to Gemini.

  5. 5

    Test the Connection

    Start Gemini CLI and verify it connects to your MCP server by asking it to list available tools. The server's tools should appear in the tool list.

  6. 6

    Debug Common Issues

    If connections fail, check that the server command is correct, the server outputs valid JSON-RPC over stdio, and there are no port conflicts. Use 'gemini --verbose' for detailed logs.