@scorehub/mcp-server 0.2.1 → 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 +23 -6
  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");
@@ -44,7 +47,9 @@ async function fetchRemoteTools(token) {
44
47
  }
45
48
  }
46
49
  catch (e) {
47
- console.error("Warning: fetchRemoteTools failed:", e instanceof Error ? e.message : String(e));
50
+ const msg = e instanceof Error ? e.message : String(e);
51
+ lastFetchError = msg;
52
+ console.error("Warning: fetchRemoteTools failed:", msg);
48
53
  return [];
49
54
  }
50
55
  }
@@ -70,15 +75,23 @@ function generateAuthUrl() {
70
75
  }
71
76
  // ── Fetch remote tools on startup ───────────────────────────
72
77
  let remoteTools = [];
78
+ let lastFetchError = null;
73
79
  // ── MCP Server ──────────────────────────────────────────────
74
80
  const server = new index_js_1.Server({ name: "scorehub-mcp", version: "0.1.0" }, { capabilities: { tools: {} } });
75
81
  server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => {
76
82
  // Refresh remote tools on each list
77
83
  try {
78
84
  const tokenResult = await (0, auth_js_1.getValidAccessToken)(HOST, TOKEN_ENDPOINT, CLIENT_ID);
79
- remoteTools = await fetchRemoteTools(tokenResult?.access_token);
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
+ }
80
93
  }
81
- catch { /* keep stale */ }
94
+ catch { /* keep stale tools and lastError */ }
82
95
  const tools = [
83
96
  {
84
97
  name: "authorize",
@@ -161,6 +174,7 @@ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
161
174
  remote_url: REMOTE_MCP_URL,
162
175
  authorized: !!tokenResult,
163
176
  tools_count: remoteTools.length,
177
+ ...(lastFetchError ? { error: lastFetchError } : {}),
164
178
  }, null, 2),
165
179
  },
166
180
  ],
@@ -220,6 +234,9 @@ async function main() {
220
234
  try {
221
235
  const tokenResult = await (0, auth_js_1.getValidAccessToken)(HOST, TOKEN_ENDPOINT, CLIENT_ID);
222
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
+ }
223
240
  }
224
241
  catch {
225
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.1",
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": {