> 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) 安装。
{% endhint %}

### 使用 UV

安装 [**uv**](https://docs.astral.sh/uv/getting-started/installation/)，作为 npm 的替代方案。请参考 [**模型上下文协议快速入门指南**](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. 点击“Add Custom 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.
