@tinycloud/mcp 0.8.0-beta.5 → 0.8.0-beta.7

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
@@ -208,9 +208,9 @@ var RemoteTenantStore = class {
208
208
  }
209
209
  async connectStatus(subject, ownerDids = []) {
210
210
  const tenant = await this.#ensureTenant(subject);
211
- if (await this.#hasValidSession(tenant, ownerDids, true)) {
212
- return { connected: true, sessionDid: tenant.sessionDid };
213
- }
211
+ const state = await this.#sessionState(tenant, ownerDids, true);
212
+ if (state === "valid") return { connected: true, sessionDid: tenant.sessionDid };
213
+ if (state === "unknown") return { connected: false, sessionDid: tenant.sessionDid };
214
214
  const pending = await this.#createPending(subject, ownerDids, "bootstrap", BOOTSTRAP_PERMISSIONS);
215
215
  return {
216
216
  connected: false,
@@ -550,7 +550,10 @@ var RemoteTenantStore = class {
550
550
  return initializing;
551
551
  }
552
552
  async #hasValidSession(tenant, ownerDids, fresh = false) {
553
- if (this.#renewalRequired.has(tenant.stateRoot)) return false;
553
+ return await this.#sessionState(tenant, ownerDids, fresh) !== "invalid";
554
+ }
555
+ async #sessionState(tenant, ownerDids, fresh = false) {
556
+ if (this.#renewalRequired.has(tenant.stateRoot)) return "invalid";
554
557
  const key = JSON.stringify([tenant.stateRoot, ownerDids.map(normalizeDid), fresh]);
555
558
  const current = this.#sessionChecks.get(key);
556
559
  if (current) return current;
@@ -567,9 +570,9 @@ var RemoteTenantStore = class {
567
570
  } catch (error) {
568
571
  if (!(error instanceof SyntaxError)) throw error;
569
572
  await this.#clearAuthority(tenant);
570
- return false;
573
+ return "invalid";
571
574
  }
572
- if (raw === null) return false;
575
+ if (raw === null) return "invalid";
573
576
  const node = new TinyCloudNode({ host: this.#config.nodeHost });
574
577
  try {
575
578
  await node.restoreSession(raw);
@@ -578,11 +581,11 @@ var RemoteTenantStore = class {
578
581
  const signedExpiry = typeof header === "string" ? signedCompactUcanExpiry(header) : void 0;
579
582
  const siweExpiry = typeof raw.siwe === "string" ? /^Expiration Time: ([^\r\n]+)\r?$/m.exec(raw.siwe)?.[1] : void 0;
580
583
  const expiry = signedExpiry ?? (siweExpiry === void 0 ? void 0 : new Date(siweExpiry));
581
- if (expiry !== void 0 && expiry.getTime() <= Date.now()) return false;
584
+ if (expiry !== void 0 && expiry.getTime() <= Date.now()) return "invalid";
582
585
  await this.#clearAuthority(tenant);
583
- return false;
586
+ return "invalid";
584
587
  }
585
- if (!samePrincipal(node.sessionDid, tenant.sessionDid) || !ownerDids.some((did) => samePrincipal(node.did, did))) return false;
588
+ if (!samePrincipal(node.sessionDid, tenant.sessionDid) || !ownerDids.some((did) => samePrincipal(node.did, did))) return "invalid";
586
589
  const additional = await readJson(this.#additionalPath(tenant.stateRoot));
587
590
  const cids = [raw.delegationCid];
588
591
  if (additional !== null) {
@@ -597,7 +600,7 @@ var RemoteTenantStore = class {
597
600
  }
598
601
  const fingerprint = cids.join("\n");
599
602
  const cached = this.#activeSessions.get(tenant.stateRoot);
600
- if (!fresh && cached?.cids === fingerprint && cached.until > Date.now()) return true;
603
+ if (!fresh && cached?.cids === fingerprint && cached.until > Date.now()) return "valid";
601
604
  let timer;
602
605
  const timeout = new Promise((resolve2) => {
603
606
  timer = setTimeout(() => resolve2(void 0), 2e3);
@@ -610,13 +613,14 @@ var RemoteTenantStore = class {
610
613
  const refusal = probe !== void 0 && !probe.ok ? nodeRevocationOf(probe.error) : void 0;
611
614
  if (refusal !== void 0 && (refusal.revokedCid === raw.delegationCid || refusal.reason === "delegation_ancestor_revoked" && refusal.ancestorCid === raw.delegationCid)) {
612
615
  await this.#clearAuthority(tenant);
613
- return false;
616
+ return "invalid";
614
617
  }
615
- if (this.#renewalRequired.has(tenant.stateRoot)) return false;
618
+ if (this.#renewalRequired.has(tenant.stateRoot)) return "invalid";
616
619
  if (probe?.ok) {
617
620
  this.#activeSessions.set(tenant.stateRoot, { cids: fingerprint, until: Date.now() + 3e4 });
621
+ return "valid";
618
622
  }
619
- return true;
623
+ return "unknown";
620
624
  }
621
625
  async #clearAuthority(tenant) {
622
626
  const current = this.#clearing.get(tenant.stateRoot);
@@ -1390,7 +1394,7 @@ function outcomeCode(result) {
1390
1394
  // package.json
1391
1395
  var package_default = {
1392
1396
  name: "@tinycloud/mcp",
1393
- version: "0.8.0-beta.5",
1397
+ version: "0.8.0-beta.7",
1394
1398
  description: "TinyCloud delegated operations MCP server",
1395
1399
  keywords: [
1396
1400
  "tinycloud",
@@ -1461,9 +1465,9 @@ var package_default = {
1461
1465
  dependencies: {
1462
1466
  "@modelcontextprotocol/node": "2.0.0-beta.5",
1463
1467
  "@modelcontextprotocol/server": "2.0.0-beta.5",
1464
- "@tinycloud/node-sdk": "3.6.0-beta.5",
1468
+ "@tinycloud/node-sdk": "3.6.0-beta.6",
1465
1469
  "@tinycloud/node-sdk-wasm": "1.7.8",
1466
- "@tinycloud/operations": "0.7.4-beta.5",
1470
+ "@tinycloud/operations": "0.7.4-beta.6",
1467
1471
  jose: "6.2.4"
1468
1472
  },
1469
1473
  devDependencies: {
@@ -1667,19 +1671,26 @@ function registerConnectTool(server, validator, store, identity, surface) {
1667
1671
  async () => {
1668
1672
  const startedAt = performance.now();
1669
1673
  let code = "INTERNAL_ERROR";
1674
+ let text;
1670
1675
  try {
1671
1676
  const status = await store.connectStatus(identity.subject, identity.ownerDids);
1672
- code = status.connected ? "ok" : "authority_required";
1677
+ if (status.connected) {
1678
+ code = "ok";
1679
+ text = "TinyCloud is connected.";
1680
+ } else if (status.approvalUrl === void 0) {
1681
+ code = "unavailable";
1682
+ text = "TinyCloud is unavailable. Call this tool again shortly.";
1683
+ } else {
1684
+ code = "authority_required";
1685
+ text = `TinyCloud approval is required. Open ${status.approvalUrl}, then call this tool again. This link expires at ${status.expiresAt}.`;
1686
+ }
1673
1687
  const visibleStatus = surface === "hosted" ? status : {
1674
1688
  connected: status.connected,
1675
1689
  ...status.approvalUrl === void 0 ? {} : { approvalUrl: status.approvalUrl },
1676
1690
  ...status.expiresAt === void 0 ? {} : { expiresAt: status.expiresAt }
1677
1691
  };
1678
1692
  return {
1679
- content: [{
1680
- type: "text",
1681
- text: status.connected ? "TinyCloud is connected." : `TinyCloud approval is required. Open ${status.approvalUrl}, then call this tool again. This link expires at ${status.expiresAt}.`
1682
- }],
1693
+ content: [{ type: "text", text }],
1683
1694
  structuredContent: visibleStatus
1684
1695
  };
1685
1696
  } finally {