# 注册 MCP OAuth 客户端

向授权服务登记回调地址、客户端认证方式及支持的授权类型。

POST `/oauth/register`

- **认证** 公开，无需登录。
- **成功状态** `201`

## 请求参数

| 参数 | 类型 | 位置 | 必填 | 说明 |
| --- | --- | --- | --- | --- |
| `client_name` | string | `body` | 否 | 最多 60 个字符。缺省时使用第一个回调地址的主机名。 |
| `redirect_uris` | URI\[\] | `body` | 是 | 1–10 个不同的 HTTPS 或回环 HTTP 地址，每项最多 1,024 个字符。 |
| `token_endpoint_auth_method` | none \| client\_secret\_basic \| client\_secret\_post | `body` | 否 | 缺省为 client\_secret\_basic。公开客户端使用 none。 |
| `grant_types` | string\[\] | `body` | 否 | 必须包含 authorization\_code，可选 refresh\_token。默认两者都有。 |
| `response_types` | string\[\] | `body` | 否 | 使用 \["code"\]，也是默认值。 |
| `scope` | mcp:tools | `body` | 否 | 接受 mcp:tools 范围。 |

## 请求示例

**cURL**

```bash
curl -i -X POST 'https://social2api.com/oauth/register' \
  -H 'Content-Type: application/json' \
  --data-binary '{
  "client_name": "Example client",
  "redirect_uris": [
    "https://example.com/oauth/callback"
  ],
  "token_endpoint_auth_method": "none",
  "grant_types": [
    "authorization_code",
    "refresh_token"
  ],
  "scope": "mcp:tools"
}'
```

**Python**

```python
from urllib.error import HTTPError
from urllib.request import Request, urlopen

request = Request(
    "https://social2api.com/oauth/register",
    method="POST",
    headers={
        "Content-Type": "application/json",
    },
    data="{\"client_name\":\"Example client\",\"redirect_uris\":[\"https://example.com/oauth/callback\"],\"token_endpoint_auth_method\":\"none\",\"grant_types\":[\"authorization_code\",\"refresh_token\"],\"scope\":\"mcp:tools\"}".encode("utf-8"),
)
send = urlopen
try:
    with send(request) as response:
        print(response.status, response.read().decode("utf-8"))
except HTTPError as error:
    print(error.code, error.read().decode("utf-8"))
```

**JavaScript**

```javascript
const response = await fetch("/oauth/register", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "client_name": "Example client",
    "redirect_uris": [
      "https://example.com/oauth/callback"
    ],
    "token_endpoint_auth_method": "none",
    "grant_types": [
      "authorization_code",
      "refresh_token"
    ],
    "scope": "mcp:tools"
  }),
});
console.log(response.status, await response.text());
```

## 响应

**201 · 示例响应**

```json
{
  "client_id": "client_4a5076aa-f9ab-46e6-b383-7b1374392dc4",
  "client_id_issued_at": 1768478400,
  "client_name": "Example client",
  "redirect_uris": [
    "https://example.com/oauth/callback"
  ],
  "token_endpoint_auth_method": "none",
  "grant_types": [
    "authorization_code",
    "refresh_token"
  ],
  "response_types": [
    "code"
  ],
  "scope": "mcp:tools"
}
```

**错误示例**

```json
{
  "error": "invalid_redirect_uri",
  "error_description": "Provide exact HTTPS or loopback redirect URIs."
}
```

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| `client_id` | string | 分配给客户端的标识。 |
| `client_id_issued_at` | integer | 客户端发放的 Unix 秒级时间戳。 |
| `client_secret` | string | 非公开客户端的密钥，仅创建时返回。 |
| `client_secret_expires_at` | integer | 存在密钥时返回，值 0 表示无到期时间。 |
| `client_name` | string | 客户端的显示名称。 |
| `redirect_uris` | URI\[\] | 已注册的回调地址。 |
| `token_endpoint_auth_method` | none \| client\_secret\_basic \| client\_secret\_post | 令牌接口的客户端认证方式。 |
| `grant_types` | string\[\] | 允许的授权类型。 |
| `response_types` | string\[\] | 允许的授权响应类型。 |
| `scope` | string | 此客户端可请求的授权范围。 |

## 错误状态

| HTTP | 原因与处理 |
| --- | --- |
| `400` | OAuth 请求、范围、资源或表单参数无效。 |
| `405` | 请求方法不受支持。 |
| `500` | 授权服务暂时不可用。 |
| `413` | 请求体超出 4,096 字节。 |
| `415` | 需要 application/json 请求体。 |
| `429` | 请求过多。等待 Retry-After 指定秒数后重试。 |

## 使用细节

-   JSON 请求体最多 4,096 字节。
-   动态注册按客户端 IP 限制为每分钟 20 次。使用返回的 client\_id 启动浏览器授权。

## 同组接口

-   [GET 检查数据源配置](<https://social2api.com/docs/api/status/>)
-   [POST 运行取数任务](<https://social2api.com/docs/api/run/>)
-   [POST 调用 MCP 服务](<https://social2api.com/docs/api/mcp/>)
-   [GET 读取 OAuth 授权服务元数据](<https://social2api.com/docs/api/oauth-server-metadata/>)
-   [GET 读取 OAuth 受保护资源元数据](<https://social2api.com/docs/api/oauth-resource-metadata/>)
-   [GET 读取 MCP 资源的 OAuth 元数据](<https://social2api.com/docs/api/oauth-mcp-metadata/>)
-   [GET 启动 MCP OAuth 授权](<https://social2api.com/docs/api/oauth-authorize-start/>)
-   [POST 提交 MCP OAuth 授权决定](<https://social2api.com/docs/api/oauth-authorize-consent/>)
-   [POST 兑换或刷新 MCP OAuth 令牌](<https://social2api.com/docs/api/oauth-token/>)

规范页面：<https://social2api.com/docs/api/oauth-register/>
