@tinycloud/mcp 0.10.1-beta.5 → 0.11.0-beta.10

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.cjs CHANGED
@@ -24,14 +24,104 @@ __export(http_cli_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(http_cli_exports);
26
26
  var import_node_http = require("http");
27
- var import_node_path4 = require("path");
27
+ var import_node_path5 = require("path");
28
28
  var import_node = require("@modelcontextprotocol/node");
29
29
 
30
30
  // src/http.ts
31
- var import_node_path3 = require("path");
31
+ var import_node_path4 = require("path");
32
32
  var import_server4 = require("@modelcontextprotocol/server");
33
33
  var import_node_sdk3 = require("@tinycloud/node-sdk");
34
34
 
35
+ // src/agent-discovery.ts
36
+ var import_node_crypto = require("crypto");
37
+ var import_node_fs = require("fs");
38
+ var import_node_path = require("path");
39
+ var import_node_url = require("url");
40
+ var import_meta = {};
41
+ var DOCUMENTATION_URL = "https://docs.tinycloud.xyz/cli/mcp";
42
+ var SKILL_NAME = "tinycloud-delegated-secrets";
43
+ var LOCAL_PACKAGES = [["@tinycloud", "cli"].join("/"), ["@tinycloud", "mcp"].join("/")];
44
+ var WEBMCP_SCRIPT_PATH = "/webmcp.js";
45
+ var WEBMCP_TOOL_NAME = "get_tinycloud_mcp_connection";
46
+ var A2A_AGENT_CARD_URL = "https://tinycloud.xyz/.well-known/agent-card.json";
47
+ var moduleDirectory = typeof __dirname === "string" ? __dirname : (0, import_node_path.dirname)((0, import_node_url.fileURLToPath)(import_meta.url));
48
+ var skillPath = (0, import_node_path.join)(moduleDirectory, "..", "skills", SKILL_NAME, "SKILL.md");
49
+ function agentDiscoveryRoutes(resourceUrl, issuer, requiredScope) {
50
+ const at = (path) => new URL(path, resourceUrl).toString();
51
+ const serverCardUrl = at("/.well-known/mcp/server-card.json");
52
+ const skillUrlPath = `/.well-known/agent-skills/${SKILL_NAME}/SKILL.md`;
53
+ const skill = (0, import_node_fs.readFileSync)(skillPath);
54
+ const apiCatalog = JSON.stringify({
55
+ linkset: [{
56
+ anchor: resourceUrl.toString(),
57
+ "service-desc": [{ href: serverCardUrl, type: "application/json" }],
58
+ "service-doc": [{ href: DOCUMENTATION_URL, type: "text/html" }],
59
+ status: [{ href: at("/healthz"), type: "application/json" }]
60
+ }]
61
+ });
62
+ const skillsIndex = JSON.stringify({
63
+ $schema: "https://schemas.agentskills.io/discovery/0.2.0/schema.json",
64
+ skills: [{
65
+ name: SKILL_NAME,
66
+ type: "skill-md",
67
+ description: skillDescription(skill.toString("utf8")),
68
+ url: at(skillUrlPath),
69
+ digest: `sha256:${(0, import_node_crypto.createHash)("sha256").update(skill).digest("hex")}`
70
+ }]
71
+ });
72
+ const connection = {
73
+ endpoint: resourceUrl.toString(),
74
+ transport: "streamable-http",
75
+ authorization: {
76
+ type: "oauth2",
77
+ authorizationServer: issuer,
78
+ protectedResourceMetadata: at(`/.well-known/oauth-protected-resource${resourceUrl.pathname}`),
79
+ scope: requiredScope
80
+ },
81
+ serverCard: serverCardUrl,
82
+ documentation: DOCUMENTATION_URL,
83
+ localAlternative: { packages: LOCAL_PACKAGES, stdioServer: "tinycloud-mcp" }
84
+ };
85
+ const webMcpScript = `(() => {
86
+ const modelContext = (typeof document !== "undefined" && document.modelContext) ||
87
+ (typeof navigator !== "undefined" && navigator.modelContext);
88
+ if (!modelContext || typeof modelContext.registerTool !== "function") return;
89
+ const connection = ${JSON.stringify(connection)};
90
+ modelContext.registerTool({
91
+ name: ${JSON.stringify(WEBMCP_TOOL_NAME)},
92
+ description: "Returns how to connect to TinyCloud MCP: the hosted endpoint, its transport, OAuth discovery, the documentation link and the local stdio option shown on this page.",
93
+ inputSchema: { type: "object", properties: {}, additionalProperties: false },
94
+ annotations: { readOnlyHint: true },
95
+ execute() {
96
+ return { content: [{ type: "text", text: JSON.stringify(connection) }], structuredContent: connection };
97
+ },
98
+ });
99
+ })();
100
+ `;
101
+ const cached = (body, contentType) => () => new Response(body, {
102
+ headers: {
103
+ "content-type": contentType,
104
+ "cache-control": "public, max-age=300",
105
+ "x-content-type-options": "nosniff"
106
+ }
107
+ });
108
+ return /* @__PURE__ */ new Map([
109
+ ["/.well-known/api-catalog", cached(apiCatalog, 'application/linkset+json; profile="https://www.rfc-editor.org/info/rfc9727"')],
110
+ ["/.well-known/agent-skills/index.json", cached(skillsIndex, "application/json; charset=utf-8")],
111
+ [skillUrlPath, cached(skill, "text/markdown; charset=utf-8")],
112
+ ["/.well-known/agent-card.json", () => new Response(null, {
113
+ status: 302,
114
+ headers: { location: A2A_AGENT_CARD_URL, "cache-control": "public, max-age=300" }
115
+ })],
116
+ [WEBMCP_SCRIPT_PATH, cached(webMcpScript, "text/javascript; charset=utf-8")]
117
+ ]);
118
+ }
119
+ function skillDescription(skill) {
120
+ const description = /^---\n(?:.*\n)*?description: (.+)\n(?:.*\n)*?---\n/.exec(skill)?.[1];
121
+ if (description === void 0) throw new Error(`${SKILL_NAME}/SKILL.md must declare a frontmatter description.`);
122
+ return description;
123
+ }
124
+
35
125
  // src/oauth.ts
36
126
  var import_server = require("@modelcontextprotocol/server");
37
127
  var import_node_sdk = require("@tinycloud/node-sdk");
@@ -134,7 +224,7 @@ function firstString(...values) {
134
224
  }
135
225
 
136
226
  // src/token-status.ts
137
- var import_node_crypto = require("crypto");
227
+ var import_node_crypto2 = require("crypto");
138
228
  var import_jose2 = require("jose");
139
229
  var ACTIVE_CACHE_MS = 3e4;
140
230
  var UNKNOWN_TOLERANCE_MS = 6e4;
@@ -231,7 +321,7 @@ function createTokenStatusChecker(config) {
231
321
  }
232
322
  return {
233
323
  async tokenStatus(token) {
234
- const key = (0, import_node_crypto.createHash)("sha256").update(token).digest("hex");
324
+ const key = (0, import_node_crypto2.createHash)("sha256").update(token).digest("hex");
235
325
  const now = clock();
236
326
  const elapsed = monotonic();
237
327
  const inactiveUntil = inactive.get(key);
@@ -246,7 +336,7 @@ function createTokenStatusChecker(config) {
246
336
  },
247
337
  toleratesUnknown(token) {
248
338
  if (credentialsRefused) return false;
249
- const confirmed = confirmedActive.get((0, import_node_crypto.createHash)("sha256").update(token).digest("hex"));
339
+ const confirmed = confirmedActive.get((0, import_node_crypto2.createHash)("sha256").update(token).digest("hex"));
250
340
  if (confirmed === void 0) return false;
251
341
  return confirmed.expiresAt > clock() && monotonic() - confirmed.at < UNKNOWN_TOLERANCE_MS;
252
342
  }
@@ -291,9 +381,9 @@ function logToolCall(tool, code, startedAt, replayedGrants) {
291
381
 
292
382
  // src/remote-store.ts
293
383
  var import_sdk_core = require("@tinycloud/sdk-core");
294
- var import_node_crypto3 = require("crypto");
384
+ var import_node_crypto4 = require("crypto");
295
385
  var import_promises = require("fs/promises");
296
- var import_node_path = require("path");
386
+ var import_node_path2 = require("path");
297
387
  var import_node_sdk2 = require("@tinycloud/node-sdk");
298
388
  var import_node_sdk_wasm = require("@tinycloud/node-sdk-wasm");
299
389
  var import_artifacts = require("@tinycloud/operations/artifacts");
@@ -303,7 +393,7 @@ var import_mcp_authority = require("@tinycloud/operations/mcp-authority");
303
393
  var import_tc_apps = require("@tinycloud/operations/tc-apps");
304
394
 
305
395
  // src/native-auth.ts
306
- var import_node_crypto2 = require("crypto");
396
+ var import_node_crypto3 = require("crypto");
307
397
  var NATIVE_SERVICE_CREDENTIAL_HEADER = "X-TinyCloud-Service-Credential";
308
398
  var NATIVE_OWNER_DID_HEADER = "X-TinyCloud-Owner-DID";
309
399
  var NATIVE_GRANT_MAX_LIFETIME_SECONDS = 30 * 24 * 60 * 60;
@@ -318,7 +408,7 @@ function serviceCredentialMatches(supplied, configured) {
318
408
  if (supplied === null || configured === void 0) return false;
319
409
  const suppliedBytes = Buffer.from(supplied, "utf8");
320
410
  const configuredBytes = Buffer.from(configured, "utf8");
321
- return suppliedBytes.byteLength === configuredBytes.byteLength && (0, import_node_crypto2.timingSafeEqual)(suppliedBytes, configuredBytes);
411
+ return suppliedBytes.byteLength === configuredBytes.byteLength && (0, import_node_crypto3.timingSafeEqual)(suppliedBytes, configuredBytes);
322
412
  }
323
413
  var OWNER_APPLICATIONS_SPACE = /^tinycloud:pkh:eip155:([1-9][0-9]*):(0x[0-9a-f]{40}):applications$/i;
324
414
  var SQL_PATH = "xyz.tinycloud.tinychat/connectors";
@@ -444,8 +534,8 @@ var RemoteTenantStore = class {
444
534
  nativeTenantStateRoot(ownerDid) {
445
535
  const canonical = canonicalOwnerDid(ownerDid);
446
536
  if (canonical === void 0) throw new NativeGrantValidationError("rejected");
447
- const tenant = (0, import_node_crypto3.createHmac)("sha256", this.#config.stateSecret).update(`native-tenant:${canonical}`).digest("hex");
448
- return (0, import_node_path.join)(this.#config.stateDir, "native-tenants", tenant);
537
+ const tenant = (0, import_node_crypto4.createHmac)("sha256", this.#config.stateSecret).update(`native-tenant:${canonical}`).digest("hex");
538
+ return (0, import_node_path2.join)(this.#config.stateDir, "native-tenants", tenant);
449
539
  }
450
540
  async acceptNativeGrant(serializedDelegation) {
451
541
  if (Buffer.byteLength(serializedDelegation) > MAX_CALLBACK_BYTES) {
@@ -613,7 +703,7 @@ var RemoteTenantStore = class {
613
703
  if (Date.parse(stored.expiresAt) <= Date.now()) throw new NativeGrantValidationError("expired");
614
704
  }
615
705
  tenantStateRoot(subject) {
616
- return (0, import_node_path.join)(this.#config.stateDir, "tenants", this.#tenantId(subject));
706
+ return (0, import_node_path2.join)(this.#config.stateDir, "tenants", this.#tenantId(subject));
617
707
  }
618
708
  /** Prepare only this authenticated account's profile before its first operation. */
619
709
  async initializeTenant(subject) {
@@ -826,7 +916,7 @@ var RemoteTenantStore = class {
826
916
  }
827
917
  if (!isRecord(data)) throw new ApprovalRequestError("body_invalid", "Callback body is invalid.");
828
918
  const pending = await this.#readPending(state, true);
829
- const stateRoot = (0, import_node_path.join)(this.#config.stateDir, "tenants", pending.tenantId);
919
+ const stateRoot = (0, import_node_path2.join)(this.#config.stateDir, "tenants", pending.tenantId);
830
920
  const prior = this.#approvalProcessing.get(stateRoot);
831
921
  const processing = (async () => {
832
922
  if (prior) await prior.catch(() => void 0);
@@ -1064,7 +1154,7 @@ var RemoteTenantStore = class {
1064
1154
  approvalEpoch: this.#approvalEpochs.get(tenant.stateRoot)
1065
1155
  });
1066
1156
  await (0, import_promises.rm)(this.#additionalPath(tenant.stateRoot), { force: true });
1067
- await (0, import_promises.rm)((0, import_node_path.join)(tenant.stateRoot, ".tinycloud", "profiles", PROFILE, "auth-requests.json"), { force: true });
1157
+ await (0, import_promises.rm)((0, import_node_path2.join)(tenant.stateRoot, ".tinycloud", "profiles", PROFILE, "auth-requests.json"), { force: true });
1068
1158
  await (0, import_promises.rm)(this.#pendingDirectory(tenant.stateRoot), { recursive: true, force: true });
1069
1159
  await (0, import_promises.rm)(this.#sessionPath(tenant.stateRoot), { force: true });
1070
1160
  })().finally(() => this.#clearing.delete(tenant.stateRoot));
@@ -1072,9 +1162,9 @@ var RemoteTenantStore = class {
1072
1162
  await clearing;
1073
1163
  }
1074
1164
  async #initializeTenant(tenantId) {
1075
- const stateRoot = (0, import_node_path.join)(this.#config.stateDir, "tenants", tenantId);
1165
+ const stateRoot = (0, import_node_path2.join)(this.#config.stateDir, "tenants", tenantId);
1076
1166
  const keyPath = this.#keyPath(stateRoot);
1077
- await secureDirectory((0, import_node_path.join)(stateRoot, ".tinycloud", "profiles", PROFILE));
1167
+ await secureDirectory((0, import_node_path2.join)(stateRoot, ".tinycloud", "profiles", PROFILE));
1078
1168
  let jwk = await readJson(keyPath);
1079
1169
  let sessionDid;
1080
1170
  if (jwk === null) {
@@ -1114,7 +1204,7 @@ var RemoteTenantStore = class {
1114
1204
  }
1115
1205
  async #readTenant(tenantId) {
1116
1206
  if (!/^[a-f0-9]{64}$/.test(tenantId)) throw new ApprovalRequestError("state_invalid", "Approval state is invalid.");
1117
- const stateRoot = (0, import_node_path.join)(this.#config.stateDir, "tenants", tenantId);
1207
+ const stateRoot = (0, import_node_path2.join)(this.#config.stateDir, "tenants", tenantId);
1118
1208
  const jwk = await readJson(this.#keyPath(stateRoot));
1119
1209
  if (jwk === null) throw new ApprovalRequestError("tenant_missing", "The TinyCloud delegate no longer exists.");
1120
1210
  const profile = await readJson(this.#profilePath(stateRoot));
@@ -1140,7 +1230,7 @@ var RemoteTenantStore = class {
1140
1230
  { tenantId, approvalEpoch: tenant.approvalEpoch, kind, requestId, permissions, ownerDids }
1141
1231
  );
1142
1232
  if (reusable !== void 0) return reusable;
1143
- const nonce = (0, import_node_crypto3.randomBytes)(24).toString("base64url");
1233
+ const nonce = (0, import_node_crypto4.randomBytes)(24).toString("base64url");
1144
1234
  const created = Date.now();
1145
1235
  const pending = {
1146
1236
  version: 1,
@@ -1165,10 +1255,10 @@ var RemoteTenantStore = class {
1165
1255
  const expected = this.#signState(tenantId, nonce);
1166
1256
  const supplied = Buffer.from(signature, "base64url");
1167
1257
  const expectedBytes = Buffer.from(expected, "base64url");
1168
- if (supplied.length !== expectedBytes.length || !(0, import_node_crypto3.timingSafeEqual)(supplied, expectedBytes)) {
1258
+ if (supplied.length !== expectedBytes.length || !(0, import_node_crypto4.timingSafeEqual)(supplied, expectedBytes)) {
1169
1259
  throw new ApprovalRequestError("state_invalid", "Approval state is invalid.");
1170
1260
  }
1171
- const stateRoot = (0, import_node_path.join)(this.#config.stateDir, "tenants", tenantId);
1261
+ const stateRoot = (0, import_node_path2.join)(this.#config.stateDir, "tenants", tenantId);
1172
1262
  const path = this.#pendingPath(stateRoot, nonce);
1173
1263
  const claimed = `${path}.processing`;
1174
1264
  if (consume) {
@@ -1207,7 +1297,7 @@ var RemoteTenantStore = class {
1207
1297
  }
1208
1298
  }
1209
1299
  async #restorePending(pending) {
1210
- const stateRoot = (0, import_node_path.join)(this.#config.stateDir, "tenants", pending.tenantId);
1300
+ const stateRoot = (0, import_node_path2.join)(this.#config.stateDir, "tenants", pending.tenantId);
1211
1301
  const path = this.#pendingPath(stateRoot, pending.nonce);
1212
1302
  await (0, import_promises.rename)(`${path}.processing`, path);
1213
1303
  }
@@ -1242,8 +1332,8 @@ var RemoteTenantStore = class {
1242
1332
  return this.#nativeIdentity;
1243
1333
  }
1244
1334
  async #readOrCreateNativeServiceKey() {
1245
- const path = (0, import_node_path.join)(this.#config.stateDir, ".tinycloud", "native-service-key.json");
1246
- await secureDirectory((0, import_node_path.dirname)(path));
1335
+ const path = (0, import_node_path2.join)(this.#config.stateDir, ".tinycloud", "native-service-key.json");
1336
+ await secureDirectory((0, import_node_path2.dirname)(path));
1247
1337
  let stored = await readJson(path);
1248
1338
  if (stored === null) {
1249
1339
  const generated = generateSessionKey();
@@ -1331,31 +1421,31 @@ var RemoteTenantStore = class {
1331
1421
  }
1332
1422
  }
1333
1423
  #nativeGrantPath(stateRoot) {
1334
- return (0, import_node_path.join)(stateRoot, ".tinycloud", "native-grant.json");
1424
+ return (0, import_node_path2.join)(stateRoot, ".tinycloud", "native-grant.json");
1335
1425
  }
1336
1426
  #tenantId(subject) {
1337
- return (0, import_node_crypto3.createHmac)("sha256", this.#config.stateSecret).update(`tenant:${subject}`).digest("hex");
1427
+ return (0, import_node_crypto4.createHmac)("sha256", this.#config.stateSecret).update(`tenant:${subject}`).digest("hex");
1338
1428
  }
1339
1429
  #signState(tenantId, nonce) {
1340
- return (0, import_node_crypto3.createHmac)("sha256", this.#config.stateSecret).update(`approval:${tenantId}:${nonce}`).digest("base64url");
1430
+ return (0, import_node_crypto4.createHmac)("sha256", this.#config.stateSecret).update(`approval:${tenantId}:${nonce}`).digest("base64url");
1341
1431
  }
1342
1432
  #profilePath(stateRoot) {
1343
- return (0, import_node_path.join)(stateRoot, ".tinycloud", "profiles", PROFILE, "profile.json");
1433
+ return (0, import_node_path2.join)(stateRoot, ".tinycloud", "profiles", PROFILE, "profile.json");
1344
1434
  }
1345
1435
  #keyPath(stateRoot) {
1346
- return (0, import_node_path.join)(stateRoot, ".tinycloud", "profiles", PROFILE, "key.json");
1436
+ return (0, import_node_path2.join)(stateRoot, ".tinycloud", "profiles", PROFILE, "key.json");
1347
1437
  }
1348
1438
  #sessionPath(stateRoot) {
1349
- return (0, import_node_path.join)(stateRoot, ".tinycloud", "profiles", PROFILE, "session.json");
1439
+ return (0, import_node_path2.join)(stateRoot, ".tinycloud", "profiles", PROFILE, "session.json");
1350
1440
  }
1351
1441
  #additionalPath(stateRoot) {
1352
- return (0, import_node_path.join)(stateRoot, ".tinycloud", "profiles", PROFILE, "additional-delegations.json");
1442
+ return (0, import_node_path2.join)(stateRoot, ".tinycloud", "profiles", PROFILE, "additional-delegations.json");
1353
1443
  }
1354
1444
  #pendingPath(stateRoot, nonce) {
1355
- return (0, import_node_path.join)(this.#pendingDirectory(stateRoot), `${nonce}.json`);
1445
+ return (0, import_node_path2.join)(this.#pendingDirectory(stateRoot), `${nonce}.json`);
1356
1446
  }
1357
1447
  #pendingDirectory(stateRoot) {
1358
- return (0, import_node_path.join)(stateRoot, ".tinycloud", "profiles", PROFILE, "pending");
1448
+ return (0, import_node_path2.join)(stateRoot, ".tinycloud", "profiles", PROFILE, "pending");
1359
1449
  }
1360
1450
  };
1361
1451
  var wasmInitialized = false;
@@ -1448,9 +1538,9 @@ async function secureDirectory(path) {
1448
1538
  await (0, import_promises.chmod)(path, 448);
1449
1539
  }
1450
1540
  async function secureWrite(path, value) {
1451
- const directory = (0, import_node_path.dirname)(path);
1541
+ const directory = (0, import_node_path2.dirname)(path);
1452
1542
  await secureDirectory(directory);
1453
- const temporary = `${path}.${process.pid}.${(0, import_node_crypto3.randomBytes)(8).toString("hex")}.tmp`;
1543
+ const temporary = `${path}.${process.pid}.${(0, import_node_crypto4.randomBytes)(8).toString("hex")}.tmp`;
1454
1544
  await (0, import_promises.writeFile)(temporary, `${JSON.stringify(value, jsonReplacer, 2)}
1455
1545
  `, { mode: 384 });
1456
1546
  await (0, import_promises.rename)(temporary, path);
@@ -1480,7 +1570,7 @@ async function restoreOptionalText(path, contents) {
1480
1570
  await (0, import_promises.rm)(path, { force: true });
1481
1571
  return;
1482
1572
  }
1483
- await secureDirectory((0, import_node_path.dirname)(path));
1573
+ await secureDirectory((0, import_node_path2.dirname)(path));
1484
1574
  await (0, import_promises.writeFile)(path, contents, { mode: 384 });
1485
1575
  await (0, import_promises.chmod)(path, 384);
1486
1576
  }
@@ -1495,7 +1585,7 @@ async function reusablePending(directory, expected) {
1495
1585
  const active = [];
1496
1586
  for (const name of names) {
1497
1587
  if (!name.endsWith(".json")) continue;
1498
- const path = (0, import_node_path.join)(directory, name);
1588
+ const path = (0, import_node_path2.join)(directory, name);
1499
1589
  const pending = await readJson(path).catch(() => null);
1500
1590
  if (pending === null || new Date(pending.expiresAt).getTime() <= Date.now()) {
1501
1591
  await (0, import_promises.rm)(path, { force: true });
@@ -1506,7 +1596,7 @@ async function reusablePending(directory, expected) {
1506
1596
  }
1507
1597
  if (active.length >= 64) {
1508
1598
  active.sort((left, right) => Date.parse(left.createdAt) - Date.parse(right.createdAt));
1509
- await (0, import_promises.rm)((0, import_node_path.join)(directory, `${active[0].nonce}.json`), { force: true });
1599
+ await (0, import_promises.rm)((0, import_node_path2.join)(directory, `${active[0].nonce}.json`), { force: true });
1510
1600
  }
1511
1601
  return void 0;
1512
1602
  }
@@ -1520,7 +1610,7 @@ var import_stdio = require("@modelcontextprotocol/server/stdio");
1520
1610
 
1521
1611
  // src/tools.ts
1522
1612
  var import_node_module = require("module");
1523
- var import_node_path2 = require("path");
1613
+ var import_node_path3 = require("path");
1524
1614
  var import_server2 = require("@modelcontextprotocol/server");
1525
1615
  var import_ajv = require("@modelcontextprotocol/server/validators/ajv");
1526
1616
  var import_operations2 = require("@tinycloud/operations");
@@ -1643,7 +1733,7 @@ function toMcpJsonSchema(schema) {
1643
1733
  }
1644
1734
 
1645
1735
  // src/tools.ts
1646
- var import_meta = {};
1736
+ var import_meta2 = {};
1647
1737
  function invocationTargetForMcp(selection) {
1648
1738
  return {
1649
1739
  profile: selection.profile,
@@ -1652,7 +1742,7 @@ function invocationTargetForMcp(selection) {
1652
1742
  };
1653
1743
  }
1654
1744
  var packageRequire = (0, import_node_module.createRequire)(
1655
- typeof __dirname === "string" ? (0, import_node_path2.join)(__dirname, "tools.cjs") : import_meta.url
1745
+ typeof __dirname === "string" ? (0, import_node_path3.join)(__dirname, "tools.cjs") : import_meta2.url
1656
1746
  );
1657
1747
  var generatedCatalog = packageRequire(
1658
1748
  "@tinycloud/operations/operations.json"
@@ -2027,7 +2117,7 @@ function outcomeCode(result) {
2027
2117
  // package.json
2028
2118
  var package_default = {
2029
2119
  name: "@tinycloud/mcp",
2030
- version: "0.10.1-beta.5",
2120
+ version: "0.11.0-beta.10",
2031
2121
  description: "TinyCloud delegated operations MCP server",
2032
2122
  keywords: [
2033
2123
  "tinycloud",
@@ -2098,10 +2188,10 @@ var package_default = {
2098
2188
  dependencies: {
2099
2189
  "@modelcontextprotocol/node": "2.0.0-beta.5",
2100
2190
  "@modelcontextprotocol/server": "2.0.0-beta.5",
2101
- "@tinycloud/node-sdk": "3.13.0-beta.4",
2102
- "@tinycloud/sdk-core": "3.13.0-beta.4",
2191
+ "@tinycloud/node-sdk": "3.13.0-beta.9",
2192
+ "@tinycloud/sdk-core": "3.13.0-beta.9",
2103
2193
  "@tinycloud/node-sdk-wasm": "1.7.9",
2104
- "@tinycloud/operations": "0.9.1-beta.5",
2194
+ "@tinycloud/operations": "0.9.1-beta.10",
2105
2195
  jose: "6.2.4"
2106
2196
  },
2107
2197
  devDependencies: {
@@ -2146,7 +2236,7 @@ function createHostedMcpApp(config) {
2146
2236
  const restricted = createHostedSurface({
2147
2237
  ...config,
2148
2238
  nativeServiceCredential: void 0,
2149
- stateDir: (0, import_node_path3.join)(config.stateDir, prefix),
2239
+ stateDir: (0, import_node_path4.join)(config.stateDir, prefix),
2150
2240
  approvalPath: connectUrl.pathname
2151
2241
  }, restrictedUrl, "public", statusFor(restrictedUrl), ANNOTATION_TITLE_PREFIXES.has(prefix));
2152
2242
  surfaces.push(restricted);
@@ -2228,6 +2318,7 @@ function createHostedSurface(config, resourceUrl, surface, tokenStatus, annotati
2228
2318
  scopesSupported: [REQUIRED_SCOPE],
2229
2319
  resourceName: surface === "public" ? "TinyCloud personal records" : "TinyCloud hosted MCP"
2230
2320
  };
2321
+ const discoveryRoutes = surface === "hosted" ? agentDiscoveryRoutes(resourceUrl, issuer, REQUIRED_SCOPE) : /* @__PURE__ */ new Map();
2231
2322
  const allowedHosts = [resourceUrl.hostname];
2232
2323
  return {
2233
2324
  async fetch(request) {
@@ -2334,9 +2425,22 @@ function createHostedSurface(config, resourceUrl, surface, tokenStatus, annotati
2334
2425
  ].join("\n") + "\n";
2335
2426
  return publicMetadataCors(publicText(authDoc, "text/markdown; charset=utf-8"), request);
2336
2427
  }
2428
+ const discoveryRoute = discoveryRoutes.get(url.pathname);
2429
+ if (discoveryRoute !== void 0) {
2430
+ if (request.method === "OPTIONS") {
2431
+ return publicMetadataCors(new Response(null, { status: 204 }), request);
2432
+ }
2433
+ if (request.method !== "GET" && request.method !== "HEAD") return methodNotAllowed("GET, HEAD");
2434
+ const response = discoveryRoute();
2435
+ return publicMetadataCors(
2436
+ request.method === "HEAD" ? new Response(null, { status: response.status, headers: response.headers }) : response,
2437
+ request
2438
+ );
2439
+ }
2337
2440
  if (url.pathname === "/robots.txt" && surface === "hosted") {
2338
2441
  return request.method === "GET" ? publicText(`User-agent: *
2339
2442
  Allow: /
2443
+ Content-Signal: search=yes, ai-input=yes, ai-train=no
2340
2444
  Sitemap: ${new URL("/sitemap.xml", resourceUrl)}
2341
2445
  Agentmap: ${new URL("/.well-known/ai-catalog.json", resourceUrl)}
2342
2446
  `, "text/plain; charset=utf-8") : methodNotAllowed("GET");
@@ -2413,17 +2517,17 @@ Hosted endpoint: <https://mcp.tinycloud.xyz/mcp> (Streamable HTTP, OpenKey OAuth
2413
2517
  [Connection documentation](https://docs.tinycloud.xyz/cli/mcp).
2414
2518
 
2415
2519
  Local alternative: install \`${LOCAL_CLI_PACKAGE}\` and \`${LOCAL_MCP_PACKAGE}\` and connect the \`tinycloud-mcp\` stdio server.
2416
- ` : `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="ai-catalog" href="/.well-known/ai-catalog.json"><title>TinyCloud MCP</title></head><main><h1>TinyCloud MCP</h1><p>Hosted MCP endpoint: <code>https://mcp.tinycloud.xyz/mcp</code> (Streamable HTTP, OpenKey OAuth).</p><p><a href="https://docs.tinycloud.xyz/cli/mcp">Connection documentation</a></p><p>Local alternative: install <code>${LOCAL_CLI_PACKAGE}</code> and <code>${LOCAL_MCP_PACKAGE}</code> and connect the <code>tinycloud-mcp</code> stdio server.</p></main></html>`;
2520
+ ` : `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="ai-catalog" href="/.well-known/ai-catalog.json"><script src="${WEBMCP_SCRIPT_PATH}" defer></script><title>TinyCloud MCP</title></head><main><h1>TinyCloud MCP</h1><p>Hosted MCP endpoint: <code>https://mcp.tinycloud.xyz/mcp</code> (Streamable HTTP, OpenKey OAuth).</p><p><a href="https://docs.tinycloud.xyz/cli/mcp">Connection documentation</a></p><p>Local alternative: install <code>${LOCAL_CLI_PACKAGE}</code> and <code>${LOCAL_MCP_PACKAGE}</code> and connect the <code>tinycloud-mcp</code> stdio server.</p></main></html>`;
2417
2521
  const headers = new Headers({
2418
2522
  "content-type": markdown ? "text/markdown; charset=utf-8" : "text/html; charset=utf-8",
2419
2523
  "cache-control": "public, max-age=300",
2420
- "content-security-policy": "default-src 'none'; base-uri 'none'; frame-ancestors 'none'",
2524
+ "content-security-policy": "default-src 'none'; script-src 'self'; base-uri 'none'; frame-ancestors 'none'",
2421
2525
  "x-content-type-options": "nosniff",
2422
2526
  vary: "Accept"
2423
2527
  });
2424
2528
  headers.set(
2425
2529
  "link",
2426
- `<${new URL("/mcp/server-card", resourceUrl)}>; rel="describedby"; type="application/json", <https://docs.tinycloud.xyz/cli/mcp>; rel="service-doc"`
2530
+ `<${new URL("/mcp/server-card", resourceUrl)}>; rel="describedby"; type="application/json", <https://docs.tinycloud.xyz/cli/mcp>; rel="service-doc", <${new URL("/.well-known/api-catalog", resourceUrl)}>; rel="api-catalog"`
2427
2531
  );
2428
2532
  return new Response(request.method === "HEAD" ? null : content, { headers });
2429
2533
  }
@@ -2765,7 +2869,7 @@ async function main() {
2765
2869
  publicUrl,
2766
2870
  stateDir,
2767
2871
  stateSecret,
2768
- nodeHost: process.env.TC_HOST ?? "https://tee.node.tinycloud.xyz",
2872
+ nodeHost: process.env.TC_HOST ?? "https://node.tinycloud.xyz",
2769
2873
  openkeyHost,
2770
2874
  approvalTtlSeconds: positiveInteger(process.env.TC_MCP_APPROVAL_TTL_SECONDS, 300),
2771
2875
  delegationExpiry: process.env.TC_MCP_DELEGATION_EXPIRY ?? "1h",
@@ -2806,8 +2910,8 @@ function requiredUrl(name) {
2806
2910
  }
2807
2911
  function requiredAbsolutePath(name) {
2808
2912
  const value = requiredString(name);
2809
- if (!(0, import_node_path4.isAbsolute)(value)) throw new Error(`${name} must be an absolute path.`);
2810
- return (0, import_node_path4.resolve)(value);
2913
+ if (!(0, import_node_path5.isAbsolute)(value)) throw new Error(`${name} must be an absolute path.`);
2914
+ return (0, import_node_path5.resolve)(value);
2811
2915
  }
2812
2916
  function introspectionAuthMethod(value) {
2813
2917
  if (value === void 0 || value === "basic") return "basic";