@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-cli.js CHANGED
@@ -124,12 +124,14 @@ function firstString(...values) {
124
124
  import { createHash } from "crypto";
125
125
  import { decodeJwt } from "jose";
126
126
  var ACTIVE_CACHE_MS = 3e4;
127
+ var UNKNOWN_TOLERANCE_MS = 6e4;
127
128
  var DEFAULT_TOKEN_LIFETIME_SECONDS = 300;
128
129
  var DEFAULT_TIMEOUT_MS = 3e3;
129
130
  var MAX_CACHED_TOKENS = 1e4;
130
131
  function createTokenStatusChecker(config) {
131
132
  const doFetch = config.fetch ?? fetch;
132
133
  const clock = config.now ?? Date.now;
134
+ const monotonic = config.monotonicNow ?? (config.now ?? (() => performance.now()));
133
135
  const log = config.log ?? ((message) => void process.stderr.write(`[tinycloud-mcp-http] ${message}
134
136
  `));
135
137
  const timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
@@ -172,6 +174,7 @@ function createTokenStatusChecker(config) {
172
174
  }
173
175
  }
174
176
  async function query(key, token) {
177
+ const askedAt = monotonic();
175
178
  const outcome = await introspect(token);
176
179
  if (outcome === "credentials") {
177
180
  if (!credentialsRefused) {
@@ -182,7 +185,7 @@ function createTokenStatusChecker(config) {
182
185
  }
183
186
  if (outcome === "unknown") return outcome;
184
187
  const now = clock();
185
- prune(now);
188
+ prune(now, monotonic());
186
189
  if (outcome === "mismatch") {
187
190
  inactive.set(key, tokenExpiryMs(token, now));
188
191
  confirmedActive.delete(key);
@@ -193,16 +196,18 @@ function createTokenStatusChecker(config) {
193
196
  inactive.set(key, tokenExpiryMs(token, now));
194
197
  confirmedActive.delete(key);
195
198
  } else {
196
- active.set(key, now + ACTIVE_CACHE_MS);
199
+ active.set(key, askedAt + ACTIVE_CACHE_MS);
197
200
  confirmedActive.delete(key);
198
- confirmedActive.set(key, { at: now, expiresAt: tokenExpiryMs(token, now) });
201
+ confirmedActive.set(key, { at: askedAt, expiresAt: tokenExpiryMs(token, now) });
199
202
  }
200
203
  return outcome;
201
204
  }
202
- function prune(now) {
203
- for (const [key, until] of active) if (until <= now) active.delete(key);
205
+ function prune(now, elapsed) {
206
+ for (const [key, until] of active) if (until <= elapsed) active.delete(key);
204
207
  for (const [key, until] of inactive) if (until <= now) inactive.delete(key);
205
- for (const [key, entry] of confirmedActive) if (entry.expiresAt <= now) confirmedActive.delete(key);
208
+ for (const [key, entry] of confirmedActive) {
209
+ if (entry.expiresAt <= now || elapsed - entry.at >= UNKNOWN_TOLERANCE_MS) confirmedActive.delete(key);
210
+ }
206
211
  for (const cache of [active, inactive, confirmedActive]) {
207
212
  while (cache.size >= MAX_CACHED_TOKENS) {
208
213
  const oldest = cache.keys().next().value;
@@ -215,10 +220,11 @@ function createTokenStatusChecker(config) {
215
220
  async tokenStatus(token) {
216
221
  const key = createHash("sha256").update(token).digest("hex");
217
222
  const now = clock();
223
+ const elapsed = monotonic();
218
224
  const inactiveUntil = inactive.get(key);
219
225
  if (inactiveUntil !== void 0 && inactiveUntil > now) return "inactive";
220
226
  const activeUntil = active.get(key);
221
- if (activeUntil !== void 0 && activeUntil > now) return "active";
227
+ if (activeUntil !== void 0 && activeUntil > elapsed) return "active";
222
228
  const pending = inFlight.get(key);
223
229
  if (pending !== void 0) return pending;
224
230
  const asking = query(key, token).finally(() => inFlight.delete(key));
@@ -229,8 +235,7 @@ function createTokenStatusChecker(config) {
229
235
  if (credentialsRefused) return false;
230
236
  const confirmed = confirmedActive.get(createHash("sha256").update(token).digest("hex"));
231
237
  if (confirmed === void 0) return false;
232
- const now = clock();
233
- return confirmed.expiresAt > now && now - confirmed.at < tokenLifetimeSeconds(token) * 1e3;
238
+ return confirmed.expiresAt > clock() && monotonic() - confirmed.at < UNKNOWN_TOLERANCE_MS;
234
239
  }
235
240
  };
236
241
  }
@@ -252,10 +257,6 @@ function tokenExpiryMs(token, now) {
252
257
  const exp = claims(token).exp;
253
258
  return typeof exp === "number" ? exp * 1e3 : now + DEFAULT_TOKEN_LIFETIME_SECONDS * 1e3;
254
259
  }
255
- function tokenLifetimeSeconds(token) {
256
- const { exp, iat } = claims(token);
257
- return typeof exp === "number" && typeof iat === "number" && exp > iat ? exp - iat : DEFAULT_TOKEN_LIFETIME_SECONDS;
258
- }
259
260
  function claims(token) {
260
261
  try {
261
262
  return decodeJwt(token);
@@ -1957,7 +1958,7 @@ function outcomeCode(result) {
1957
1958
  // package.json
1958
1959
  var package_default = {
1959
1960
  name: "@tinycloud/mcp",
1960
- version: "0.8.7-beta.1",
1961
+ version: "0.8.7-beta.3",
1961
1962
  description: "TinyCloud delegated operations MCP server",
1962
1963
  keywords: [
1963
1964
  "tinycloud",
@@ -2028,9 +2029,9 @@ var package_default = {
2028
2029
  dependencies: {
2029
2030
  "@modelcontextprotocol/node": "2.0.0-beta.5",
2030
2031
  "@modelcontextprotocol/server": "2.0.0-beta.5",
2031
- "@tinycloud/node-sdk": "3.11.0-beta.1",
2032
+ "@tinycloud/node-sdk": "3.11.0-beta.2",
2032
2033
  "@tinycloud/node-sdk-wasm": "1.7.8",
2033
- "@tinycloud/operations": "0.7.11-beta.1",
2034
+ "@tinycloud/operations": "0.7.11-beta.2",
2034
2035
  jose: "6.2.4"
2035
2036
  },
2036
2037
  devDependencies: {