@mcp-ts/sdk 2.2.0 → 2.3.0
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.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +66 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +66 -2
- package/dist/index.mjs.map +1 -1
- package/dist/server/index.d.mts +13 -1
- package/dist/server/index.d.ts +13 -1
- package/dist/server/index.js +66 -1
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +66 -2
- package/dist/server/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/server/index.ts +8 -1
- package/src/server/storage/index.ts +77 -2
- package/src/server/storage/types.ts +14 -0
package/dist/server/index.mjs
CHANGED
|
@@ -1171,6 +1171,59 @@ function warnIfNeonConnectionStringIsInsecure(connectionString) {
|
|
|
1171
1171
|
}
|
|
1172
1172
|
var storageInstance = null;
|
|
1173
1173
|
var storagePromise = null;
|
|
1174
|
+
var sessionMutationListeners = /* @__PURE__ */ new Set();
|
|
1175
|
+
function emitSessionMutation(event) {
|
|
1176
|
+
for (const listener of sessionMutationListeners) {
|
|
1177
|
+
try {
|
|
1178
|
+
const result = listener(event);
|
|
1179
|
+
if (result && typeof result.catch === "function") {
|
|
1180
|
+
void result.catch((error) => {
|
|
1181
|
+
console.error("[mcp-ts][Storage] Session mutation listener failed:", error);
|
|
1182
|
+
});
|
|
1183
|
+
}
|
|
1184
|
+
} catch (error) {
|
|
1185
|
+
console.error("[mcp-ts][Storage] Session mutation listener failed:", error);
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
function createSessionMutationEvent(prop, args) {
|
|
1190
|
+
const timestamp = Date.now();
|
|
1191
|
+
if (prop === "create") {
|
|
1192
|
+
const [session, ttl] = args;
|
|
1193
|
+
if (!session?.userId || !session?.sessionId) return null;
|
|
1194
|
+
return {
|
|
1195
|
+
type: "create",
|
|
1196
|
+
userId: session.userId,
|
|
1197
|
+
sessionId: session.sessionId,
|
|
1198
|
+
session,
|
|
1199
|
+
ttl,
|
|
1200
|
+
timestamp
|
|
1201
|
+
};
|
|
1202
|
+
}
|
|
1203
|
+
if (prop === "update") {
|
|
1204
|
+
const [userId, sessionId, patch, ttl] = args;
|
|
1205
|
+
if (!userId || !sessionId) return null;
|
|
1206
|
+
return {
|
|
1207
|
+
type: "update",
|
|
1208
|
+
userId,
|
|
1209
|
+
sessionId,
|
|
1210
|
+
patch,
|
|
1211
|
+
ttl,
|
|
1212
|
+
timestamp
|
|
1213
|
+
};
|
|
1214
|
+
}
|
|
1215
|
+
if (prop === "delete") {
|
|
1216
|
+
const [userId, sessionId] = args;
|
|
1217
|
+
if (!userId || !sessionId) return null;
|
|
1218
|
+
return {
|
|
1219
|
+
type: "delete",
|
|
1220
|
+
userId,
|
|
1221
|
+
sessionId,
|
|
1222
|
+
timestamp
|
|
1223
|
+
};
|
|
1224
|
+
}
|
|
1225
|
+
return null;
|
|
1226
|
+
}
|
|
1174
1227
|
async function initializeStorage(store) {
|
|
1175
1228
|
if (typeof store.init === "function") {
|
|
1176
1229
|
await store.init();
|
|
@@ -1308,13 +1361,24 @@ async function getStorage() {
|
|
|
1308
1361
|
storageInstance = await storagePromise;
|
|
1309
1362
|
return storageInstance;
|
|
1310
1363
|
}
|
|
1364
|
+
function onSessionMutation(listener) {
|
|
1365
|
+
sessionMutationListeners.add(listener);
|
|
1366
|
+
return () => {
|
|
1367
|
+
sessionMutationListeners.delete(listener);
|
|
1368
|
+
};
|
|
1369
|
+
}
|
|
1311
1370
|
var sessions = new Proxy({}, {
|
|
1312
1371
|
get(_target, prop) {
|
|
1313
1372
|
return async (...args) => {
|
|
1314
1373
|
const instance = await getStorage();
|
|
1315
1374
|
const value = instance[prop];
|
|
1316
1375
|
if (typeof value === "function") {
|
|
1317
|
-
|
|
1376
|
+
const result = await value.apply(instance, args);
|
|
1377
|
+
const event = createSessionMutationEvent(prop, args);
|
|
1378
|
+
if (event) {
|
|
1379
|
+
emitSessionMutation(event);
|
|
1380
|
+
}
|
|
1381
|
+
return result;
|
|
1318
1382
|
}
|
|
1319
1383
|
return value;
|
|
1320
1384
|
};
|
|
@@ -3290,6 +3354,6 @@ data: ${JSON.stringify(data)}
|
|
|
3290
3354
|
return { GET, POST };
|
|
3291
3355
|
}
|
|
3292
3356
|
|
|
3293
|
-
export { MCPClient, MultiSessionClient, SSEConnectionManager, StorageOAuthClientProvider, UnauthorizedError, createNextMcpHandler, createSSEHandler, sanitizeServerLabel, sessions };
|
|
3357
|
+
export { MCPClient, MultiSessionClient, SSEConnectionManager, StorageOAuthClientProvider, UnauthorizedError, createNextMcpHandler, createSSEHandler, onSessionMutation, sanitizeServerLabel, sessions };
|
|
3294
3358
|
//# sourceMappingURL=index.mjs.map
|
|
3295
3359
|
//# sourceMappingURL=index.mjs.map
|