搜索与天气MCP服务器

一个通过SerpAPI和OpenWeatherMap集成提供Google搜索和天气信息的模型上下文协议(MCP)服务器,适用于Spring AI和其他MCP客户端。

  • by RathodVijay9524
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 RathodVijay9524/search_google_mcp

使用说明

Google搜索与天气MCP服务器

一个模型上下文协议(MCP)服务器,通过SerpAPI和OpenWeatherMap的集成,为Spring AI及其他MCP客户端提供谷歌搜索和天气信息。

🚀 特性

  • 7款强大工具 具有不同的输出格式
  • FastMCP框架 - 现代MCP(多控制器协议/管理控制平面)实现
  • 谷歌搜索 - 通过SerpAPI获取可靠搜索结果
  • 天气信息 - 通过OpenWeatherMap获取当前天气和天气预报
  • JSON & 文本格式 - 结构化数据,便于集成
  • 模块化架构 - 清晰的职责分离
  • 错误处理 - 全面的错误管理

🛠️ 可用工具

谷歌搜索工具(3)

1. googlesearch - 标准谷歌搜索

返回包含标题、链接和摘要的结构化JSON数据

2. quicksearch - 简单文本格式

返回易于阅读的文本格式以供快速查询

3. searchdetails - 详细搜索

返回全面的元数据和搜索信息

天气API工具(3)

4. weather - 当前天气

获取任何城市的详细实时天气信息(JSON格式)

5. quickweather - 简单天气

以易于阅读的文本格式获取当前天气

6. forecast - 天气预报

获取接下来几天(1-5天)的天气预报

系统工具 (1)

7. health - 健康检查

检查服务器状态和可用工具数量

📦 安装

先决条件

  • Python 3.8及以上版本
  • SerpAPI账号和API密钥(用于Google搜索)
  • OpenWeatherMap API密钥(用于天气 - 可免费使用)

设置

# Navigate to project directory
cd search-google-mcp

# Install dependencies
pip install -r requirements.txt

# Set API keys (optional - demo keys included)
set SERPAPI_KEY=your_serpapi_key_here
set OPENWEATHER_API_KEY=your_openweather_key_here

# Run the MCP server
python search_google_mcp.py

依赖项

mcp[server]
google-search-results
requests

📖 使用方法

来自Spring AI

将您的Spring Boot应用程序与之集成,为您的AI聊天机器人添加谷歌搜索功能。

工具示例

标准搜索:

{
  "tool": "googlesearch",
  "arguments": {
    "query": "Spring Boot best practices",
    "num_results": 3
  }
}

快速搜索:

{
  "tool": "quicksearch",
  "arguments": {
    "query": "Python decorators tutorial"
  }
}

当前天气:

{
  "tool": "weather",
  "arguments": {
    "city": "London",
    "units": "metric"
  }
}

简易天气

{
  "tool": "quickweather",
  "arguments": {
    "city": "New York",
    "units": "imperial"
  }
}

天气预报:

{
  "tool": "forecast",
  "arguments": {
    "city": "Tokyo",
    "days": 5,
    "units": "metric"
  }
}

🔑 API 配置

SerpAPI(谷歌搜索)

  1. 在……注册 SerpAPI
  2. 从仪表板获取您的API密钥
  3. 设置环境变量:
    set SERPAPI_KEY=your_api_key_here
    

OpenWeatherMap(天气)

  1. 在(以下网址)注册 OpenWeatherMap(开放天气图)
  2. 获取你的 免费 仪表板上的API密钥
  3. 设置环境变量:
    set OPENWEATHER_API_KEY=your_api_key_here
    

📊 回复格式

成功响应

{
  "status": "success",
  "query": "python tutorial",
  "total_results": 3,
  "results": [
    {
      "rank": 1,
      "title": "Learn Python",
      "link": "https://example.com",
      "snippet": "Description..."
    }
  ]
}

错误响应

{
  "status": "error",
  "error": "Error message"
}

🏗️ 建筑学

使用……构建 FastMCP 遵循与AI编码助手MCP服务器相同的模式:

  • 使用(某工具)进行清晰的工具注册 @mcp.tool 装饰器
  • 一致的JSON响应格式
  • 专业的错误处理
  • 类型提示和文档说明

🤝 与Spring AI的集成

这个MCP服务器为您的Spring AI聊天机器人和助手提供谷歌搜索功能。


版本1.0.0
兼容性Python 3.8+,MCP 协议 v1.0+