@scorehub/mcp-server 0.3.3 → 0.4.1

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 CHANGED
@@ -62,13 +62,23 @@ Common configuration locations are:
62
62
  | Other MCP clients | The MCP configuration file used by that client |
63
63
  | WorkBuddy | `mcp.json` |
64
64
 
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.
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. In WorkBuddy, the successful callback page can launch Tiky through “Return to WorkBuddy.” Later calls reuse the cached token and do not require another login.
66
66
 
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.
67
+ > After you install Tiky through the WorkBuddy share link, Tiky's first-turn bootstrap gate writes or repairs this MCP configuration after the user's one-time confirmation. Manual editing is not required.
68
+
69
+ ### Startup self-check
70
+
71
+ Before writing the WorkBuddy configuration, creator-outreach prefetches npm latest and runs:
72
+
73
+ ```bash
74
+ npx -y @scorehub/mcp-server@latest --self-check --json
75
+ ```
76
+
77
+ The command reports the package version, Node.js version, and executable entrypoint status, then exits immediately. It does not start stdio, contact the remote MCP endpoint, enter OAuth, or write tokens.
68
78
 
69
79
  ## Windows
70
80
 
71
- Windows uses the same MCP JSON configuration as macOS and Linux. You do not need `npx.cmd` or a separate global installation.
81
+ For manually configured MCP clients, Windows uses the same `"command": "npx"` configuration shown above as macOS and Linux; you do not need to switch it to `npx.cmd` or install the package globally. Tiky's public WorkBuddy installation path generates a managed configuration instead: it uses WorkBuddy's bundled `node.exe` to load the matching npm `npx-cli.js` directly, avoiding host process-launch compatibility problems with `.cmd` / `.bat` files.
72
82
 
73
83
  1. After installing Node.js 18+, reopen PowerShell or Windows Terminal and run the three version commands from the prerequisites section.
74
84
  2. If `node`, `npm`, or `npx` cannot be found, Node.js is not available on the current process PATH. Close and reopen the client and terminal; if the problem remains, verify the Node.js installation.
@@ -76,7 +86,7 @@ Windows uses the same MCP JSON configuration as macOS and Linux. You do not need
76
86
  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
87
  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
88
 
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.
89
+ 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 resolves the managed `node.exe`, `npx-cli.js`, and PATH automatically; no wrapper script or manual `mcp.json` edit is required.
80
90
 
81
91
  ## Optional: Global Installation
82
92
 
@@ -173,7 +183,7 @@ Local mcp-server ScoreHub Remote MCP
173
183
  | `rate_limited` / `quota_exhausted` | Wait, split the operation into batches, or narrow the request. Do not reauthorize for rate limits. |
174
184
  | `invalid_input` | Correct the tool parameters; do not start authorization. |
175
185
  | 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
- | 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. |
186
+ | The authorization page says the link is invalid, or the browser URL has no `redirect_uri` | Fully quit and restart WorkBuddy, then confirm the `scorehub` entry in `~/.workbuddy/mcp.json` still includes `@scorehub/mcp-server@latest` and is managed by `@scorehub/creator-outreach`. If not, rerun Tiky's bootstrap repair. Newer versions open the OAuth URL through PowerShell to avoid truncating query parameters. |
177
187
 
178
188
  Key `status` fields:
179
189
 
@@ -203,6 +213,8 @@ With `npx -y ...@latest`, every launch resolves npm's current `latest` tag. For
203
213
  npm update -g @scorehub/mcp-server
