Brave搜索MCP服务器

为Brave搜索实现的模型上下文协议(MCP)服务器,支持与Claude等AI助手集成,提供网页搜索和本地商业搜索功能。

  • by thomasvan
  • Python
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 thomasvan/mcp-brave-search

使用说明

Brave Search MCP服务器

该项目为Brave Search实现了一个模型上下文协议(MCP)服务器,允许与Claude等人工智能助手集成。

先决条件

  • Python 3.11+
  • 紫外线 -一个快速的Python包安装程序和解析器

安装

通过Smithery安装

通过以下方式自动为Claude Desktop安装Brave Search MCP服务器 史密瑟里:

npx -y @smithery/cli install @thomasvan/mcp-brave-search --client claude

手动安装

  1. 克隆存储库:

    git clone https://github.com/thomasvan/mcp-brave-search.git
    cd mcp-brave-search
    
  2. 使用uv创建虚拟环境并安装依赖项:

    uv venv
    source .venv/bin/activate  # On Windows, use: .venv\Scripts\activate
    uv pip install -r requirements.txt
    
  3. 设置Brave Search API密钥:

    export BRAVE_API_KEY=your_api_key_here
    

    在Windows上,使用: set BRAVE_API_KEY=your_api_key_here

用法

  1. 配置您的MCP设置文件(例如。, claude_desktop_config.json)包括Brave Search MCP服务器:

    {
      "mcpServers": {
        "brave-search": {
          "command": "uv",
          "args": [
            "--directory",
            "path-to\\mcp-python\\mcp-brave-search\\src",
            "run",
            "server.py"
          ],
          "env": {
            "BRAVE_API_KEY": "YOUR_BRAVE_API_KEY_HERE"
          }
        }
      }
    }
    

    替换 YOUR_BRAVE_API_KEY_HERE 使用您的Brave API密钥。

  2. 使用更新的配置运行兼容MCP的AI助手,启动Brave Search MCP服务器。

  3. 服务器现在将运行并准备接受来自MCP客户端的请求。

  4. 现在,您可以通过调用可用工具在MCP兼容的AI助手(如Claude)中使用Brave搜索功能。

可用工具

服务器提供两个主要工具:

  1. brave_web_search:使用Brave search API执行web搜索。
  2. brave_local_search:搜索当地企业和地点。

请参阅中的工具文档字符串 src/server.py 了解详细的使用信息。

发展

要更改项目,请执行以下操作:

  1. 修改代码 src 目录根据需要。
  2. 更新 requirements.txt 如果添加或删除依赖项,请使用文件:
    uv pip freeze > requirements.txt
    
  3. 重新启动服务器以应用更改。

测试

该项目包括单元测试和集成测试:

安装测试依赖项

uv pip install pytest pytest-asyncio pytest-cov

运行单元测试

单元测试可以在没有API密钥的情况下运行,并使用模拟来模拟API响应:

# Run all unit tests
python -m pytest tests/unit/

# Run with verbose output
python -m pytest tests/unit/ -v

运行集成测试

集成测试需要一个有效的Brave API密钥,并进行真正的API调用:

# Run integration tests with your API key
BRAVE_API_KEY_INTEGRATION="your_api_key_here" python -m pytest tests/integration/ -v

测试覆盖率

检查测试覆盖率:

python -m pytest --cov=src/mcp_brave_search

故障排除

如果您遇到任何问题:

  1. 确保Brave API密钥设置正确。
  2. 检查是否安装了所有依赖项。
  3. 验证您使用的是兼容的Python版本。
  4. 如果对代码进行了更改,请确保重新启动服务器。

许可证

此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。