@giantswarm-io/pro 1.11.0 → 1.11.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/package.json +1 -1
- package/src/lib/mcp/http.js +11 -5
package/package.json
CHANGED
package/src/lib/mcp/http.js
CHANGED
|
@@ -51,11 +51,15 @@ const sessions = {};
|
|
|
51
51
|
* @param {Object} options
|
|
52
52
|
* @param {number} options.port - Port to listen on (default: 8080; 0 picks a free port)
|
|
53
53
|
* @param {string} options.endpoint - MCP endpoint path (default: /mcp)
|
|
54
|
+
* @param {number} options.sessionTtlMs - Idle time after which a session is evicted (default: 30 minutes)
|
|
55
|
+
* @param {number} options.sessionSweepIntervalMs - How often idle sessions are swept (default: 5 minutes)
|
|
54
56
|
* @returns {Promise<import('http').Server>} the listening server
|
|
55
57
|
*/
|
|
56
58
|
export async function startHTTPServer(options = {}) {
|
|
57
59
|
const port = options.port ?? (parseInt(process.env.HTTP_PORT, 10) || DEFAULT_PORT);
|
|
58
60
|
const endpoint = options.endpoint || DEFAULT_ENDPOINT;
|
|
61
|
+
const sessionTtlMs = options.sessionTtlMs ?? SESSION_TTL_MS;
|
|
62
|
+
const sessionSweepIntervalMs = options.sessionSweepIntervalMs ?? SESSION_SWEEP_INTERVAL_MS;
|
|
59
63
|
|
|
60
64
|
const app = express();
|
|
61
65
|
// Trust exactly 1 proxy hop (Envoy Gateway). express-rate-limit requires
|
|
@@ -208,11 +212,13 @@ export async function startHTTPServer(options = {}) {
|
|
|
208
212
|
await transport.handleRequest(req, res, req.body);
|
|
209
213
|
return;
|
|
210
214
|
} else if (sessionId) {
|
|
211
|
-
// Session ID provided but not found — expired or invalid
|
|
212
|
-
|
|
215
|
+
// Session ID provided but not found — expired or invalid. The MCP
|
|
216
|
+
// spec (Streamable HTTP, session management) requires 404 here: it is
|
|
217
|
+
// the client's signal to start a new session with a fresh initialize.
|
|
218
|
+
res.status(404).json({
|
|
213
219
|
jsonrpc: '2.0',
|
|
214
220
|
error: {
|
|
215
|
-
code: -
|
|
221
|
+
code: -32001,
|
|
216
222
|
message: 'Session not found or expired'
|
|
217
223
|
},
|
|
218
224
|
id: null
|
|
@@ -246,7 +252,7 @@ export async function startHTTPServer(options = {}) {
|
|
|
246
252
|
const sweepInterval = setInterval(() => {
|
|
247
253
|
const now = Date.now();
|
|
248
254
|
for (const sessionId in sessions) {
|
|
249
|
-
if (now - sessions[sessionId].lastActivity >
|
|
255
|
+
if (now - sessions[sessionId].lastActivity > sessionTtlMs) {
|
|
250
256
|
logger.info(`Evicting idle session: ${sessionId}`);
|
|
251
257
|
try {
|
|
252
258
|
sessions[sessionId].transport.close();
|
|
@@ -256,7 +262,7 @@ export async function startHTTPServer(options = {}) {
|
|
|
256
262
|
delete sessions[sessionId];
|
|
257
263
|
}
|
|
258
264
|
}
|
|
259
|
-
},
|
|
265
|
+
}, sessionSweepIntervalMs);
|
|
260
266
|
sweepInterval.unref();
|
|
261
267
|
|
|
262
268
|
// Start listening
|