@scorehub/mcp-server 0.2.0 → 0.2.2

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.
Files changed (2) hide show
  1. package/dist/index.js +27 -7
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -16,9 +16,12 @@ const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
16
16
  const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
17
17
  const index_js_2 = require("@modelcontextprotocol/sdk/client/index.js");
18
18
  const streamableHttp_js_1 = require("@modelcontextprotocol/sdk/client/streamableHttp.js");
19
- const REMOTE_MCP_URL = process.env.SCOREHUB_REMOTE_MCP_URL || "https://mcp.scorehub.cn";
20
- const TOKEN_ENDPOINT = `${REMOTE_MCP_URL}/token`;
21
- const AUTHORIZE_URL = `${REMOTE_MCP_URL}/authorize`;
19
+ const SCOREHUB_BASE_URL = process.env.SCOREHUB_REMOTE_MCP_URL || "https://mcp.scorehub.cn";
20
+ // OAuth endpoints are at the root path
21
+ const TOKEN_ENDPOINT = `${SCOREHUB_BASE_URL}/token`;
22
+ const AUTHORIZE_URL = `${SCOREHUB_BASE_URL}/authorize`;
23
+ // MCP Streamable HTTP transport endpoints are at /mcp
24
+ const REMOTE_MCP_URL = `${SCOREHUB_BASE_URL}/mcp`;
22
25
  // ── Auth State ──────────────────────────────────────────────
23
26
  const auth_js_1 = require("./auth.js");
24
27
  const node_child_process_1 = require("node:child_process");
@@ -43,7 +46,10 @@ async function fetchRemoteTools(token) {
43
46
  await client.close();
44
47
  }
45
48
  }
46
- catch {
49
+ catch (e) {
50
+ const msg = e instanceof Error ? e.message : String(e);
51
+ lastFetchError = msg;
52
+ console.error("Warning: fetchRemoteTools failed:", msg);
47
53
  return [];
48
54
  }
49
55
  }
@@ -69,14 +75,23 @@ function generateAuthUrl() {
69
75
  }
70
76
  // ── Fetch remote tools on startup ───────────────────────────
71
77
  let remoteTools = [];
78
+ let lastFetchError = null;
72
79
  // ── MCP Server ──────────────────────────────────────────────
73
80
  const server = new index_js_1.Server({ name: "scorehub-mcp", version: "0.1.0" }, { capabilities: { tools: {} } });
74
81
  server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => {
75
82
  // Refresh remote tools on each list
76
83
  try {
77
- remoteTools = await fetchRemoteTools();
84
+ const tokenResult = await (0, auth_js_1.getValidAccessToken)(HOST, TOKEN_ENDPOINT, CLIENT_ID);
85
+ const freshTools = await fetchRemoteTools(tokenResult?.access_token);
86
+ if (freshTools.length > 0 || remoteTools.length === 0) {
87
+ remoteTools = freshTools;
88
+ }
89
+ // On success, clear any previous error
90
+ if (freshTools.length > 0) {
91
+ lastFetchError = null;
92
+ }
78
93
  }
79
- catch { /* keep stale */ }
94
+ catch { /* keep stale tools and lastError */ }
80
95
  const tools = [
81
96
  {
82
97
  name: "authorize",
@@ -159,6 +174,7 @@ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
159
174
  remote_url: REMOTE_MCP_URL,
160
175
  authorized: !!tokenResult,
161
176
  tools_count: remoteTools.length,
177
+ ...(lastFetchError ? { error: lastFetchError } : {}),
162
178
  }, null, 2),
163
179
  },
164
180
  ],
@@ -216,7 +232,11 @@ async function main() {
216
232
  }
217
233
  catch { /* ignore PID file write errors */ }
218
234
  try {
219
- remoteTools = await fetchRemoteTools();
235
+ const tokenResult = await (0, auth_js_1.getValidAccessToken)(HOST, TOKEN_ENDPOINT, CLIENT_ID);
236
+ remoteTools = await fetchRemoteTools(tokenResult?.access_token);
237
+ if (remoteTools.length === 0 && lastFetchError) {
238
+ console.error(`Warning: Could not fetch remote tools on startup: ${lastFetchError}. Retrying on first ListTools request.`);
239
+ }
220
240
  }
221
241
  catch {
222
242
  console.error("Warning: Could not fetch remote tools on startup. Retrying on first ListTools request.");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scorehub/mcp-server",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "ScoreHub local MCP proxy — OAuth login, token caching, and tool forwarding to remote MCP endpoint",
5
5
  "main": "dist/index.js",
6
6
  "bin": {