> For the complete documentation index, see [llms.txt](https://developers.oxylabs.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.oxylabs.io/products/cn/web-scraper-api/solutions-for-ai-workflows/model-context-protocol-mcp.md).

# 模型上下文协议（MCP）

该 **模型上下文协议（MCP）** 与……集成 [**Oxylabs 的网页爬虫API**](https://oxylabs.io/products/scraper-api/web) 可提供结构化、适合 AI 使用的数据，针对大语言模型（LLM）工作流进行了优化。

MCP 可确保上下文、元数据和指令格式正确，使 Anthropic 的 Claude 等 LLM 能够有效解析并使用这些数据。

你可以轻松地将网页爬虫API MCP 集成用于：

* [**Claude Desktop**](#setup-with-claude-desktop)
* [**Claude Code**](#claude-code-cli-setup)
* [**Cursor**](#running-on-cursor)

{% hint style="success" %}
请访问 Oxylabs GitHub 仓库，查看 [与网页爬虫API的 MCP 集成](https://github.com/oxylabs/oxylabs-mcp).
{% endhint %}

## Claude Desktop 设置

{% hint style="warning" %}
开始之前，请确保你已 [**Claude Desktop**](https://claude.ai/download) 安装。&#x20;
{% endhint %}

### 使用 Smithery.ai

安装 [**Node.js 和 npm**](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) 命令行界面。如果你已经安装了它们，请运行以下命令将 npm 更新到最新版本：

```
npm install -g npm
```

要通过 [Smithery](https://smithery.ai/server/@oxylabs/oxylabs-mcp)自动为 Claude Desktop 安装 Oxylabs MCP 服务器，请运行此命令：

```
npx -y @smithery/cli install @oxylabs/oxylabs-mcp --client claude
```

在安装过程中，系统会提示你输入 API 用户名和密码。按要求输入这些凭据。

安装完成后，打开 Claude Desktop 并配置抓取器，即可开始使用 MCP 增强输出。

### 使用 UV

安装 [**uv**](https://docs.astral.sh/uv/getting-started/installation/)，作为 npm 的替代方案。请参阅 [**Model Context Protocol 快速入门指南**](https://modelcontextprotocol.io/quickstart/user) 以了解配置流程。

要将 MCP 服务器与 **Claude Desktop**集成，请更新 `claude_desktop_config.json` 文件如下：

```json
{
  "mcpServers": {
    "oxylabs_mcp": {
      "command": "uvx",
      "args": ["oxylabs-mcp"],
      "env": {
        "OXYLABS_USERNAME": "your_username",
        "OXYLABS_PASSWORD": "your_password"
      }
    }
  }
}
```

将 `your_username` 和 `your_password` 替换为你的 API 用户名和密码。

保存对配置文件的更改并重启 Claude Desktop，以确保更新后的设置生效。

## Claude Code CLI 设置

{% hint style="warning" %}
开始之前，请确保你已 [**Claude Code**](https://docs.anthropic.com/en/docs/claude-code) 安装。
{% endhint %}

Claude Code 内置了一个命令，可以直接从终端添加 MCP 服务器。根据你偏好的包管理器，选择以下一种设置方法。

### 使用 UV（推荐）

安装 [**uv**](https://docs.astral.sh/uv/getting-started/installation/) （如果还没有安装）。然后在终端中运行以下命令，将 Oxylabs MCP 服务器添加到 Claude Code：

```bash
claude mcp add oxylabs -- command uvx args oxylabs-mcp --env OXYLABS_USERNAME=your_username --env OXYLABS_PASSWORD=your_password
```

将 `your_username` 和 `your_password` 替换为你的 API 用户名和密码。

### 使用 NPM / NPX

安装 [**Node.js 和 npm**](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) （如果你还没有安装）。如果 `npm` 已安装，请确保它已更新到最新版本：

```bash
npm install -g npm
```

然后在终端中运行以下命令，将 Oxylabs MCP 服务器添加到 Claude Code：

```bash
claude mcp add oxylabs -- command npx args -y @oxylabs/oxylabs-mcp --env OXYLABS_USERNAME=your_username --env OXYLABS_PASSWORD=your_password
```

将 `your_username` 和 `your_password` 替换为你的 API 用户名和密码。

{% hint style="info" %}
**注意：** 如果你更喜欢手动编辑文件，Claude Code 会在以下位置查找其配置文件： `~/.config/claude/mcp.json` （在 Mac/Linux 上）或 `%USERPROFILE%.config\claude\mcp.json` （在 Windows 上）。该文件中的 JSON 结构与 Claude Desktop 使用的精确格式相同。
{% endhint %}

## 在 Cursor 中运行

配置 Cursor 注意：需要 Cursor 版本 0.46+

要在 Cursor 中配置 Oxylabs：<br>

1. 选择 Cursor → 设置 → Cursor 设置 → MCP 工具
2. 点击“添加自定义 MCP”
3. 添加以下配置：

```
{
  "mcpServers": {
    "oxylabs": {
      "command": "uvx",
      "args": ["oxylabs-mcp"],
      "env": {
        "OXYLABS_USERNAME": "your_username",
        "OXYLABS_PASSWORD": "your_password",
        "OXYLABS_AI_STUDIO_API_KEY": "your_ai_studio_api_key"
      }
    }
  }
}
```

将 `your_username` 和 `your_password` ，替换为你的 API 用户名和密码。另请将 `your_ai_studio_api_key` 替换为你的 Oxylabs AI Studio API 密钥。

添加配置后，刷新 MCP 服务器列表即可看到新工具。Composer Agent 会在适当时自动使用 Oxylabs，但你也可以通过描述你的网页爬取需求来明确请求它。通过 Command+L（Mac）访问 Composer，选择提交按钮旁边的“Agent”，然后输入你的查询。


---

# 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, and the optional `goal` query parameter:

```
GET https://developers.oxylabs.io/products/cn/web-scraper-api/solutions-for-ai-workflows/model-context-protocol-mcp.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
