Gemini MCP Server
Integrates Google's Gemini API with MCP-compatible clients for chat, real-time web search, knowledge queries, code/text analysis, and content generation.
README
Gemini MCP Server
A Model Context Protocol (MCP) server that integrates Google's Gemini API with AI assistants like Claude Desktop, Kiro, Cursor, VS Code, and other MCP-compatible clients.
Features
- Chat: Multi-turn conversations with Gemini models
- Search: Real-time web search using Google Search integration
- Knowledge: Query Gemini's knowledge base (training data)
- Analyze: Analyze code, text, or data with AI-powered insights
- Generate: Generate code, documentation, and creative content
- Latest Models: Support for Gemini 3 preview models (gemini-3-pro-preview, gemini-3-flash-preview)
Prerequisites
- Node.js v20 or later
- A Google Gemini API key (Get one here)
Installation
1. Clone or Download
git clone <your-repo-url>
cd gemini-mcp-server
2. Install Dependencies
npm install
# or
pnpm install
3. Get Your Gemini API Key
- Visit Google AI Studio
- Click "Create API Key" or "Get API Key"
- Copy your API key for use in the configuration steps below
4. Find Your Repository Path
Before configuring MCP clients, you need to get the absolute path to your cloned repository. Run this command in your terminal:
pwd
This will output your current directory path. For example:
/Downloads/projects/gemini-mcp-server
Copy this path - you'll use it in the MCP client configurations below. Replace cloned_repo_location with this actual path in all configuration examples.
Integration with MCP Clients
Kiro
Add this to your Kiro MCP configuration file:
Location: ~/.kiro/settings/mcp.json (user-level) or .kiro/settings/mcp.json (workspace-level)
{
"mcpServers": {
"gemini": {
"command": "node",
"args": ["/cloned_repo_location/gemini-mcp-server/src/index.js"],
"env": {
"GEMINI_API_KEY": "your_api_key_here",
"GEMINI_MODEL": "gemini-2.5-flash"
},
"disabled": false,
"autoApprove": ["chat", "search", "analyze", "generate", "knowledge"]
}
}
}
Note: Replace /cloned_repo_location/gemini-mcp-server with the actual path on your system. You can optionally set GEMINI_MODEL to use a different model (e.g., gemini-3-pro-preview).
After adding the configuration:
- Open Kiro's MCP Server view in the feature panel
- Click "Reconnect" on the gemini server, or restart Kiro
Claude Desktop
Add this to your Claude Desktop configuration file:
Location:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
{
"mcpServers": {
"gemini": {
"command": "node",
"args": ["/cloned_repo_location/gemini-mcp-server/src/index.js"],
"env": {
"GEMINI_API_KEY": "your_api_key_here",
"GEMINI_MODEL": "gemini-2.5-flash"
}
}
}
}
After adding the configuration:
- Restart Claude Desktop completely (quit and reopen)
- Look for the 🔌 icon in the bottom right to verify the server is connected
- You can now use Gemini tools in your conversations
Cursor
Add this to your Cursor MCP configuration file:
Location:
- macOS:
~/Library/Application Support/Cursor/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json - Windows:
%APPDATA%\Cursor\User\globalStorage\saoudrizwan.claude-dev\settings\cline_mcp_settings.json - Linux:
~/.config/Cursor/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json
{
"mcpServers": {
"gemini": {
"command": "node",
"args": ["/cloned_repo_location/gemini-mcp-server/src/index.js"],
"env": {
"GEMINI_API_KEY": "your_api_key_here",
"GEMINI_MODEL": "gemini-2.5-flash"
}
}
}
}
After adding the configuration:
- Restart Cursor
- Open the Cline extension
- The Gemini tools should now be available
VS Code (with Cline/Claude Dev Extension)
Add this to your VS Code MCP configuration file:
Location:
- macOS:
~/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json - Windows:
%APPDATA%\Code\User\globalStorage\saoudrizwan.claude-dev\settings\cline_mcp_settings.json - Linux:
~/.config/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json
{
"mcpServers": {
"gemini": {
"command": "node",
"args": ["/cloned_repo_location/gemini-mcp-server/src/index.js"],
"env": {
"GEMINI_API_KEY": "your_api_key_here",
"GEMINI_MODEL": "gemini-2.5-flash"
}
}
}
}
After adding the configuration:
- Reload VS Code window (Cmd/Ctrl + Shift + P → "Developer: Reload Window")
- Open the Cline/Claude Dev extension
- The Gemini tools should now be available
Other MCP Clients
For any other MCP-compatible client, use the standard MCP server configuration format:
{
"mcpServers": {
"gemini": {
"command": "node",
"args": ["/cloned_repo_location/gemini-mcp-server/src/index.js"],
"env": {
"GEMINI_API_KEY": "your_api_key_here",
"GEMINI_MODEL": "gemini-2.5-flash"
}
}
}
}
Refer to your specific client's documentation for the exact configuration file location. You can optionally set GEMINI_MODEL to use a different model.
Available Tools
chat
Send messages to Gemini with optional conversation history for multi-turn conversations.
Parameters:
message(string, required): The message to send to GeminiconversationHistory(array, optional): Previous messages in the conversation- Format:
[{role: "user"|"model", content: "message text"}]
- Format:
Example:
{
"message": "What is React?",
"conversationHistory": [
{"role": "user", "content": "Hello!"},
{"role": "model", "content": "Hi! How can I help you today?"}
]
}
search
Search for current information using real-time web search powered by Google Search.
Parameters:
query(string, required): The search query
Example:
{
"query": "What are the latest AI developments in 2025?"
}
Note: This tool uses Google Search integration for real-time information. If web search is unavailable, it falls back to knowledge base with a warning.
knowledge
Query Gemini's knowledge base (training data) without web search.
Parameters:
query(string, required): The knowledge query
Example:
{
"query": "Explain the concept of machine learning"
}
Note: This tool uses only Gemini's training data and doesn't access real-time information.
analyze
Analyze content with AI-powered insights.
Parameters:
content(string, required): The content to analyzeanalysisType(string, required): Type of analysis- Options:
code,text,data,general
- Options:
Example:
{
"content": "function add(a, b) { return a + b; }",
"analysisType": "code"
}
generate
Generate content based on a prompt.
Parameters:
prompt(string, required): The generation promptcontentType(string, required): Type of content to generate- Options:
code,documentation,creative,technical
- Options:
Example:
{
"prompt": "Create a React component for a todo list",
"contentType": "code"
}
Testing the Server
You can test the server directly using Node.js:
# Set your API key
export GEMINI_API_KEY="your_api_key_here"
# Run the server
node src/index.js
The server will start and listen on stdio. You should see:
Gemini MCP Server running on stdio
Development
Run in watch mode for development:
npm run dev
This will automatically restart the server when you make changes to the code.
Configuration Options
Model Selection
By default, the server uses gemini-2.5-flash. To use a different model, set the GEMINI_MODEL environment variable in your MCP configuration:
{
"mcpServers": {
"gemini": {
"command": "node",
"args": ["/path/to/gemini-mcp-server/src/index.js"],
"env": {
"GEMINI_API_KEY": "your_api_key_here",
"GEMINI_MODEL": "gemini-3-pro-preview"
}
}
}
}
Available models:
Latest (Recommended)
gemini-3-pro-preview- Latest generation, most capable (preview)gemini-3-flash-preview- Latest generation, fast and efficient (preview)
Current Generation
gemini-2.5-flash- Fast and efficient (default)gemini-2.5-pro- More capable, slower
Previous Generation
gemini-1.5-pro- Previous generation, capablegemini-1.5-flash- Previous generation, fast
Note: Preview models (gemini-3-*) are experimental and may have breaking changes. Use production models for stable deployments.
Switching to Gemini 3 Models
To use the latest Gemini 3 preview models, simply set the GEMINI_MODEL environment variable in your MCP configuration:
{
"mcpServers": {
"gemini": {
"command": "node",
"args": ["/path/to/gemini-mcp-server/src/index.js"],
"env": {
"GEMINI_API_KEY": "your_api_key_here",
"GEMINI_MODEL": "gemini-3-pro-preview"
}
}
}
}
Or for the fast variant:
{
"mcpServers": {
"gemini": {
"command": "node",
"args": ["/path/to/gemini-mcp-server/src/index.js"],
"env": {
"GEMINI_API_KEY": "your_api_key_here",
"GEMINI_MODEL": "gemini-3-flash-preview"
}
}
}
}
No code changes needed - the server automatically uses the model specified in the environment variable!
Environment Variables
GEMINI_API_KEY(required): Your Google Gemini API keyGEMINI_MODEL(optional): The Gemini model to use (default:gemini-2.5-flash)- Examples:
gemini-3-pro-preview,gemini-3-flash-preview,gemini-2.5-pro,gemini-1.5-pro
- Examples:
Troubleshooting
API Key Error
Error: Error: GEMINI_API_KEY environment variable is not set
Solution: Ensure your API key is properly set in the MCP configuration file under the env section.
Import Error
Error: SyntaxError: The requested module '@google/genai' does not provide an export named 'genai'
Solution: This has been fixed in the latest version. Make sure you're using the correct import:
import { GoogleGenAI } from "@google/genai";
Connection Closed Error
Error: MCP error -32000: Connection closed
Solution:
- Check that Node.js v20+ is installed:
node --version - Verify all dependencies are installed:
npm install - Check that the path in your MCP config is absolute and correct
- Look at the server logs for more details
Server Not Showing Up
Solution:
- Verify the configuration file path is correct for your client
- Ensure the JSON syntax is valid (no trailing commas, proper quotes)
- Restart your MCP client completely
- Check the client's logs for error messages
Rate Limiting
If you encounter rate limiting errors from the Gemini API:
- Check your API quota in Google AI Studio
- Implement exponential backoff in your requests
- Consider upgrading your API plan if needed
API Limits
Free tier limits (as of 2025):
- 15 requests per minute
- 1,500 requests per day
- 1 million tokens per minute
For higher limits, check Google AI Studio pricing.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT
Resources
- Google Gemini API Documentation
- Model Context Protocol Specification
- MCP TypeScript SDK
- Google AI Studio
Support
For issues and questions:
- Open an issue on GitHub
- Check the MCP documentation
- Visit Google AI Studio for API-related questions
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。