> 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/integrations/cn/wang-ye-pa-chong-api-ji-cheng/model-context-protocol-mcp.md).

# 模型上下文协议（MCP）

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

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

你可以轻松使用网页爬虫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/integrations/cn/wang-ye-pa-chong-api-ji-cheng/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.
