cross-agent-teams-mcp 0.5.10 → 0.5.11
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/cli.js +73 -12
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
- package/src/daemon/server.ts +5 -1
- package/src/daemon/shutdown.ts +66 -5
- package/src/mcp/transport.ts +19 -7
package/dist/cli.js
CHANGED
|
@@ -3712,12 +3712,14 @@ function mountMcp(app, db, fanout, channelWakeFanout, opts = {}) {
|
|
|
3712
3712
|
sessionIdGenerator: () => randomUUID5(),
|
|
3713
3713
|
onsessioninitialized: (sid) => {
|
|
3714
3714
|
sessionIdForCaller = sid;
|
|
3715
|
+
const now2 = Date.now();
|
|
3715
3716
|
sessions.set(sid, {
|
|
3716
3717
|
transport,
|
|
3717
3718
|
server,
|
|
3718
3719
|
sessionId: sid,
|
|
3719
3720
|
agentIdHolder,
|
|
3720
|
-
createdAt:
|
|
3721
|
+
createdAt: now2,
|
|
3722
|
+
lastActivityAt: now2,
|
|
3721
3723
|
clientInfo: void 0,
|
|
3722
3724
|
originInfo: { origin: "local", remote_addr: null }
|
|
3723
3725
|
});
|
|
@@ -3771,12 +3773,14 @@ function mountMcp(app, db, fanout, channelWakeFanout, opts = {}) {
|
|
|
3771
3773
|
registerSvc
|
|
3772
3774
|
);
|
|
3773
3775
|
server.connect(transport);
|
|
3776
|
+
const now = Date.now();
|
|
3774
3777
|
return {
|
|
3775
3778
|
transport,
|
|
3776
3779
|
server,
|
|
3777
3780
|
sessionId: "",
|
|
3778
3781
|
agentIdHolder,
|
|
3779
|
-
createdAt:
|
|
3782
|
+
createdAt: now,
|
|
3783
|
+
lastActivityAt: now,
|
|
3780
3784
|
originInfo: { origin: "local", remote_addr: null }
|
|
3781
3785
|
};
|
|
3782
3786
|
}
|
|
@@ -3820,6 +3824,7 @@ function mountMcp(app, db, fanout, channelWakeFanout, opts = {}) {
|
|
|
3820
3824
|
}
|
|
3821
3825
|
if (session) {
|
|
3822
3826
|
session.originInfo = originInfo;
|
|
3827
|
+
session.lastActivityAt = Date.now();
|
|
3823
3828
|
}
|
|
3824
3829
|
if (body?.method === "initialize") {
|
|
3825
3830
|
const params = body.params;
|
|
@@ -3842,6 +3847,7 @@ function mountMcp(app, db, fanout, channelWakeFanout, opts = {}) {
|
|
|
3842
3847
|
const sid = req.headers["mcp-session-id"];
|
|
3843
3848
|
const session = sid ? sessions.get(sid) : void 0;
|
|
3844
3849
|
if (!session) return reply.code(400).send({ error: "unknown_session" });
|
|
3850
|
+
session.lastActivityAt = Date.now();
|
|
3845
3851
|
await session.transport.handleRequest(req.raw, reply.raw);
|
|
3846
3852
|
return reply;
|
|
3847
3853
|
});
|
|
@@ -3849,14 +3855,15 @@ function mountMcp(app, db, fanout, channelWakeFanout, opts = {}) {
|
|
|
3849
3855
|
const sid = req.headers["mcp-session-id"];
|
|
3850
3856
|
const session = sid ? sessions.get(sid) : void 0;
|
|
3851
3857
|
if (!session) return reply.code(400).send({ error: "unknown_session" });
|
|
3858
|
+
session.lastActivityAt = Date.now();
|
|
3852
3859
|
await session.transport.handleRequest(req.raw, reply.raw);
|
|
3853
3860
|
return reply;
|
|
3854
3861
|
});
|
|
3855
|
-
function reapOrphanSessions(now, graceMs =
|
|
3862
|
+
function reapOrphanSessions(now, graceMs = 18e5) {
|
|
3856
3863
|
for (const session of sessions.values()) {
|
|
3857
3864
|
if (session.agentIdHolder.current !== void 0) continue;
|
|
3858
|
-
const
|
|
3859
|
-
if (
|
|
3865
|
+
const idleMs = now - session.lastActivityAt;
|
|
3866
|
+
if (idleMs < graceMs) continue;
|
|
3860
3867
|
try {
|
|
3861
3868
|
void session.transport.close();
|
|
3862
3869
|
} catch {
|
|
@@ -4040,6 +4047,7 @@ function isLoopbackHost(host) {
|
|
|
4040
4047
|
// src/daemon/server.ts
|
|
4041
4048
|
var DEFAULT_KEEP_ALIVE_TIMEOUT_MS = 12e4;
|
|
4042
4049
|
var DEFAULT_ORPHAN_GC_INTERVAL_MS = 6e4;
|
|
4050
|
+
var DEFAULT_ORPHAN_GC_IDLE_MS = 18e5;
|
|
4043
4051
|
function parsePositiveInt(raw, fallback) {
|
|
4044
4052
|
const n = Number(raw);
|
|
4045
4053
|
return Number.isInteger(n) && n > 0 ? n : fallback;
|
|
@@ -4073,9 +4081,10 @@ async function buildServer(opts) {
|
|
|
4073
4081
|
}, cleanupIntervalMs);
|
|
4074
4082
|
if (typeof interval.unref === "function") interval.unref();
|
|
4075
4083
|
const orphanGcIntervalMs = opts.orphanGcIntervalMs ?? parsePositiveInt(process.env.ORPHAN_GC_INTERVAL_MS, DEFAULT_ORPHAN_GC_INTERVAL_MS);
|
|
4084
|
+
const orphanGcIdleMs = opts.orphanGcIdleMs ?? parsePositiveInt(process.env.ORPHAN_GC_IDLE_MS, DEFAULT_ORPHAN_GC_IDLE_MS);
|
|
4076
4085
|
const orphanGcInterval = setInterval(() => {
|
|
4077
4086
|
try {
|
|
4078
|
-
mcp.reapOrphanSessions(Date.now());
|
|
4087
|
+
mcp.reapOrphanSessions(Date.now(), orphanGcIdleMs);
|
|
4079
4088
|
} catch {
|
|
4080
4089
|
}
|
|
4081
4090
|
}, orphanGcIntervalMs);
|
|
@@ -4130,17 +4139,69 @@ function releasePidFile(path) {
|
|
|
4130
4139
|
}
|
|
4131
4140
|
|
|
4132
4141
|
// src/daemon/shutdown.ts
|
|
4133
|
-
|
|
4134
|
-
|
|
4142
|
+
var DEFAULT_GRACE_MS = 5e3;
|
|
4143
|
+
function resolveGraceMs(explicit) {
|
|
4144
|
+
if (typeof explicit === "number" && Number.isFinite(explicit)) {
|
|
4145
|
+
return explicit < 0 ? 0 : Math.floor(explicit);
|
|
4146
|
+
}
|
|
4147
|
+
const raw = process.env.XATS_SHUTDOWN_GRACE_MS;
|
|
4148
|
+
if (raw === void 0 || raw === "") return DEFAULT_GRACE_MS;
|
|
4149
|
+
const n = Number(raw);
|
|
4150
|
+
if (!Number.isFinite(n)) return DEFAULT_GRACE_MS;
|
|
4151
|
+
return n < 0 ? 0 : Math.floor(n);
|
|
4152
|
+
}
|
|
4153
|
+
function wireShutdown(app, pidPath, opts = {}) {
|
|
4154
|
+
const graceMs = resolveGraceMs(opts.graceMs);
|
|
4155
|
+
const exit = opts.exit ?? ((code) => {
|
|
4156
|
+
process.exit(code);
|
|
4157
|
+
});
|
|
4158
|
+
let shuttingDown = false;
|
|
4159
|
+
const handler = (_signal) => {
|
|
4160
|
+
if (shuttingDown) {
|
|
4161
|
+
releasePidFile(pidPath);
|
|
4162
|
+
exit(0);
|
|
4163
|
+
return;
|
|
4164
|
+
}
|
|
4165
|
+
shuttingDown = true;
|
|
4166
|
+
void runDrain(app, pidPath, graceMs, exit);
|
|
4167
|
+
};
|
|
4168
|
+
process.on("SIGTERM", handler);
|
|
4169
|
+
process.on("SIGINT", handler);
|
|
4170
|
+
}
|
|
4171
|
+
async function runDrain(app, pidPath, graceMs, exit) {
|
|
4172
|
+
if (graceMs <= 0) {
|
|
4173
|
+
try {
|
|
4174
|
+
app.server.closeAllConnections();
|
|
4175
|
+
} catch {
|
|
4176
|
+
}
|
|
4135
4177
|
try {
|
|
4136
4178
|
await app.close();
|
|
4137
4179
|
} catch {
|
|
4138
4180
|
}
|
|
4139
4181
|
releasePidFile(pidPath);
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
|
|
4182
|
+
exit(0);
|
|
4183
|
+
return;
|
|
4184
|
+
}
|
|
4185
|
+
let timer;
|
|
4186
|
+
const deadline = new Promise((resolve) => {
|
|
4187
|
+
timer = setTimeout(() => resolve("timeout"), graceMs);
|
|
4188
|
+
if (typeof timer.unref === "function") timer.unref();
|
|
4189
|
+
});
|
|
4190
|
+
const closed = app.close().then(() => "closed").catch(() => "closed");
|
|
4191
|
+
const winner = await Promise.race([closed, deadline]);
|
|
4192
|
+
if (winner === "timeout") {
|
|
4193
|
+
try {
|
|
4194
|
+
app.server.closeAllConnections();
|
|
4195
|
+
} catch {
|
|
4196
|
+
}
|
|
4197
|
+
try {
|
|
4198
|
+
await app.close();
|
|
4199
|
+
} catch {
|
|
4200
|
+
}
|
|
4201
|
+
}
|
|
4202
|
+
if (timer) clearTimeout(timer);
|
|
4203
|
+
releasePidFile(pidPath);
|
|
4204
|
+
exit(0);
|
|
4144
4205
|
}
|
|
4145
4206
|
|
|
4146
4207
|
// src/daemon/port.ts
|