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

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.cjs CHANGED
@@ -23,10 +23,100 @@ __export(http_exports, {
23
23
  createHostedMcpApp: () => createHostedMcpApp
24
24
  });
25
25
  module.exports = __toCommonJS(http_exports);
26
- var import_node_path3 = require("path");
26
+ var import_node_path4 = require("path");
27
27
  var import_server4 = require("@modelcontextprotocol/server");
28
28
  var import_node_sdk3 = require("@tinycloud/node-sdk");
29
29
 
30
+ // src/agent-discovery.ts
31
+ var import_node_crypto = require("crypto");
32
+ var import_node_fs = require("fs");
33
+ var import_node_path = require("path");
34
+ var import_node_url = require("url");
35
+ var import_meta = {};
36
+ var DOCUMENTATION_URL = "https://docs.tinycloud.xyz/cli/mcp";
37
+ var SKILL_NAME = "tinycloud-delegated-secrets";
38
+ var LOCAL_PACKAGES = [["@tinycloud", "cli"].join("/"), ["@tinycloud", "mcp"].join("/")];
39
+ var WEBMCP_SCRIPT_PATH = "/webmcp.js";
40
+ var WEBMCP_TOOL_NAME = "get_tinycloud_mcp_connection";
41
+ var A2A_AGENT_CARD_URL = "https://tinycloud.xyz/.well-known/agent-card.json";
42
+ var moduleDirectory = typeof __dirname === "string" ? __dirname : (0, import_node_path.dirname)((0, import_node_url.fileURLToPath)(import_meta.url));
43
+ var skillPath = (0, import_node_path.join)(moduleDirectory, "..", "skills", SKILL_NAME, "SKILL.md");
44
+ function agentDiscoveryRoutes(resourceUrl, issuer, requiredScope) {
45
+ const at = (path) => new URL(path, resourceUrl).toString();
46
+ const serverCardUrl = at("/.well-known/mcp/server-card.json");
47
+ const skillUrlPath = `/.well-known/agent-skills/${SKILL_NAME}/SKILL.md`;
48
+ const skill = (0, import_node_fs.readFileSync)(skillPath);
49
+ const apiCatalog = JSON.stringify({
50
+ linkset: [{
51
+ anchor: resourceUrl.toString(),
52
+ "service-desc": [{ href: serverCardUrl, type: "application/json" }],
53
+ "service-doc": [{ href: DOCUMENTATION_URL, type: "text/html" }],
54
+ status: [{ href: at("/healthz"), type: "application/json" }]
55
+ }]
56
+ });
57
+ const skillsIndex = JSON.stringify({
58
+ $schema: "https://schemas.agentskills.io/discovery/0.2.0/schema.json",
59
+ skills: [{
60
+ name: SKILL_NAME,
61
+ type: "skill-md",
62
+ description: skillDescription(skill.toString("utf8")),
63
+ url: at(skillUrlPath),
64
+ digest: `sha256:${(0, import_node_crypto.createHash)("sha256").update(skill).digest("hex")}`
65
+ }]
66
+ });
67
+ const connection = {
68
+ endpoint: resourceUrl.toString(),
69
+ transport: "streamable-http",
70
+ authorization: {
71
+ type: "oauth2",
72
+ authorizationServer: issuer,
73
+ protectedResourceMetadata: at(`/.well-known/oauth-protected-resource${resourceUrl.pathname}`),
74
+ scope: requiredScope
75
+ },
76
+ serverCard: serverCardUrl,
77
+ documentation: DOCUMENTATION_URL,
78
+ localAlternative: { packages: LOCAL_PACKAGES, stdioServer: "tinycloud-mcp" }
79
+ };
80
+ const webMcpScript = `(() => {
81
+ const modelContext = (typeof document !== "undefined" && document.modelContext) ||
82
+ (typeof navigator !== "undefined" && navigator.modelContext);
83
+ if (!modelContext || typeof modelContext.registerTool !== "function") return;
84
+ const connection = ${JSON.stringify(connection)};
85
+ modelContext.registerTool({
86
+ name: ${JSON.stringify(WEBMCP_TOOL_NAME)},
87
+ 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.",
88
+ inputSchema: { type: "object", properties: {}, additionalProperties: false },
89
+ annotations: { readOnlyHint: true },
90
+ execute() {
91
+ return { content: [{ type: "text", text: JSON.stringify(connection) }], structuredContent: connection };
92
+ },
93
+ });
94
+ })();
95
+ `;
96
+ const cached = (body, contentType) => () => new Response(body, {
97
+ headers: {
98
+ "content-type": contentType,
99
+ "cache-control": "public, max-age=300",
100
+ "x-content-type-options": "nosniff"
101
+ }
102
+ });
103
+ return /* @__PURE__ */ new Map([
104
+ ["/.well-known/api-catalog", cached(apiCatalog, 'application/linkset+json; profile="https://www.rfc-editor.org/info/rfc9727"')],
105
+ ["/.well-known/agent-skills/index.json", cached(skillsIndex, "application/json; charset=utf-8")],
106
+ [skillUrlPath, cached(skill, "text/markdown; charset=utf-8")],
107
+ ["/.well-known/agent-card.json", () => new Response(null, {
108
+ status: 302,
109
+ headers: { location: A2A_AGENT_CARD_URL, "cache-control": "public, max-age=300" }
110
+ })],
111
+ [WEBMCP_SCRIPT_PATH, cached(webMcpScript, "text/javascript; charset=utf-8")]
112
+ ]);
113
+ }
114
+ function skillDescription(skill) {
115
+ const description = /^---\n(?:.*\n)*?description: (.+)\n(?:.*\n)*?---\n/.exec(skill)?.[1];
116
+ if (description === void 0) throw new Error(`${SKILL_NAME}/SKILL.md must declare a frontmatter description.`);
117
+ return description;
118
+ }
119
+
30
120
  // src/oauth.ts
