@mcp-ts/sdk 2.1.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
  };
@@ -4929,6 +4993,7 @@ var ToolRouter = class {
4929
4993
  __publicField(this, "index");
4930
4994
  __publicField(this, "allTools", []);
4931
4995
  __publicField(this, "pinnedTools", []);
4996
+ __publicField(this, "deferredTools", []);
4932
4997
  __publicField(this, "discoverableTools", []);
4933
4998
  __publicField(this, "groupsMap", /* @__PURE__ */ new Map());
4934
4999
  __publicField(this, "strategy");
@@ -4937,6 +5002,7 @@ var ToolRouter = class {
4937
5002
  __publicField(this, "activeGroups");
4938
5003
  __publicField(this, "customGroups");
4939
5004
  __publicField(this, "pinnedToolNames");
5005
+ __publicField(this, "deferredToolNames");
4940
5006
  __publicField(this, "excludeToolMatchers");
4941
5007
  __publicField(this, "initialized", false);
4942
5008
  this.strategy = options.strategy ?? "all";
@@ -4945,6 +5011,7 @@ var ToolRouter = class {
4945
5011
  this.activeGroups = new Set(options.activeGroups ?? []);
4946
5012
  this.customGroups = options.groups;
4947
5013
  this.pinnedToolNames = new Set(options.pinnedTools ?? []);
5014
+ this.deferredToolNames = new Set(options.deferredTools ?? []);
4948
5015
  this.excludeToolMatchers = (options.excludeTools ?? []).map(
4949
5016
  (pattern) => globToRegExp(pattern)
4950
5017
  );
@@ -4973,8 +5040,9 @@ var ToolRouter = class {
4973
5040
  return this.getGroupFilteredTools();
4974
5041
  case "all":
4975
5042
  default:
5043
+ const directlyVisibleTools = this.getDirectlyVisibleTools();
4976
5044
  if (this.compactSchemas) {
4977
- return this.allTools.map((t) => {
5045
+ return directlyVisibleTools.map((t) => {
4978
5046
  const compact = SchemaCompressor.toCompact(t);
4979
5047
  return {
4980
5048
  name: compact.name,
@@ -4983,7 +5051,7 @@ var ToolRouter = class {
4983
5051
  };
4984
5052
  });
4985
5053
  }
4986
- return [...this.allTools];
5054
+ return [...directlyVisibleTools];
4987
5055
  }
4988
5056
  }
4989
5057
  /**
@@ -5098,6 +5166,9 @@ var ToolRouter = class {
5098
5166
  const fetchedTools = await this.fetchAllTools();
5099
5167
  this.allTools = fetchedTools.filter((tool) => !this.matchesExcludedTool(tool.name));
5100
5168
  this.pinnedTools = this.allTools.filter((tool) => this.matchesPinnedTool(tool.name));
5169
+ this.deferredTools = this.allTools.filter(
5170
+ (tool) => !this.matchesPinnedTool(tool.name) && this.matchesDeferredTool(tool)
5171
+ );
5101
5172
  this.discoverableTools = this.allTools.filter((tool) => !this.matchesPinnedTool(tool.name));
5102
5173
  await this.index.buildIndex(this.discoverableTools);
5103
5174
  this.buildGroups();
@@ -5175,7 +5246,7 @@ var ToolRouter = class {
5175
5246
  }
5176
5247
  }
5177
5248
  }
5178
- const filtered = this.allTools.filter((t) => activeToolNames.has(t.name));
5249
+ const filtered = this.getDirectlyVisibleTools().filter((t) => activeToolNames.has(t.name));
5179
5250
  if (this.compactSchemas) {
5180
5251
  return filtered.slice(0, this.maxTools).map((t) => {
5181
5252
  const compact = SchemaCompressor.toCompact(t);
@@ -5201,9 +5272,19 @@ var ToolRouter = class {
5201
5272
  matchesPinnedTool(toolName) {
5202
5273
  return this.pinnedToolNames.has(toolName);
5203
5274
  }
5275
+ matchesDeferredTool(tool) {
5276
+ if (this.deferredToolNames.has(tool.name)) {
5277
+ return true;
5278
+ }
5279
+ const meta = tool._meta;
5280
+ return meta?.toolRouter?.deferred === true;
5281
+ }
5204
5282
  matchesExcludedTool(toolName) {
5205
5283
  return this.excludeToolMatchers.some((matcher) => matcher.test(toolName));
5206
5284
  }
5285
+ getDirectlyVisibleTools() {
5286
+ return this.allTools.filter((tool) => !this.matchesDeferredTool(tool) || this.matchesPinnedTool(tool.name));
5287
+ }
5207
5288
  };
5208
5289
  function globToRegExp(pattern) {
5209
5290
  const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&");
@@ -5211,6 +5292,6 @@ function globToRegExp(pattern) {
5211
5292
  return new RegExp(regexPattern);
5212
5293
  }
5213
5294
 
5214
- 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 };
5215
5296
  //# sourceMappingURL=index.mjs.map
5216
5297
  //# sourceMappingURL=index.mjs.map