# 查询当前凭证的组织、权限和可用操作

返回当前凭证所属的组织、scope、档位（access_level）和各操作是否可用。可用 operations 指定最多 20 个操作名过滤；available 只表示凭证和配置允许尝试，不保证分区或资源权限。

## 请求

```text
POST https://open.cli.im/api/v2/rpc/auth/getContext
```

| 项目 | 要求 |
|---|---|
| 最低权限 | 只读，见[权限档位](https://cli.im/open-api/openapi/v2/auth.md#org-policy) |
| 需要的 scope | 不需要，有效凭证即可 |
| 组织 Key | 可以调用 |

## 请求参数

请求体为 JSON。

| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| `detail` | string | 否 | 返回内容的详略：summary（默认）或 full。本接口始终返回完整的 capabilities 列表，这个参数不改变返回内容。可选值：`summary`、`full`。默认 `"summary"` |
| `operations` | string[] | 否 | 只返回这些操作的可用情况，传操作名（即 operationId），最多 20 个，不能重复；不传返回全部。至少 1 项。最多 20 项 |

## 请求示例

示例里的 ID、幂等键等换成实际值。

```bash
curl -sS -X POST 'https://open.cli.im/api/v2/rpc/auth/getContext' \
  -H "Authorization: Bearer ${CAOLIAO_API_KEY}" \
  -H 'Content-Type: application/json' \
  -d '{
  "operations": [
    "qrcodes_create",
    "qrcodes_delete"
  ]
}'
```

## 响应

成功时 HTTP 状态码为 200，顶层 `code` 为 `0`，结果在 `data` 里。失败时的返回见[错误码与调用额度](https://cli.im/open-api/openapi/v2/error-codes.md)和[业务错误码](https://cli.im/open-api/openapi/v2/error-catalog.md)。

| 字段 | 类型 | 一定返回 | 说明 |
|---|---|---|---|
| `data.organization` | object | 是 | 凭证所属组织 |
| `data.organization.id` | string | 是 | 组织 ID |
| `data.organization.name` | string | 是 | 组织名称 |
| `data.auth_type` | string | 是 | oauth 表示个人 API Key 或 OAuth 令牌；api_key 表示组织 Key。可选值：`oauth`、`api_key` |
| `data.user_id` | string | 是 | 凭证对应的成员 ID；组织 Key 为 null |
| `data.authorization_mode` | string | 是 | oauth_scoped 按 scope 授权；organization_full 组织 Key，不检查 scope。可选值：`oauth_scoped`、`organization_full` |
| `data.client_id` | string | 是 | 凭证的客户端标识；个人 API Key 为 pk: 开头 |
| `data.effective_scopes` | string[] | 是 | 当前凭证实际生效的 scope |
| `data.capabilities` | object[] | 是 | 各操作是否可用 |
| `data.capabilities[].operation` | string | 是 | 操作名，即各接口的 operationId |
| `data.capabilities[].required_scope` | string | 是 | 所需 scope；不需要 scope 时为 null |
| `data.capabilities[].required_scopes` | string[] | 否 | 需要多个 scope 时列出全部 |
| `data.capabilities[].available` | boolean | 是 | 当前凭证和配置是否允许调用。不代表分区、资源权限或额度一定满足 |
| `data.capabilities[].unavailable_reason` | string | 是 | 不可用的原因：scope_denied 缺少 scope；not_configured_or_disabled 未开放；org_content_access_disabled 组织的最高权限不允许；unknown_operation 未知操作。可用时为 null |
| `data.capabilities[].resource_check_required` | boolean | 是 | 调用时是否还要检查分区或资源权限 |
| `data.access_level` | string | 是 | 组织设置的最高权限档位。可选值：`read`、`write`、`full` |
| `data.content_access` | object | 是 | 由 access_level 得出的修改、删除范围 |
| `data.content_access.edit` | string | 是 | ai_created 只能修改通过接口创建的内容；all 可修改全部内容。可选值：`ai_created`、`all` |
| `data.content_access.delete` | string | 是 | none 不能删除；all 可以删除。可选值：`none`、`all` |
| `data.capability_scope` | string | 是 | capabilities 覆盖的范围，固定为 registered_mcp_operations |
| `data.notes` | string[] | 是 | 对结果的补充说明 |

### 响应示例

```json
{
  "code": 0,
  "message": "ok",
  "data": {
    "organization": {
      "id": "94910252",
      "name": "示例企业"
    },
    "auth_type": "oauth",
    "user_id": "831988",
    "authorization_mode": "oauth_scoped",
    "client_id": "pk:1024",
    "effective_scopes": [
      "assets.write",
      "qrcodes.read",
      "qrcodes.write",
      "records.read",
      "templates.read",
      "templates.write"
    ],
    "capabilities": [
      {
        "operation": "qrcodes_create",
        "required_scope": "qrcodes.write",
        "available": true,
        "unavailable_reason": null,
        "resource_check_required": true
      },
      {
        "operation": "qrcodes_delete",
        "required_scope": "qrcodes.write",
        "available": false,
        "unavailable_reason": "scope_denied",
        "resource_check_required": true,
        "required_scopes": [
          "qrcodes.write",
          "content.delete"
        ]
      }
    ],
    "access_level": "write",
    "content_access": {
      "edit": "ai_created",
      "delete": "none"
    },
    "capability_scope": "registered_mcp_operations",
    "notes": [
      "available 表示凭证和配置允许尝试，不保证分区或资源权限。"
    ]
  }
}
```

---

本页由 [openapi.json](https://cli.im/open-api/openapi/v2/overview.md#%E6%8E%A5%E5%8F%A3%E8%A7%84%E8%8C%83-openapi-json) 生成。全部接口见[接口清单](https://cli.im/open-api/openapi/v2/api-index.md)。
