@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/README.md +2 -1
- package/dist/cli.cjs +3 -3
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +3 -3
- package/dist/cli.js.map +1 -1
- package/dist/http-cli.cjs +17 -16
- package/dist/http-cli.cjs.map +1 -1
- package/dist/http-cli.js +17 -16
- package/dist/http-cli.js.map +1 -1
- package/dist/http.cjs +17 -16
- package/dist/http.cjs.map +1 -1
- package/dist/http.d.cts +6 -1
- package/dist/http.d.ts +6 -1
- package/dist/http.js +17 -16
- package/dist/http.js.map +1 -1
- package/dist/index.cjs +17 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +17 -16
- package/dist/index.js.map +1 -1
- package/dist/server.cjs +3 -3
- package/dist/server.cjs.map +1 -1
- package/dist/server.js +3 -3
- package/dist/server.js.map +1 -1
- package/package.json +3 -3
package/dist/http.d.cts
CHANGED
|
@@ -10,9 +10,14 @@ interface TokenStatusConfig {
|
|
|
10
10
|
/** How the confidential client authenticates: `client_secret_basic` or `client_secret_post`. */
|
|
11
11
|
readonly authMethod: "basic" | "post";
|
|
12
12
|
readonly timeoutMs?: number;
|
|
13
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Test seams. `now` is the wall clock, compared with the token's `exp`;
|
|
15
|
+
* `monotonicNow` measures the 30 s and 60 s windows and defaults to
|
|
16
|
+
* `performance.now` (to `now` when only `now` is given).
|
|
17
|
+
*/
|
|
14
18
|
readonly fetch?: typeof fetch;
|
|
15
19
|
readonly now?: () => number;
|
|
20
|
+
readonly monotonicNow?: () => number;
|
|
16
21
|
readonly log?: (message: string) => void;
|
|
17
22
|
}
|
|
18
23
|
|
package/dist/http.d.ts
CHANGED
|
@@ -10,9 +10,14 @@ interface TokenStatusConfig {
|
|
|
10
10
|
/** How the confidential client authenticates: `client_secret_basic` or `client_secret_post`. */
|
|
11
11
|
readonly authMethod: "basic" | "post";
|
|
12
12
|
readonly timeoutMs?: number;
|
|
13
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Test seams. `now` is the wall clock, compared with the token's `exp`;
|
|
15
|
+
* `monotonicNow` measures the 30 s and 60 s windows and defaults to
|
|
16
|
+
* `performance.now` (to `now` when only `now` is given).
|
|
17
|
+
*/
|
|
14
18
|
readonly fetch?: typeof fetch;
|
|
15
19
|
readonly now?: () => number;
|
|
20
|
+
readonly monotonicNow?: () => number;
|
|
16
21
|
readonly log?: (message: string) => void;
|
|
17
22
|
}
|
|
18
23
|
|
package/dist/http.js
CHANGED
|
@@ -107,12 +107,14 @@ function firstString(...values) {
|
|
|
107
107
|
import { createHash } from "crypto";
|
|
108
108
|
import { decodeJwt } from "jose";
|
|
109
109
|
var ACTIVE_CACHE_MS = 3e4;
|
|
110
|
+
var UNKNOWN_TOLERANCE_MS = 6e4;
|
|
110
111
|
var DEFAULT_TOKEN_LIFETIME_SECONDS = 300;
|
|
111
112
|
var DEFAULT_TIMEOUT_MS = 3e3;
|
|
112
113
|
var MAX_CACHED_TOKENS = 1e4;
|
|
113
114
|
function createTokenStatusChecker(config) {
|
|
114
115
|
const doFetch = config.fetch ?? fetch;
|
|
115
116
|
const clock = config.now ?? Date.now;
|
|
117
|
+
const monotonic = config.monotonicNow ?? (config.now ?? (() => performance.now()));
|
|
116
118
|
const log = config.log ?? ((message) => void process.stderr.write(`[tinycloud-mcp-http] ${message}
|
|
117
119
|
`));
|
|
118
120
|
const timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
@@ -155,6 +157,7 @@ function createTokenStatusChecker(config) {
|
|
|
155
157
|
}
|
|
156
158
|
}
|
|
157
159
|
async function query(key, token) {
|
|
160
|
+
const askedAt = monotonic();
|
|
158
161
|
const outcome = await introspect(token);
|
|
159
162
|
if (outcome === "credentials") {
|
|
160
163
|
if (!credentialsRefused) {
|
|
@@ -165,7 +168,7 @@ function createTokenStatusChecker(config) {
|
|
|
165
168
|
}
|
|
166
169
|
if (outcome === "unknown") return outcome;
|
|
167
170
|
const now = clock();
|
|
168
|
-
prune(now);
|
|
171
|
+
prune(now, monotonic());
|
|
169
172
|
if (outcome === "mismatch") {
|
|
170
173
|
inactive.set(key, tokenExpiryMs(token, now));
|
|
171
174
|
confirmedActive.delete(key);
|
|
@@ -176,16 +179,18 @@ function createTokenStatusChecker(config) {
|
|
|
176
179
|
inactive.set(key, tokenExpiryMs(token, now));
|
|
177
180
|
confirmedActive.delete(key);
|
|
178
181
|
} else {
|
|
179
|
-
active.set(key,
|
|
182
|
+
active.set(key, askedAt + ACTIVE_CACHE_MS);
|
|
180
183
|
confirmedActive.delete(key);
|
|
181
|
-
confirmedActive.set(key, { at:
|
|
184
|
+
confirmedActive.set(key, { at: askedAt, expiresAt: tokenExpiryMs(token, now) });
|
|
182
185
|
}
|
|
183
186
|
return outcome;
|
|
184
187
|
}
|
|
185
|
-
function prune(now) {
|
|
186
|
-
for (const [key, until] of active) if (until <=
|
|
188
|
+
function prune(now, elapsed) {
|
|
189
|
+
for (const [key, until] of active) if (until <= elapsed) active.delete(key);
|
|
187
190
|
for (const [key, until] of inactive) if (until <= now) inactive.delete(key);
|
|
188
|
-
for (const [key, entry] of confirmedActive)
|
|
191
|
+
for (const [key, entry] of confirmedActive) {
|
|
192
|
+
if (entry.expiresAt <= now || elapsed - entry.at >= UNKNOWN_TOLERANCE_MS) confirmedActive.delete(key);
|
|
193
|
+
}
|
|
189
194
|
for (const cache of [active, inactive, confirmedActive]) {
|
|
190
195
|
while (cache.size >= MAX_CACHED_TOKENS) {
|
|
191
196
|
const oldest = cache.keys().next().value;
|
|
@@ -198,10 +203,11 @@ function createTokenStatusChecker(config) {
|
|
|
198
203
|
async tokenStatus(token) {
|
|
199
204
|
const key = createHash("sha256").update(token).digest("hex");
|
|
200
205
|
const now = clock();
|
|
206
|
+
const elapsed = monotonic();
|
|
201
207
|
const inactiveUntil = inactive.get(key);
|
|
202
208
|
if (inactiveUntil !== void 0 && inactiveUntil > now) return "inactive";
|
|
203
209
|
const activeUntil = active.get(key);
|
|
204
|
-
if (activeUntil !== void 0 && activeUntil >
|
|
210
|
+
if (activeUntil !== void 0 && activeUntil > elapsed) return "active";
|
|
205
211
|
const pending = inFlight.get(key);
|
|
206
212
|
if (pending !== void 0) return pending;
|
|
207
213
|
const asking = query(key, token).finally(() => inFlight.delete(key));
|
|
@@ -212,8 +218,7 @@ function createTokenStatusChecker(config) {
|
|
|
212
218
|
if (credentialsRefused) return false;
|
|
213
219
|
const confirmed = confirmedActive.get(createHash("sha256").update(token).digest("hex"));
|
|
214
220
|
if (confirmed === void 0) return false;
|
|
215
|
-
|
|
216
|
-
return confirmed.expiresAt > now && now - confirmed.at < tokenLifetimeSeconds(token) * 1e3;
|
|
221
|
+
return confirmed.expiresAt > clock() && monotonic() - confirmed.at < UNKNOWN_TOLERANCE_MS;
|
|
217
222
|
}
|
|
218
223
|
};
|
|
219
224
|
}
|
|
@@ -235,10 +240,6 @@ function tokenExpiryMs(token, now) {
|
|
|
235
240
|
const exp = claims(token).exp;
|
|
236
241
|
return typeof exp === "number" ? exp * 1e3 : now + DEFAULT_TOKEN_LIFETIME_SECONDS * 1e3;
|
|
237
242
|
}
|
|
238
|
-
function tokenLifetimeSeconds(token) {
|
|
239
|
-
const { exp, iat } = claims(token);
|
|
240
|
-
return typeof exp === "number" && typeof iat === "number" && exp > iat ? exp - iat : DEFAULT_TOKEN_LIFETIME_SECONDS;
|
|
241
|
-
}
|
|
242
243
|
function claims(token) {
|
|
243
244
|
try {
|
|
244
245
|
return decodeJwt(token);
|
|
@@ -1940,7 +1941,7 @@ function outcomeCode(result) {
|
|
|
1940
1941
|
// package.json
|
|
1941
1942
|
var package_default = {
|
|
1942
1943
|
name: "@tinycloud/mcp",
|
|
1943
|
-
version: "0.8.7-beta.
|
|
1944
|
+
version: "0.8.7-beta.3",
|
|
1944
1945
|
description: "TinyCloud delegated operations MCP server",
|
|
1945
1946
|
keywords: [
|
|
1946
1947
|
"tinycloud",
|
|
@@ -2011,9 +2012,9 @@ var package_default = {
|
|
|
2011
2012
|
dependencies: {
|
|
2012
2013
|
"@modelcontextprotocol/node": "2.0.0-beta.5",
|
|
2013
2014
|
"@modelcontextprotocol/server": "2.0.0-beta.5",
|
|
2014
|
-
"@tinycloud/node-sdk": "3.11.0-beta.
|
|
2015
|
+
"@tinycloud/node-sdk": "3.11.0-beta.2",
|
|
2015
2016
|
"@tinycloud/node-sdk-wasm": "1.7.8",
|
|
2016
|
-
"@tinycloud/operations": "0.7.11-beta.
|
|
2017
|
+
"@tinycloud/operations": "0.7.11-beta.2",
|
|
2017
2018
|
jose: "6.2.4"
|
|
2018
2019
|
},
|
|
2019
2020
|
devDependencies: {
|