@scorehub/mcp-server 0.2.4 → 0.2.5
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/dist/index.js +21 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -28,6 +28,8 @@ const node_http_1 = require("node:http");
|
|
|
28
28
|
const node_child_process_1 = require("node:child_process");
|
|
29
29
|
const HOST = new URL(REMOTE_MCP_URL).host;
|
|
30
30
|
const CLIENT_ID = "scorehub-mcp";
|
|
31
|
+
// Proactively refresh token every 4 hours to prevent expiry during long sessions
|
|
32
|
+
const TOKEN_KEEPALIVE_INTERVAL = 4 * 60 * 60 * 1000;
|
|
31
33
|
// ── Remote Tool Proxy (MCP Streamable HTTP) ─────────────────
|
|
32
34
|
async function fetchRemoteTools(token) {
|
|
33
35
|
try {
|
|
@@ -258,6 +260,24 @@ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
|
258
260
|
}
|
|
259
261
|
}
|
|
260
262
|
});
|
|
263
|
+
// ── Token Keep-Alive ────────────────────────────────────────
|
|
264
|
+
// Proactively refresh the access token on a fixed interval so long-running
|
|
265
|
+
// sessions never hit an expiry mid-call. Uses timer.unref() so the keep-alive
|
|
266
|
+
// loop does not prevent the process from exiting normally.
|
|
267
|
+
function startTokenKeepAlive() {
|
|
268
|
+
const timer = setInterval(async () => {
|
|
269
|
+
try {
|
|
270
|
+
const result = await (0, auth_js_1.getValidAccessToken)(HOST, TOKEN_ENDPOINT, CLIENT_ID);
|
|
271
|
+
if (result?.source === "refresh") {
|
|
272
|
+
console.error("[keep-alive] access token refreshed proactively");
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
catch {
|
|
276
|
+
// Non-fatal: will retry on next interval
|
|
277
|
+
}
|
|
278
|
+
}, TOKEN_KEEPALIVE_INTERVAL);
|
|
279
|
+
timer.unref(); // Don't block process exit when no other work remains
|
|
280
|
+
}
|
|
261
281
|
// ── Start ───────────────────────────────────────────────────
|
|
262
282
|
async function main() {
|
|
263
283
|
// Set process title for easy identification in ps/task manager
|
|
@@ -283,6 +303,7 @@ async function main() {
|
|
|
283
303
|
const transport = new stdio_js_1.StdioServerTransport();
|
|
284
304
|
await server.connect(transport);
|
|
285
305
|
console.error(`ScoreHub MCP Server started (remote: ${REMOTE_MCP_URL})`);
|
|
306
|
+
startTokenKeepAlive();
|
|
286
307
|
}
|
|
287
308
|
main().catch((err) => {
|
|
288
309
|
console.error("Fatal:", err);
|