> 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/help-center/cn/mian-xiang-llm-de-shu-ju/how-do-i-use-model-context-protocol-mcp-with-web-api.md).

# 如何将模型上下文协议（MCP）与 Web API 配合使用？

了解如何将 MCP 客户端连接到 Web API。

MCP 是可选的。你现有对 [Web API](https://developers.oxylabs.io/products/web-api) 的请求会继续正常工作，并且你可以在需要 AI 代理直接调用 Web API 时随时连接 MCP 服务器。

### **连接到 Oxylabs MCP 服务器**

远程 MCP 服务器由 Oxylabs 托管和维护，因此无需安装任何东西。

{% stepper %}
{% step %}
在仪表盘中创建一个 Web API 实例并复制其 API 密钥。
{% endstep %}

{% step %}
将你的 API 密钥添加到环境中：

{% code overflow="wrap" expandable="true" %}

```bash
export OXYLABS_WEB_API_KEY="your_api_key_here"
```

{% endcode %}
{% endstep %}

{% step %}
将服务器添加到你的 MCP 客户端。

{% tabs %}
{% tab title="Claude Code" icon="claude" %}

```bash
claude mcp add --transport http --scope user oxylabs-web-api \
  https://mcp.oxylabs.io/web-api-mcp \
  --header "Authorization: Bearer ${OXYLABS_WEB_API_KEY}"
```

{% endtab %}

{% tab title="ChatGPT/Codex" icon="openai" %}

```bash
codex mcp add oxylabs-web-api \
  --url https://mcp.oxylabs.io/web-api-mcp \
  --bearer-token-env-var OXYLABS_WEB_API_KEY
```

{% endtab %}

{% tab title="Cursor（以及其他）" icon="cursor" %}
对于任何支持带自定义标头的远程 MCP 服务器的客户端，添加服务器 URL 和一个 `Authorization` 标头到客户端的 MCP 配置中。对于 Cursor `mcp.json`:

```json
{
  "mcpServers": {
    "oxylabs-web-api": {
      "url": "https://mcp.oxylabs.io/web-api-mcp",
      "headers": {
        "Authorization": "Bearer ${env:OXYLABS_WEB_API_KEY}"
      }
    }
  }
}
```

字段名称在不同客户端之间可能不同——请查看你的客户端文档，了解如何添加带标头的远程 MCP 服务器。
{% endtab %}
{% endtabs %}
{% endstep %}
{% endstepper %}

{% hint style="info" %}
**注意：** 远程 MCP 可与支持带自定义标头的远程 MCP 服务器的客户端配合使用。仅支持 OAuth 登录的客户端，例如 claude.ai 网页界面中的自定义连接器，无法连接到它。如果你的客户端属于这一类，或者你更希望自己运行服务器，请使用 [自托管选项](https://developers.oxylabs.io/ai-workflows/mcp#option-2-self-hosted-mcp).
{% endhint %}

🧠 有关配置、自托管和完整工具列表，请参见 [MCP 服务器文档](https://developers.oxylabs.io/ai-workflows/mcp) 和 [GitHub](https://github.com/oxylabs/web-api-mcp).


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://developers.oxylabs.io/help-center/cn/mian-xiang-llm-de-shu-ju/how-do-i-use-model-context-protocol-mcp-with-web-api.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
