> For the complete documentation index, see [llms.txt](https://docs.console.zenlayer.com/test/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.console.zenlayer.com/test/compute/mcpg/web-search/brave.md).

# Brave

Brave Search 是 Brave 公司基于独立索引构建的搜索引擎服务，不依赖 Google 或 Bing 等第三方索引，具备较强的隐私保护特性。其 Search API 支持网页搜索、新闻搜索、图片搜索和视频搜索，适用于 AI 应用的数据检索场景。

## MCP 工具

### Web Search（网页搜索）

从独立的大型网页索引中搜索网页内容。

#### 参数

**Header 参数**

* `Authorization` (string, 可选): API KEY | 示例值：`Bearer {{YOUR_API_KEY}}`

**Body 参数**

* `q` (string, 必需): 用户搜索查询词，不能为空，最多 400 个字符、50 个词 | 示例值：`Brave Search`
* `country` (string, 可选): 搜索结果来源的 2 位国家代码 | 示例值：`US`
* `search_lang` (string, 可选): 搜索结果的 2 位或更多字符语言代码 | 示例值：`en`
* `ui_lang` (string, 可选): 响应中偏好的界面语言，格式通常为 `<语言代码>-<国家代码>` | 示例值：`en-US`
* `count` (integer, 可选): 返回的搜索结果数量，最大值为 20，实际数量可能少于请求值。仅适用于网页结果 | 默认值：`10`
* `offset` (integer, 可选): 从零开始的偏移量，用于跳过若干页结果，最大值为 9，与 `count` 配合使用实现分页 | 默认值：`0`
* `safesearch` (string, 可选): 过滤成人内容。可选值：`off`（不过滤）、`moderate`（过滤显式内容但保留成人域名）、`strict`（完全过滤成人内容）| 默认值：`moderate`
* `spellcheck` (boolean, 可选): 是否对查询进行拼写检查，启用后始终使用修正后的查询 | 默认值：`false`
* `freshness` (string, 可选): 按页面时间过滤结果。可选值：`pd`（24小时内）、`pw`（7天内）、`pm`（31天内）、`py`（365天内）、`YYYY-MM-DDtoYYYY-MM-DD`（自定义日期范围）
* `text_decorations` (boolean, 可选): 结果摘要中是否包含高亮等修饰标记 | 默认值：`false`
* `result_filter` (string\[], 可选): 逗号分隔的结果类型列表，可选值：`discussions`、`faq`、`infobox`、`news`、`query`、`summarizer`、`videos`、`web`、`locations`
* `units` (string, 可选): 计量单位。可选值：`metric`（公制）、`imperial`（英制）
* `extra_snippets` (boolean, 可选): 是否返回最多 5 条额外的摘要片段 | 默认值：`false`
* `summary` (boolean, 可选): 是否在网页搜索结果中启用摘要键生成（summarizer 功能所必需）| 默认值：`false`

### News Search（新闻搜索）

从独立的大型网页索引中搜索新闻内容。

#### 参数

**Header 参数**

* `Authorization` (string, 可选): API KEY | 示例值：`Bearer {{YOUR_API_KEY}}`

**Body 参数**

* `q` (string, 必需): 用户搜索查询词，不能为空，最多 400 个字符、50 个词 | 示例值：`machine learning`
* `country` (string, 可选): 搜索结果来源的 2 位国家代码，或使用 `ALL` 表示全球范围 | 示例值：`US`
* `search_lang` (string, 可选): 搜索结果的语言代码 | 示例值：`en`
* `ui_lang` (string, 可选): 响应中偏好的界面语言
* `safesearch` (string, 可选): 过滤成人内容。可选值：`off`、`moderate`、`strict` | 默认值：`moderate`
* `count` (integer, 可选): 返回的新闻结果数量，最大值为 50 | 默认值：`10`
* `offset` (integer, 可选): 跳过的结果页数，最大值为 9，与 `count` 配合分页 | 默认值：`0`
* `spellcheck` (boolean, 可选): 是否启用拼写检查 | 默认值：`false`
* `freshness` (string, 可选): 按时间过滤。可选值：`pd`（24小时）、`pw`（7天）、`pm`（31天）、`py`（365天）、`YYYY-MM-DDtoYYYY-MM-DD`（自定义范围）
* `extra_snippets` (boolean, 可选): 是否返回最多 5 条额外摘要片段 | 默认值：`false`

### Image Search（图片搜索）

从独立的大型图片索引中搜索图片。

#### 参数

**Header 参数**

* `Authorization` (string, 可选): API KEY | 示例值：`Bearer {{YOUR_API_KEY}}`

**Query 参数**

* `q` (string, 必需): 用户搜索查询词，不能为空，最多 400 个字符、50 个词 | 示例值：`mountain landscape`
* `country` (string, 可选): 结果来源的 2 位国家代码，或使用 `ALL` 表示全球 | 示例值：`US`
* `search_lang` (string, 可选): 搜索结果的语言代码 | 示例值：`en`
* `safesearch` (string, 可选): 内容过滤。可选值：`off`（仅过滤违法内容）、`strict`（过滤所有成人内容）| 默认值：`strict`
* `count` (integer, 可选): 返回结果数量，最大值为 200 | 默认值：`10`
* `spellcheck` (boolean, 可选): 是否启用拼写检查 | 默认值：`false`

### Video Search（视频搜索）

从独立的大型网页索引中搜索视频内容。

#### 参数

**Header 参数**

* `Authorization` (string, 可选): API KEY | 示例值：`Bearer {{YOUR_API_KEY}}`

**Body 参数**

* `q` (string, 必需): 用户搜索查询词，不能为空，最多 400 个字符、50 个词 | 示例值：`machine learning tutorial`
* `country` (string, 可选): 结果来源的 2 位国家代码，或使用 `ALL` 表示全球 | 示例值：`US`
* `search_lang` (string, 可选): 搜索结果的语言代码 | 示例值：`en`
* `ui_lang` (string, 可选): 响应中偏好的界面语言
* `safesearch` (string, 可选): 过滤成人内容。可选值：`off`、`moderate`、`strict` | 默认值：`moderate`
* `count` (integer, 可选): 返回结果数量，最大值为 50 | 默认值：`10`
* `offset` (integer, 可选): 跳过的结果页数，最大值为 9 | 默认值：`0`
* `spellcheck` (boolean, 可选): 是否启用拼写检查 | 默认值：`false`
* `freshness` (string, 可选): 按时间过滤。可选值：`pd`（24小时）、`pw`（7天）、`pm`（31天）、`py`（365天）、`YYYY-MM-DDtoYYYY-MM-DD`（自定义范围）

### MCP Cline 配置

此服务器需要通过您的 MCP 客户端进行配置。以下是不同环境下的示例：

需要替换你的租户ID和API Key（必需）

```
{
  "mcpServers": {
    "brave": {
      "type": "streamable_http",
      "url": "https://mcp.ecn.ai/{租户ID}/brave/mcp",
      "headers": {
        "Authorization": "Bearer 你的API Key"
      }
    }
  }
}
```

## API 接口

### Web Search（网页搜索）

#### 请求信息

* **Method**: POST
* **Endpoint**: `/brave/res/v1/web/search`

#### 请求参数

**Header 参数**

* `Authorization` (string, 可选): API KEY | 示例值：`Bearer {{YOUR_API_KEY}}`
* `Content-Type` (string, 必需): `application/json`

**Body 参数**

* `q` (string, 必需): 搜索查询词，最多 400 个字符、50 个词 | 示例值：`Brave Search`
* `country` (string, 可选): 2 位国家代码 | 示例值：`US`
* `search_lang` (string, 可选): 语言代码 | 示例值：`en`
* `ui_lang` (string, 可选): 界面语言代码 | 示例值：`en-US`
* `count` (integer, 可选): 返回结果数，最大 20 | 默认值：`10`
* `offset` (integer, 可选): 分页偏移量，最大 9 | 默认值：`0`
* `safesearch` (string, 可选): 内容过滤级别 | 可选值：`off`, `moderate`, `strict`
* `spellcheck` (boolean, 可选): 是否启用拼写检查 | 默认值：`false`
* `freshness` (string, 可选): 时间过滤 | 可选值：`pd`, `pw`, `pm`, `py`, `YYYY-MM-DDtoYYYY-MM-DD`
* `text_decorations` (boolean, 可选): 是否包含摘要修饰标记 | 默认值：`false`
* `result_filter` (string, 可选): 结果类型过滤，逗号分隔 | 可选值：`discussions`, `faq`, `infobox`, `news`, `query`, `summarizer`, `videos`, `web`, `locations`
* `extra_snippets` (boolean, 可选): 是否返回额外摘要片段 | 默认值：`false`
* `summary` (boolean, 可选): 是否启用摘要键生成 | 默认值：`false`

#### 返回响应

* **200 成功**
  * Content-Type：`application/json`

#### 请求示例

```bash
curl --location --request POST 'https://api.ecn.ai/brave/res/v1/web/search' \
	--header 'Content-Type: application/json' \
	--header 'Authorization: Bearer {{YOUR_API_KEY}}' \
	--data-raw '{
  "q": "Brave Search",
  "country": "US",
  "search_lang": "en",
  "count": 10
}'
```

#### 响应示例

```json
{
  "type": "search",
  "query": {
    "original": "Brave Search",
    "altered": "",
    "spellcheck_off": false,
    "show_strict_warning": false
  },
  "web": {
    "type": "search",
    "results": [
      {
        "title": "Brave Search",
        "url": "https://search.brave.com",
        "description": "Brave Search is a privacy-preserving search engine...",
        "age": "2024-01-15T00:00:00Z",
        "extra_snippets": []
      }
    ]
  }
}
```

### News Search（新闻搜索）

#### 请求信息

* **Method**: POST
* **Endpoint**: `/brave/res/v1/news/search`

#### 请求参数

**Header 参数**

* `Authorization` (string, 可选): API KEY | 示例值：`Bearer {{YOUR_API_KEY}}`
* `Content-Type` (string, 必需): `application/json`

**Body 参数**

* `q` (string, 必需): 搜索查询词 | 示例值：`machine learning`
* `country` (string, 可选): 2 位国家代码或 `ALL` | 示例值：`US`
* `search_lang` (string, 可选): 语言代码 | 示例值：`en`
* `safesearch` (string, 可选): 内容过滤级别 | 可选值：`off`, `moderate`, `strict`
* `count` (integer, 可选): 返回结果数，最大 50 | 默认值：`10`
* `offset` (integer, 可选): 分页偏移量，最大 9 | 默认值：`0`
* `freshness` (string, 可选): 时间过滤 | 可选值：`pd`, `pw`, `pm`, `py`, `YYYY-MM-DDtoYYYY-MM-DD`
* `extra_snippets` (boolean, 可选): 是否返回额外摘要片段 | 默认值：`false`

#### 返回响应

* **200 成功**
  * Content-Type：`application/json`

#### 请求示例

```bash
curl --location --request POST 'https://api.ecn.ai/brave/res/v1/news/search' \
	--header 'Content-Type: application/json' \
	--header 'Authorization: Bearer {{YOUR_API_KEY}}' \
	--data-raw '{
  "q": "machine learning",
  "country": "US",
  "search_lang": "en",
  "count": 20
}'
```

#### 响应示例

```json
{
  "type": "news",
  "query": {
    "original": "machine learning"
  },
  "results": [
    {
      "title": "Latest Advances in Machine Learning",
      "url": "https://example.com/ml-news",
      "description": "Researchers have developed...",
      "age": "2024-03-10T08:00:00Z",
      "source": "TechNews",
      "thumbnail": {
        "src": "https://example.com/thumbnail.jpg"
      }
    }
  ]
}
```

### Image Search（图片搜索）

#### 请求信息

* **Method**: GET
* **Endpoint**: `/brave/res/v1/images/search`

#### 请求参数

**Header 参数**

* `Authorization` (string, 可选): API KEY | 示例值：`Bearer {{YOUR_API_KEY}}`

**Query 参数**

* `q` (string, 必需): 搜索查询词 | 示例值：`mountain landscape`
* `country` (string, 可选): 2 位国家代码或 `ALL` | 示例值：`US`
* `search_lang` (string, 可选): 语言代码 | 示例值：`en`
* `safesearch` (string, 可选): 内容过滤 | 可选值：`off`, `strict`
* `count` (integer, 可选): 返回结果数，最大 200 | 默认值：`10`
* `spellcheck` (boolean, 可选): 是否启用拼写检查 | 默认值：`false`

#### 返回响应

* **200 成功**
  * Content-Type：`application/json`

#### 请求示例

```bash
curl --location --request GET 'https://api.ecn.ai/brave/res/v1/images/search?q=mountain+landscape&count=10' \
	--header 'Authorization: Bearer {{YOUR_API_KEY}}'
```

#### 响应示例

```json
{
  "type": "images",
  "query": {
    "original": "mountain landscape"
  },
  "results": [
    {
      "title": "Beautiful Mountain Landscape",
      "url": "https://example.com/image.jpg",
      "source": "https://example.com",
      "thumbnail": {
        "src": "https://example.com/thumb.jpg",
        "width": 200,
        "height": 150
      },
      "properties": {
        "url": "https://example.com/image.jpg",
        "width": 1920,
        "height": 1080,
        "format": "jpeg"
      }
    }
  ]
}
```

### Video Search（视频搜索）

#### 请求信息

* **Method**: POST
* **Endpoint**: `/brave/res/v1/videos/search`

#### 请求参数

**Header 参数**

* `Authorization` (string, 可选): API KEY | 示例值：`Bearer {{YOUR_API_KEY}}`
* `Content-Type` (string, 必需): `application/json`

**Body 参数**

* `q` (string, 必需): 搜索查询词 | 示例值：`machine learning tutorial`
* `country` (string, 可选): 2 位国家代码或 `ALL` | 示例值：`US`
* `search_lang` (string, 可选): 语言代码 | 示例值：`en`
* `safesearch` (string, 可选): 内容过滤级别 | 可选值：`off`, `moderate`, `strict`
* `count` (integer, 可选): 返回结果数，最大 50 | 默认值：`10`
* `offset` (integer, 可选): 分页偏移量，最大 9 | 默认值：`0`
* `freshness` (string, 可选): 时间过滤 | 可选值：`pd`, `pw`, `pm`, `py`, `YYYY-MM-DDtoYYYY-MM-DD`

#### 返回响应

* **200 成功**
  * Content-Type：`application/json`

#### 请求示例

```bash
curl --location --request POST 'https://api.ecn.ai/brave/res/v1/videos/search' \
	--header 'Content-Type: application/json' \
	--header 'Authorization: Bearer {{YOUR_API_KEY}}' \
	--data-raw '{
  "q": "machine learning tutorial",
  "country": "US",
  "search_lang": "en",
  "count": 20
}'
```

#### 响应示例

```json
{
  "type": "videos",
  "query": {
    "original": "machine learning tutorial"
  },
  "results": [
    {
      "title": "Machine Learning Tutorial for Beginners",
      "url": "https://www.youtube.com/watch?v=example",
      "description": "Learn machine learning from scratch...",
      "age": "2024-02-20T00:00:00Z",
      "publisher": "TechChannel",
      "thumbnail": {
        "src": "https://img.youtube.com/vi/example/hqdefault.jpg",
        "width": 480,
        "height": 360
      },
      "video": {
        "duration": "15:32",
        "views": 125000
      }
    }
  ]
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.console.zenlayer.com/test/compute/mcpg/web-search/brave.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
