@mcp-ts/sdk 2.2.0 → 2.3.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.
Files changed (48) hide show
  1. package/dist/adapters/agui-adapter.d.mts +1 -1
  2. package/dist/adapters/agui-adapter.d.ts +1 -1
  3. package/dist/adapters/agui-adapter.js +9 -5
  4. package/dist/adapters/agui-adapter.js.map +1 -1
  5. package/dist/adapters/agui-adapter.mjs +9 -5
  6. package/dist/adapters/agui-adapter.mjs.map +1 -1
  7. package/dist/adapters/agui-middleware.d.mts +1 -1
  8. package/dist/adapters/agui-middleware.d.ts +1 -1
  9. package/dist/adapters/ai-adapter.d.mts +1 -1
  10. package/dist/adapters/ai-adapter.d.ts +1 -1
  11. package/dist/adapters/ai-adapter.js +9 -5
  12. package/dist/adapters/ai-adapter.js.map +1 -1
  13. package/dist/adapters/ai-adapter.mjs +9 -5
  14. package/dist/adapters/ai-adapter.mjs.map +1 -1
  15. package/dist/adapters/langchain-adapter.d.mts +1 -1
  16. package/dist/adapters/langchain-adapter.d.ts +1 -1
  17. package/dist/adapters/langchain-adapter.js +9 -5
  18. package/dist/adapters/langchain-adapter.js.map +1 -1
  19. package/dist/adapters/langchain-adapter.mjs +9 -5
  20. package/dist/adapters/langchain-adapter.mjs.map +1 -1
  21. package/dist/client/react.js.map +1 -1
  22. package/dist/client/react.mjs.map +1 -1
  23. package/dist/index.d.mts +2 -2
  24. package/dist/index.d.ts +2 -2
  25. package/dist/index.js +83 -6
  26. package/dist/index.js.map +1 -1
  27. package/dist/index.mjs +83 -7
  28. package/dist/index.mjs.map +1 -1
  29. package/dist/server/index.d.mts +13 -1
  30. package/dist/server/index.d.ts +13 -1
  31. package/dist/server/index.js +66 -1
  32. package/dist/server/index.js.map +1 -1
  33. package/dist/server/index.mjs +66 -2
  34. package/dist/server/index.mjs.map +1 -1
  35. package/dist/shared/index.d.mts +2 -2
  36. package/dist/shared/index.d.ts +2 -2
  37. package/dist/shared/index.js +17 -5
  38. package/dist/shared/index.js.map +1 -1
  39. package/dist/shared/index.mjs +17 -5
  40. package/dist/shared/index.mjs.map +1 -1
  41. package/dist/{tool-router-C8hIA-tg.d.mts → tool-router-BfE_9tay.d.mts} +5 -0
  42. package/dist/{tool-router-CdX8e9bk.d.ts → tool-router-CP7qLk1J.d.ts} +5 -0
  43. package/package.json +1 -1
  44. package/src/server/index.ts +8 -1
  45. package/src/server/storage/index.ts +77 -2
  46. package/src/server/storage/types.ts +14 -0
  47. package/src/shared/meta-tools.ts +16 -7
  48. package/src/shared/tool-router.ts +13 -0
@@ -31,6 +31,17 @@ interface Session {
31
31
  codeVerifier?: string;
32
32
  clientId?: string;
33
33
  }
34
+ type SessionMutationType = 'create' | 'update' | 'delete';
35
+ interface SessionMutationEvent {
36
+ type: SessionMutationType;
37
+ userId: string;
38
+ sessionId: string;
39
+ timestamp: number;
40
+ session?: Session;
41
+ patch?: Partial<Session>;
42
+ ttl?: number;
43
+ }
44
+ type SessionMutationListener = (event: SessionMutationEvent) => void | Promise<void>;
34
45
  /**
35
46
  * Interface for MCP session stores.
36
47
  */
@@ -91,6 +102,7 @@ interface SessionStore {
91
102
  disconnect(): Promise<void>;
92
103
  }
93
104
 
105
+ declare function onSessionMutation(listener: SessionMutationListener): () => void;
94
106
  /**
95
107
  * Global session store instance
96
108
  * Uses lazy initialization with a Proxy to handle async setup transparently
@@ -262,4 +274,4 @@ declare function createNextMcpHandler(options?: NextMcpHandlerOptions): {
262
274
  POST: (request: Request) => Promise<Response>;
263
275
  };
264
276
 
265
- export { type ClientMetadata, McpConnectionEvent, McpObservabilityEvent, McpRpcRequest, McpRpcResponse, type NextMcpHandlerOptions, SSEConnectionManager, type SSEHandlerOptions, type SessionStore, createNextMcpHandler, createSSEHandler, sessions };
277
+ export { type ClientMetadata, McpConnectionEvent, McpObservabilityEvent, McpRpcRequest, McpRpcResponse, type NextMcpHandlerOptions, SSEConnectionManager, type SSEHandlerOptions, type Session, type SessionMutationEvent, type SessionMutationListener, type SessionMutationType, type SessionStore, createNextMcpHandler, createSSEHandler, onSessionMutation, sessions };
@@ -31,6 +31,17 @@ interface Session {
31
31
  codeVerifier?: string;
32
32
  clientId?: string;
33
33
  }
34
+ type SessionMutationType = 'create' | 'update' | 'delete';
35
+ interface SessionMutationEvent {
36
+ type: SessionMutationType;
37
+ userId: string;
38
+ sessionId: string;
39
+ timestamp: number;
40
+ session?: Session;
41
+ patch?: Partial<Session>;
42
+ ttl?: number;
43
+ }
44
+ type SessionMutationListener = (event: SessionMutationEvent) => void | Promise<void>;
34
45
  /**
35
46
  * Interface for MCP session stores.
36
47
  */
