> ## Documentation Index
> Fetch the complete documentation index at: https://glasser.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# 通过 MCP 接入

> 将 Glasser 连接到 AI 工具，并使用 Glasser 账号登录。

MCP 让 AI 工具直接使用 Glasser。连接账号后，即可在对话中搜索数据、查看价格并获取结果，无需安装 Glasser CLI。

## 选择 AI 工具

> [card] [Claude Code](https://glasser.ai/docs/zh/mcp-server/claude-code.md)
>
> 在终端中添加 Glasser，然后从 Claude Code 登录。

> [card] [Codex](https://glasser.ai/docs/zh/mcp-server/codex.md)
>
> 使用共享的 MCP 配置连接本机 Codex 客户端。

> [card] [Claude.ai](https://glasser.ai/docs/zh/mcp-server/claude.md)
>
> 连接网页版或桌面版 Claude，包括 Cowork。

> [card] [ChatGPT](https://glasser.ai/docs/zh/mcp-server/chatgpt.md)
>
> 将 Glasser 作为插件连接，在 ChatGPT 中使用付费数据。

> [card] [Manus](https://glasser.ai/docs/zh/mcp-server/manus.md)
>
> 连接 Glasser，在研究和报告中使用付费数据。

> [card] [Cursor](https://glasser.ai/docs/zh/mcp-server/cursor.md)
>
> 将 Glasser 添加到 Cursor，并为 Agent 启用。

> [card] [OpenCode](https://glasser.ai/docs/zh/mcp-server/opencode.md)
>
> 将 Glasser 添加到 OpenCode 配置，并在终端中登录。

> [card] [VS Code](https://glasser.ai/docs/zh/mcp-server/vscode.md)
>
> 将 Glasser 添加到 VS Code 中的 GitHub Copilot Chat。

> [card] [其他客户端](https://glasser.ai/docs/zh/mcp-server/other.md)
>
> 通过服务器 URL 连接，或使用已有的 Glasser API Key。

## 已熟悉客户端配置？

使用以下服务器 URL，并选择 OAuth 登录：

```text theme={null}
https://api.glasser.ai/mcp
```

登录 Glasser，选择客户端可以使用其余额的工作空间，然后点击 **Allow**。你可以在登录过程中创建账号和工作空间。如果客户端不支持 OAuth，按 [其他客户端](https://glasser.ai/docs/zh/mcp-server/other.md)中的说明使用 API Key 连接。

## 检查连接

向 AI 工具发送以下提示词：

```text wrap theme={null}
Suggest one small task I can try with Glasser. Check my available balance and mention any first-run reward returned. Explain what the task will do, then wait for me to choose it before a paid Run.
```

收到余额响应即表示连接正常，即使可用余额为零。此检查免费。如果可用余额不足以执行任务，请在 [Glasser 控制台](https://app.glasser.ai?locale=zh-CN)充值。

## 首次任务与奖励

配置完成后，Agent 会推荐一个小任务，并等待你选择，然后按工具的定价和授权规则发起付费 Run。如果你已经提出了任务， Agent 会继续处理该任务。

余额响应可能包含 `first_run_reward`，其中有 `amount_usd`、`expires_at` 和服务器根据当前奖励状态生成的 `description`。Agent 会使用你的语言，在推荐任务时转述该信息。如果没有该字段，就不会提及奖励。Agent 会复用配置时的余额响应，不会仅为查询奖励而额外调用。

## 管理访问权限

浏览器登录会在工作空间中创建名为 `MCP · <client>` 的 API Key。若要撤销客户端权限，请在 [API Key 页面](https://app.glasser.ai/keys?locale=zh-CN)撤销该 Key。仅在客户端中断开或移除 Glasser，不会撤销 API Key。

## 服务器地址

```
POST https://api.glasser.ai/mcp
```

使用 **Streamable HTTP**。通过浏览器登录认证，或在 `Authorization: Bearer` 请求头中发送 Glasser API Key。

> [accordion] 传输与认证详情
>
> 服务器无状态，并返回 JSON 响应。每个请求都包含 API Key，或可解析为工作空间 API Key 的 OAuth 访问令牌。
>
> OAuth 客户端通过 `401` 响应中 `WWW-Authenticate` 请求头的 `resource_metadata` 发现授权服务器。客户端只需服务器 URL 即可开始此流程。

## 工具

Glasser 提供七个工具。Agent 使用 `search` 发现接口，再通过 `inspect` 和 `run` 获取数据，无需为每个接口单独配置 MCP 工具。

| 工具 | 用途 |
| - | - |
| `search` | 查找当前 API Key 可运行的接口。 |
| `inspect` | 获取接口的输入 Schema、当前价格、版本和运行方式。 |
| `run` | 运行接口，必须提供 `idempotency_key`。 |
| `runs_get` | 读取 Run 状态、数据提供商响应和费用。 |
| `runs_list` | 按时间倒序分页查看 Run。 |
| `runs_stop` | 请求停止 Run；通过返回状态确认是否已停止。 |
| `balance` | 查看可用余额并确认连接正常。 |

## 付费操作规则

服务器向 Agent 提供以下规则，与 [Skill](https://glasser.ai/docs/zh/setup-skill.md) 向 CLI Agent 提供的规则一致：

* **优先使用已有连接。** 当现有 API Key 和集成无法满足需求时，再使用 Glasser。
* **付费前先检查。** 查看价格，从小规模请求开始，并在试探性、重复或批量运行前取得授权。
* **重试时使用同一个键。** 保留 `idempotency_key` 和执行参数，读取原 Run，避免再次扣费。
* **分别检查状态与费用。** 即使 Run 为 `COMPLETED`，也要检查 `provider_response` 和 `charge_usd`。

> [accordion] 重试与错误响应
>
> 重放的 MCP Run 包含 `replayed: true`。`charge_usd` 中的金额为精确的美元十进制字符串。数据提供商返回 404 时，Run 仍可能为 `COMPLETED`，并按接口的 `NO_RESULT` 规则计费。
>
> 数据提供商错误保留在 Run 的 `provider_response.http_status` 和 `provider_response.error` 中。即使工具结果没有 `isError` 标记，也要检查这些字段。完整错误正文通过 `runs_get` 获取；`runs_list` 只返回摘要。
>
> `insufficient_balance`、`rate_limited` 和 Policy 限制等可处理的拒绝会返回带 `isError` 的工具结果，不属于协议错误。遇到限流时，按 `retry_after_ms` 等待后再重试。

## 何时优先使用 CLI

对于 Claude Code、Codex、Cursor 等本地 Agent，推荐使用 [Skill](https://glasser.ai/docs/zh/setup-skill.md) 加 [CLI](https://glasser.ai/docs/zh/cli.md)。Skill 会引导配置，并提供工作规则。 Claude Chat 和 Cowork 的配置见[连接指南](https://glasser.ai/docs/zh/mcp-server/claude.md)。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.