Gemini AI模型服务器

一个提供Google Gemini AI模型访问的MCP(Model Context Protocol)服务器。

  • by reouno
  • Shell
  • 本地部署
  • 更新于
在 GitHub 查看 reouno/gemini-mcp

使用说明

Gemini MCP服务器

一个MCP(模型上下文协议)服务器,提供对Google Gemini AI模型的访问。

快速开始

  1. 安装依赖项:
npm install
  1. 创建 .env 使用Gemini API密钥文件:
GEMINI_API_KEY=your_api_key_here
  1. 启动服务器:
npm run dev

服务器将在以下时间运行 http://localhost:3333/mcp

可用工具

gemini_generateText

使用Google Gemini模型生成文本。

参数:

  • prompt (string,必填):文本提示
  • model (字符串,可选):要使用的Gemini模型(默认值: gemini-2.5-pro)
  • temperature (数字,可选):发电温度,0-2(默认值:1)

退货:

  • text:生成的文本响应
  • model:使用的型号
  • temperature:使用的温度设置

用法示例

import { Client as McpClient } from '@modelcontextprotocol/sdk/client/index.js';
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';

const transport = new StreamableHTTPClientTransport(
  new URL('http://localhost:3333/mcp')
);

const client = new McpClient(
  { name: 'my-client', version: '1.0.0' },
  { capabilities: {} }
);

await client.connect(transport);

const result = await client.callTool({
  name: 'gemini_generateText',
  arguments: {
    prompt: 'Explain AI in simple terms',
    model: 'gemini-2.5-pro',
    temperature: 0.7
  }
});

console.log(result);
await client.close();

测试

运行附带的测试客户端(要求服务器正在运行):

npm test

配置

环境变量:

  • GEMINI_API_KEY (必需):您的Google Gemini API密钥
  • PORT (可选):服务器端口(默认:3333)

部署

使用自动化脚本部署到Google Cloud Run:

# 0. Prerequisites (one-time, via GCP Console)
#    - Create GCP project
#    - Link billing account
#    - Run: gcloud auth login

# 1. Setup GCP (one-time)
./bin/setup-gcp.sh \
  --project-id=my-project \
  --github-user=your-username \
  --github-repo=gemini-mcp

# 2. Set GitHub Secrets (follow script output)

# 3. Deploy
git push origin main

有关详细的部署说明,请参阅 部署.md.

许可证

ISC