@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/index.cjs
CHANGED
|
@@ -522,7 +522,7 @@ function outcomeCode(result) {
|
|
|
522
522
|
// package.json
|
|
523
523
|
var package_default = {
|
|
524
524
|
name: "@tinycloud/mcp",
|
|
525
|
-
version: "0.8.7-beta.
|
|
525
|
+
version: "0.8.7-beta.3",
|
|
526
526
|
description: "TinyCloud delegated operations MCP server",
|
|
527
527
|
keywords: [
|
|
528
528
|
"tinycloud",
|
|
@@ -593,9 +593,9 @@ var package_default = {
|
|
|
593
593
|
dependencies: {
|
|
594
594
|
"@modelcontextprotocol/node": "2.0.0-beta.5",
|
|
595
595
|
"@modelcontextprotocol/server": "2.0.0-beta.5",
|
|
596
|
-
"@tinycloud/node-sdk": "3.11.0-beta.
|
|
596
|
+
"@tinycloud/node-sdk": "3.11.0-beta.2",
|
|
597
597
|
"@tinycloud/node-sdk-wasm": "1.7.8",
|
|
598
|
-
"@tinycloud/operations": "0.7.11-beta.
|
|
598
|
+
"@tinycloud/operations": "0.7.11-beta.2",
|
|
599
599
|
jose: "6.2.4"
|
|
600
600
|
},
|
|
601
601
|
devDependencies: {
|
|
@@ -831,12 +831,14 @@ function firstString(...values) {
|
|
|
831
831
|
var import_node_crypto = require("crypto");
|
|
832
832
|
var import_jose2 = require("jose");
|
|
833
833
|
var ACTIVE_CACHE_MS = 3e4;
|
|
834
|
+
var UNKNOWN_TOLERANCE_MS = 6e4;
|
|
834
835
|
var DEFAULT_TOKEN_LIFETIME_SECONDS = 300;
|
|
835
836
|
var DEFAULT_TIMEOUT_MS = 3e3;
|
|
836
837
|
var MAX_CACHED_TOKENS = 1e4;
|
|
837
838
|
function createTokenStatusChecker(config) {
|
|
838
839
|
const doFetch = config.fetch ?? fetch;
|
|
839
840
|
const clock = config.now ?? Date.now;
|
|
841
|
+
const monotonic = config.monotonicNow ?? (config.now ?? (() => performance.now()));
|
|
840
842
|
const log = config.log ?? ((message) => void process.stderr.write(`[tinycloud-mcp-http] ${message}
|
|
841
843
|
`));
|
|
842
844
|
const timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
@@ -879,6 +881,7 @@ function createTokenStatusChecker(config) {
|
|
|
879
881
|
}
|
|
880
882
|
}
|
|
881
883
|
async function query(key, token) {
|
|
884
|
+
const askedAt = monotonic();
|
|
882
885
|
const outcome = await introspect(token);
|
|
883
886
|
if (outcome === "credentials") {
|
|
884
887
|
if (!credentialsRefused) {
|
|
@@ -889,7 +892,7 @@ function createTokenStatusChecker(config) {
|
|
|
889
892
|
}
|
|
890
893
|
if (outcome === "unknown") return outcome;
|
|
891
894
|
const now = clock();
|
|
892
|
-
prune(now);
|
|
895
|
+
prune(now, monotonic());
|
|
893
896
|
if (outcome === "mismatch") {
|
|
894
897
|
inactive.set(key, tokenExpiryMs(token, now));
|
|
895
898
|
confirmedActive.delete(key);
|
|
@@ -900,16 +903,18 @@ function createTokenStatusChecker(config) {
|
|
|
900
903
|
inactive.set(key, tokenExpiryMs(token, now));
|
|
901
904
|
confirmedActive.delete(key);
|
|
902
905
|
} else {
|
|
903
|
-
active.set(key,
|
|
906
|
+
active.set(key, askedAt + ACTIVE_CACHE_MS);
|
|
904
907
|
confirmedActive.delete(key);
|
|
905
|
-
confirmedActive.set(key, { at:
|
|
908
|
+
confirmedActive.set(key, { at: askedAt, expiresAt: tokenExpiryMs(token, now) });
|
|
906
909
|
}
|
|
907
910
|
return outcome;
|
|
908
911
|
}
|
|
909
|
-
function prune(now) {
|
|
910
|
-
for (const [key, until] of active) if (until <=
|
|
912
|
+
function prune(now, elapsed) {
|
|
913
|
+
for (const [key, until] of active) if (until <= elapsed) active.delete(key);
|
|
911
914
|
for (const [key, until] of inactive) if (until <= now) inactive.delete(key);
|
|
912
|
-
for (const [key, entry] of confirmedActive)
|
|
915
|
+
for (const [key, entry] of confirmedActive) {
|
|
916
|
+
if (entry.expiresAt <= now || elapsed - entry.at >= UNKNOWN_TOLERANCE_MS) confirmedActive.delete(key);
|
|
917
|
+
}
|
|
913
918
|
for (const cache of [active, inactive, confirmedActive]) {
|
|
914
919
|
while (cache.size >= MAX_CACHED_TOKENS) {
|
|
915
920
|
const oldest = cache.keys().next().value;
|
|
@@ -922,10 +927,11 @@ function createTokenStatusChecker(config) {
|
|
|
922
927
|
async tokenStatus(token) {
|
|
923
928
|
const key = (0, import_node_crypto.createHash)("sha256").update(token).digest("hex");
|
|
924
929
|
const now = clock();
|
|
930
|
+
const elapsed = monotonic();
|
|
925
931
|
const inactiveUntil = inactive.get(key);
|
|
926
932
|
if (inactiveUntil !== void 0 && inactiveUntil > now) return "inactive";
|
|
927
933
|
const activeUntil = active.get(key);
|
|
928
|
-
if (activeUntil !== void 0 && activeUntil >
|
|
934
|
+
if (activeUntil !== void 0 && activeUntil > elapsed) return "active";
|
|
929
935
|
const pending = inFlight.get(key);
|
|
930
936
|
if (pending !== void 0) return pending;
|
|
931
937
|
const asking = query(key, token).finally(() => inFlight.delete(key));
|
|
@@ -936,8 +942,7 @@ function createTokenStatusChecker(config) {
|
|
|
936
942
|
if (credentialsRefused) return false;
|
|
937
943
|
const confirmed = confirmedActive.get((0, import_node_crypto.createHash)("sha256").update(token).digest("hex"));
|
|
938
944
|
if (confirmed === void 0) return false;
|
|
939
|
-
|
|
940
|
-
return confirmed.expiresAt > now && now - confirmed.at < tokenLifetimeSeconds(token) * 1e3;
|
|
945
|
+
return confirmed.expiresAt > clock() && monotonic() - confirmed.at < UNKNOWN_TOLERANCE_MS;
|
|
941
946
|
}
|
|
942
947
|
};
|
|
943
948
|
}
|
|
@@ -959,10 +964,6 @@ function tokenExpiryMs(token, now) {
|
|
|
959
964
|
const exp = claims(token).exp;
|
|
960
965
|
return typeof exp === "number" ? exp * 1e3 : now + DEFAULT_TOKEN_LIFETIME_SECONDS * 1e3;
|
|
961
966
|
}
|
|
962
|
-
function tokenLifetimeSeconds(token) {
|
|
963
|
-
const { exp, iat } = claims(token);
|
|
964
|
-
return typeof exp === "number" && typeof iat === "number" && exp > iat ? exp - iat : DEFAULT_TOKEN_LIFETIME_SECONDS;
|
|
965
|
-
}
|
|
966
967
|
function claims(token) {
|
|
967
968
|
try {
|
|
968
969
|
return (0, import_jose2.decodeJwt)(token);
|