@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.mjs CHANGED
@@ -1174,6 +1174,59 @@ function warnIfNeonConnectionStringIsInsecure(connectionString) {
1174
1174
  }
1175
1175
  var storageInstance = null;
1176
1176
  var storagePromise = null;
1177
+ var sessionMutationListeners = /* @__PURE__ */ new Set();
1178
+ function emitSessionMutation(event) {
1179
+ for (const listener of sessionMutationListeners) {
1180
+ try {
1181
+ const result = listener(event);
1182
+ if (result && typeof result.catch === "function") {
1183
+ void result.catch((error) => {
1184
+ console.error("[mcp-ts][Storage] Session mutation listener failed:", error);
1185
+ });
1186
+ }
1187
+ } catch (error) {
1188
+ console.error("[mcp-ts][Storage] Session mutation listener failed:", error);
1189
+ }
1190
+ }
1191
+ }
1192
+ function createSessionMutationEvent(prop, args) {
1193
+ const timestamp = Date.now();
1194
+ if (prop === "create") {
1195
+ const [session, ttl] = args;
1196
+ if (!session?.userId || !session?.sessionId) return null;
1197
+ return {
1198
+ type: "create",
1199
+ userId: session.userId,
1200
+ sessionId: session.sessionId,
1201
+ session,
1202
+ ttl,
1203
+ timestamp
1204
+ };
1205
+ }
1206
+ if (prop === "update") {
1207
+ const [userId, sessionId, patch, ttl] = args;
1208
+ if (!userId || !sessionId) return null;
1209
+ return {
1210
+ type: "update",
1211
+ userId,
1212
+ sessionId,
1213
+ patch,
1214
+ ttl,
1215
+ timestamp
1216
+ };
1217
+ }
1218
+ if (prop === "delete") {
1219
+ const [userId, sessionId] = args;
1220
+ if (!userId || !sessionId) return null;
1221
+ return {
1222
+ type: "delete",
1223
+ userId,
1224
+ sessionId,
1225
+ timestamp
1226
+ };
1227
+ }
1228
+ return null;
1229
+ }
1177
1230
  async function initializeStorage(store) {
1178
1231
  if (typeof store.init === "function") {
1179
1232
  await store.init();
@@ -1311,13 +1364,24 @@ async function getStorage() {
1311
1364
  storageInstance = await storagePromise;
1312
1365
  return storageInstance;
1313
1366
  }
1367
+ function onSessionMutation(listener) {
1368
+ sessionMutationListeners.add(listener);
1369
+ return () => {
1370
+ sessionMutationListeners.delete(listener);
1371
+ };
1372
+ }
1314
1373
  var sessions = new Proxy({}, {
1315
1374
  get(_target, prop) {
1316
1375
  return async (...args) => {
1317
1376
  const instance = await getStorage();
1318
1377
  const value = instance[prop];
1319
1378
  if (typeof value === "function") {
1320
- return value.apply(instance, args);
1379
+ const result = await value.apply(instance, args);
1380
+ const event = createSessionMutationEvent(prop, args);
1381
+ if (event) {
1382
+ emitSessionMutation(event);
1383
+ }
1384
+ return result;
1321
1385
  }
1322
1386
  return value;
1323
1387
  };
@@ -5228,6 +5292,6 @@ function globToRegExp(pattern) {
5228
5292
  return new RegExp(regexPattern);
5229
5293
  }
5230
5294
 
5231
- export { APP_HOST_DEFAULTS, AppHost, AuthenticationError, ConfigurationError, ConnectionError, DEFAULT_CLIENT_NAME, DEFAULT_CLIENT_URI, DEFAULT_HEARTBEAT_INTERVAL_MS, DEFAULT_LOGO_URI, DEFAULT_MCP_APP_CSP, DEFAULT_POLICY_URI, DisposableStore, Emitter, InvalidStateError, MCPClient, MCP_CLIENT_NAME, MCP_CLIENT_VERSION, McpError, MultiSessionClient, NotConnectedError, REDIS_KEY_PREFIX, RpcErrorCodes, SANDBOX_PROXY_READY_METHOD, SANDBOX_RESOURCE_READY_METHOD, SESSION_TTL_SECONDS, SOFTWARE_ID, SOFTWARE_VERSION, SSEClient, SSEConnectionManager, STATE_EXPIRATION_MS, SchemaCompressor, SessionNotFoundError, SessionValidationError, StorageOAuthClientProvider, TOKEN_EXPIRY_BUFFER_MS, ToolExecutionError, ToolIndex, ToolRouter, UnauthorizedError, createExecuteToolDefinition, createGetSchemaToolDefinition, createListServersToolDefinition, createNextMcpHandler, createRegexSearchToolDefinition, createSSEHandler, createSearchToolDefinition, executeMetaTool, findToolByName, getToolUiResourceUri, isCallToolSuccess, isConnectAuthRequired, isConnectError, isConnectSuccess, isListToolsSuccess, isMetaTool, resolveMetaToolProxy, sanitizeServerLabel, sessions };
5295
+ export { APP_HOST_DEFAULTS, AppHost, AuthenticationError, ConfigurationError, ConnectionError, DEFAULT_CLIENT_NAME, DEFAULT_CLIENT_URI, DEFAULT_HEARTBEAT_INTERVAL_MS, DEFAULT_LOGO_URI, DEFAULT_MCP_APP_CSP, DEFAULT_POLICY_URI, DisposableStore, Emitter, InvalidStateError, MCPClient, MCP_CLIENT_NAME, MCP_CLIENT_VERSION, McpError, MultiSessionClient, NotConnectedError, REDIS_KEY_PREFIX, RpcErrorCodes, SANDBOX_PROXY_READY_METHOD, SANDBOX_RESOURCE_READY_METHOD, SESSION_TTL_SECONDS, SOFTWARE_ID, SOFTWARE_VERSION, SSEClient, SSEConnectionManager, STATE_EXPIRATION_MS, SchemaCompressor, SessionNotFoundError, SessionValidationError, StorageOAuthClientProvider, TOKEN_EXPIRY_BUFFER_MS, ToolExecutionError, ToolIndex, ToolRouter, UnauthorizedError, createExecuteToolDefinition, createGetSchemaToolDefinition, createListServersToolDefinition, createNextMcpHandler, createRegexSearchToolDefinition, createSSEHandler, createSearchToolDefinition, executeMetaTool, findToolByName, getToolUiResourceUri, isCallToolSuccess, isConnectAuthRequired, isConnectError, isConnectSuccess, isListToolsSuccess, isMetaTool, onSessionMutation, resolveMetaToolProxy, sanitizeServerLabel, sessions };
5232
5296
  //# sourceMappingURL=index.mjs.map
5233
5297
  //# sourceMappingURL=index.mjs.map