返回 AiToEarn
mcp-connector.md
1 # AiToEarn MCP 连接器说明
2
3 AiToEarn 的内容生成(文案、图片、视频)与全平台发布能力通过 MCP 服务提供。
4 本插件在 DeepSeek Harness 内直接连接远端 Streamable HTTP 端点,使用 OAuth 2.1 授权。
5
6 ## 连接方式
7
8 - 插件加载 `cordis.patch.yml` 后,用配置里的 `url` 连接 MCP 端点:
9 - 国内站(默认):`https://aitoearn.cn/api/ai/agent/mcp`
10 - 海外站:`https://aitoearn.ai/api/ai/agent/mcp`
11 - 每次请求前从 `~/.aitoearn/oauth.json` 取访问令牌并加 `Authorization: Bearer`;
12 令牌临近过期时自动用刷新令牌续期,收到 401/403 时强制刷新并重试一次。
13 - 默认授权国内站。海外站在 `cordis.patch.yml` 写 `site: ai`,或登录时加 `--site ai`。两站授权不通用。
14
15 ## OAuth 授权
16
17 ```bash
18 # 市场安装:<profile> 与 dsh plugin --profile 相同,dsh web 一般是 web
19 ~/.dsh/profiles/<profile>/node_modules/.bin/aitoearn login
20
21 # 手工复制到 ~/.dsh/plugins 时
22 node ~/.dsh/plugins/dsh-plugin-aitoearn/scripts/aitoearn.mjs login
23 ```
24
25 登录默认打开 https://aitoearn.cn 。海外站加 `--site ai`,打开 https://aitoearn.ai 。
26
27 脚本按以下顺序工作:
28
29 1. 通过 MCP 端点的 `/.well-known/oauth-protected-resource` 与授权服务器的
30 `/.well-known/oauth-authorization-server` 自动发现端点。
31 2. 优先使用设备码流程(`device_authorization_endpoint`);否则在本地
32 `127.0.0.1` 起回调服务,走授权码 + PKCE(S256)。
33 3. 需要时用动态客户端注册(RFC 7591)获取 public client;也可用
34 `AITOEARN_OAUTH_CLIENT_ID` 指定已有客户端。
35 4. 令牌写入 `~/.aitoearn/oauth.json`(chmod 600),并立即调用一次
36 `tools/list` 验证。
37
38 其他子命令:
39
40 ```bash
41 ~/.dsh/profiles/<profile>/node_modules/.bin/aitoearn status
42 ~/.dsh/profiles/<profile>/node_modules/.bin/aitoearn refresh
43 ~/.dsh/profiles/<profile>/node_modules/.bin/aitoearn logout
44 ```
45
46 ## 无 OAuth 元数据时
47
48 如果部署尚未开启 OAuth(发现不到授权服务器),可用环境变量显式指定端点:
49
50 ```bash
51 AITOEARN_OAUTH_ISSUER=https://your-issuer.example.com \
52 AITOEARN_OAUTH_AUTHORIZE_URL=https://your-issuer.example.com/oauth/authorize \
53 AITOEARN_OAUTH_TOKEN_URL=https://your-issuer.example.com/oauth/token \
54 AITOEARN_OAUTH_REGISTRATION_URL=https://your-issuer.example.com/oauth/register \
55 AITOEARN_OAUTH_CLIENT_ID=your-public-client \
56 ~/.dsh/profiles/<profile>/node_modules/.bin/aitoearn login
57 ```
58
59 支持的环境变量:`AITOEARN_OAUTH_STORE`、`AITOEARN_OAUTH_ISSUER`、
60 `AITOEARN_OAUTH_AUTHORIZE_URL`、`AITOEARN_OAUTH_TOKEN_URL`、
61 `AITOEARN_OAUTH_REGISTRATION_URL`、`AITOEARN_OAUTH_DEVICE_AUTHORIZATION_URL`、
62 `AITOEARN_OAUTH_CLIENT_ID`、`AITOEARN_OAUTH_CLIENT_SECRET`、
63 `AITOEARN_OAUTH_SCOPE`、`AITOEARN_OAUTH_CALLBACK_PORT`、
64 `AITOEARN_OAUTH_OPEN_BROWSER=0`、`AITOEARN_MCP_URL`。
65
66 ## 故障排查
67
68 - 会话里看不到 aitoearn 工具:先运行 `status` 确认已授权,再新开一个会话;
69 插件也会在检测到 `oauth.json` 变化后自动重新同步工具。
70 - 调用返回 `-32001`:令牌缺失或过期。运行 `login` 重新授权;不要手工编辑令牌文件。
71 - 工具数量明显偏少或调用 401/403:重新执行 `aitoearn login`。国内站用 aitoearn.cn 账号,海外站加 `--site ai` 后用 aitoearn.ai 账号。两站授权不能混用。
72 - 授权脚本报“未发现 OAuth 授权服务器”:按上一节显式指定端点,或联系部署方开启 OAuth。
73
73 lines MARKDOWN