31
121
  var import_server = require("@modelcontextprotocol/server");
32
122
  var import_node_sdk = require("@tinycloud/node-sdk");
@@ -117,7 +207,7 @@ function firstString(...values) {
117
207
  }
118
208
 
119
209
  // src/token-status.ts
120
- var import_node_crypto = require("crypto");
210
+ var import_node_crypto2 = require("crypto");
121
211
  var import_jose2 = require("jose");
122
212
  var ACTIVE_CACHE_MS = 3e4;
123
213
  var UNKNOWN_TOLERANCE_MS = 6e4;
@@ -214,7 +304,7 @@ function createTokenStatusChecker(config) {
214
304
  }
215
305
  return {
216
306
  async tokenStatus(token) {
217
- const key = (0, import_node_crypto.createHash)("sha256").update(token).digest("hex");
307
+ const key = (0, import_node_crypto2.createHash)("sha256").update(token).digest("hex");
218
308
  const now = clock();
219
309
  const elapsed = monotonic();
220
310
  const inactiveUntil = inactive.get(key);
@@ -229,7 +319,7 @@ function createTokenStatusChecker(config) {
229
319
  },
230
320
  toleratesUnknown(token) {
231
321
  if (credentialsRefused) return false;
232
- const confirmed = confirmedActive.get((0, import_node_crypto.createHash)("sha256").update(token).digest("hex"));
322
+ const confirmed = confirmedActive.get((0, import_node_crypto2.createHash)("sha256").update(token).digest("hex"));
233
323
  if (confirmed === void 0) return false;
234
324
  return confirmed.expiresAt > clock() && monotonic() - confirmed.at < UNKNOWN_TOLERANCE_MS;
235
325
  }
@@ -274,9 +364,9 @@ function logToolCall(tool, code, startedAt, replayedGrants) {
274
364
 
275
365
  // src/remote-store.ts
276
366
  var import_sdk_core = require("@tinycloud/sdk-core");
277
- var import_node_crypto3 = require("crypto");
367
+ var import_node_crypto4 = require("crypto");
278
368
  var import_promises = require("fs/promises");
279
- var import_node_path = require("path");
369
+ var import_node_path2 = require("path");
280
370
  var import_node_sdk2 = require("@tinycloud/node-sdk");
281
371
  var import_node_sdk_wasm = require("@tinycloud/node-sdk-wasm");
282
372
  var import_artifacts = require("@tinycloud/operations/artifacts");
@@ -286,7 +376,7 @@ var import_mcp_authority = require("@tinycloud/operations/mcp-authority");
286
376
  var import_tc_apps = require("@tinycloud/operations/tc-apps");
287
377
 
288
378
  // src/native-auth.ts
289
- var import_node_crypto2 = require("crypto");
379
+ var import_node_crypto3 = require("crypto");
290
380
  var NATIVE_SERVICE_CREDENTIAL_HEADER = "X-TinyCloud-Service-Credential";
291
381
  var NATIVE_OWNER_DID_HEADER = "X-TinyCloud-Owner-DID";
292
382
  var NATIVE_GRANT_MAX_LIFETIME_SECONDS = 30 * 24 * 60 * 60;
@@ -301,7 +391,7 @@ function serviceCredentialMatches(supplied, configured) {
301
391
  if (supplied === null || configured === void 0) return false;
302
392
  const suppliedBytes = Buffer.from(supplied, "utf8");
303
393
  const configuredBytes = Buffer.from(configured, "utf8");
304
- return suppliedBytes.byteLength === configuredBytes.byteLength && (0, import_node_crypto2.timingSafeEqual)(suppliedBytes, configuredBytes);
394
+ return suppliedBytes.byteLength === configuredBytes.byteLength && (0, import_node_crypto3.timingSafeEqual)(suppliedBytes, configuredBytes);
305
395
  }
306
396
  var OWNER_APPLICATIONS_SPACE = /^tinycloud:pkh:eip155:([1-9][0-9]*):(0x[0-9a-f]{40}):applications$/i;
307
397
  var SQL_PATH = "xyz.tinycloud.tinychat/connectors";
@@ -427,8 +517,8 @@ var RemoteTenantStore = class {
427
517
  nativeTenantStateRoot(ownerDid) {
428
518
  const canonical = canonicalOwnerDid(ownerDid);
429
519
  if (canonical === void 0) throw new NativeGrantValidationError("rejected");
430
- const tenant = (0, import_node_crypto3.createHmac)("sha256", this.#config.stateSecret).update(`native-tenant:${canonical}`).digest("hex");
431
- return (0, import_node_path.join)(this.#config.stateDir, "native-tenants", tenant);
520
+ const tenant = (0, import_node_crypto4.createHmac)("sha256", this.#config.stateSecret).update(`native-tenant:${canonical}`).digest("hex");
521
+ return (0, import_node_path2.join)(this.#config.stateDir, "native-tenants", tenant);
432
522
  }
433
523
  async acceptNativeGrant(serializedDelegation) {
434
524
  if (Buffer.byteLength(serializedDelegation) > MAX_CALLBACK_BYTES) {
@@ -596,7 +686,7 @@ var RemoteTenantStore = class {
596
686
  if (Date.parse(stored.expiresAt) <= Date.now()) throw new NativeGrantValidationError("expired");
597
687
  }
598
688
  tenantStateRoot(subject) {
599
- return (0, import_node_path.join)(this.#config.stateDir, "tenants", this.#tenantId(subject));
689
+ return (0, import_node_path2.join)(this.#config.stateDir, "tenants", this.#tenantId(subject));
600
690
  }
601
691
  /** Prepare only this authenticated account's profile before its first operation. */
602
692
  async initializeTenant(subject) {
@@ -809,7 +899,7 @@ var RemoteTenantStore = class {
809
899
  }
810
900
  if (!isRecord(data)) throw new ApprovalRequestError("body_invalid", "Callback body is invalid.");
811
901
  const pending = await this.#readPending(state, true);
812
- const stateRoot = (0, import_node_path.join)(this.#config.stateDir, "tenants", pending.tenantId);
902
+ const stateRoot = (0, import_node_path2.join)(this.#config.stateDir, "tenants", pending.tenantId);
813
903
  const prior = this.#approvalProcessing.get(stateRoot);
814
904
  const processing = (async () => {
815
905
  if (prior) await prior.catch(() => void 0);
@@ -1047,7 +1137,7 @@ var RemoteTenantStore = class {
1047
1137
  approvalEpoch: this.#approvalEpochs.get(tenant.stateRoot)
1048
1138
  });
1049
1139
  await (0, import_promises.rm)(this.#additionalPath(tenant.stateRoot), { force: true });
1050
- await (0, import_promises.rm)((0, import_node_path.join)(tenant.stateRoot, ".tinycloud", "profiles", PROFILE, "auth-requests.json"), { force: true });
1140
+ await (0, import_promises.rm)((0, import_node_path2.join)(tenant.stateRoot, ".tinycloud", "profiles", PROFILE, "auth-requests.json"), { force: true });
1051
1141
  await (0, import_promises.rm)(this.#pendingDirectory(tenant.stateRoot), { recursive: true, force: true });
1052
1142
  await (0, import_promises.rm)(this.#sessionPath(tenant.stateRoot), { force: true });
1053
1143
  })().finally(() => this.#clearing.delete(tenant.stateRoot));
@@ -1055,9 +1145,9 @@ var RemoteTenantStore = class {
1055
1145
  await clearing;
1056
1146
  }
1057
1147
  async #initializeTenant(tenantId) {
1058
- const stateRoot = (0, import_node_path.join)(this.#config.stateDir, "tenants", tenantId);
1148
+ const stateRoot = (0, import_node_path2.join)(this.#config.stateDir, "tenants", tenantId);
1059
1149
  const keyPath = this.#keyPath(stateRoot);
1060
- await secureDirectory((0, import_node_path.join)(stateRoot, ".tinycloud", "profiles", PROFILE));
1150
+ await secureDirectory((0, import_node_path2.join)(stateRoot, ".tinycloud", "profiles", PROFILE));
1061
1151
  let jwk = await readJson(keyPath);
1062
1152
  let sessionDid;
1063
1153
  if (jwk === null) {
@@ -1097,7 +1187,7 @@ var RemoteTenantStore = class {
1097
1187
  }
1098
1188
  async #readTenant(tenantId) {
1099
1189
  if (!/^[a-f0-9]{64}$/.test(tenantId)) throw new ApprovalRequestError("state_invalid", "Approval state is invalid.");
1100
- const stateRoot = (0, import_node_path.join)(this.#config.stateDir, "tenants", tenantId);
1190
+ const stateRoot = (0, import_node_path2.join)(this.#config.stateDir, "tenants", tenantId);
1101
1191
  const jwk = await readJson(this.#keyPath(stateRoot));
1102
1192
  if (jwk === null) throw new ApprovalRequestError("tenant_missing", "The TinyCloud delegate no longer exists.");
1103
1193
  const profile = await readJson(this.#profilePath(stateRoot));
@@ -1123,7 +1213,7 @@ var RemoteTenantStore = class {
1123
1213
  { tenantId, approvalEpoch: tenant.approvalEpoch, kind, requestId, permissions, ownerDids }
1124
1214
  );
1125
1215
  if (reusable !== void 0) return reusable;
1126
- const nonce = (0, import_node_crypto3.randomBytes)(24).toString("base64url");
1216
+ const nonce = (0, import_node_crypto4.randomBytes)(24).toString("base64url");
1127
1217
  const created = Date.now();
1128
1218
  const pending = {
1129
1219
  version: 1,
@@ -1148,10 +1238,10 @@ var RemoteTenantStore = class {
1148
1238
  const expected = this.#signState(tenantId, nonce);
1149
1239
  const supplied = Buffer.from(signature, "base64url");
1150
1240
  const expectedBytes = Buffer.from(expected, "base64url");
1151
- if (supplied.length !== expectedBytes.length || !(0, import_node_crypto3.timingSafeEqual)(supplied, expectedBytes)) {
1241
+ if (supplied.length !== expectedBytes.length || !(0, import_node_crypto4.timingSafeEqual)(supplied, expectedBytes)) {
1152
1242
  throw new ApprovalRequestError("state_invalid", "Approval state is invalid.");
1153
1243
  }
1154
- const stateRoot = (0, import_node_path.join)(this.#config.stateDir, "tenants", tenantId);
1244
+ const stateRoot = (0, import_node_path2.join)(this.#config.stateDir, "tenants", tenantId);
1155
1245
  const path = this.#pendingPath(stateRoot, nonce);
1156
1246
  const claimed = `${path}.processing`;
1157
1247
  if (consume) {
@@ -1190,7 +1280,7 @@ var RemoteTenantStore = class {
1190
1280
  }
1191
1281
  }
1192
1282
  async #restorePending(pending) {
1193
- const stateRoot = (0, import_node_path.join)(this.#config.stateDir, "tenants", pending.tenantId);
1283
+ const stateRoot = (0, import_node_path2.join)(this.#config.stateDir, "tenants", pending.tenantId);
1194
1284
  const path = this.#pendingPath(stateRoot, pending.nonce);
1195
1285
  await (0, import_promises.rename)(`${path}.processing`, path);
1196
1286
  }
@@ -1225,8 +1315,8 @@ var RemoteTenantStore = class {
1225
1315
  return this.#nativeIdentity;
1226
1316
  }
1227
1317
  async #readOrCreateNativeServiceKey() {
1228
- const path = (0, import_node_path.join)(this.#config.stateDir, ".tinycloud", "native-service-key.json");
1229
- await secureDirectory((0, import_node_path.dirname)(path));
1318
+ const path = (0, import_node_path2.join)(this.#config.stateDir, ".tinycloud", "native-service-key.json");
1319
+ await secureDirectory((0, import_node_path2.dirname)(path));
1230
1320
  let stored = await readJson(path);
1231
1321
  if (stored === null) {
1232
1322
  const generated = generateSessionKey();
@@ -1314,31 +1404,31 @@ var RemoteTenantStore = class {
1314
1404
  }
1315
1405
  }
1316
1406
  #nativeGrantPath(stateRoot) {
1317
- return (0, import_node_path.join)(stateRoot, ".tinycloud", "native-grant.json");
1407
+ return (0, import_node_path2.join)(stateRoot, ".tinycloud", "native-grant.json");
1318
1408
  }
1319
1409
  #tenantId(subject) {
1320
- return (0, import_node_crypto3.createHmac)("sha256", this.#config.stateSecret).update(`tenant:${subject}`).digest("hex");
1410
+ return (0, import_node_crypto4.createHmac)("sha256", this.#config.stateSecret).update(`tenant:${subject}`).digest("hex");
1321
1411
  }
1322
1412
  #signState(tenantId, nonce) {
1323
- return (0, import_node_crypto3.createHmac)("sha256", this.#config.stateSecret).update(`approval:${tenantId}:${nonce}`).digest("base64url");
1413
+ return (0, import_node_crypto4.createHmac)("sha256", this.#config.stateSecret).update(`approval:${tenantId}:${nonce}`).digest("base64url");
1324
1414
  }
1325
1415
  #profilePath(stateRoot) {
1326
- return (0, import_node_path.join)(stateRoot, ".tinycloud", "profiles", PROFILE, "profile.json");
1416
+ return (0, import_node_path2.join)(stateRoot, ".tinycloud", "profiles", PROFILE, "profile.json");
1327
1417
  }
1328
1418
  #keyPath(stateRoot) {
1329
- return (0, import_node_path.join)(stateRoot, ".tinycloud", "profiles", PROFILE, "key.json");
1419
+ return (0, import_node_path2.join)(stateRoot, ".tinycloud", "profiles", PROFILE, "key.json");
1330
1420
  }
1331
1421
  #sessionPath(stateRoot) {
1332
- return (0, import_node_path.join)(stateRoot, ".tinycloud", "profiles", PROFILE, "session.json");
1422
+ return (0, import_node_path2.join)(stateRoot, ".tinycloud", "profiles", PROFILE, "session.json");
1333
1423
  }
1334
1424
  #additionalPath(stateRoot) {
1335
- return (0, import_node_path.join)(stateRoot, ".tinycloud", "profiles", PROFILE, "additional-delegations.json");
1425
+ return (0, import_node_path2.join)(stateRoot, ".tinycloud", "profiles", PROFILE, "additional-delegations.json");
1336
1426
  }
1337
1427
  #pendingPath(stateRoot, nonce) {
1338
- return (0, import_node_path.join)(this.#pendingDirectory(stateRoot), `${nonce}.json`);
1428
+ return (0, import_node_path2.join)(this.#pendingDirectory(stateRoot), `${nonce}.json`);
1339
1429
  }
1340
1430
  #pendingDirectory(stateRoot) {
1341
- return (0, import_node_path.join)(stateRoot, ".tinycloud", "profiles", PROFILE, "pending");
1431
+ return (0, import_node_path2.join)(stateRoot, ".tinycloud", "profiles", PROFILE, "pending");
1342
1432
  }
1343
1433
  };
1344
1434
  var wasmInitialized = false;
@@ -1431,9 +1521,9 @@ async function secureDirectory(path) {
1431
1521
  await (0, import_promises.chmod)(path, 448);
1432
1522
  }
1433
1523
  async function secureWrite(path, value) {
1434
- const directory = (0, import_node_path.dirname)(path);
1524
+ const directory = (0, import_node_path2.dirname)(path);
1435
1525
  await secureDirectory(directory);
1436
- const temporary = `${path}.${process.pid}.${(0, import_node_crypto3.randomBytes)(8).toString("hex")}.tmp`;
1526
+ const temporary = `${path}.${process.pid}.${(0, import_node_crypto4.randomBytes)(8).toString("hex")}.tmp`;
1437
1527
  await (0, import_promises.writeFile)(temporary, `${JSON.stringify(value, jsonReplacer, 2)}
1438
1528
  `, { mode: 384 });
1439
1529
  await (0, import_promises.rename)(temporary, path);
@@ -1463,7 +1553,7 @@ async function restoreOptionalText(path, contents) {
1463
1553
  await (0, import_promises.rm)(path, { force: true });
1464
1554
  return;
1465
1555
  }
1466
- await secureDirectory((0, import_node_path.dirname)(path));
1556
+ await secureDirectory((0, import_node_path2.dirname)(path));
1467
1557
  await (0, import_promises.writeFile)(path, contents, { mode: 384 });
1468
1558
  await (0, import_promises.chmod)(path, 384);
1469
1559
  }
@@ -1478,7 +1568,7 @@ async function reusablePending(directory, expected) {
1478
1568
  const active = [];
1479
1569
  for (const name of names) {
1480
1570
  if (!name.endsWith(".json")) continue;
1481
- const path = (0, import_node_path.join)(directory, name);
1571
+ const path = (0, import_node_path2.join)(directory, name);
1482
1572
  const pending = await readJson(path).catch(() => null);
1483
1573
  if (pending === null || new Date(pending.expiresAt).getTime() <= Date.now()) {
1484
1574
  await (0, import_promises.rm)(path, { force: true });
@@ -1489,7 +1579,7 @@ async function reusablePending(directory, expected) {
1489
1579
  }
1490
1580
  if (active.length >= 64) {
1491
1581
  active.sort((left, right) => Date.parse(left.createdAt) - Date.parse(right.createdAt));
1492
- await (0, import_promises.rm)((0, import_node_path.join)(directory, `${active[0].nonce}.json`), { force: true });
1582
+ await (0, import_promises.rm)((0, import_node_path2.join)(directory, `${active[0].nonce}.json`), { force: true });
1493
1583
  }
1494
1584
  return void 0;
1495
1585
  }
@@ -1503,7 +1593,7 @@ var import_stdio = require("@modelcontextprotocol/server/stdio");
1503
1593
 
1504
1594
  // src/tools.ts
1505
1595
  var import_node_module = require("module");
1506
- var import_node_path2 = require("path");
1596
+ var import_node_path3 = require("path");
1507
1597
  var import_server2 = require("@modelcontextprotocol/server");
1508
1598
  var import_ajv = require("@modelcontextprotocol/server/validators/ajv");
1509
1599
  var import_operations2 = require("@tinycloud/operations");
@@ -1626,7 +1716,7 @@ function toMcpJsonSchema(schema) {
1626
1716
  }
1627
1717
 
1628
1718
  // src/tools.ts
1629
- var import_meta = {};
1719
+ var import_meta2 = {};
1630
1720
  function invocationTargetForMcp(selection) {
1631
1721
  return {
1632
1722
  profile: selection.profile,
@@ -1635,7 +1725,7 @@ function invocationTargetForMcp(selection) {
1635
1725
  };
1636
1726
  }
1637
1727
  var packageRequire = (0, import_node_module.createRequire)(
1638
- typeof __dirname === "string" ? (0, import_node_path2.join)(__dirname, "tools.cjs") : import_meta.url
1728
+ typeof __dirname === "string" ? (0, import_node_path3.join)(__dirname, "tools.cjs") : import_meta2.url
1639
1729
  );
1640
1730
  var generatedCatalog = packageRequire(
1641
1731
  "@tinycloud/operations/operations.json"
@@ -2010,7 +2100,7 @@ function outcomeCode(result) {
2010
2100
  // package.json
2011
2101
  var package_default = {
2012
2102
  name: "@tinycloud/mcp",
2013
- version: "0.10.1-beta.5",
2103
+ version: "0.11.0-beta.11",
2014
2104
  description: "TinyCloud delegated operations MCP server",
2015
2105
  keywords: [
2016
2106
  "tinycloud",
@@ -2081,10 +2171,10 @@ var package_default = {
2081
2171
  dependencies: {
2082
2172
  "@modelcontextprotocol/node": "2.0.0-beta.5",
2083
2173
  "@modelcontextprotocol/server": "2.0.0-beta.5",
2084
- "@tinycloud/node-sdk": "3.13.0-beta.4",
2085
- "@tinycloud/sdk-core": "3.13.0-beta.4",
2174
+ "@tinycloud/node-sdk": "3.13.0-beta.9",
2175
+ "@tinycloud/sdk-core": "3.13.0-beta.9",
2086
2176
  "@tinycloud/node-sdk-wasm": "1.7.9",
2087
- "@tinycloud/operations": "0.9.1-beta.5",
2177
+ "@tinycloud/operations": "0.9.1-beta.11",
2088
2178
  jose: "6.2.4"
2089
2179
  },
2090
2180
  devDependencies: {
@@ -2129,7 +2219,7 @@ function createHostedMcpApp(config) {
2129
2219
  const restricted = createHostedSurface({
2130
2220
  ...config,
2131
2221
  nativeServiceCredential: void 0,
2132
- stateDir: (0, import_node_path3.join)(config.stateDir, prefix),
2222
+ stateDir: (0, import_node_path4.join)(config.stateDir, prefix),
2133
2223
  approvalPath: connectUrl.pathname
2134
2224
  }, restrictedUrl, "public", statusFor(restrictedUrl), ANNOTATION_TITLE_PREFIXES.has(prefix));
2135
2225
  surfaces.push(restricted);
@@ -2211,6 +2301,7 @@ function createHostedSurface(config, resourceUrl, surface, tokenStatus, annotati
2211
2301
  scopesSupported: [REQUIRED_SCOPE],
2212
2302
  resourceName: surface === "public" ? "TinyCloud personal records" : "TinyCloud hosted MCP"
2213
2303
  };
2304
+ const discoveryRoutes = surface === "hosted" ? agentDiscoveryRoutes(resourceUrl, issuer, REQUIRED_SCOPE) : /* @__PURE__ */ new Map();
2214
2305
  const allowedHosts = [resourceUrl.hostname];
2215
2306
  return {
2216
2307
  async fetch(request) {
@@ -2317,9 +2408,22 @@ function createHostedSurface(config, resourceUrl, surface, tokenStatus, annotati
2317
2408
  ].join("\n") + "\n";
2318
2409
  return publicMetadataCors(publicText(authDoc, "text/markdown; charset=utf-8"), request);
2319
2410
  }
2411
+ const discoveryRoute = discoveryRoutes.get(url.pathname);
2412
+ if (discoveryRoute !== void 0) {
2413
+ if (request.method === "OPTIONS") {
2414
+ return publicMetadataCors(new Response(null, { status: 204 }), request);
2415
+ }
2416
+ if (request.method !== "GET" && request.method !== "HEAD") return methodNotAllowed("GET, HEAD");
2417
+ const response = discoveryRoute();
2418
+ return publicMetadataCors(
2419
+ request.method === "HEAD" ? new Response(null, { status: response.status, headers: response.headers }) : response,
2420
+ request
2421
+ );
2422
+ }
2320
2423
  if (url.pathname === "/robots.txt" && surface === "hosted") {
2321
2424
  return request.method === "GET" ? publicText(`User-agent: *
2322
2425
  Allow: /
2426
+ Content-Signal: search=yes, ai-input=yes, ai-train=no
2323
2427
  Sitemap: ${new URL("/sitemap.xml", resourceUrl)}
2324
2428
  Agentmap: ${new URL("/.well-known/ai-catalog.json", resourceUrl)}
2325
2429
  `, "text/plain; charset=utf-8") : methodNotAllowed("GET");
@@ -2396,17 +2500,17 @@ Hosted endpoint: <https://mcp.tinycloud.xyz/mcp> (Streamable HTTP, OpenKey OAuth
2396
2500
  [Connection documentation](https://docs.tinycloud.xyz/cli/mcp).
2397
2501
 
2398
2502
  Local alternative: install \`${LOCAL_CLI_PACKAGE}\` and \`${LOCAL_MCP_PACKAGE}\` and connect the \`tinycloud-mcp\` stdio server.
2399
- ` : `<!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>`;
2503
+ ` : `<!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>`;
2400
2504
  const headers = new Headers({
2401
2505
  "content-type": markdown ? "text/markdown; charset=utf-8" : "text/html; charset=utf-8",
2402
2506
  "cache-control": "public, max-age=300",
2403
- "content-security-policy": "default-src 'none'; base-uri 'none'; frame-ancestors 'none'",
2507
+ "content-security-policy": "default-src 'none'; script-src 'self'; base-uri 'none'; frame-ancestors 'none'",
2404
2508
  "x-content-type-options": "nosniff",
2405
2509
  vary: "Accept"
2406
2510
  });
2407
2511
  headers.set(
2408
2512
  "link",
2409
- `<${new URL("/mcp/server-card", resourceUrl)}>; rel="describedby"; type="application/json", <https://docs.tinycloud.xyz/cli/mcp>; rel="service-doc"`
2513
+ `<${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"`
2410
2514
  );
2411
2515
  return new Response(request.method === "HEAD" ? null : content, { headers });
2412
2516
  }