谷歌搜索工具

一个基于MCP框架的Python服务器,提供谷歌搜索和个性化问候功能。

  • by Dhineshkumar272005
  • Python
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 dhineshkumar272005/mcp_project_google_search

使用说明

MCP_项目_谷歌_搜索


MCP谷歌搜索工具

该项目提供了一个使用MCP(模块化命令平台)框架的简单Python服务器,为谷歌搜索和问候用户提供工具。它演示了如何创建自定义MCP工具和资源,包括在浏览器中打开谷歌搜索和生成个性化问候语。

特性

  • 谷歌搜索工具:
    立即打开谷歌搜索,查找Python代码中的任何查询。
  • 问候资源:
    为任何名字生成个性化问候语。

文件结构

.
├── google_mcp_server.py
└── requirement.txt

需求

  • Python 3.7+
  • MCP框架(必须提供 mcp.server.fastmcp)
  • 标准Python库: webbrowser, urllib.parse

安装

  1. 克隆存储库:

    git clone https://github.com/Dhineshkumar272005/MCP_Project_Google_Search.git
    cd MCP_Project_Google_Search
    
  2. 安装依赖项:

    pip install -r requirement.txt
    

    注:
    确保MCP框架可用。如果它是私有或自定义包,请按照您所在组织的安装说明进行操作。

在Claude Desktop中安装

{
  "mcpServers": {
    "google_mcp_server":{
      "command": "uv",
      "args": [
        "run",
        "--with",
        "mcp[cli]",
        "mcp",
        "run",
        "path\to\your\location\google_mcp_server.py"
      ]
    }
  }
}

注: 它应该放在 claude_desktop_config.json

用法

1.启动服务器

运行Python文件:

python google_mcp_server.py

2.可用工具

a.谷歌搜索工具

  • 功能: open_google_search(query: str)
  • 说明: 打开默认web浏览器,并对提供的查询执行Google搜索。
  • 例子:
    open_google_search("Python programming")
    
    这将打开您的浏览器:
    https://www.google.com/search?q=Python+programming

b.问候资源

  • 功能: get_greeting(name: str) -> str
  • 说明: 返回给定姓名的个性化问候语。
  • 例子:
    get_greeting("Alice")
    # Output: "Hello Alice!"
    

代码概述

  • fastmcp:使用名称“Google搜索”初始化MCP服务器。
  • @mcp.tool():Decorator将函数注册为MCP工具。
  • @mcp.resource():Decorator将函数注册为MCP资源。

故障排除

  • 模块故障:
    如果您看到以下错误 mcp.server.fastmcp,确保MCP框架已安装并可在Python环境中访问。

  • Web浏览器未打开:
    这 webbrowser.open() 函数使用系统的默认浏览器。如果什么都没有发生,请检查系统的浏览器设置。

  • Decorators中的拼写错误:
    确保您使用 @mcp.resource (不是 @mcp.reseource)以及所有导入和类名的正确大小写。

贡献

欢迎拉取请求!对于重大更改,请先打开一个问题来讨论您想要更改的内容。

许可证

麻省理工学院 (或在此处指定您的许可证)