返回市场
双子座-MCP服务器

双子座-MCP服务器

作者:philschmid47 星标更新:2025-06-13

项目介绍

[!NOTE]
当前MCP服务器可通过以下地址访问:https://gemini-mcp-server-231532712093.europe-west1.run.app/mcp/。该服务器部署在Google Cloud Run上,并可使用AI Studio API密钥进行身份验证。请参阅examples/test_remote.py,了解如何使用google-genai客户端与服务器交互的示例。

Gemini MCP Server

这是一个提供对Google Gemini API访问的Model Context Protocol服务器。此服务器使LLMs能够执行智能网络搜索、生成内容并访问其他Gemini功能。它支持STDIO和streamable-http传输模式,并且可以本地或远程运行。如果使用STDIO模式,它会尝试使用GEMINI_API_KEY环境变量。如果使用streamable-http模式,它会尝试使用Authorization头中的Bearer令牌。

可用工具:

  • web_search - 使用Gemini执行网络搜索并返回带有引文的合成结果
    • query (字符串,必需):要执行的搜索查询
    • include_citations (布尔值,可选):是否在响应中包含引文。默认值是False
  • use_gemini - 将任务委托给指定的Gemini 2.5模型(Pro或Flash)。
    • prompt (字符串,必需):Gemini的任务或提示。
    • model (字符串,可选):要使用的Gemini模型。默认值是gemini-2.5-flash-preview-05-20

安装

pip install git+https://github.com/philschmid/gemini-mcp-server.git

认证

  • STDIO模式:使用GEMINI_API_KEY环境变量
  • HTTP模式:需要Authorization头中的Bearer令牌

运行服务器

STDIO模式(本地/直接集成)

GEMINI_API_KEY="your_gemini_api_key_here" gemini-mcp --transport stdio

HTTP模式(网络访问)

gemini-mcp --transport streamable-http

服务器将在http://0.0.0.0:8000/mcp/启动。

部署

您可以将Gemini MCP服务器部署为远程MCP服务器到Google Cloud Run,以便轻松地让任何客户端访问。

要部署服务器,请从您的终端运行以下命令,替换[PROJECT-ID][REGION]为您自己的Google Cloud项目ID和所需区域:

# 设置您的项目ID和区域
export PROJECT_ID=remote-mcp-test-462811
export REGION=europe-west1
export SERVICE_NAME=gemini-mcp-server

# 使用Google Cloud进行身份验证
gcloud auth login
gcloud config set project $PROJECT_ID

# 启用所需服务
gcloud services enable run.googleapis.com artifactregistry.googleapis.com cloudbuild.googleapis.com

# 部署服务
g
gcloud run deploy $SERVICE_NAME \
  --source . \
  --region $REGION \
  --port 8000 \
  --allow-unauthenticated

该命令将构建Docker镜像,将其推送到Google Artifact Registry,并将其部署到Cloud Run。部署完成后,您将获得一个服务URL。我们将允许未认证的访问服务,这意味着拥有URL的任何人都可以向服务器发送请求,而服务器本身受Authorization头保护。如果您想保护服务,可以参考Cloud Run文档中的说明。

清理

SERVICE_NAME=gemini-mcp-server
REGION=europe-west1
gcloud run services delete $SERVICE_NAME --region $REGION

使用示例

添加到您的mcpServers配置:

STDIO模式:

{
  "mcpServers": {
    "gemini-search": {
      "command": "gemini-mcp",
      "args": ["--transport", "stdio"],
      "env": {
        "GEMINI_API_KEY": "your_gemini_api_key_here"
      }
    }
  }
}

HTTP模式:

{
  "mcpServers": {
    "gemini-mcp": {
      "url": "https://remote-mcp-test.com/mcp/", // 替换为您的远程MCP服务器URL
      "headers": { "Authorization": "Bearer YOUR_KEY" } // 替换为您的AI Studio API密钥
    }
  }
}

或者查看examples/test_remote.py文件中的示例。

from mcp.client.streamable_http import streamablehttp_client

remote_url = "https://remote-mcp-test.com/mcp/" # 替换为您的远程MCP服务器URL

async with streamablehttp_client(
    remote_url, headers={"Authorization": f"Bearer {api_key}"}
) as (read, write, _):

使用MCP Inspector

使用streamable-http启动服务器并使用MCP inspector测试您的服务器。或者启动inspector并使用stdio运行服务器。

npx @modelcontextprotocol/inspector

网络搜索工具示例

include_citations设置为False时:

{
  "text": "最近的人工智能进展包括大型语言模型、计算机视觉和自主系统方面的突破性发展……"
}

include_citations设置为True时:

{
  "text": "最近的人工智能进展包括大型语言模型、计算机视觉和自主系统方面的突破性发展……",
  "web_search_queries": ["2024年最新人工智能进展", "人工智能突破"],
  "citations": [
    {
      "start_index": 24,
      "end_index": 56,
      "sources": [
        {
          "title": "2024年最新人工智能进展",
          "uri": "https://example.com/ai-news"
        }
        ...
      ],
      "text": "大型语言模型方面的突破性发展"
    },
    ...
  ]
}

使用Gemini工具响应示例

{
  "text": "法国的首都是巴黎。"
}

测试

要在根目录下运行测试,请运行以下命令:

注意:您需要设置GEMINI_API_KEY环境变量来运行测试。

pytest

许可证

本项目根据MIT许可证发布。