Gemini CLI with MCP Integration: AI Powered Terminal Coding Assistant and AI Development Workflow
Gemini CLI: Google’s AI Coding Assistant with MCP Integration
Google’s Gemini CLI brings the power of Gemini 2.5 Pro directly into your terminal, offering code understanding, file manipulation, and intelligent automation. With its 1-million-token context window, it can handle large codebases and complex development tasks with ease.
Key Features
- Large Codebase Analysis: Handle projects beyond typical token limits
- Multimodal Capabilities: Generate code from PDFs, sketches, and documents
- Workflow Automation: Streamline development tasks and troubleshooting
- MCP Integration: Connect to external tools like GitHub, Git, and databases
Installation and Setup
Install Gemini CLI
1
2
3
4
5
6
7
npm install -g @google/gemini-cli
OR
brew install gemini-cli
gemini
Authentication Options
Option 1: Google Account (Personal Use)
1
gemini auth
Grants 60 model requests/minute and 1,000 model requests/day.
Option 2: API Key (Production)
- Get API key from Google AI Studio
- Set environment variable:
1 2 3
export GEMINI_API_KEY="your_api_key_here" # Make persistent echo 'export GEMINI_API_KEY="your_key_here"' >> ~/.bashrc
Verify Installation
1
2
3
gemini --version
# 0.1.14
gemini --help
Basic Usage Examples
Code Generation
1
2
gemini "Create a React todo app with local storage"
gemini "Write a Python class for CSV file operations"
Code Analysis
1
2
gemini "Review this code for performance issues: [paste code]"
gemini "Debug this function: [paste code and error]"
File Operations
1
2
gemini "Create a Node.js project structure with package.json"
gemini "Generate README.md for this project"
MCP Server Integration
What is MCP?
Model Context Protocol (MCP) enables AI tools to connect to external data sources and tools. It’s like a USB-C port for AI applications, providing standardized access to GitHub, Git, databases, and more.
Install Git MCP Servers
GitHub MCP Server:
1
2
npm install -g @modelcontextprotocol/server-github
export GITHUB_PERSONAL_ACCESS_TOKEN="your_github_token"
Local Git MCP Server:
1
npm install -g @cyanheads/git-mcp-server
MCP Inspector (for debugging):
1
npm install -g @modelcontextprotocol/inspector
MCP Configuration
Create mcp-config.json
:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{
"servers": {
"github": {
"command": "node",
"args": ["path/to/github-mcp-server"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "your_token"
}
},
"git": {
"command": "git-mcp-server",
"args": ["stdio"],
"cwd": "/path/to/git/repository"
}
}
}
OR, In CLINE, Go to MCP sections, install Git Tools
.
MCP + Gemini CLI Examples
GitHub Operations:
1
2
3
gemini "Show all open issues in this repository"
gemini "Create a GitHub issue for the API bug"
gemini "Review the latest 3 pull requests"
Git Operations:
1
2
3
gemini "Create feature branch 'user-auth' and switch to it"
gemini "Show diff for last 3 commits and explain changes"
gemini "Generate release notes since last tag"
Repository Analysis:
1
2
3
gemini "Analyze git history and find top contributors"
gemini "Review uncommitted changes before committing"
gemini "Audit repository for security issues"
Best Practices
Effective Prompting
- Be specific with requirements and context
- Include relevant code snippets and error messages
- Use follow-up questions to refine results
MCP Security
- Store tokens in environment variables
- Use minimal necessary permissions
- Rotate access tokens regularly
Performance Tips
- Start sessions in project root for full context
- Combine related questions in single prompts
- Use
/clear
to reset context when switching projects
Troubleshooting
Authentication Issues
1
2
3
4
5
# Reset authentication
gemini auth --reset
# Check environment variables
echo $GEMINI_API_KEY
MCP Server Issues
1
2
3
4
5
# Debug MCP servers
mcp-inspector github-mcp-server
# Test connections
gemini "List available MCP resources and tools"
Quick Reference
Essential Commands
1
2
3
4
5
6
7
8
9
10
11
12
13
# Installation
npm install -g @google/gemini-cli
npm install -g @modelcontextprotocol/server-github
npm install -g @cyanheads/git-mcp-server
# Authentication
gemini auth
export GEMINI_API_KEY="your_key"
# Usage
gemini # Interactive session
gemini "your prompt" # One-shot command
gemini --help # Help
Key Prompts
"Analyze this codebase and suggest improvements"
"Create tests for this function: [code]"
"Show all GitHub issues and categorize by priority"
"Review latest commits and suggest optimizations"
"Generate project documentation"
Conclusion
Gemini CLI with MCP integration provides a powerful, context-aware development experience. The combination of Google’s AI capabilities, extensive context window, and standardized protocol integration makes it an excellent choice for modern development workflows.
Gemini-Cli in Action: A Visual Walkthrough
To demonstrate Gemini-Cli’s capabilities in practice, here’s a step-by-step visual guide showing the feature: