@tinycloud/mcp 0.10.0-beta.5 → 0.10.0-beta.50

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/index.cjs CHANGED
@@ -48,6 +48,7 @@ var import_node_path = require("path");
48
48
  var import_server = require("@modelcontextprotocol/server");
49
49
  var import_ajv = require("@modelcontextprotocol/server/validators/ajv");
50
50
  var import_operations = require("@tinycloud/operations");
51
+ var import_tc_apps = require("@tinycloud/operations/tc-apps");
51
52
 
52
53
  // src/results.ts
53
54
  function toMcpToolResult(result, bindings = [], options = {}) {
@@ -206,8 +207,7 @@ var TOOL_NAMES = [
206
207
  "tinycloud_apps_context",
207
208
  "tinycloud_apps_read",
208
209
  "tinycloud_apps_write",
209
- "tinycloud_apps_query",
210
- "tinycloud_apps_move"
210
+ "tinycloud_apps_query"
211
211
  ];
212
212
  function invocationTargetForMcp(selection) {
213
213
  return {
@@ -431,7 +431,7 @@ var TOOL_BINDINGS = [
431
431
  operationVersion: 1,
432
432
  readOnlyHint: false,
433
433
  idempotentHint: true,
434
- destructiveHint: true,
434
+ destructiveHint: false,
435
435
  openWorldHint: false,
436
436
  surfaces: ["hosted", "public"]
437
437
  },
@@ -461,19 +461,9 @@ var TOOL_BINDINGS = [
461
461
  operationVersion: 1,
462
462
  readOnlyHint: false,
463
463
  idempotentHint: true,
464
- destructiveHint: true,
465
- openWorldHint: false,
466
- surfaces: ["hosted", "public"]
467
- },
468
- {
469
- name: "tinycloud_apps_move",
470
- operationId: "tinycloud.apps.move",
471
- operationVersion: 1,
472
- readOnlyHint: false,
473
- idempotentHint: true,
474
464
  destructiveHint: false,
475
465
  openWorldHint: false,
476
- surfaces: ["hosted"]
466
+ surfaces: ["hosted", "public"]
477
467
  }
478
468
  ];
479
469
  var definitions = new Map(generatedCatalog.operations.map((operation) => [
@@ -484,18 +474,50 @@ var definitions = new Map(generatedCatalog.operations.map((operation) => [
484
474
  result: toMcpJsonSchema(operation.result)
485
475
  }
486
476
  ]));
477
+ var CATALOG_APP_TOOLS = [
478
+ "tinycloud_knowledge_list",
479
+ "tinycloud_knowledge_read",
480
+ "tinycloud_sql_query",
481
+ "tinycloud_sql_execute"
482
+ ];
483
+ var APP_WITHOUT_CATALOG_APPS = "Pass one existing personal app id to request its task access together.";
484
+ function withPropertyDescription(schema, property, description) {
485
+ const properties = schema.properties;
486
+ const current = properties?.[property];
487
+ if (current === void 0) throw new Error(`Generated operations catalog has no ${property} input to describe.`);
488
+ return { ...schema, properties: { ...properties, [property]: { ...current, description } } };
489
+ }
490
+ function catalogAppRefusal(binding, profile, input) {
491
+ const app = typeof input === "object" && input !== null ? input.app : void 0;
492
+ if (typeof app !== "string" || !Object.hasOwn(import_tc_apps.TC_APPS_CATALOG_APPS, app)) return void 0;
493
+ const { title, link } = import_tc_apps.TC_APPS_CATALOG_APPS[app];
494
+ return {
495
+ status: "error",
496
+ operation: { operationId: binding.operationId, operationVersion: binding.operationVersion },
497
+ context: { profile, host: "unresolved", posture: "unauthenticated" },
498
+ error: {
499
+ code: "INPUT_INVALID",
500
+ message: `${title} is not available through this connector. Its page is ${link}. If the user asked for ${title}, tell them so and give them that link. For any other personal records, call tinycloud_apps_context without app.`,
501
+ retryable: false,
502
+ details: { reason: "catalog_app_unavailable", app, link }
503
+ }
504
+ };
505
+ }
487
506
  function createJsonSchemaValidator() {
488
507
  return new import_ajv.AjvJsonSchemaValidator();
489
508
  }
490
509
  function registerTinyCloudTools(server, selection, validator) {
491
510
  const bindings = TOOL_BINDINGS.filter((binding) => bindingSurfaces(binding).includes(selection.surface) && (selection.allowedTools === void 0 || selection.allowedTools.includes(binding.name)));
511
+ const servesCatalogApps = CATALOG_APP_TOOLS.every((name) => bindings.some((binding) => binding.name === name));
492
512
  for (const binding of bindings) {
493
513
  const operation = definitions.get(`${binding.operationId}@${binding.operationVersion}`);
494
514
  if (operation === void 0) {
495
515
  throw new Error(`Generated operations catalog is missing ${binding.operationId}@${binding.operationVersion}.`);
496
516
  }
517
+ const offersCatalogApps = servesCatalogApps || binding.operationId !== "tinycloud.apps.context";
518
+ const inputJsonSchema = offersCatalogApps ? operation.input : withPropertyDescription(operation.input, "app", APP_WITHOUT_CATALOG_APPS);
497
519
  const inputSchema = (0, import_server.fromJsonSchema)(
498
- operation.input,
520
+ inputJsonSchema,
499
521
  validator
500
522
  );
501
523
  const outputSchema = (0, import_server.fromJsonSchema)(
@@ -522,19 +544,22 @@ function registerTinyCloudTools(server, selection, validator) {
522
544
  const metrics = { replayedGrants: 0 };
523
545
  let code = "INTERNAL_ERROR";
524
546
  try {
525
- await selection.beforeOperation?.();
526
- const result = await (0, import_operations.invokeOperation)(
527
- binding.operationId,
528
- binding.operationVersion,
529
- invocationTargetForMcp(selection),
530
- input,
531
- metrics
532
- );
533
- const projected = selection.transformOperationResult === void 0 ? result : await selection.transformOperationResult(result, {
534
- operationId: binding.operationId,
535
- operationVersion: binding.operationVersion,
536
- input
537
- });
547
+ let projected = offersCatalogApps ? void 0 : catalogAppRefusal(binding, selection.profile, input);
548
+ if (projected === void 0) {
549
+ await selection.beforeOperation?.();
550
+ const result = await (0, import_operations.invokeOperation)(
551
+ binding.operationId,
552
+ binding.operationVersion,
553
+ invocationTargetForMcp(selection),
554
+ input,
555
+ metrics
556
+ );
557
+ projected = selection.transformOperationResult === void 0 ? result : await selection.transformOperationResult(result, {
558
+ operationId: binding.operationId,
559
+ operationVersion: binding.operationVersion,
560
+ input
561
+ });
562
+ }
538
563
  const response = toMcpToolResult(projected, bindings, {
539
564
  surface: selection.surface === "local" ? "local" : "hosted",
540
565
  readOnly: binding.readOnlyHint,
@@ -566,7 +591,7 @@ function outcomeCode(result) {
566
591
  // package.json
567
592
  var package_default = {
568
593
  name: "@tinycloud/mcp",
569
- version: "0.10.0-beta.5",
594
+ version: "0.10.0-beta.50",
570
595
  description: "TinyCloud delegated operations MCP server",
571
596
  keywords: [
572
597
  "tinycloud",
@@ -637,9 +662,10 @@ var package_default = {
637
662
  dependencies: {
638
663
  "@modelcontextprotocol/node": "2.0.0-beta.5",
639
664
  "@modelcontextprotocol/server": "2.0.0-beta.5",
640
- "@tinycloud/node-sdk": "3.12.0-beta.2",
641
- "@tinycloud/node-sdk-wasm": "1.7.8",
642
- "@tinycloud/operations": "0.9.0-beta.4",
665
+ "@tinycloud/node-sdk": "3.12.0-beta.38",
666
+ "@tinycloud/sdk-core": "3.12.0-beta.37",
667
+ "@tinycloud/node-sdk-wasm": "1.7.9-beta.0",
668
+ "@tinycloud/operations": "0.9.0-beta.45",
643
669
  jose: "6.2.4"
644
670
  },
645
671
  devDependencies: {
@@ -1017,6 +1043,7 @@ function claims(token) {
1017
1043
  }
1018
1044
 
1019
1045
  // src/remote-store.ts
1046
+ var import_sdk_core = require("@tinycloud/sdk-core");
1020
1047
  var import_node_crypto3 = require("crypto");
1021
1048
  var import_promises = require("fs/promises");
1022
1049
  var import_node_path3 = require("path");
@@ -1026,7 +1053,7 @@ var import_artifacts = require("@tinycloud/operations/artifacts");
1026
1053
  var import_state = require("@tinycloud/operations/state");
1027
1054
  var import_operations2 = require("@tinycloud/operations");
1028
1055
  var import_mcp_authority = require("@tinycloud/operations/mcp-authority");
1029
- var import_tc_apps = require("@tinycloud/operations/tc-apps");
1056
+ var import_tc_apps2 = require("@tinycloud/operations/tc-apps");
1030
1057
 
1031
1058
  // src/native-auth.ts
1032
1059
  var import_node_crypto2 = require("crypto");
@@ -1096,7 +1123,7 @@ var NATIVE_GRANT_IMPORT_REJECTION_CODES = /* @__PURE__ */ new Set([
1096
1123
  "DELEGATION_HOST_MISMATCH",
1097
1124
  "DELEGATION_REJECTED"
1098
1125
  ]);
1099
- var LEGACY_DEFAULT_NODE_HOST = "https://node.tinycloud.xyz";
1126
+ var PRODUCTION_NODE_HOSTS = /* @__PURE__ */ new Set(["https://node.tinycloud.xyz", "https://tee.node.tinycloud.xyz"]);
1100
1127
  var BOOTSTRAP_PERMISSIONS = [
1101
1128
  {
1102
1129
  service: "tinycloud.kv",
@@ -1422,7 +1449,7 @@ var RemoteTenantStore = class {
1422
1449
  kind: "openkey",
1423
1450
  requestId,
1424
1451
  url: this.#connectUrl(pending),
1425
- fallback: (0, import_tc_apps.tcAppsApprovalMessage)(requested) ?? "Open the approval URL, then retry the same MCP tool."
1452
+ fallback: (0, import_tc_apps2.tcAppsApprovalMessage)(requested) ?? "Open the approval URL, then retry the same MCP tool."
1426
1453
  }
1427
1454
  };
1428
1455
  }
@@ -1457,7 +1484,7 @@ var RemoteTenantStore = class {
1457
1484
  kind: "openkey",
1458
1485
  requestId,
1459
1486
  url: this.#connectUrl(pending),
1460
- fallback: (0, import_tc_apps.tcAppsApprovalMessage)(requested) ?? "Open the approval URL, then retry the same MCP tool."
1487
+ fallback: (0, import_tc_apps2.tcAppsApprovalMessage)(requested) ?? "Open the approval URL, then retry the same MCP tool."
1461
1488
  },
1462
1489
  retry: (0, import_mcp_authority.operationRetryDescriptor)(invocation, invocation.input)
1463
1490
  };
@@ -1519,14 +1546,16 @@ var RemoteTenantStore = class {
1519
1546
  did: tenant.sessionDid,
1520
1547
  callback: callback.toString(),
1521
1548
  host: this.#config.nodeHost,
1522
- jwk: Buffer.from(JSON.stringify(publicJwk(tenant.jwk))).toString("base64url"),
1549
+ requesterOrigin: this.#config.publicUrl.origin,
1550
+ jwk: Buffer.from(JSON.stringify((0, import_node_sdk2.publicJwk)(tenant.jwk))).toString("base64url"),
1523
1551
  permissions: Buffer.from(JSON.stringify({
1524
1552
  permissions: pending.permissions,
1525
1553
  reason: [
1526
- pending.kind === "bootstrap" ? "Connect this TinyCloud account to the hosted MCP delegate." : (0, import_tc_apps.tcAppsApprovalReason)(pending.permissions) ?? "Approve the exact capabilities requested by the TinyCloud MCP operation.",
1554
+ pending.kind === "bootstrap" ? "Connect this TinyCloud account to the hosted MCP delegate." : (0, import_tc_apps2.tcAppsApprovalReason)(pending.permissions) ?? "Approve the exact capabilities requested by the TinyCloud MCP operation.",
1527
1555
  // Owner DIDs come from the verified OpenKey access token of the MCP
1528
- // client that created this link, never from the link itself.
1529
- ...pending.ownerDids.length === 0 ? [] : [`Requested by TinyCloud account ${pending.ownerDids.join(", ")}; approve only if that is you.`]
1556
+ // client that created this link, never from the link itself. The
1557
+ // callback refuses a signer outside them, so the approver isn't asked to check.
1558
+ ...pending.ownerDids.length === 0 ? [] : [`Requested by TinyCloud account ${pending.ownerDids.join(", ")}.`]
1530
1559
  ].join(" ")
1531
1560
  })).toString("base64url"),
1532
1561
  expiry: this.#config.delegationExpiry
@@ -1825,10 +1854,10 @@ var RemoteTenantStore = class {
1825
1854
  authMethod: "openkey",
1826
1855
  openkeyHost: this.#config.openkeyHost
1827
1856
  });
1828
- } else if (typeof profile.host === "string" && profile.host.replace(/\/+$/, "") === LEGACY_DEFAULT_NODE_HOST && this.#config.nodeHost.replace(/\/+$/, "") !== LEGACY_DEFAULT_NODE_HOST) {
1857
+ } else if (typeof profile.host === "string" && PRODUCTION_NODE_HOSTS.has(profile.host.replace(/\/+$/, "")) && PRODUCTION_NODE_HOSTS.has(this.#config.nodeHost.replace(/\/+$/, "")) && profile.host.replace(/\/+$/, "") !== this.#config.nodeHost.replace(/\/+$/, "")) {
1829
1858
  await secureWrite(profilePath, { ...profile, host: this.#config.nodeHost });
1830
1859
  process.stderr.write(
1831
- `[tinycloud-mcp-http] tenant node host migrated: from=${LEGACY_DEFAULT_NODE_HOST} to=${new URL(this.#config.nodeHost).origin}
1860
+ `[tinycloud-mcp-http] tenant node host migrated: from=${profile.host.replace(/\/+$/, "")} to=${new URL(this.#config.nodeHost).origin}
1832
1861
  `
1833
1862
  );
1834
1863
  }
@@ -2134,11 +2163,6 @@ function sessionFromCallback(data, privateJwk) {
2134
2163
  signature: data.signature
2135
2164
  };
2136
2165
  }
2137
- function publicJwk(jwk) {
2138
- const copy = { ...jwk };
2139
- for (const field of ["d", "p", "q", "dp", "dq", "qi", "oth", "k"]) delete copy[field];
2140
- return copy;
2141
- }
2142
2166
  function samePrincipal(left, right) {
2143
2167
  if (typeof left !== "string") return false;
2144
2168
  try {
@@ -2151,6 +2175,7 @@ function normalizeDid(value) {
2151
2175
  return value.split("#", 1)[0];
2152
2176
  }
2153
2177
  function sameNodeHost(left, right) {
2178
+ if (PRODUCTION_NODE_HOSTS.has(left) && (0, import_sdk_core.sameTinyCloudNode)(left, right)) return true;
2154
2179
  try {
2155
2180
  const normalize = (value) => {
2156
2181
  const url = new URL(value);
@@ -2245,32 +2270,42 @@ function samePendingRequest(pending, expected) {
2245
2270
  // src/http.ts
2246
2271
  var REQUIRED_SCOPE = "tinycloud:mcp";
2247
2272
  var MCP_CORS_ALLOWED_HEADERS = "Authorization, Content-Type, Accept, Mcp-Protocol-Version, Mcp-Session-Id, Last-Event-ID, Mcp-Method, Mcp-Name";
2273
+ var MCP_CORS_EXPOSED_HEADERS = "WWW-Authenticate, Mcp-Session-Id, Mcp-Protocol-Version";
2248
2274
  var LOCAL_CLI_PACKAGE = ["@tinycloud", "cli"].join("/");
2249
2275
  var LOCAL_MCP_PACKAGE = ["@tinycloud", "mcp"].join("/");
2276
+ var RESTRICTED_ADDRESS_PREFIXES = ["chatgpt", "claude", "grok", "muse"];
2250
2277
  function createHostedMcpApp(config) {
2251
2278
  if (config.nativeServiceCredential !== void 0 && Buffer.byteLength(config.nativeServiceCredential, "utf8") < 32) {
2252
2279
  throw new Error("TC_MCP_NATIVE_SERVICE_CREDENTIAL must contain at least 32 bytes.");
2253
2280
  }
2254
2281
  const resourceUrl = canonicalResourceUrl(config.publicUrl);
2255
- const pluginUrl = new URL("./chatgpt/mcp", resourceUrl);
2256
2282
  const statusFor = (resource) => config.introspection === void 0 ? void 0 : createTokenStatusChecker({ ...config.introspection, resourceUrl: resource.toString() });
2257
2283
  const hosted = createHostedSurface(config, resourceUrl, "hosted", statusFor(resourceUrl));
2258
- const plugin = createHostedSurface({
2259
- ...config,
2260
- nativeServiceCredential: void 0,
2261
- stateDir: (0, import_node_path4.join)(config.stateDir, "chatgpt"),
2262
- approvalPath: new URL("./connect", pluginUrl).pathname
2263
- }, pluginUrl, "public", statusFor(pluginUrl));
2264
- const pluginPaths = {
2265
- [pluginUrl.pathname]: true,
2266
- [new URL("./connect", pluginUrl).pathname]: true,
2267
- [new URL("./connect/callback", pluginUrl).pathname]: true,
2268
- [new URL((0, import_server5.getOAuthProtectedResourceMetadataUrl)(pluginUrl)).pathname]: true
2269
- };
2284
+ const surfaces = [hosted];
2285
+ const restrictedByPath = /* @__PURE__ */ new Map();
2286
+ for (const prefix of RESTRICTED_ADDRESS_PREFIXES) {
2287
+ const restrictedUrl = new URL(`./${prefix}/mcp`, resourceUrl);
2288
+ const connectUrl = new URL("./connect", restrictedUrl);
2289
+ const restricted = createHostedSurface({
2290
+ ...config,
2291
+ nativeServiceCredential: void 0,
2292
+ stateDir: (0, import_node_path4.join)(config.stateDir, prefix),
2293
+ approvalPath: connectUrl.pathname
2294
+ }, restrictedUrl, "public", statusFor(restrictedUrl));
2295
+ surfaces.push(restricted);
2296
+ for (const owned of [
2297
+ restrictedUrl,
2298
+ connectUrl,
2299
+ new URL("./connect/callback", restrictedUrl),
2300
+ new URL((0, import_server5.getOAuthProtectedResourceMetadataUrl)(restrictedUrl))
2301
+ ]) {
2302
+ restrictedByPath.set(owned.pathname, restricted);
2303
+ }
2304
+ }
2270
2305
  return {
2271
- fetch: (request) => (pluginPaths[new URL(request.url).pathname] === true ? plugin : hosted).fetch(request),
2306
+ fetch: (request) => (restrictedByPath.get(new URL(request.url).pathname) ?? hosted).fetch(request),
2272
2307
  close: async () => {
2273
- await Promise.all([hosted.close(), plugin.close()]);
2308
+ await Promise.all(surfaces.map((surface) => surface.close()));
2274
2309
  }
2275
2310
  };
2276
2311
  }
@@ -2542,10 +2577,12 @@ Local alternative: install \`${LOCAL_CLI_PACKAGE}\` and \`${LOCAL_MCP_PACKAGE}\`
2542
2577
  try {
2543
2578
  const destination = await store.approvalRedirect(requiredState(url));
2544
2579
  return Response.redirect(destination, 302);
2545
- } catch {
2580
+ } catch (error) {
2581
+ const reason = error instanceof ApprovalRequestError ? error.detail : "unknown";
2582
+ writeDiagnostic(`connect rejected: reason=${reason} path=${connectPath}`);
2546
2583
  if (request.headers.get("accept")?.includes("text/html")) {
2547
2584
  return new Response(
2548
- '<!doctype html><html lang="en"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>TinyCloud approval unavailable</title><main><h1>This approval link is unavailable</h1><p>It may have expired or already been used. No new approval was accepted through this link.</p><p>Return to the conversation that requested access. In ChatGPT, select @TinyCloud and ask it to continue your original request. If access is still needed, it can provide a fresh approval link.</p><p>If you declined access, no further approval is required. Never paste passwords, codes or approval links into support messages.</p></main></html>',
2585
+ '<!doctype html><html lang="en"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>TinyCloud approval unavailable</title><main><h1>This approval link is unavailable</h1><p>It may have expired or already been used. Go back to the assistant that sent it and ask it to connect TinyCloud again.</p><p>If you declined access, no further approval is required. Never paste passwords, codes or approval links into support messages.</p></main></html>',
2549
2586
  {
2550
2587
  status: 400,
2551
2588
  headers: {
@@ -2756,7 +2793,7 @@ function mcpCors(response, request) {
2756
2793
  if (request.headers.has("origin")) {
2757
2794
  headers.set("access-control-allow-origin", "*");
2758
2795
  headers.set("access-control-allow-methods", "GET, POST, DELETE, OPTIONS");
2759
- headers.set("access-control-expose-headers", "WWW-Authenticate");
2796
+ headers.set("access-control-expose-headers", MCP_CORS_EXPOSED_HEADERS);
2760
2797
  if (request.method === "OPTIONS") headers.set("access-control-allow-headers", MCP_CORS_ALLOWED_HEADERS);
2761
2798
  }
2762
2799
  return new Response(response.body, { status: response.status, statusText: response.statusText, headers });