用于Instana验证的Gemini MCP服务器
这是一个简单的模型上下文协议(MCP)服务器,与谷歌的Gemini模型集成。它旨在取代Instana的MCP可观察性文档中的“天气”示例,以演示如何使用Traceloop对MCP服务器进行检测并将跟踪发送到Instana。
先决条件
- 客户端:带克劳德桌面的Windows 11
- 服务器:WSL2(Linux的Windows子系统)与Ubuntu 22.04.5 LTS
- Python 3.10+
- 启用Gemini API和API密钥的谷歌云项目。
- Instana代理(本地运行)或Instana后端OTLP端点(用于无代理模式)。
设置
- 克隆/导航到目录:
cd gemini-mcp-server- 创建并激活虚拟环境(在WSL2 Ubuntu中):
python3 -m venv venv
source venv/bin/activate- 安装依赖项:
pip install -r requirements.txt配置和使用
您可以直接通过Claude Desktop或任何MCP客户端运行此服务器。
环境变量
您需要提供以下环境变量。您可以将它们设置为 .env 文件(如果手动运行)或Claude Desktop配置中。
GOOGLE_API_KEY:您的Gemini API密钥。GEMINI_MODEL:(可选)要使用的模型。默认为models/gemini-2.5-flash。您可以将其设置为models/gemini-3-pro-image-preview如果你有权限。
WSL2 Ubuntu环境示例设置
在WSL2 Ubuntu终端中:
export GOOGLE_API_KEY="YOUR_GOOGLE_API_KEY_HERE"
export GEMINI_MODEL="gemini-2.5-flash-image"
export TRACELOOP_BASE_URL="http://localhost:4318"
export TRACELOOP_HEADERS="x-instana-key=YOUR_INSTANA_KEY_HERE"
export OTEL_EXPORTER_OTLP_INSECURE="true"
# Start the server
python gemini_server.pyInstana跟踪变量:
- 代理模式(本地Instana代理):
- TRACELOOP_BASE_URL=http://localhost:4318 - TRACELOOP_HEADERS="x-instana-key=" - OTEL_EXPORTER_OTLP_INSECURE=true
- 无代理模式(直接到后端):
- TRACELOOP_BASE_URL= (例如。, https://otlp-pink-saas.instana.rocks:4318 如果使用HTTP) - TRACELOOP_HEADERS="x-instana-key=" - OTEL_EXPORTER_OTLP_INSECURE=false
Claude桌面配置
由于服务器作为持久web服务(流式http)运行,Claude Desktop通过 mcp-remote npm包。
1.使用环境变量启动服务器:
在您的终端中 gemini-mcp-server 目录(venv已激活),设置所有环境变量并启动服务器:
# Set server environment variables
export GOOGLE_API_KEY="your-google-api-key"
export GEMINI_MODEL="gemini-2.5-flash-image"
export TRACELOOP_BASE_URL="http://localhost:4318"
export TRACELOOP_HEADERS="x-instana-key=your-instana-key"
export OTEL_EXPORTER_OTLP_INSECURE="true"
# Start the server
python gemini_server.py您应该看到输出指示 Uvicorn running on http://127.0.0.1:8000.
2.配置克劳德桌面(在Windows 11上):
在以下位置编辑您的Claude Desktop配置文件:
- Windows路径:
%APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"gemini": {
"command": "npx",
"args": [
"mcp-remote",
"http://localhost:8000/mcp"
]
}
}
}*注意:所有环境变量都在服务器端设置(步骤1)。这 mcp-remote 代理不需要它们。*
验证步骤
- 重新启动克劳德桌面。
- 查找插头图标以确认“gemini”服务器已连接。
- 问克劳德:“让双子座为Instana建筑创建一个3D图像。”
- 测试图像生成:
- 问克劳德:“生成一个未来城市的图像。” - Claude应该返回由提供的模型生成的图像。
- 查看您的Instana仪表板:
- 首选 GenAI可观察性. - 查找名为的服务 gemini-mcp-server. - 点击它,然后你可以看到它的痕迹 generate_image 等等。
