@frontmcp/plugin-cache 1.8.5 → 1.8.6

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.
@@ -1 +1 @@
1
- {"version":3,"file":"cache.plugin.d.ts","sourceRoot":"","sources":["../src/cache.plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAOb,KAAK,SAAS,EAEd,KAAK,YAAY,EAClB,MAAM,eAAe,CAAC;AAIvB,OAAO,EAAE,KAAK,kBAAkB,EAAsC,MAAM,eAAe,CAAC;AA2C5F,MAAM,CAAC,OAAO,OAAO,WAAY,SAAQ,aAAa,CAAC,kBAAkB,CAAC;IACxE,OAAgB,gBAAgB,GAAI,SAAS,kBAAkB,oBAqD7D;IAEF,MAAM,CAAC,cAAc,EAAE,kBAAkB,CAEvC;IACF,OAAO,EAAE,kBAAkB,CAAC;gBAEhB,OAAO,GAAE,kBAA+C;IAQpE;;OAEG;IACH,OAAO,CAAC,eAAe;IAYvB;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAsBzB;;OAEG;IACH,OAAO,CAAC,MAAM;IAQR,aAAa,CAAC,OAAO,EAAE,SAAS,CAAC,iBAAiB,CAAC;IA0EnD,cAAc,CAAC,OAAO,EAAE,SAAS,CAAC,iBAAiB,CAAC;IAyB1D;;;;;;;;;OASG;IACH,OAAO,CAAC,qBAAqB;IAyB7B;;;;;;OAMG;IACH,OAAO,CAAC,aAAa;IAQrB;;;OAGG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;CAGvC"}
1
+ {"version":3,"file":"cache.plugin.d.ts","sourceRoot":"","sources":["../src/cache.plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAOb,KAAK,SAAS,EAEd,KAAK,YAAY,EAClB,MAAM,eAAe,CAAC;AAIvB,OAAO,EAAE,KAAK,kBAAkB,EAAsC,MAAM,eAAe,CAAC;AA8C5F,MAAM,CAAC,OAAO,OAAO,WAAY,SAAQ,aAAa,CAAC,kBAAkB,CAAC;IACxE,OAAgB,gBAAgB,GAAI,SAAS,kBAAkB,oBAuD7D;IAEF,MAAM,CAAC,cAAc,EAAE,kBAAkB,CAEvC;IACF,OAAO,EAAE,kBAAkB,CAAC;gBAEhB,OAAO,GAAE,kBAA+C;IAQpE;;OAEG;IACH,OAAO,CAAC,eAAe;IAkBvB;;;OAGG;IACH,OAAO,CAAC,iBAAiB;IAsBzB;;OAEG;IACH,OAAO,CAAC,MAAM;IAQR,aAAa,CAAC,OAAO,EAAE,SAAS,CAAC,iBAAiB,CAAC;IA0DnD,cAAc,CAAC,OAAO,EAAE,SAAS,CAAC,iBAAiB,CAAC;IAyB1D;;;;;;;;;OASG;IACH,OAAO,CAAC,qBAAqB;IAyB7B;;;;;;OAMG;IACH,OAAO,CAAC,aAAa;IAQrB;;;OAGG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;CAGvC"}
package/esm/index.mjs CHANGED
@@ -2562,25 +2562,29 @@ function getRedisClass() {
2562
2562
  const msg = error instanceof Error ? error.message : String(error);
2563
2563
  if (msg.includes("Dynamic require") || msg.includes("require is not defined")) {
2564
2564
  throw new Error(
2565
- `Failed to load ioredis: ${msg}. This typically happens with ESM bundlers (esbuild, Vite). Ensure your bundler externalizes ioredis or use CJS mode.`
2565
+ `Failed to load ioredis: ${msg}. This typically happens with ESM bundlers (esbuild, Vite). Ensure your bundler externalizes ioredis or use CJS mode.`,
2566
+ { cause: error }
2566
2567
  );
2567
2568
  }
2568
- throw new Error("ioredis is required for Redis storage adapter. Install it with: npm install ioredis");
2569
+ throw new Error("ioredis is required for Redis storage adapter. Install it with: npm install ioredis", {
2570
+ cause: error
2571
+ });
2569
2572
  }
2570
2573
  }
2571
2574
  var RedisStorageAdapter;
2572
2575
  var init_redis = __esm({
2573
2576
  "libs/utils/src/storage/adapters/redis.ts"() {
2574
2577
  "use strict";
2575
- init_base();
2576
2578
  init_errors();
2577
2579
  init_utils();
2580
+ init_base();
2578
2581
  RedisStorageAdapter = class extends BaseStorageAdapter {
2579
2582
  backendName = "redis";
2580
2583
  client;
2581
2584
  subscriber;
2582
2585
  options;
2583
2586
  ownsClient;
2587
+ connecting;
2584
2588
  keyPrefix;
2585
2589
  subscriptionHandlers = /* @__PURE__ */ new Map();
2586
2590
  constructor(options = {}) {
@@ -2610,21 +2614,42 @@ var init_redis = __esm({
2610
2614
  // ============================================
2611
2615
  async connect() {
2612
2616
  if (this.connected) return;
2617
+ this.connecting ??= this.openConnection().finally(() => {
2618
+ this.connecting = void 0;
2619
+ });
2620
+ return this.connecting;
2621
+ }
2622
+ async openConnection() {
2623
+ let socketError;
2624
+ const recordSocketError = (error) => {
2625
+ socketError = error;
2626
+ };
2627
+ let client;
2613
2628
  try {
2614
2629
  if (this.options.client) {
2615
- this.client = this.options.client;
2630
+ client = this.options.client;
2616
2631
  } else {
2617
2632
  const RedisClass = getRedisClass();
2618
2633
  if (this.options.url) {
2619
- this.client = new RedisClass(this.options.url, this.buildRedisOptions());
2634
+ client = new RedisClass(this.options.url, this.buildRedisOptions());
2620
2635
  } else {
2621
- this.client = new RedisClass(this.buildRedisOptions());
2636
+ client = new RedisClass(this.buildRedisOptions());
2622
2637
  }
2638
+ client.on("error", recordSocketError);
2623
2639
  }
2624
- await this.client.ping();
2640
+ await client.ping();
2641
+ this.client = client;
2625
2642
  this.connected = true;
2643
+ if (this.ownsClient) client.removeListener("error", recordSocketError);
2626
2644
  } catch (e) {
2627
- throw new StorageConnectionError("Failed to connect to Redis", e instanceof Error ? e : void 0, "redis");
2645
+ if (this.ownsClient && client) {
2646
+ try {
2647
+ client.disconnect();
2648
+ } catch {
2649
+ }
2650
+ }
2651
+ const cause = socketError ?? (e instanceof Error ? e : void 0);
2652
+ throw new StorageConnectionError("Failed to connect to Redis", cause, "redis");
2628
2653
  }
2629
2654
  }
2630
2655
  async disconnect() {
@@ -3916,6 +3941,9 @@ var CachePlugin = class extends DynamicPlugin {
3916
3941
  * Check if a tool should be cached based on metadata or tools list.
3917
3942
  */
3918
3943
  shouldCacheTool(toolName, cacheMetadata) {
3944
+ if (typeof cacheMetadata === "object" && cacheMetadata.ttl !== void 0 && cacheMetadata.ttl <= 0) {
3945
+ return false;
3946
+ }
3919
3947
  if (cacheMetadata) return true;
3920
3948
  const patterns = this.options.toolPatterns ?? [];
3921
3949
  return matchesToolPattern(toolName, patterns);
@@ -3970,23 +3998,9 @@ var CachePlugin = class extends DynamicPlugin {
3970
3998
  await cacheStore.delete(hash);
3971
3999
  return;
3972
4000
  }
3973
- const isPlainObject = typeof cached === "object" && cached !== null && !Array.isArray(cached);
3974
- let cachedWithMeta;
3975
- if (isPlainObject) {
3976
- const cachedRecord = cached;
3977
- const existingMeta = cachedRecord["_meta"] || {};
3978
- cachedWithMeta = {
3979
- ...cachedRecord,
3980
- _meta: {
3981
- ...existingMeta,
3982
- cache: "hit"
3983
- }
3984
- };
3985
- } else {
3986
- cachedWithMeta = cached;
3987
- }
3988
- flowCtx.state.rawOutput = cachedWithMeta;
3989
- toolContext.respond(cachedWithMeta);
4001
+ flowCtx.state.set("resultMeta", { ...flowCtx.state.resultMeta, cache: "hit" });
4002
+ flowCtx.state.set("rawOutput", cached);
4003
+ toolContext.respond(cached);
3990
4004
  }
3991
4005
  }
3992
4006
  async willWriteCache(flowCtx) {
@@ -4089,7 +4103,9 @@ __publicField(CachePlugin, "dynamicProviders", (options) => {
4089
4103
  providers.push({
4090
4104
  name: "cache:memory",
4091
4105
  provide: CacheStoreToken,
4092
- useValue: new CacheMemoryProvider(options.defaultTTL)
4106
+ // Built per server: `init()` runs once, so a value here would be shared by every server using it.
4107
+ inject: () => [],
4108
+ useFactory: () => new CacheMemoryProvider(options.defaultTTL)
4093
4109
  });
4094
4110
  break;
4095
4111
  }
@@ -4111,10 +4127,13 @@ CachePlugin = __decorateClass([
4111
4127
  providers: [
4112
4128
  /* add providers that always loaded with the plugin or default providers */
4113
4129
  {
4114
- // this is a default provider for cache, will be overridden if dynamicProviders based on config
4130
+ // this is a default provider for cache, will be overridden if dynamicProviders based on config.
4131
+ // A factory, so each server gets its own store: a value built here is one store for every
4132
+ // server in the process, created when this module loads.
4115
4133
  name: "cache:memory",
4116
4134
  provide: CacheStoreToken,
4117
- useValue: new CacheMemoryProvider(60 * 60 * 24)
4135
+ inject: () => [],
4136
+ useFactory: () => new CacheMemoryProvider(60 * 60 * 24)
4118
4137
  }
4119
4138
  ]
4120
4139
  })
package/esm/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frontmcp/plugin-cache",
3
- "version": "1.8.5",
3
+ "version": "1.8.6",
4
4
  "description": "Cache plugin for FrontMCP - Redis, Vercel KV, and in-memory caching with automatic tool result caching",
5
5
  "author": "AgentFront <info@agentfront.dev>",
6
6
  "license": "Apache-2.0",
@@ -48,8 +48,8 @@
48
48
  }
49
49
  },
50
50
  "dependencies": {
51
- "@frontmcp/sdk": "1.8.5",
52
- "@frontmcp/utils": "1.8.5",
51
+ "@frontmcp/sdk": "1.8.6",
52
+ "@frontmcp/utils": "1.8.6",
53
53
  "ioredis": "^5.8.0"
54
54
  },
55
55
  "peerDependencies": {
package/index.js CHANGED
@@ -2563,25 +2563,29 @@ function getRedisClass() {
2563
2563
  const msg = error instanceof Error ? error.message : String(error);
2564
2564
  if (msg.includes("Dynamic require") || msg.includes("require is not defined")) {
2565
2565
  throw new Error(
2566
- `Failed to load ioredis: ${msg}. This typically happens with ESM bundlers (esbuild, Vite). Ensure your bundler externalizes ioredis or use CJS mode.`
2566
+ `Failed to load ioredis: ${msg}. This typically happens with ESM bundlers (esbuild, Vite). Ensure your bundler externalizes ioredis or use CJS mode.`,
2567
+ { cause: error }
2567
2568
  );
2568
2569
  }
2569
- throw new Error("ioredis is required for Redis storage adapter. Install it with: npm install ioredis");
2570
+ throw new Error("ioredis is required for Redis storage adapter. Install it with: npm install ioredis", {
2571
+ cause: error
2572
+ });
2570
2573
  }
2571
2574
  }
2572
2575
  var RedisStorageAdapter;
2573
2576
  var init_redis = __esm({
2574
2577
  "libs/utils/src/storage/adapters/redis.ts"() {
2575
2578
  "use strict";
2576
- init_base();
2577
2579
  init_errors();
2578
2580
  init_utils();
2581
+ init_base();
2579
2582
  RedisStorageAdapter = class extends BaseStorageAdapter {
2580
2583
  backendName = "redis";
2581
2584
  client;
2582
2585
  subscriber;
2583
2586
  options;
2584
2587
  ownsClient;
2588
+ connecting;
2585
2589
  keyPrefix;
2586
2590
  subscriptionHandlers = /* @__PURE__ */ new Map();
2587
2591
  constructor(options = {}) {
@@ -2611,21 +2615,42 @@ var init_redis = __esm({
2611
2615
  // ============================================
2612
2616
  async connect() {
2613
2617
  if (this.connected) return;
2618
+ this.connecting ??= this.openConnection().finally(() => {
2619
+ this.connecting = void 0;
2620
+ });
2621
+ return this.connecting;
2622
+ }
2623
+ async openConnection() {
2624
+ let socketError;
2625
+ const recordSocketError = (error) => {
2626
+ socketError = error;
2627
+ };
2628
+ let client;
2614
2629
  try {
2615
2630
  if (this.options.client) {
2616
- this.client = this.options.client;
2631
+ client = this.options.client;
2617
2632
  } else {
2618
2633
  const RedisClass = getRedisClass();
2619
2634
  if (this.options.url) {
2620
- this.client = new RedisClass(this.options.url, this.buildRedisOptions());
2635
+ client = new RedisClass(this.options.url, this.buildRedisOptions());
2621
2636
  } else {
2622
- this.client = new RedisClass(this.buildRedisOptions());
2637
+ client = new RedisClass(this.buildRedisOptions());
2623
2638
  }
2639
+ client.on("error", recordSocketError);
2624
2640
  }
2625
- await this.client.ping();
2641
+ await client.ping();
2642
+ this.client = client;
2626
2643
  this.connected = true;
2644
+ if (this.ownsClient) client.removeListener("error", recordSocketError);
2627
2645
  } catch (e) {
2628
- throw new StorageConnectionError("Failed to connect to Redis", e instanceof Error ? e : void 0, "redis");
2646
+ if (this.ownsClient && client) {
2647
+ try {
2648
+ client.disconnect();
2649
+ } catch {
2650
+ }
2651
+ }
2652
+ const cause = socketError ?? (e instanceof Error ? e : void 0);
2653
+ throw new StorageConnectionError("Failed to connect to Redis", cause, "redis");
2629
2654
  }
2630
2655
  }
2631
2656
  async disconnect() {
@@ -3917,6 +3942,9 @@ var CachePlugin = class extends import_sdk4.DynamicPlugin {
3917
3942
  * Check if a tool should be cached based on metadata or tools list.
3918
3943
  */
3919
3944
  shouldCacheTool(toolName, cacheMetadata) {
3945
+ if (typeof cacheMetadata === "object" && cacheMetadata.ttl !== void 0 && cacheMetadata.ttl <= 0) {
3946
+ return false;
3947
+ }
3920
3948
  if (cacheMetadata) return true;
3921
3949
  const patterns = this.options.toolPatterns ?? [];
3922
3950
  return matchesToolPattern(toolName, patterns);
@@ -3971,23 +3999,9 @@ var CachePlugin = class extends import_sdk4.DynamicPlugin {
3971
3999
  await cacheStore.delete(hash);
3972
4000
  return;
3973
4001
  }
3974
- const isPlainObject = typeof cached === "object" && cached !== null && !Array.isArray(cached);
3975
- let cachedWithMeta;
3976
- if (isPlainObject) {
3977
- const cachedRecord = cached;
3978
- const existingMeta = cachedRecord["_meta"] || {};
3979
- cachedWithMeta = {
3980
- ...cachedRecord,
3981
- _meta: {
3982
- ...existingMeta,
3983
- cache: "hit"
3984
- }
3985
- };
3986
- } else {
3987
- cachedWithMeta = cached;
3988
- }
3989
- flowCtx.state.rawOutput = cachedWithMeta;
3990
- toolContext.respond(cachedWithMeta);
4002
+ flowCtx.state.set("resultMeta", { ...flowCtx.state.resultMeta, cache: "hit" });
4003
+ flowCtx.state.set("rawOutput", cached);
4004
+ toolContext.respond(cached);
3991
4005
  }
3992
4006
  }
3993
4007
  async willWriteCache(flowCtx) {
@@ -4090,7 +4104,9 @@ __publicField(CachePlugin, "dynamicProviders", (options) => {
4090
4104
  providers.push({
4091
4105
  name: "cache:memory",
4092
4106
  provide: CacheStoreToken,
4093
- useValue: new CacheMemoryProvider(options.defaultTTL)
4107
+ // Built per server: `init()` runs once, so a value here would be shared by every server using it.
4108
+ inject: () => [],
4109
+ useFactory: () => new CacheMemoryProvider(options.defaultTTL)
4094
4110
  });
4095
4111
  break;
4096
4112
  }
@@ -4112,10 +4128,13 @@ CachePlugin = __decorateClass([
4112
4128
  providers: [
4113
4129
  /* add providers that always loaded with the plugin or default providers */
4114
4130
  {
4115
- // this is a default provider for cache, will be overridden if dynamicProviders based on config
4131
+ // this is a default provider for cache, will be overridden if dynamicProviders based on config.
4132
+ // A factory, so each server gets its own store: a value built here is one store for every
4133
+ // server in the process, created when this module loads.
4116
4134
  name: "cache:memory",
4117
4135
  provide: CacheStoreToken,
4118
- useValue: new CacheMemoryProvider(60 * 60 * 24)
4136
+ inject: () => [],
4137
+ useFactory: () => new CacheMemoryProvider(60 * 60 * 24)
4119
4138
  }
4120
4139
  ]
4121
4140
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frontmcp/plugin-cache",
3
- "version": "1.8.5",
3
+ "version": "1.8.6",
4
4
  "description": "Cache plugin for FrontMCP - Redis, Vercel KV, and in-memory caching with automatic tool result caching",
5
5
  "author": "AgentFront <info@agentfront.dev>",
6
6
  "license": "Apache-2.0",
@@ -48,8 +48,8 @@
48
48
  }
49
49
  },
50
50
  "dependencies": {
51
- "@frontmcp/sdk": "1.8.5",
52
- "@frontmcp/utils": "1.8.5",
51
+ "@frontmcp/sdk": "1.8.6",
52
+ "@frontmcp/utils": "1.8.6",
53
53
  "ioredis": "^5.8.0"
54
54
  },
55
55
  "peerDependencies": {