注册 MCP OAuth 客户端
向授权服务登记回调地址、客户端认证方式及支持的授权类型。
POST
/oauth/register请求参数
| 参数 | 类型 | 位置 | 必填 | 说明 |
|---|---|---|---|---|
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
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_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 启动浏览器授权。