@@ -91,6 +102,7 @@ interface SessionStore {
91
102
  disconnect(): Promise<void>;
92
103
  }
93
104
 
105
+ declare function onSessionMutation(listener: SessionMutationListener): () => void;
94
106
  /**
95
107
  * Global session store instance
96
108
  * Uses lazy initialization with a Proxy to handle async setup transparently
@@ -262,4 +274,4 @@ declare function createNextMcpHandler(options?: NextMcpHandlerOptions): {
262
274
  POST: (request: Request) => Promise<Response>;
263
275
  };
264
276
 
265
- export { type ClientMetadata, McpConnectionEvent, McpObservabilityEvent, McpRpcRequest, McpRpcResponse, type NextMcpHandlerOptions, SSEConnectionManager, type SSEHandlerOptions, type SessionStore, createNextMcpHandler, createSSEHandler, sessions };
277
+ export { type ClientMetadata, McpConnectionEvent, McpObservabilityEvent, McpRpcRequest, McpRpcResponse, type NextMcpHandlerOptions, SSEConnectionManager, type SSEHandlerOptions, type Session, type SessionMutationEvent, type SessionMutationListener, type SessionMutationType, type SessionStore, createNextMcpHandler, createSSEHandler, onSessionMutation, sessions };
@@ -1236,6 +1236,59 @@ function warnIfNeonConnectionStringIsInsecure(connectionString) {
1236
1236
  }
1237
1237
  var storageInstance = null;
1238
1238
  var storagePromise = null;
1239
+ var sessionMutationListeners = /* @__PURE__ */ new Set();
1240
+ function emitSessionMutation(event) {
1241
+ for (const listener of sessionMutationListeners) {
1242
+ try {
1243
+ const result = listener(event);
1244
+ if (result && typeof result.catch === "function") {
1245
+ void result.catch((error) => {
1246
+ console.error("[mcp-ts][Storage] Session mutation listener failed:", error);
1247
+ });
1248
+ }
1249
+ } catch (error) {
1250
+ console.error("[mcp-ts][Storage] Session mutation listener failed:", error);
1251
+ }
1252
+ }
1253
+ }
1254
+ function createSessionMutationEvent(prop, args) {
1255
+ const timestamp = Date.now();
1256
+ if (prop === "create") {
1257
+ const [session, ttl] = args;
1258
+ if (!session?.userId || !session?.sessionId) return null;
1259
+ return {
1260
+ type: "create",
1261
+ userId: session.userId,
1262
+ sessionId: session.sessionId,
1263
+ session,
1264
+ ttl,
1265
+ timestamp
1266
+ };
1267
+ }
1268
+ if (prop === "update") {
1269
+ const [userId, sessionId, patch, ttl] = args;
1270
+ if (!userId || !sessionId) return null;
1271
+ return {
1272
+ type: "update",
1273
+ userId,
1274
+ sessionId,
1275
+ patch,
1276
+ ttl,
1277
+ timestamp
1278
+ };
1279
+ }
1280
+ if (prop === "delete") {
1281
+ const [userId, sessionId] = args;
1282
+ if (!userId || !sessionId) return null;
1283
+ return {
1284
+ type: "delete",
1285
+ userId,
1286
+ sessionId,
1287
+ timestamp
1288
+ };
1289
+ }
1290
+ return null;
1291
+ }
1239
1292
  async function initializeStorage(store) {
1240
1293
  if (typeof store.init === "function") {
1241
1294
  await store.init();
@@ -1373,13 +1426,24 @@ async function getStorage() {
1373
1426
  storageInstance = await storagePromise;
1374
1427
  return storageInstance;
1375
1428
  }
1429
+ function onSessionMutation(listener) {
1430
+ sessionMutationListeners.add(listener);
1431
+ return () => {
1432
+ sessionMutationListeners.delete(listener);
1433
+ };
1434
+ }
1376
1435
  var sessions = new Proxy({}, {
1377
1436
  get(_target, prop) {
1378
1437
  return async (...args) => {
1379
1438
  const instance = await getStorage();
1380
1439
  const value = instance[prop];
1381
1440
  if (typeof value === "function") {
1382
- return value.apply(instance, args);
1441
+ const result = await value.apply(instance, args);
1442
+ const event = createSessionMutationEvent(prop, args);
1443
+ if (event) {
1444
+ emitSessionMutation(event);
1445
+ }
1446
+ return result;
1383
1447
  }
1384
1448
  return value;
1385
1449
  };
@@ -3370,6 +3434,7 @@ exports.StorageOAuthClientProvider = StorageOAuthClientProvider;
3370
3434
  exports.UnauthorizedError = UnauthorizedError;
3371
3435
  exports.createNextMcpHandler = createNextMcpHandler;
3372
3436
  exports.createSSEHandler = createSSEHandler;
3437
+ exports.onSessionMutation = onSessionMutation;
3373
3438
  exports.sanitizeServerLabel = sanitizeServerLabel;
3374
3439
  exports.sessions = sessions;
3375
3440
  //# sourceMappingURL=index.js.map