@tinycloud/mcp 0.8.7-beta.1 → 0.8.7-beta.3

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/http.cjs CHANGED
@@ -120,12 +120,14 @@ function firstString(...values) {
120
120
  var import_node_crypto = require("crypto");
121
121
  var import_jose2 = require("jose");
122
122
  var ACTIVE_CACHE_MS = 3e4;
123
+ var UNKNOWN_TOLERANCE_MS = 6e4;
123
124
  var DEFAULT_TOKEN_LIFETIME_SECONDS = 300;
124
125
  var DEFAULT_TIMEOUT_MS = 3e3;
125
126
  var MAX_CACHED_TOKENS = 1e4;
126
127
  function createTokenStatusChecker(config) {
127
128
  const doFetch = config.fetch ?? fetch;
128
129
  const clock = config.now ?? Date.now;
130
+ const monotonic = config.monotonicNow ?? (config.now ?? (() => performance.now()));
129
131
  const log = config.log ?? ((message) => void process.stderr.write(`[tinycloud-mcp-http] ${message}
130
132
  `));
131
133
  const timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
@@ -168,6 +170,7 @@ function createTokenStatusChecker(config) {
168
170
  }
169
171
  }
170
172
  async function query(key, token) {
173
+ const askedAt = monotonic();
171
174
  const outcome = await introspect(token);
172
175
  if (outcome === "credentials") {
173
176
  if (!credentialsRefused) {
@@ -178,7 +181,7 @@ function createTokenStatusChecker(config) {
178
181
  }
179
182
  if (outcome === "unknown") return outcome;
180
183
  const now = clock();
181
- prune(now);
184
+ prune(now, monotonic());
182
185
  if (outcome === "mismatch") {
183
186
  inactive.set(key, tokenExpiryMs(token, now));
184
187
  confirmedActive.delete(key);
@@ -189,16 +192,18 @@ function createTokenStatusChecker(config) {
189
192
  inactive.set(key, tokenExpiryMs(token, now));
190
193
  confirmedActive.delete(key);
191
194
  } else {
192
- active.set(key, now + ACTIVE_CACHE_MS);
195
+ active.set(key, askedAt + ACTIVE_CACHE_MS);
193
196
  confirmedActive.delete(key);
194
- confirmedActive.set(key, { at: now, expiresAt: tokenExpiryMs(token, now) });
197
+ confirmedActive.set(key, { at: askedAt, expiresAt: tokenExpiryMs(token, now) });
195
198
  }
196
199
  return outcome;
197
200
  }
198
- function prune(now) {
199
- for (const [key, until] of active) if (until <= now) active.delete(key);
201
+ function prune(now, elapsed) {
202
+ for (const [key, until] of active) if (until <= elapsed) active.delete(key);
200
203
  for (const [key, until] of inactive) if (until <= now) inactive.delete(key);
201
- for (const [key, entry] of confirmedActive) if (entry.expiresAt <= now) confirmedActive.delete(key);
204
+ for (const [key, entry] of confirmedActive) {
205
+ if (entry.expiresAt <= now || elapsed - entry.at >= UNKNOWN_TOLERANCE_MS) confirmedActive.delete(key);
206
+ }
202
207
  for (const cache of [active, inactive, confirmedActive]) {
203
208
  while (cache.size >= MAX_CACHED_TOKENS) {
204
209
  const oldest = cache.keys().next().value;
@@ -211,10 +216,11 @@ function createTokenStatusChecker(config) {
211
216
  async tokenStatus(token) {
212
217
  const key = (0, import_node_crypto.createHash)("sha256").update(token).digest("hex");
213
218
  const now = clock();
219
+ const elapsed = monotonic();
214
220
  const inactiveUntil = inactive.get(key);
215
221
  if (inactiveUntil !== void 0 && inactiveUntil > now) return "inactive";
216
222
  const activeUntil = active.get(key);
217
- if (activeUntil !== void 0 && activeUntil > now) return "active";
223
+ if (activeUntil !== void 0 && activeUntil > elapsed) return "active";
218
224
  const pending = inFlight.get(key);
219
225
  if (pending !== void 0) return pending;
220
226
  const asking = query(key, token).finally(() => inFlight.delete(key));
@@ -225,8 +231,7 @@ function createTokenStatusChecker(config) {
225
231
  if (credentialsRefused) return false;
226
232
  const confirmed = confirmedActive.get((0, import_node_crypto.createHash)("sha256").update(token).digest("hex"));
227
233
  if (confirmed === void 0) return false;
228
- const now = clock();
229
- return confirmed.expiresAt > now && now - confirmed.at < tokenLifetimeSeconds(token) * 1e3;
234
+ return confirmed.expiresAt > clock() && monotonic() - confirmed.at < UNKNOWN_TOLERANCE_MS;
230
235
  }
231
236
  };
232
237
  }
@@ -248,10 +253,6 @@ function tokenExpiryMs(token, now) {
248
253
  const exp = claims(token).exp;
249
254
  return typeof exp === "number" ? exp * 1e3 : now + DEFAULT_TOKEN_LIFETIME_SECONDS * 1e3;
250
255
  }
251
- function tokenLifetimeSeconds(token) {
252
- const { exp, iat } = claims(token);
253
- return typeof exp === "number" && typeof iat === "number" && exp > iat ? exp - iat : DEFAULT_TOKEN_LIFETIME_SECONDS;
254
- }
255
256
  function claims(token) {
256
257
  try {
257
258
  return (0, import_jose2.decodeJwt)(token);
@@ -1942,7 +1943,7 @@ function outcomeCode(result) {
1942
1943
  // package.json
1943
1944
  var package_default = {
1944
1945
  name: "@tinycloud/mcp",
1945
- version: "0.8.7-beta.1",
1946
+ version: "0.8.7-beta.3",
1946
1947
  description: "TinyCloud delegated operations MCP server",
1947
1948
  keywords: [
1948
1949
  "tinycloud",
@@ -2013,9 +2014,9 @@ var package_default = {
2013
2014
  dependencies: {
2014
2015
  "@modelcontextprotocol/node": "2.0.0-beta.5",
2015
2016
  "@modelcontextprotocol/server": "2.0.0-beta.5",
2016
- "@tinycloud/node-sdk": "3.11.0-beta.1",
2017
+ "@tinycloud/node-sdk": "3.11.0-beta.2",
2017
2018
  "@tinycloud/node-sdk-wasm": "1.7.8",
2018
- "@tinycloud/operations": "0.7.11-beta.1",
2019
+ "@tinycloud/operations": "0.7.11-beta.2",
2019
2020
  jose: "6.2.4"
2020
2021
  },
2021
2022
  devDependencies: {