204
214
  ```
205
215
 
216
+ Because the public WorkBuddy configuration always follows `@latest`, releases under this package name must preserve backward compatibility for tool names, parameters, OAuth, and the `status` contract. An incompatible protocol must use a new package name.
217
+
206
218
  ## Related Packages
207
219
 
208
220
  | Package | Description |
package/README.md CHANGED
@@ -62,13 +62,23 @@ npx --version
62
62
  | 其他 MCP 客户端 | 该客户端使用的 MCP 配置文件 |
63
63
  | WorkBuddy | `mcp.json` |
64
64
 
65
- 首次启动时,`npx` 会下载 `@scorehub/mcp-server` 并连接远程端点。首次调用远程工具时,按客户端提示调用 `authorize`:浏览器会打开 ScoreHub 登录页,授权完成后回调到 `127.0.0.1` 的随机端口并写入本地 Token。之后会复用缓存,不需要每次登录。
65
+ 首次启动时,`npx` 会下载 `@scorehub/mcp-server` 并连接远程端点。首次调用远程工具时,按客户端提示调用 `authorize`:浏览器会打开 ScoreHub 登录页,授权完成后回调到 `127.0.0.1` 的随机端口并写入本地 Token。在 WorkBuddy 中,成功回调页可通过“切换到终端继续”唤起 Tiky;之后会复用缓存,不需要每次登录。
66
66
 
67
- > 通过 WorkBuddy 分享链接安装 Tiky 后,Tiky 会在需要时执行 `npx -y @scorehub/creator-outreach@latest` 完成本地引导,并自动写入或修复这份 MCP 配置;无需手动编辑。
67
+ > 通过 WorkBuddy 分享链接安装 Tiky 后,Tiky 会在首轮 bootstrap 门禁中经用户首次确认后自动写入或修复这份 MCP 配置;无需手动编辑。
68
+
69
+ ### 启动前自检
70
+
71
+ 在写入 WorkBuddy 配置前,creator-outreach 会预拉取 npm latest 并执行:
72
+
73
+ ```bash
74
+ npx -y @scorehub/mcp-server@latest --self-check --json
75
+ ```
76
+
77
+ 该命令返回包版本、Node.js 版本和可执行入口状态,然后立即退出。它不启动 stdio 服务、不访问远端 MCP、不进入 OAuth,也不写入 Token。
68
78
 
69
79
  ## Windows 使用说明
70
80
 
71
- Windows 与 macOS、Linux 使用同一份 MCP JSON 配置,不需要改成 `npx.cmd` 或另行全局安装。
81
+ 手工配置普通 MCP 客户端时,Windows 与 macOS、Linux 一样使用前文的 `"command": "npx"`,不需要手工改成 `npx.cmd` 或另行全局安装。WorkBuddy 的公开安装路径由 Tiky 自动生成配置:它会使用 WorkBuddy 托管的 `node.exe` 直接加载同版本 npm 的 `npx-cli.js`,避免宿主原生进程 API 直接启动 `.cmd` / `.bat` 的兼容问题。
72
82
 
73
83
  1. 安装 Node.js 18+ 后,重新打开 PowerShell 或 Windows Terminal,运行前置条件中的三个版本命令。
74
84
  2. 如果提示找不到 `node`、`npm` 或 `npx`,说明 Node.js 尚未加入当前进程的 PATH:关闭并重新打开客户端和终端;仍无法识别时,检查 Node.js 安装是否完成。
@@ -76,7 +86,7 @@ Windows 与 macOS、Linux 使用同一份 MCP JSON 配置,不需要改成 `npx
76
86
  4. 授权时会优先使用 `cmd.exe /c start` 打开默认浏览器。被系统策略拦截时,复制终端输出的授权 URL,在**运行 mcp-server 的同一台 Windows 电脑**上打开并完成授权。
77
87
  5. 回调固定使用 `127.0.0.1` 随机端口。不要在另一台电脑打开授权 URL;本机安全软件若拦截回环回调,应允许本地回环连接后重试。
78
88
 
79
- WorkBuddy 若使用其捆绑的 Node.js,建议先通过分享链接安装 Tiky,再由 Tiky 执行 `npx -y @scorehub/creator-outreach@latest` 完成本地引导;该流程会按平台处理 `npx` / `npx.cmd` 与 PATH。
89
+ WorkBuddy 若使用其捆绑的 Node.js,建议先通过分享链接安装 Tiky,再由 Tiky 执行 `npx -y @scorehub/creator-outreach@latest` 完成本地引导;该流程会自动解析托管的 `node.exe`、`npx-cli.js` 与 PATH,不需要创建包装脚本或手工编辑 `mcp.json`。
80
90
 
81
91
  ## 可选:全局安装
82
92
 
@@ -173,7 +183,7 @@ Token 持久化在本机文件中;调用默认 ScoreHub 生产端点时,mcp-
173
183
  | `rate_limited` / `quota_exhausted` | 等待、分批执行或缩小请求范围;不要为了限流重新授权。 |
174
184
  | `invalid_input` | 修正工具参数,不走授权流程。 |
175
185
  | 浏览器无法自动打开 | 使用终端输出的授权 URL,并在运行 mcp-server 的同一台机器上完成回调。 |
176
- | Windows 授权页提示授权链接无效,或浏览器地址栏缺少 `redirect_uri` | 完全退出并重启 WorkBuddy,确认 `~/.workbuddy/mcp.json` 仍使用 `npx -y @scorehub/mcp-server@latest`;新版会通过 PowerShell 打开授权 URL,避免 `cmd.exe start` 截断带 `&` 的参数。 |
186
+ | Windows 授权页提示授权链接无效,或浏览器地址栏缺少 `redirect_uri` | 完全退出并重启 WorkBuddy,确认 `~/.workbuddy/mcp.json` 的 `scorehub` 参数仍包含 `@scorehub/mcp-server@latest`,且配置由 `@scorehub/creator-outreach` 托管;若不符合,重新运行 Tiky bootstrap 修复。新版会通过 PowerShell 打开授权 URL,避免 `cmd.exe start` 截断带 `&` 的参数。 |
177
187
 
