Brave搜索MCP服务器

一个集成了Brave搜索API的MCP服务器实现,提供包括网页搜索、本地商家搜索、图像搜索、视频搜索、新闻搜索和AI驱动的摘要生成在内的全面搜索功能。

  • by Prakarann-Innovation
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 Prakarann-Innovation/internet-mcp-server

使用说明

Brave Search MCP 服务器

一个集成了Brave Search API的MCP服务器实现,提供包括网页搜索、本地商家搜索、图片搜索、视频搜索、新闻搜索以及AI驱动的摘要功能在内的全面搜索能力。该项目支持STDIO和HTTP传输方式,其中STDIO为默认模式。

移民

1.x 到 2.x

默认传输方式现在为STDIO

为了遵循已建立的MCP(可能是指某种通信协议或平台)规范,服务器现在默认使用STDIO(标准输入输出)。如果您希望继续使用HTTP,则需要设置 BRAVE_MCP_TRANSPORT 环境变量用于 http或者提供运行时参数 --transport http 在启动服务器时。

响应结构 brave_image_search

MCP服务器的1.x版本会返回base64编码的图像数据以及图像URL。这极大地减慢了响应速度,同时也无谓地消耗了会话上下文。2.x版本去除了base64编码数据,并返回了一个更接近原始Brave搜索API响应的响应对象。更新后的输出模式定义在 src/tools/images/schemas/output.ts.

工具

网页搜索(brave_web_search)

执行全面的网页搜索,提供丰富结果类型和高级筛选选项。

参数:

  • query (字符串,必填):搜索词(最多400个字符,50个单词)
  • country (字符串,可选):国家代码(默认:“US”)
  • search_lang (字符串,可选):搜索语言(默认:“en”)
  • ui_lang (字符串,可选):用户界面语言(默认:“en-US”)
  • count (数字,可选):每页显示的结果数(1-20,默认:10)
  • offset (数字,可选):分页偏移量(最大9,默认:0)
  • safesearch (字符串,可选):内容过滤(“关闭”,“中等”,“严格”,默认值:“中等”)
  • freshness (字符串,可选):时间过滤器(“pd”、“pw”、“pm”、“py”或日期范围)
  • text_decorations (布尔值,可选):是否包含高亮标记(默认:true)
  • spellcheck (布尔值,可选):启用拼写检查(默认:true)
  • result_filter (数组,可选):过滤结果类型(默认:["web", "query"])
  • goggles (数组,可选):自定义重排序定义
  • units (字符串,可选):测量单位(“公制”或“英制”)
  • extra_snippets (布尔值,可选):获取额外摘要(仅限专业版)
  • summary (布尔值,可选):为AI摘要功能启用摘要键生成

本地搜索(brave_local_search)

搜索本地商家和地点,获取包括评分、营业时间和AI生成描述在内的详细信息。

参数:

  • 与……相同 brave_web_search 带有自动位置过滤功能
  • 在结果过滤器中自动包含“web”和“locations”

注: 需要Pro计划才能启用完整的本地搜索功能,否则将回退到网页搜索。

视频搜索(brave_video_search)

搜索包含全面元数据和缩略图信息的视频。

参数:

  • query (字符串,必填):搜索词(最多400个字符,50个单词)
  • country (字符串,可选):国家代码(默认:“US”)
  • search_lang (字符串,可选):搜索语言(默认:“en”)
  • ui_lang (字符串,可选):用户界面语言(默认:“en-US”)
  • count (数字,可选):每页结果数(1-50,默认:20)
  • offset (数字,可选):分页偏移量(最大值为9,默认值:0)
  • spellcheck (布尔值,可选):启用拼写检查(默认:true)
  • safesearch (字符串,可选):内容过滤(“关闭”,“中等”,“严格”,默认:“中等”)
  • freshness (字符串,可选):时间过滤器("pd"(按天)、"pw"(按周)、"pm"(按月)、"py"(按年)或日期范围)

图像搜索(brave_image_search)

搜索图片并自动获取,使用base64编码以直接显示。

