@ateam-ai/mcp 0.3.17 → 0.3.18
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/http.js +8 -40
package/package.json
CHANGED
package/src/http.js
CHANGED
|
@@ -242,48 +242,16 @@ export function startHttpServer(port = 3100) {
|
|
|
242
242
|
await server.connect(transport);
|
|
243
243
|
|
|
244
244
|
if (isStaleRecovery) {
|
|
245
|
-
//
|
|
246
|
-
//
|
|
247
|
-
//
|
|
248
|
-
const
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
params: {
|
|
253
|
-
protocolVersion: "2025-03-26",
|
|
254
|
-
capabilities: {},
|
|
255
|
-
clientInfo: { name: "auto-reinit", version: "1.0" },
|
|
256
|
-
},
|
|
257
|
-
};
|
|
258
|
-
// Mock response object that swallows the init response
|
|
259
|
-
const mockRes = {
|
|
260
|
-
_h: {},
|
|
261
|
-
statusCode: 200,
|
|
262
|
-
headersSent: false,
|
|
263
|
-
setHeader(k, v) { this._h[k.toLowerCase()] = v; },
|
|
264
|
-
getHeader(k) { return this._h[k.toLowerCase()]; },
|
|
265
|
-
removeHeader(k) { delete this._h[k.toLowerCase()]; },
|
|
266
|
-
writeHead() { return this; },
|
|
267
|
-
write() { return true; },
|
|
268
|
-
end() { this.headersSent = true; return this; },
|
|
269
|
-
json() { return this; },
|
|
270
|
-
status() { return this; },
|
|
271
|
-
on() {},
|
|
272
|
-
once() {},
|
|
273
|
-
emit() {},
|
|
274
|
-
};
|
|
275
|
-
// Strip the stale session-id header so the SDK treats this as a new init
|
|
276
|
-
const initReq = { ...req, headers: { ...req.headers } };
|
|
277
|
-
delete initReq.headers["mcp-session-id"];
|
|
278
|
-
try {
|
|
279
|
-
await transport.handleRequest(initReq, mockRes, fakeInit);
|
|
280
|
-
} catch (e) {
|
|
281
|
-
console.error("[HTTP] Auto-reinit synthetic initialize failed:", e.message);
|
|
245
|
+
// Force the underlying web-standard transport into "initialized" state without
|
|
246
|
+
// requiring a real initialize handshake. This bypasses the SDK's built-in check
|
|
247
|
+
// (`Bad Request: Server not initialized`) so the non-initialize request dispatches.
|
|
248
|
+
const inner = transport._webStandardTransport;
|
|
249
|
+
if (inner) {
|
|
250
|
+
inner.sessionId = newSessionId;
|
|
251
|
+
inner._initialized = true;
|
|
282
252
|
}
|
|
283
|
-
// Ensure the transport is registered under the new id and update the real request
|
|
284
253
|
transports[newSessionId] = transport;
|
|
285
|
-
//
|
|
286
|
-
// routes the real request to the freshly-initialized transport.
|
|
254
|
+
// Rewrite the request's session-id header so SDK session validation passes.
|
|
287
255
|
req.headers["mcp-session-id"] = newSessionId;
|
|
288
256
|
// Tell the client about the new session id so future requests use it.
|
|
289
257
|
res.setHeader("mcp-session-id", newSessionId);
|