178
188
  `status` 的关键字段说明:
179
189
 
@@ -203,6 +213,8 @@ Token 持久化在本机文件中;调用默认 ScoreHub 生产端点时,mcp-
203
213
  npm update -g @scorehub/mcp-server
204
214
  ```
205
215
 
216
+ 由于 WorkBuddy 公开配置始终跟随 `@latest`,同一包名下的 latest 发布必须保持工具名、参数、OAuth 和 `status` 契约向后兼容。无法兼容的新协议必须使用新包名。
217
+
206
218
  ## 相关包
207
219
 
208
220
  | 包 | 说明 |
package/dist/index.js CHANGED
@@ -18,11 +18,12 @@ const index_js_2 = require("@modelcontextprotocol/sdk/client/index.js");
18
18
  const streamableHttp_js_1 = require("@modelcontextprotocol/sdk/client/streamableHttp.js");
19
19
  const node_fs_1 = require("node:fs");
20
20
  const node_path_1 = require("node:path");
21
- function readPackageVersion() {
22
- const packageJson = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(__dirname, "../package.json"), "utf-8"));
23
- return packageJson.version;
21
+ const self_check_js_1 = require("./self-check.js");
22
+ function readPackageMetadata() {
23
+ return JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(__dirname, "../package.json"), "utf-8"));
24
24
  }
25
- const SERVER_VERSION = readPackageVersion();
25
+ const PACKAGE_METADATA = readPackageMetadata();
26
+ const SERVER_VERSION = PACKAGE_METADATA.version;
26
27
  const DEFAULT_SCOREHUB_BASE_URL = "https://app.scorehub.cn/mcp";
27
28
  const SCOREHUB_BASE_URL = normalizeBaseUrl(process.env.SCOREHUB_REMOTE_MCP_URL || DEFAULT_SCOREHUB_BASE_URL);
28
29
  // OAuth endpoints are at the root path
@@ -378,6 +379,23 @@ function startTokenKeepAlive() {
378
379
  }
379
380
  // ── Start ───────────────────────────────────────────────────
380
381
  async function main() {
382
+ if (process.argv.includes("--self-check")) {
383
+ const payload = (0, self_check_js_1.buildSelfCheckPayload)({
384
+ packageName: PACKAGE_METADATA.name,
385
+ serverVersion: SERVER_VERSION,
386
+ });
387
+ if (process.argv.includes("--json")) {
388
+ process.stdout.write(`${JSON.stringify(payload)}\n`);
389
+ }
390
+ else {
391
+ process.stdout.write(payload.ok
392
+ ? `ScoreHub MCP Server v${payload.server_version} is ready (Node.js ${payload.node_version}).\n`
393
+ : `Node.js ${payload.minimum_node_major}+ is required. Detected ${payload.node_version}.\n`);
394
+ }
395
+ if (!payload.ok)
396
+ process.exitCode = 1;
397
+ return;
398
+ }
381
399
  // Set process title for easy identification in ps/task manager
382
400
  process.title = 'scorehub-mcp';
383
401
  // Gracefully exit when parent AI agent closes stdin (normal shutdown or crash).
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildCallbackPage = buildCallbackPage;
4
4
  const logo_data_js_1 = require("./logo-data.js");
5
+ const WORKBUDDY_LAUNCH_URL = "workbuddy://launch?expertname=Tiky%20%C2%B7%20TikTok%E8%BE%BE%E4%BA%BA%E8%90%A5%E9%94%80%E4%B8%93%E5%AE%B6&buddy_type=workbuddy";
5
6
  const CALLBACK_BASE_STYLES = `
6
7
  * { margin:0; padding:0; box-sizing:border-box; }
7
8
  body {
@@ -191,6 +192,9 @@ const CALLBACK_BASE_STYLES = `
191
192
  margin-top:22px;
192
193
  }
193
194
  .btn {
195
+ display:flex;
196
+ align-items:center;
197
+ justify-content:center;
194
198
  min-height:44px;
195
199
  padding:10px 16px;
196
200
  border-radius:12px;
@@ -198,6 +202,7 @@ const CALLBACK_BASE_STYLES = `
198
202
  font-weight:800;
199
203
  cursor:pointer;
200
204
  border:1px solid transparent;
205
+ text-decoration:none;
201
206
  transition:background 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.15s;
202
207
  }
203
208
  .btn:hover { transform:translateY(-1px); }
@@ -267,6 +272,19 @@ function escapeHtml(value) {
267
272
  }
