NanoBanana MCP Server
An MCP server that wraps the OpenRouter API, enabling users to access diverse language models like Google Gemini 3 Pro for chat and image tasks. It provides tools for generating completions and listing available models within MCP-compatible clients.
README
NanoBanana MCP Server
一个封装 OpenRouter API 的 MCP (Model Context Protocol) 服务器,可供 Claude Code CLI、Claude Desktop 等 MCP 客户端使用。
功能特性
- 🚀 通过 MCP 协议访问 OpenRouter API
- 🤖 默认使用 Google Gemini 3 Pro Image Preview 模型
- 💬 支持聊天补全(Chat Completion)
- 📋 支持列出所有可用模型
- 🖼️ 支持文本和图像输入
📦 安装
方式 1: 通过 uvx(推荐)
使用 uvx 直接从 GitHub 运行,无需克隆仓库:
# 首先安装 uv(如果还没有)
pip install uv
在 Claude Code CLI 中配置
编辑 Claude Code 配置文件并添加:
{
"mcpServers": {
"nano-banana": {
"command": "uvx",
"args": ["nano-banana-mcp@git+https://github.com/caoshuo594/nano_banana.git"],
"env": {
"OPENROUTER_API_KEY": "sk-or-v1-your-actual-key-here"
}
}
}
}
在 Claude Desktop 中配置
使用相同的配置格式。
方式 2: 克隆仓库(用于开发)
# 1. 克隆仓库
git clone https://github.com/caoshuo594/nano_banana.git
cd nano_banana
# 2. 安装依赖
pip install -r requirements.txt
在 Claude Code CLI 中配置
{
"mcpServers": {
"nano-banana": {
"command": "python",
"args": ["-m", "mcp_server"],
"cwd": "/path/to/nano_banana",
"env": {
"OPENROUTER_API_KEY": "sk-or-v1-your-actual-key-here"
}
}
}
}
在 Claude Desktop 中配置
使用相同的配置格式。
🔑 获取 OpenRouter API Key
⚠️ 必需步骤:
- 访问 OpenRouter
- 注册/登录账号
- 在 API Keys 页面 创建新的 API Key
- 复制您的 API Key(格式:
sk-or-v1-...) - 在 Claude Desktop 配置的
env部分填入
配置说明
- API URL: https://openrouter.ai/api/v1
- 默认模型: google/gemini-3-pro-image-preview
配置文件位置:
-
Claude Code CLI:
- Windows:
%APPDATA%\Claude Code\config.json - macOS:
~/Library/Application Support/Claude Code/config.json - Linux:
~/.config/claude-code/config.json
- Windows:
-
Claude Desktop:
- Windows:
%APPDATA%\Claude\claude_desktop_config.json - macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
- Windows:
⚠️ 重要:
- 将
sk-or-v1-your-actual-key-here替换为您的实际 API Key - 如果使用方式 2,将
/path/to/nano_banana替换为实际路径 - 配置完成后重启 Claude Code CLI 或 Claude Desktop
🎨 使用方法
在 Claude Code CLI 中使用
配置完成后,在终端中启动 Claude Code,直接描述您的需求:
claude-code
# 或
claude code
# 然后输入:
帮我生成一张熊猫武士的图片
Claude 会自动:
- 理解您的需求
- 生成详细的提示词
- 调用 MCP 图像生成工具
- 返回 2 张高质量图片(base64 格式)
在 Claude Desktop 中使用
使用方式与 Claude Code CLI 相同,直接用自然语言描述需求即可。
直接测试(开发用)
可以使用 MCP Inspector 进行测试:
npx @modelcontextprotocol/inspector python mcp_server.py
可用工具
1. chat_completion
发送聊天补全请求到 OpenRouter API。
参数:
messages(必需): 消息数组,每个消息包含role和contentrole: "user", "assistant", 或 "system"content: 消息内容(文本或图像 URL)
model(可选): 使用的模型,默认为google/gemini-3-pro-image-previewtemperature(可选): 采样温度 (0-2),默认为 1max_tokens(可选): 生成的最大 token 数stream(可选): 是否流式返回,默认为 false
示例:
{
"messages": [
{
"role": "user",
"content": "你好,请介绍一下自己"
}
],
"temperature": 0.7
}
2. list_models
列出 OpenRouter API 上所有可用的模型。
参数: 无
可用资源
nano-banana://config
返回 NanoBanana MCP Server 的配置信息,包括 API URL 和默认模型。
架构说明
┌─────────────────┐
│ MCP 客户端 │
│ (Claude/Gemini) │
└────────┬────────┘
│ MCP Protocol
│ (stdio)
┌────────▼────────┐
│ MCP Server │
│ (mcp_server.py)│
└────────┬────────┘
│ HTTPS
│
┌────────▼────────┐
│ OpenRouter API │
│ (Gemini 3 Pro) │
└─────────────────┘
开发说明
项目结构
nano_banana/
├── mcp_server.py # MCP 服务器主程序
├── requirements.txt # Python 依赖
├── claude_desktop_config.json # Claude Desktop 配置示例
├── README.md # 本文档
├── nano_banana.md # API 配置信息
└── prompt.md # 项目需求说明
修改配置
如需修改 API Key 或默认模型,请编辑 mcp_server.py 中的以下常量:
OPENROUTER_API_URL = "https://openrouter.ai/api/v1"
OPENROUTER_API_KEY = "your-api-key-here"
DEFAULT_MODEL = "google/gemini-3-pro-image-preview"
添加新工具
在 mcp_server.py 中:
- 在
list_tools()函数中添加新工具的定义 - 在
call_tool()函数中添加工具调用逻辑 - 实现具体的工具函数
故障排除
问题:Claude Desktop 无法连接到 MCP 服务器
解决方案:
- 检查 Python 是否在系统 PATH 中
- 确认
mcp_server.py的路径正确 - 查看 Claude Desktop 的日志文件
- 尝试手动运行
python mcp_server.py检查是否有错误
问题:API 请求失败
解决方案:
- 检查 API Key 是否有效
- 确认网络连接正常
- 查看 OpenRouter API 状态页面
- 检查是否超出 API 配额
问题:依赖安装失败
解决方案:
# 升级 pip
python -m pip install --upgrade pip
# 重新安装依赖
pip install -r requirements.txt --force-reinstall
许可证
MIT License
贡献
欢迎提交 Issue 和 Pull Request!
相关链接
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.