@scorehub/mcp-server 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +16 -6
- package/README.md +16 -6
- package/dist/index.js +12 -10
- package/dist/startup-check.d.ts +39 -0
- package/dist/startup-check.js +120 -0
- package/dist/status.d.ts +35 -0
- package/dist/status.js +42 -0
- package/package.json +1 -1
package/README.en.md
CHANGED
|
@@ -10,7 +10,7 @@ Chinese version: [README.md](./README.md)
|
|
|
10
10
|
|
|
11
11
|
## Overview
|
|
12
12
|
|
|
13
|
-
`@scorehub/mcp-server` runs on your computer between MCP clients such as
|
|
13
|
+
`@scorehub/mcp-server` runs on your computer between MCP clients such as WorkBuddy and Codex and the ScoreHub remote MCP server. It provides:
|
|
14
14
|
|
|
15
15
|
- **OAuth login**: Opens a browser for authorization when needed and caches ScoreHub tokens locally.
|
|
16
16
|
- **Token lifecycle management**: Checks token validity before calls, refreshes tokens within five minutes of expiry, and keeps long-running sessions alive every four hours.
|
|
@@ -19,7 +19,7 @@ Chinese version: [README.md](./README.md)
|
|
|
19
19
|
```
|
|
20
20
|
┌─────────────┐ stdio ┌──────────────────┐ Streamable HTTP ┌─────────────────┐
|
|
21
21
|
│ AI client │ ◄────────────► │ @scorehub/ │ ◄─────────────────► │ ScoreHub │
|
|
22
|
-
│
|
|
22
|
+
│ WorkBuddy etc│ │ mcp-server │ │ Remote MCP │
|
|
23
23
|
└─────────────┘ └──────────────────┘ └────────┬────────┘
|
|
24
24
|
│
|
|
25
25
|
TikTok Shop
|
|
@@ -59,12 +59,12 @@ Common configuration locations are:
|
|
|
59
59
|
|
|
60
60
|
| Client | Configuration file |
|
|
61
61
|
|---|---|
|
|
62
|
-
|
|
|
62
|
+
| Other MCP clients | The MCP configuration file used by that client |
|
|
63
63
|
| WorkBuddy | `mcp.json` |
|
|
64
64
|
|
|
65
65
|
On the first launch, `npx` downloads `@scorehub/mcp-server` and connects it to the remote endpoint. When you first call a remote tool, invoke `authorize` when prompted by your client. A browser opens the ScoreHub login page; after authorization it returns to a random `127.0.0.1` port and stores the token locally. Later calls reuse the cached token and do not require another login.
|
|
66
66
|
|
|
67
|
-
>
|
|
67
|
+
> After you install Tiky through the WorkBuddy share link, Tiky can run `npx -y @scorehub/creator-outreach@latest` when needed to complete the local bootstrap and write or repair this MCP configuration automatically. Manual editing is not required.
|
|
68
68
|
|
|
69
69
|
## Windows
|
|
70
70
|
|
|
@@ -76,7 +76,7 @@ Windows uses the same MCP JSON configuration as macOS and Linux. You do not need
|
|
|
76
76
|
4. Authorization uses PowerShell `Start-Process` to open your default browser, so OAuth URL parameters such as `redirect_uri` are preserved. If system policy blocks it, copy the authorization URL printed in the terminal and open it on the **same Windows computer that runs mcp-server**.
|
|
77
77
|
5. The callback always uses a random `127.0.0.1` port. Do not open the authorization URL on another computer. If local security software blocks the loopback callback, allow local loopback connections and try again.
|
|
78
78
|
|
|
79
|
-
If WorkBuddy uses its bundled Node.js, install through
|
|
79
|
+
If WorkBuddy uses its bundled Node.js, install Tiky through the share link first, then let Tiky run `npx -y @scorehub/creator-outreach@latest` to complete the local bootstrap. That flow handles `npx` / `npx.cmd` and PATH differences for each platform.
|
|
80
80
|
|
|
81
81
|
## Optional: Global Installation
|
|
82
82
|
|
|
@@ -131,7 +131,7 @@ By default, `authorize` reuses a valid access token or refresh token and does no
|
|
|
131
131
|
| Tool | Description |
|
|
132
132
|
|---|---|
|
|
133
133
|
| `authorize` | Checks ScoreHub OAuth. Use `force: true` to log in as another account or `switch_shop: true` to open the current account's shop picker. |
|
|
134
|
-
| `status` | Returns the
|
|
134
|
+
| `status` | Returns the local proxy version, runtime state, authorization state, remote-tool availability, current account/shop, and host-installation metadata. |
|
|
135
135
|
|
|
136
136
|
### Remote Tools
|
|
137
137
|
|
|
@@ -175,6 +175,16 @@ Local mcp-server ScoreHub Remote MCP
|
|
|
175
175
|
| Browser does not open automatically | Use the authorization URL printed in the terminal and complete the callback on the same machine that runs mcp-server. |
|
|
176
176
|
| The authorization page says the link is invalid, or the browser URL has no `redirect_uri` | Fully quit and restart WorkBuddy, and confirm `~/.workbuddy/mcp.json` still uses `npx -y @scorehub/mcp-server@latest`. Newer versions open the OAuth URL through PowerShell to avoid truncating query parameters. |
|
|
177
177
|
|
|
178
|
+
Key `status` fields:
|
|
179
|
+
|
|
180
|
+
- `server_version`: the local `@scorehub/mcp-server` version
|
|
181
|
+
- `local_state`:
|
|
182
|
+
- `running_ready`: the local proxy is running, authorized, and remote tools are available
|
|
183
|
+
- `running_unauthorized`: the local proxy is running but ScoreHub OAuth is not complete yet
|
|
184
|
+
- `running_authorized_remote_unavailable`: the local proxy is running and authorized, but remote tool discovery is temporarily unavailable
|
|
185
|
+
- `running_authorized_no_remote_tools`: the local proxy is running and authorized, but no remote tools are currently discovered and no explicit remote error was captured
|
|
186
|
+
- `config_source`: host and installation-source metadata. When it shows `client_host = "workbuddy"` and `managed_by = "@scorehub/creator-outreach"`, the configuration comes from Tiky's public WorkBuddy installation path; typically Tiky is first installed through the share link and then runs `npx -y @scorehub/creator-outreach@latest` to complete the local bootstrap
|
|
187
|
+
|
|
178
188
|
## FAQ
|
|
179
189
|
|
|
180
190
|
### Why do I need this package?
|
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ English version: [README.en.md](./README.en.md)
|
|
|
10
10
|
|
|
11
11
|
## 概览
|
|
12
12
|
|
|
13
|
-
`@scorehub/mcp-server` 运行在你的电脑上,位于
|
|
13
|
+
`@scorehub/mcp-server` 运行在你的电脑上,位于 WorkBuddy、Codex 等 MCP 客户端与 ScoreHub 远程 MCP 之间,负责:
|
|
14
14
|
|
|
15
15
|
- **账号与店铺切换**:`authorize(force=true)` 可重新登录切换账号;`authorize(switch_shop=true)` 可在当前账号下切换店铺,无需重新登录。
|
|
16
16
|
- **Token 生命周期**:调用前检查 Token 有效期;距过期不足 5 分钟时自动刷新,并为长会话每 4 小时主动保活一次。
|
|
@@ -19,7 +19,7 @@ English version: [README.en.md](./README.en.md)
|
|
|
19
19
|
```
|
|
20
20
|
┌─────────────┐ stdio ┌──────────────────┐ Streamable HTTP ┌─────────────────┐
|
|
21
21
|
│ AI 客户端 │ ◄────────────► │ @scorehub/ │ ◄─────────────────► │ ScoreHub │
|
|
22
|
-
│
|
|
22
|
+
│ WorkBuddy 等│ │ mcp-server │ │ 远程 MCP │
|
|
23
23
|
└─────────────┘ └──────────────────┘ └────────┬────────┘
|
|
24
24
|
│
|
|
25
25
|
TikTok Shop
|
|
@@ -59,12 +59,12 @@ npx --version
|
|
|
59
59
|
|
|
60
60
|
| 客户端 | 配置文件 |
|
|
61
61
|
|---|---|
|
|
62
|
-
|
|
|
62
|
+
| 其他 MCP 客户端 | 该客户端使用的 MCP 配置文件 |
|
|
63
63
|
| WorkBuddy | `mcp.json` |
|
|
64
64
|
|
|
65
65
|
首次启动时,`npx` 会下载 `@scorehub/mcp-server` 并连接远程端点。首次调用远程工具时,按客户端提示调用 `authorize`:浏览器会打开 ScoreHub 登录页,授权完成后回调到 `127.0.0.1` 的随机端口并写入本地 Token。之后会复用缓存,不需要每次登录。
|
|
66
66
|
|
|
67
|
-
>
|
|
67
|
+
> 通过 WorkBuddy 分享链接安装 Tiky 后,Tiky 会在需要时执行 `npx -y @scorehub/creator-outreach@latest` 完成本地引导,并自动写入或修复这份 MCP 配置;无需手动编辑。
|
|
68
68
|
|
|
69
69
|
## Windows 使用说明
|
|
70
70
|
|
|
@@ -76,7 +76,7 @@ Windows 与 macOS、Linux 使用同一份 MCP JSON 配置,不需要改成 `npx
|
|
|
76
76
|
4. 授权时会优先使用 `cmd.exe /c start` 打开默认浏览器。被系统策略拦截时,复制终端输出的授权 URL,在**运行 mcp-server 的同一台 Windows 电脑**上打开并完成授权。
|
|
77
77
|
5. 回调固定使用 `127.0.0.1` 随机端口。不要在另一台电脑打开授权 URL;本机安全软件若拦截回环回调,应允许本地回环连接后重试。
|
|
78
78
|
|
|
79
|
-
WorkBuddy 若使用其捆绑的 Node.js
|
|
79
|
+
WorkBuddy 若使用其捆绑的 Node.js,建议先通过分享链接安装 Tiky,再由 Tiky 执行 `npx -y @scorehub/creator-outreach@latest` 完成本地引导;该流程会按平台处理 `npx` / `npx.cmd` 与 PATH。
|
|
80
80
|
|
|
81
81
|
## 可选:全局安装
|
|
82
82
|
|
|
@@ -131,7 +131,7 @@ Token 持久化在本机文件中;调用默认 ScoreHub 生产端点时,mcp-
|
|
|
131
131
|
| 工具 | 说明 |
|
|
132
132
|
|---|---|
|
|
133
133
|
| `authorize` | 检查 ScoreHub OAuth 状态;`force: true` 重新登录以切换账号,`switch_shop: true` 打开当前账号的店铺选择页。 |
|
|
134
|
-
| `status` |
|
|
134
|
+
| `status` | 返回本地代理版本、运行状态、授权状态、远端工具可用性、当前账号/店铺和宿主安装来源元数据。 |
|
|
135
135
|
|
|
136
136
|
### 远程工具
|
|
137
137
|
|
|
@@ -175,6 +175,16 @@ Token 持久化在本机文件中;调用默认 ScoreHub 生产端点时,mcp-
|
|
|
175
175
|
| 浏览器无法自动打开 | 使用终端输出的授权 URL,并在运行 mcp-server 的同一台机器上完成回调。 |
|
|
176
176
|
| Windows 授权页提示授权链接无效,或浏览器地址栏缺少 `redirect_uri` | 完全退出并重启 WorkBuddy,确认 `~/.workbuddy/mcp.json` 仍使用 `npx -y @scorehub/mcp-server@latest`;新版会通过 PowerShell 打开授权 URL,避免 `cmd.exe start` 截断带 `&` 的参数。 |
|
|
177
177
|
|
|
178
|
+
`status` 的关键字段说明:
|
|
179
|
+
|
|
180
|
+
- `server_version`:当前本地 `@scorehub/mcp-server` 版本
|
|
181
|
+
- `local_state`:
|
|
182
|
+
- `running_ready`:本地代理已启动、已授权,且远端工具可用
|
|
183
|
+
- `running_unauthorized`:本地代理已启动,但尚未完成 ScoreHub OAuth
|
|
184
|
+
- `running_authorized_remote_unavailable`:本地代理已启动且已授权,但远端工具发现暂时不可用
|
|
185
|
+
- `running_authorized_no_remote_tools`:本地代理已启动且已授权,但当前尚未发现远端工具,且没有明确抓到远端错误
|
|
186
|
+
- `config_source`:宿主与安装来源元数据。若显示 `client_host = "workbuddy"` 且 `managed_by = "@scorehub/creator-outreach"`,表示当前配置来自 Tiky 的 WorkBuddy 公开安装路径;通常先由分享链接把 Tiky 装入 WorkBuddy,再由 Tiky 执行 `npx -y @scorehub/creator-outreach@latest` 完成本地引导
|
|
187
|
+
|
|
178
188
|
## 常见问题
|
|
179
189
|
|
|
180
190
|
### 为什么需要这个包?
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
5
5
|
* ScoreHub MCP Server — Local MCP Proxy
|
|
6
6
|
*
|
|
7
7
|
* Architecture (mirrors @lessie/mcp-server):
|
|
8
|
-
* Agent (WorkBuddy/
|
|
8
|
+
* Agent (WorkBuddy/other MCP client) ──stdio── Local MCP Server ──Streamable HTTP── Remote MCP Server
|
|
9
9
|
*
|
|
10
10
|
* The local server handles:
|
|
11
11
|
* 1. OAuth 2.1 Authorization Code + PKCE — browser-based login to ScoreHub
|
|
@@ -45,6 +45,7 @@ function endpointTokenKey(baseUrl) {
|
|
|
45
45
|
}
|
|
46
46
|
// ── Auth State ──────────────────────────────────────────────
|
|
47
47
|
const auth_js_1 = require("./auth.js");
|
|
48
|
+
const status_js_1 = require("./status.js");
|
|
48
49
|
const TOKEN_STORE_KEY = endpointTokenKey(SCOREHUB_BASE_URL);
|
|
49
50
|
const CLIENT_ID = "scorehub-mcp";
|
|
50
51
|
// Proactively refresh token every 4 hours to prevent expiry during long sessions
|
|
@@ -292,19 +293,20 @@ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
|
292
293
|
case "status": {
|
|
293
294
|
const tokenResult = await (0, auth_js_1.getValidAccessToken)(TOKEN_STORE_KEY, TOKEN_ENDPOINT, CLIENT_ID);
|
|
294
295
|
const tokenStore = (0, auth_js_1.loadTokens)(TOKEN_STORE_KEY);
|
|
296
|
+
const payload = (0, status_js_1.buildStatusPayload)({
|
|
297
|
+
serverVersion: SERVER_VERSION,
|
|
298
|
+
remoteUrl: REMOTE_MCP_URL,
|
|
299
|
+
tokenStoreKey: TOKEN_STORE_KEY,
|
|
300
|
+
tokenResult,
|
|
301
|
+
tokenStore,
|
|
302
|
+
remoteToolsCount: remoteTools.length,
|
|
303
|
+
lastFetchError,
|
|
304
|
+
});
|
|
295
305
|
return {
|
|
296
306
|
content: [
|
|
297
307
|
{
|
|
298
308
|
type: "text",
|
|
299
|
-
text: JSON.stringify(
|
|
300
|
-
remote_url: REMOTE_MCP_URL,
|
|
301
|
-
token_store_key: TOKEN_STORE_KEY,
|
|
302
|
-
authorized: !!tokenResult,
|
|
303
|
-
...(tokenStore?.account ? { account: tokenStore.account } : {}),
|
|
304
|
-
...(tokenStore?.selected_shop ? { selected_shop: tokenStore.selected_shop } : {}),
|
|
305
|
-
tools_count: remoteTools.length,
|
|
306
|
-
...(lastFetchError ? { error: lastFetchError } : {}),
|
|
307
|
-
}, null, 2),
|
|
309
|
+
text: JSON.stringify(payload, null, 2),
|
|
308
310
|
},
|
|
309
311
|
],
|
|
310
312
|
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export declare const VERSION_CACHE_TTL_MS: number;
|
|
2
|
+
export declare const VERSION_REQUEST_TIMEOUT_MS = 3000;
|
|
3
|
+
export type StartupCheckStatus = "ready" | "restart_required" | "migration_required" | "verification_unavailable";
|
|
4
|
+
export interface LatestVersions {
|
|
5
|
+
creatorOutreach?: string;
|
|
6
|
+
mcpServer?: string;
|
|
7
|
+
checkedAt: string;
|
|
8
|
+
error?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface StartupCheckResult {
|
|
11
|
+
status: StartupCheckStatus;
|
|
12
|
+
creator_outreach: {
|
|
13
|
+
agent_version: string;
|
|
14
|
+
bootstrap_version: string | null;
|
|
15
|
+
latest_version: string | null;
|
|
16
|
+
};
|
|
17
|
+
mcp_server: {
|
|
18
|
+
running_version: string;
|
|
19
|
+
latest_version: string | null;
|
|
20
|
+
};
|
|
21
|
+
checked_at: string;
|
|
22
|
+
message: string;
|
|
23
|
+
}
|
|
24
|
+
interface GetLatestVersionsOptions {
|
|
25
|
+
registryUrl?: string;
|
|
26
|
+
fetchImpl?: typeof fetch;
|
|
27
|
+
now?: () => number;
|
|
28
|
+
timeoutMs?: number;
|
|
29
|
+
}
|
|
30
|
+
interface EvaluateStartupCheckOptions {
|
|
31
|
+
agentVersion: string;
|
|
32
|
+
bootstrapVersion?: string;
|
|
33
|
+
mcpServerVersion: string;
|
|
34
|
+
latestVersions: LatestVersions;
|
|
35
|
+
}
|
|
36
|
+
export declare function getLatestVersions({ registryUrl, fetchImpl, now, timeoutMs, }?: GetLatestVersionsOptions): Promise<LatestVersions>;
|
|
37
|
+
export declare function evaluateStartupCheck({ agentVersion, bootstrapVersion, mcpServerVersion, latestVersions, }: EvaluateStartupCheckOptions): StartupCheckResult;
|
|
38
|
+
export declare function resetVersionCacheForTests(): void;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VERSION_REQUEST_TIMEOUT_MS = exports.VERSION_CACHE_TTL_MS = void 0;
|
|
4
|
+
exports.getLatestVersions = getLatestVersions;
|
|
5
|
+
exports.evaluateStartupCheck = evaluateStartupCheck;
|
|
6
|
+
exports.resetVersionCacheForTests = resetVersionCacheForTests;
|
|
7
|
+
const DEFAULT_NPM_REGISTRY = "https://registry.npmjs.org";
|
|
8
|
+
exports.VERSION_CACHE_TTL_MS = 15 * 60 * 1000;
|
|
9
|
+
exports.VERSION_REQUEST_TIMEOUT_MS = 3000;
|
|
10
|
+
const CREATOR_OUTREACH_PACKAGE = "@scorehub/creator-outreach";
|
|
11
|
+
const MCP_SERVER_PACKAGE = "@scorehub/mcp-server";
|
|
12
|
+
let versionCache = null;
|
|
13
|
+
function normalizeRegistryUrl(value) {
|
|
14
|
+
const registry = (value || DEFAULT_NPM_REGISTRY).trim();
|
|
15
|
+
return registry.endsWith("/") ? registry : `${registry}/`;
|
|
16
|
+
}
|
|
17
|
+
async function fetchPackageVersion(packageName, registryUrl, fetchImpl, timeoutMs) {
|
|
18
|
+
const controller = new AbortController();
|
|
19
|
+
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
20
|
+
timeout.unref?.();
|
|
21
|
+
try {
|
|
22
|
+
const url = new URL(`${encodeURIComponent(packageName)}/latest`, registryUrl);
|
|
23
|
+
const response = await fetchImpl(url, {
|
|
24
|
+
headers: { accept: "application/json" },
|
|
25
|
+
signal: controller.signal,
|
|
26
|
+
});
|
|
27
|
+
if (!response.ok) {
|
|
28
|
+
throw new Error(`${packageName} returned HTTP ${response.status}`);
|
|
29
|
+
}
|
|
30
|
+
const payload = await response.json();
|
|
31
|
+
if (typeof payload.version !== "string" || payload.version.trim() === "") {
|
|
32
|
+
throw new Error(`${packageName} latest metadata did not include a version`);
|
|
33
|
+
}
|
|
34
|
+
return payload.version.trim();
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
clearTimeout(timeout);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async function getLatestVersions({ registryUrl = process.env.npm_config_registry, fetchImpl = fetch, now = Date.now, timeoutMs = exports.VERSION_REQUEST_TIMEOUT_MS, } = {}) {
|
|
41
|
+
const nowMs = now();
|
|
42
|
+
if (versionCache && versionCache.expiresAt > nowMs) {
|
|
43
|
+
return versionCache.value;
|
|
44
|
+
}
|
|
45
|
+
const checkedAt = new Date(nowMs).toISOString();
|
|
46
|
+
const normalizedRegistry = normalizeRegistryUrl(registryUrl);
|
|
47
|
+
const [creatorResult, mcpResult] = await Promise.allSettled([
|
|
48
|
+
fetchPackageVersion(CREATOR_OUTREACH_PACKAGE, normalizedRegistry, fetchImpl, timeoutMs),
|
|
49
|
+
fetchPackageVersion(MCP_SERVER_PACKAGE, normalizedRegistry, fetchImpl, timeoutMs),
|
|
50
|
+
]);
|
|
51
|
+
const errors = [];
|
|
52
|
+
const value = { checkedAt };
|
|
53
|
+
if (creatorResult.status === "fulfilled") {
|
|
54
|
+
value.creatorOutreach = creatorResult.value;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
errors.push(`creator-outreach: ${String(creatorResult.reason)}`);
|
|
58
|
+
}
|
|
59
|
+
if (mcpResult.status === "fulfilled") {
|
|
60
|
+
value.mcpServer = mcpResult.value;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
errors.push(`mcp-server: ${String(mcpResult.reason)}`);
|
|
64
|
+
}
|
|
65
|
+
if (errors.length > 0) {
|
|
66
|
+
value.error = errors.join("; ");
|
|
67
|
+
}
|
|
68
|
+
versionCache = {
|
|
69
|
+
expiresAt: nowMs + exports.VERSION_CACHE_TTL_MS,
|
|
70
|
+
value,
|
|
71
|
+
};
|
|
72
|
+
return value;
|
|
73
|
+
}
|
|
74
|
+
function evaluateStartupCheck({ agentVersion, bootstrapVersion, mcpServerVersion, latestVersions, }) {
|
|
75
|
+
const result = {
|
|
76
|
+
creator_outreach: {
|
|
77
|
+
agent_version: agentVersion,
|
|
78
|
+
bootstrap_version: bootstrapVersion || null,
|
|
79
|
+
latest_version: latestVersions.creatorOutreach || null,
|
|
80
|
+
},
|
|
81
|
+
mcp_server: {
|
|
82
|
+
running_version: mcpServerVersion,
|
|
83
|
+
latest_version: latestVersions.mcpServer || null,
|
|
84
|
+
},
|
|
85
|
+
checked_at: latestVersions.checkedAt,
|
|
86
|
+
};
|
|
87
|
+
if (!bootstrapVersion) {
|
|
88
|
+
return {
|
|
89
|
+
status: "migration_required",
|
|
90
|
+
...result,
|
|
91
|
+
message: "当前仍在使用旧版 MCP 启动配置。请执行一次 npx -y @scorehub/creator-outreach@latest,然后完全退出并重新打开客户端。",
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
if (agentVersion !== bootstrapVersion
|
|
95
|
+
|| (latestVersions.creatorOutreach && bootstrapVersion !== latestVersions.creatorOutreach)
|
|
96
|
+
|| (latestVersions.mcpServer && mcpServerVersion !== latestVersions.mcpServer)) {
|
|
97
|
+
return {
|
|
98
|
+
status: "restart_required",
|
|
99
|
+
...result,
|
|
100
|
+
message: "检测到 Tiky 配置或 ScoreHub MCP 版本已变化。请完全退出并重新打开客户端,以加载已刷新的版本。",
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
if (latestVersions.error
|
|
104
|
+
|| !latestVersions.creatorOutreach
|
|
105
|
+
|| !latestVersions.mcpServer) {
|
|
106
|
+
return {
|
|
107
|
+
status: "verification_unavailable",
|
|
108
|
+
...result,
|
|
109
|
+
message: "暂时无法连接 npm registry 确认是否为最新版;当前本地版本一致,可以继续使用。",
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
status: "ready",
|
|
114
|
+
...result,
|
|
115
|
+
message: "Tiky 配置与 ScoreHub MCP 均已就绪。",
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function resetVersionCacheForTests() {
|
|
119
|
+
versionCache = null;
|
|
120
|
+
}
|
package/dist/status.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { OAuthAccount, OAuthShop, TokenStore } from "./auth.js";
|
|
2
|
+
export type LocalStatusState = "running_ready" | "running_unauthorized" | "running_authorized_remote_unavailable" | "running_authorized_no_remote_tools";
|
|
3
|
+
export type AuthorizationState = "authorized" | "unauthorized";
|
|
4
|
+
export type RemoteToolsState = "available" | "unavailable";
|
|
5
|
+
export interface StatusPayload {
|
|
6
|
+
server_version: string;
|
|
7
|
+
remote_url: string;
|
|
8
|
+
token_store_key: string;
|
|
9
|
+
local_state: LocalStatusState;
|
|
10
|
+
authorization_state: AuthorizationState;
|
|
11
|
+
remote_tools_state: RemoteToolsState;
|
|
12
|
+
authorized: boolean;
|
|
13
|
+
tools_count: number;
|
|
14
|
+
config_source: {
|
|
15
|
+
client_host: string;
|
|
16
|
+
managed_by: string;
|
|
17
|
+
creator_outreach_version?: string;
|
|
18
|
+
};
|
|
19
|
+
account?: OAuthAccount;
|
|
20
|
+
selected_shop?: OAuthShop;
|
|
21
|
+
error?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface StatusInput {
|
|
24
|
+
serverVersion: string;
|
|
25
|
+
remoteUrl: string;
|
|
26
|
+
tokenStoreKey: string;
|
|
27
|
+
tokenResult: {
|
|
28
|
+
access_token: string;
|
|
29
|
+
} | null;
|
|
30
|
+
tokenStore: Pick<TokenStore, "account" | "selected_shop"> | null;
|
|
31
|
+
remoteToolsCount: number;
|
|
32
|
+
lastFetchError: string | null;
|
|
33
|
+
env?: NodeJS.ProcessEnv;
|
|
34
|
+
}
|
|
35
|
+
export declare function buildStatusPayload(input: StatusInput): StatusPayload;
|
package/dist/status.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildStatusPayload = buildStatusPayload;
|
|
4
|
+
function getLocalState(authorized, remoteToolsCount, lastFetchError) {
|
|
5
|
+
if (!authorized) {
|
|
6
|
+
return "running_unauthorized";
|
|
7
|
+
}
|
|
8
|
+
if (lastFetchError) {
|
|
9
|
+
return "running_authorized_remote_unavailable";
|
|
10
|
+
}
|
|
11
|
+
if (remoteToolsCount === 0) {
|
|
12
|
+
return "running_authorized_no_remote_tools";
|
|
13
|
+
}
|
|
14
|
+
return "running_ready";
|
|
15
|
+
}
|
|
16
|
+
function buildStatusPayload(input) {
|
|
17
|
+
const env = input.env ?? process.env;
|
|
18
|
+
const authorized = !!input.tokenResult;
|
|
19
|
+
const remoteToolsState = input.remoteToolsCount > 0 && !input.lastFetchError
|
|
20
|
+
? "available"
|
|
21
|
+
: "unavailable";
|
|
22
|
+
return {
|
|
23
|
+
server_version: input.serverVersion,
|
|
24
|
+
remote_url: input.remoteUrl,
|
|
25
|
+
token_store_key: input.tokenStoreKey,
|
|
26
|
+
local_state: getLocalState(authorized, input.remoteToolsCount, input.lastFetchError),
|
|
27
|
+
authorization_state: authorized ? "authorized" : "unauthorized",
|
|
28
|
+
remote_tools_state: remoteToolsState,
|
|
29
|
+
authorized,
|
|
30
|
+
tools_count: input.remoteToolsCount,
|
|
31
|
+
config_source: {
|
|
32
|
+
client_host: env.SCOREHUB_CLIENT_HOST || "unknown",
|
|
33
|
+
managed_by: env.SCOREHUB_MANAGED_BY || "direct",
|
|
34
|
+
...(env.SCOREHUB_CREATOR_OUTREACH_VERSION
|
|
35
|
+
? { creator_outreach_version: env.SCOREHUB_CREATOR_OUTREACH_VERSION }
|
|
36
|
+
: {}),
|
|
37
|
+
},
|
|
38
|
+
...(input.tokenStore?.account ? { account: input.tokenStore.account } : {}),
|
|
39
|
+
...(input.tokenStore?.selected_shop ? { selected_shop: input.tokenStore.selected_shop } : {}),
|
|
40
|
+
...(input.lastFetchError ? { error: input.lastFetchError } : {}),
|
|
41
|
+
};
|
|
42
|
+
}
|