268
273
  function buildCallbackPage(page) {
269
274
  const statusClass = page.tone === "success" ? "status-badge-success" : "status-badge-error";
275
+ const primaryAction = page.tone === "success"
276
+ ? `<a class="btn btn-primary" id="workbuddy-launch-link" href="${WORKBUDDY_LAUNCH_URL}">切换到终端继续</a>`
277
+ : `<button class="btn btn-primary" type="button" id="focus-button">切回终端继续</button>`;
278
+ const focusScript = page.tone === "success"
279
+ ? ""
280
+ : `
281
+ const focusButton = document.getElementById('focus-button');
282
+ focusButton?.addEventListener('click', function() {
283
+ window.close();
284
+ setTimeout(function() {
285
+ window.focus();
286
+ }, 60);
287
+ });`;
270
288
  const detailBlock = page.detail
271
289
  ? `<div class="detail-card">
272
290
  <span class="section-title">错误详情</span>
@@ -326,7 +344,7 @@ function buildCallbackPage(page) {
326
344
  </div>
327
345
 
328
346
  <div class="actions">
329
- <button class="btn btn-primary" type="button" id="focus-button">切回终端继续</button>
347
+ ${primaryAction}
330
348
  <button class="btn btn-secondary" type="button" id="close-button">${escapeHtml(page.closeLabel ?? "关闭当前页面")}</button>
331
349
  </div>
332
350
  <div class="helper-note">${escapeHtml(page.helperText ?? "如果浏览器无法自动关闭,请手动切回终端继续。")}</div>
@@ -334,18 +352,11 @@ function buildCallbackPage(page) {
334
352
  </div>
335
353
  <script>
336
354
  const closeButton = document.getElementById('close-button');
337
- const focusButton = document.getElementById('focus-button');
338
355
 
339
356
  closeButton?.addEventListener('click', function() {
340
357
  window.close();
341
358
  });
342
-
343
- focusButton?.addEventListener('click', function() {
344
- window.close();
345
- setTimeout(function() {
346
- window.focus();
347
- }, 60);
348
- });
359
+ ${focusScript}
349
360
  </script>
350
361
  </body>
351
362
  </html>`;
@@ -0,0 +1,18 @@
1
+ export declare const MIN_NODE_MAJOR = 18;
2
+ export interface SelfCheckPayload {
3
+ schema_version: 1;
4
+ ok: boolean;
5
+ package_name: string;
6
+ server_version: string;
7
+ node_version: string;
8
+ node_supported: boolean;
9
+ minimum_node_major: number;
10
+ entrypoint: "scorehub-mcp";
11
+ }
12
+ export interface SelfCheckInput {
13
+ packageName: string;
14
+ serverVersion: string;
15
+ nodeVersion?: string;
16
+ }
17
+ export declare function getNodeMajorVersion(nodeVersion: string): number;
18
+ export declare function buildSelfCheckPayload(input: SelfCheckInput): SelfCheckPayload;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MIN_NODE_MAJOR = void 0;
4
+ exports.getNodeMajorVersion = getNodeMajorVersion;
5
+ exports.buildSelfCheckPayload = buildSelfCheckPayload;
6
+ exports.MIN_NODE_MAJOR = 18;
7
+ function getNodeMajorVersion(nodeVersion) {
8
+ return Number.parseInt(nodeVersion.split(".")[0], 10);
9
+ }
10
+ function buildSelfCheckPayload(input) {
11
+ const nodeVersion = input.nodeVersion ?? process.versions.node;
12
+ const nodeSupported = getNodeMajorVersion(nodeVersion) >= exports.MIN_NODE_MAJOR;
13
+ return {
14
+ schema_version: 1,
15
+ ok: nodeSupported,
16
+ package_name: input.packageName,
17
+ server_version: input.serverVersion,
18
+ node_version: nodeVersion,
19
+ node_supported: nodeSupported,
20
+ minimum_node_major: exports.MIN_NODE_MAJOR,
21
+ entrypoint: "scorehub-mcp",
22
+ };
23
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scorehub/mcp-server",
3
- "version": "0.3.3",
3
+ "version": "0.4.1",
4
4
  "description": "ScoreHub local MCP proxy — OAuth login, token caching, and tool forwarding to remote MCP endpoint",
5
5
  "engines": {
6
6
  "node": ">=18"
@@ -18,7 +18,7 @@
18
18
  "access": "public"
19
19
  },
20
20
  "scripts": {
21
- "build": "tsc && node -e \"const fs=require('fs');const f='dist/index.js';fs.writeFileSync(f,'#!/usr/bin/env node\\n'+fs.readFileSync(f,'utf8'));fs.chmodSync(f,0o755)\"",
21
+ "build": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc && node -e \"const fs=require('fs');const f='dist/index.js';fs.writeFileSync(f,'#!/usr/bin/env node\\n'+fs.readFileSync(f,'utf8'));fs.chmodSync(f,0o755)\"",
22
22
  "dev": "tsx src/index.ts",
23
23
  "start": "node dist/index.js",
24
24
  "test": "tsx --test test/*.test.ts"
@@ -1,39 +0,0 @@
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 {};
@@ -1,120 +0,0 @@
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
- }