注册 MCP OAuth 客户端

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

POST/oauth/register
认证
公开,无需登录。
成功状态
201

请求参数

参数类型位置必填说明
client_namestringbody否最多 60 个字符。缺省时使用第一个回调地址的主机名。
redirect_urisURI[]body是1–10 个不同的 HTTPS 或回环 HTTP 地址,每项最多 1,024 个字符。
token_endpoint_auth_methodnone | client_secret_basic | client_secret_postbody否缺省为 client_secret_basic。公开客户端使用 none。
grant_typesstring[]body否必须包含 authorization_code,可选 refresh_token。默认两者都有。
response_typesstring[]body否使用 ["code"],也是默认值。
scopemcp:toolsbody否接受 mcp:tools 范围。

请求示例

cURL
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
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
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 · 示例响应
{
  "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"
}
错误示例
{
  "error": "invalid_redirect_uri",
  "error_description": "Provide exact HTTPS or loopback redirect URIs."
}
字段类型说明
client_idstring分配给客户端的标识。
client_id_issued_atinteger客户端发放的 Unix 秒级时间戳。
client_secretstring非公开客户端的密钥,仅创建时返回。
client_secret_expires_atinteger存在密钥时返回,值 0 表示无到期时间。
client_namestring客户端的显示名称。
redirect_urisURI[]已注册的回调地址。
token_endpoint_auth_methodnone | client_secret_basic | client_secret_post令牌接口的客户端认证方式。
grant_typesstring[]允许的授权类型。
response_typesstring[]允许的授权响应类型。
scopestring此客户端可请求的授权范围。

错误状态

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

使用细节

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