> ## Documentation Index
> Fetch the complete documentation index at: https://cndoc-langchain.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 认证感知的工具响应

> 格式化工具响应以触发 OAuth 流程并自动恢复执行。

某些[工具](/langsmith/fleet/tools)需要用户授权（例如 Google、Slack、GitHub）。LangSmith Fleet 包含中间件，用于检测工具何时需要授权，并暂停运行，向用户显示明确的提示。用户完成授权后，相同的工具调用会自动重试。

## 请求授权的返回格式

如果工具检测到缺少授权，应返回一个包含以下字段的 JSON 字符串：

```json theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
{
  "auth_required": true,
  "auth_url": "https://auth.example.com/start",
  "auth_id": "opaque-tracking-id"
}
```

* `auth_required`：设置为 `true` 以表示需要中断。
* `auth_url`：用户应被重定向到的授权地址。
* `auth_id`：可选的关联 ID，用于跟踪认证会话。

当 Fleet 检测到此响应时，它会中断运行，向用户显示认证界面，并在授权完成后自动重试工具调用。

如果您希望自定义工具复用相同的“需要授权”中断和界面，请确保您的工具返回相同格式的 JSON。

<Note>
  仅返回此 JSON 作为工具的输出。避免包含额外文本或内容。Fleet 会解析响应以触发认证流程。
</Note>

***

<div className="source-links">
  <Callout icon="terminal-2">
    [将这些文档连接](/use-these-docs)到 Claude、VSCode 等，通过 MCP 获取实时答案。
  </Callout>

  <Callout icon="edit">
    [在 GitHub 上编辑此页面](https://github.com/langchain-ai/docs/edit/main/src/langsmith/fleet/auth-format.mdx) 或 [提交问题](https://github.com/langchain-ai/docs/issues/new/choose)。
  </Callout>
</div>