参数:

  • query (字符串,必填):搜索词(最多400个字符,50个单词)
  • country (字符串,可选):国家代码(默认:“US”)
  • search_lang (字符串,可选):搜索语言(默认:“en”)
  • count (数字,可选):每页结果数量(1-200,默认:50)
  • safesearch (字符串,可选):内容过滤(“关闭”,“严格”,默认:“严格”)
  • spellcheck (布尔值,可选):启用拼写检查(默认:true)

新闻搜索(brave_news_search)

搜索最新新闻文章,具备新鲜度控制和突发新闻标识。

参数:

  • query (字符串,必填):搜索词(最多400个字符,50个单词)
  • country (字符串,可选):国家代码(默认:“US”)
  • search_lang (字符串,可选):搜索语言(默认:“en”)
  • ui_lang (字符串,可选):用户界面语言(默认:“en-US”)
  • count (数字,可选):每页结果数(1-50,默认:20)
  • offset (数字,可选):分页偏移量(最大值为9,默认值:0)
  • spellcheck (布尔型,可选):启用拼写检查(默认:true)
  • safesearch (字符串,可选):内容过滤(“关闭”,“中等”,“严格”,默认:“中等”)
  • freshness (字符串,可选):时间过滤器(默认:“pd”表示过去24小时)
  • extra_snippets (布尔值,可选):获取额外摘录(仅限专业版计划)
  • goggles (数组,可选):自定义重排序定义

摘要搜索(brave_summarizer)

利用Brave的摘要生成API,从网页搜索结果中生成AI驱动的摘要。

