创建 OAuth 会话
curl --request POST \
--url https://api.moonshot.cn/v1/vaults/{id}/oauth-sessions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"mcp_server_url": "https://example.invalid/mcp"
}
'import requests
url = "https://api.moonshot.cn/v1/vaults/{id}/oauth-sessions"
payload = { "mcp_server_url": "https://example.invalid/mcp" }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({mcp_server_url: 'https://example.invalid/mcp'})
};
fetch('https://api.moonshot.cn/v1/vaults/{id}/oauth-sessions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.moonshot.cn/v1/vaults/{id}/oauth-sessions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'mcp_server_url' => 'https://example.invalid/mcp'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.moonshot.cn/v1/vaults/{id}/oauth-sessions"
payload := strings.NewReader("{\n \"mcp_server_url\": \"https://example.invalid/mcp\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.moonshot.cn/v1/vaults/{id}/oauth-sessions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"mcp_server_url\": \"https://example.invalid/mcp\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.moonshot.cn/v1/vaults/{id}/oauth-sessions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"mcp_server_url\": \"https://example.invalid/mcp\"\n}"
response = http.request(request)
puts response.read_body{
"oauth_session_id": "voss_01h455vb4pex5vsknk084sn02q",
"authorize_url": "https://example.invalid/authorize",
"mcp_server_url": "https://example.invalid/mcp"
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}为一个 MCP 服务器发起 OAuth 授权流程,并返回需在浏览器中打开的 URL。完成授权会在凭据库(Vault)中创建一条 mcp_oauth 凭据。
- 省略
client时,会通过动态客户端注册自动注册一个客户端。client.scope会替换探测到的权限范围。 - 同一服务器已有进行中的授权流程时再次发起,返回该进行中的 OAuth 会话。同一服务器 URL 已有活跃凭据时返回 409
conflict_error——先归档该凭据再重新授权。 - 用
GET /v1/vaults/{id}/oauth-sessions/{session_id}轮询结果。
POST
/
v1
/
vaults
/
{id}
/
oauth-sessions
创建 OAuth 会话
curl --request POST \
--url https://api.moonshot.cn/v1/vaults/{id}/oauth-sessions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"mcp_server_url": "https://example.invalid/mcp"
}
'import requests
url = "https://api.moonshot.cn/v1/vaults/{id}/oauth-sessions"
payload = { "mcp_server_url": "https://example.invalid/mcp" }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({mcp_server_url: 'https://example.invalid/mcp'})
};
fetch('https://api.moonshot.cn/v1/vaults/{id}/oauth-sessions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.moonshot.cn/v1/vaults/{id}/oauth-sessions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'mcp_server_url' => 'https://example.invalid/mcp'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.moonshot.cn/v1/vaults/{id}/oauth-sessions"
payload := strings.NewReader("{\n \"mcp_server_url\": \"https://example.invalid/mcp\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.moonshot.cn/v1/vaults/{id}/oauth-sessions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"mcp_server_url\": \"https://example.invalid/mcp\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.moonshot.cn/v1/vaults/{id}/oauth-sessions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"mcp_server_url\": \"https://example.invalid/mcp\"\n}"
response = http.request(request)
puts response.read_body{
"oauth_session_id": "voss_01h455vb4pex5vsknk084sn02q",
"authorize_url": "https://example.invalid/authorize",
"mcp_server_url": "https://example.invalid/mcp"
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}{
"error": {
"type": "invalid_parameter_error",
"message": "<string>",
"param": "<string>",
"request_id": "<string>"
}
}路径参数
凭据库(Vault)ID。
Pattern:
^vlt_[0-9a-hjkmnp-tv-z]{26}$请求体
application/json
此页面对您有帮助吗?