参数:

  • key (字符串,必填):来自网页搜索结果的摘要关键词(使用 summary: true (在网页搜索中)
  • entity_info (布尔型,可选):是否包含实体信息(默认:false)
  • inline_references (布尔型,可选):添加源URL引用(默认:false)

用法: 首先使用(某个关键词或短语)进行网页搜索 summary: true然后,使用此工具返回的摘要密钥。

配置

获取API密钥

  1. 注册一个 Brave 搜索 API 账户
  2. 选择一个计划:
    • 免费每月2,000次查询,基础网页搜索
    • 专业版增强功能包括本地搜索、AI摘要、额外片段
  3. 根据上面的信息,执行如下指令:你是个专业的翻译,负责把英语内容翻译成中文内容,请帮我翻译一下原文内容 开发者仪表板

环境变量

服务器支持以下环境变量:

  • BRAVE_API_KEY您的Brave搜索API密钥(必填)
  • BRAVE_MCP_TRANSPORT传输模式(“http”或“stdio”,默认:“stdio”)
  • BRAVE_MCP_PORTHTTP服务器端口(默认:8080)
  • BRAVE_MCP_HOSTHTTP 服务器主机(默认:“0.0.0.0”)
  • BRAVE_MCP_LOG_LEVEL期望的日志级别(“debug”、“info”、“notice”、“warning”、“error”、“critical”、“alert”或“emergency”,默认值:“info”)
  • BRAVE_MCP_ENABLED_TOOLS使用时,指定支持工具的白名单
  • BRAVE_MCP_DISABLED_TOOLS使用时,为支持的工具指定一个黑名单

命令行选项

node dist/index.js [options]

Options:
  --brave-api-key <string>    Brave API key
  --transport <stdio|http>    Transport type (default: stdio)
  --port <number>             HTTP server port (default: 8080)
  --host <string>             HTTP server host (default: 0.0.0.0)
  --logging-level <string>    Desired logging level (one of _debug_, _info_, _notice_, _warning_, _error_, _critical_, _alert_, or _emergency_)
  --enabled-tools             Tools whitelist (only the specified tools will be enabled)
  --disabled-tools            Tools blacklist (included tools will be disabled)

安装

通过Smithery进行安装

通过自动安装Brave Search “Smithery”可以翻译为“铁匠铺”或“锻造工坊”。这个词通常指的是一个进行金属加工,特别是锻造金属(如铁或钢)的场所:

npx -y @smithery/cli install brave

与Claude桌面版的使用

把这个加到你的(列表/计划/东西里) claude_desktop_config.json:

Docker

{
  "mcpServers": {
    "brave-search": {
      "command": "docker",
      "args": ["run", "-i", "--rm", "-e", "BRAVE_API_KEY", "docker.io/mcp/brave-search"],
      "env": {
        "BRAVE_API_KEY": "YOUR_API_KEY_HERE"
      }
    }
  }
}

NPX

{
  "mcpServers": {
    "brave-search": {
      "command": "npx",
      "args": ["-y", "@brave/brave-search-mcp-server", "--transport", "http"],
      "env": {
        "BRAVE_API_KEY": "YOUR_API_KEY_HERE"
      }
    }
  }
}

与 VS Code 的使用

为了快速安装,请使用下面的一键安装按钮:


对于手动安装,请将以下内容添加到您的用户设置(JSON)中或 .vscode/mcp.json:

Docker

{
  "inputs": [
    {
      "password": true,
      "id": "brave-api-key",
      "type": "promptString",
      "description": "Brave Search API Key",
    }
  ],
  "servers": {
    "brave-search": {
      "command": "docker",
      "args": ["run", "-i", "--rm", "-e", "BRAVE_API_KEY", "mcp/brave-search"],
      "env": {
        "BRAVE_API_KEY": "${input:brave-api-key}"
      }
    }
  }
}

NPX

{
  "inputs": [
    {
      "password": true,
      "id": "brave-api-key",
      "type": "promptString",
      "description": "Brave Search API Key",
    }
  ],
  "servers": {
    "brave-search-mcp-server": {
      "command": "npx",
      "args": ["-y", "@brave/brave-search-mcp-server", "--transport", "stdio"],
      "env": {
        "BRAVE_API_KEY": "${input:brave-api-key}"
      }
    }
  }
}

构建

Docker

docker build -t mcp/brave-search:latest .

本地构建

npm install
npm run build

发展

先决条件

  • Node.js 22.x 或更高版本
  • npm
  • Brave搜索API密钥

设置

  1. 克隆仓库:
git clone https://github.com/brave/brave-search-mcp-server.git
cd brave-search-mcp-server
  1. 安装依赖项:
npm install
  1. 构建项目:
npm run build

通过Claude桌面版进行测试

在本地构建中添加引用 claude_desktop_config.json:

{
  "mcpServers": {
    "brave-search-dev": {
      "command": "node",
      "args": ["C:\\GitHub\\brave-search-mcp-server\\dist\\index.js"], // Verify your path
      "env": {
        "BRAVE_API_KEY": "YOUR_API_KEY_HERE"
      }
    }
  }
}

通过MCP Inspector进行测试

  1. 构建并启动服务器:
npm run build
node dist/index.js
  1. 在另一个终端中,启动MCP Inspector:
npx @modelcontextprotocol/inspector node dist/index.js

STDIO 是默认模式。若要进行 HTTP 模式测试,请添加 --transport http 到检查器(Inspector)用户界面中的参数。

通过Smithery.AI进行测试

  1. 建立并获取smithery.ai账户和API密钥
  2. 跑 npm run install, npm run smithery:build,最后 npm run smithery:dev 开始测试

可用脚本

  • npm run build构建TypeScript项目

  • npm run watch监控变化并重新构建

  • npm run format使用 Prettier 格式化代码

  • npm run format:check检查代码格式

  • npm run prepare格式化和构建(在 npm install 时自动运行)

  • npm run inspector启动一个MCP Inspector实例

  • npm run inspector:stdio启动一个配置为STDIO的MCP Inspector实例

  • npm run smithery:build为smithery.ai构建项目

  • npm run smithery:dev启动smithery.ai的开发环境

Docker Compose

使用 Docker 进行本地开发:

docker-compose up --build

许可证

此MCP服务器遵循MIT许可证进行授权。这意味着您可以在遵守MIT许可证条款和条件的前提下,自由地使用、修改和分发该软件。如需更多详情,请参阅项目仓库中的LICENSE文件。