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

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.js CHANGED
@@ -12,6 +12,7 @@ import { join } from "path";
12
12
  import { fromJsonSchema } from "@modelcontextprotocol/server";
13
13
  import { AjvJsonSchemaValidator } from "@modelcontextprotocol/server/validators/ajv";
14
14
  import { invokeOperation } from "@tinycloud/operations";
15
+ import { TC_APPS_CATALOG_APPS } from "@tinycloud/operations/tc-apps";
15
16
 
16
17
  // src/results.ts
17
18
  function toMcpToolResult(result, bindings = [], options = {}) {
@@ -169,8 +170,7 @@ var TOOL_NAMES = [
169
170
  "tinycloud_apps_context",
170
171
  "tinycloud_apps_read",
171
172
  "tinycloud_apps_write",
172
- "tinycloud_apps_query",
173
- "tinycloud_apps_move"
173
+ "tinycloud_apps_query"
174
174
  ];
175
175
  function invocationTargetForMcp(selection) {
176
176
  return {
@@ -394,7 +394,7 @@ var TOOL_BINDINGS = [
394
394
  operationVersion: 1,
395
395
  readOnlyHint: false,
396
396
  idempotentHint: true,
397
- destructiveHint: true,
397
+ destructiveHint: false,
398
398
  openWorldHint: false,
399
399
  surfaces: ["hosted", "public"]
400
400
  },
@@ -424,19 +424,9 @@ var TOOL_BINDINGS = [
424
424
  operationVersion: 1,
425
425
  readOnlyHint: false,
426
426
  idempotentHint: true,
427
- destructiveHint: true,
428
- openWorldHint: false,
429
- surfaces: ["hosted", "public"]
430
- },
431
- {
432
- name: "tinycloud_apps_move",
433
- operationId: "tinycloud.apps.move",
434
- operationVersion: 1,
435
- readOnlyHint: false,
436
- idempotentHint: true,
437
427
  destructiveHint: false,
438
428
  openWorldHint: false,
439
- surfaces: ["hosted"]
429
+ surfaces: ["hosted", "public"]
440
430
  }
441
431
  ];
442
432
  var definitions = new Map(generatedCatalog.operations.map((operation) => [
@@ -447,18 +437,50 @@ var definitions = new Map(generatedCatalog.operations.map((operation) => [
447
437
  result: toMcpJsonSchema(operation.result)
448
438
  }
449
439
  ]));
440
+ var CATALOG_APP_TOOLS = [
441
+ "tinycloud_knowledge_list",
442
+ "tinycloud_knowledge_read",
443
+ "tinycloud_sql_query",
444
+ "tinycloud_sql_execute"
445
+ ];
446
+ var APP_WITHOUT_CATALOG_APPS = "Pass one existing personal app id to request its task access together.";
447
+ function withPropertyDescription(schema, property, description) {
448
+ const properties = schema.properties;
449
+ const current = properties?.[property];
450
+ if (current === void 0) throw new Error(`Generated operations catalog has no ${property} input to describe.`);
451
+ return { ...schema, properties: { ...properties, [property]: { ...current, description } } };
452
+ }
453
+ function catalogAppRefusal(binding, profile, input) {
454
+ const app = typeof input === "object" && input !== null ? input.app : void 0;
455
+ if (typeof app !== "string" || !Object.hasOwn(TC_APPS_CATALOG_APPS, app)) return void 0;
456
+ const { title, link } = TC_APPS_CATALOG_APPS[app];
457
+ return {
458
+ status: "error",
459
+ operation: { operationId: binding.operationId, operationVersion: binding.operationVersion },
460
+ context: { profile, host: "unresolved", posture: "unauthenticated" },
461
+ error: {
462
+ code: "INPUT_INVALID",
463
+ 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.`,
464
+ retryable: false,
465
+ details: { reason: "catalog_app_unavailable", app, link }
466
+ }
467
+ };
468
+ }
450
469
  function createJsonSchemaValidator() {
451
470
  return new AjvJsonSchemaValidator();
452
471
  }
453
472
  function registerTinyCloudTools(server, selection, validator) {
454
473
  const bindings = TOOL_BINDINGS.filter((binding) => bindingSurfaces(binding).includes(selection.surface) && (selection.allowedTools === void 0 || selection.allowedTools.includes(binding.name)));
474
+ const servesCatalogApps = CATALOG_APP_TOOLS.every((name) => bindings.some((binding) => binding.name === name));
455
475
  for (const binding of bindings) {
456
476
  const operation = definitions.get(`${binding.operationId}@${binding.operationVersion}`);
457
477
  if (operation === void 0) {
458
478
  throw new Error(`Generated operations catalog is missing ${binding.operationId}@${binding.operationVersion}.`);
459
479
  }
480
+ const offersCatalogApps = servesCatalogApps || binding.operationId !== "tinycloud.apps.context";
481
+ const inputJsonSchema = offersCatalogApps ? operation.input : withPropertyDescription(operation.input, "app", APP_WITHOUT_CATALOG_APPS);
460
482
  const inputSchema = fromJsonSchema(
461
- operation.input,
483
+ inputJsonSchema,
462
484
  validator
463
485
  );
464
486
  const outputSchema = fromJsonSchema(
@@ -466,6 +488,7 @@ function registerTinyCloudTools(server, selection, validator) {
466
488
  validator
467
489
  );
468
490
  const annotations = {
491
+ ...selection.annotationTitles === true ? { title: operation.title } : {},
469
492
  readOnlyHint: binding.readOnlyHint,
470
493
  idempotentHint: binding.idempotentHint,
471
494
  destructiveHint: binding.destructiveHint,
@@ -485,19 +508,22 @@ function registerTinyCloudTools(server, selection, validator) {
485
508
  const metrics = { replayedGrants: 0 };
486
509
  let code = "INTERNAL_ERROR";
487
510
  try {
488
- await selection.beforeOperation?.();
489
- const result = await invokeOperation(
490
- binding.operationId,
491
- binding.operationVersion,
492
- invocationTargetForMcp(selection),
493
- input,
494
- metrics
495
- );
496
- const projected = selection.transformOperationResult === void 0 ? result : await selection.transformOperationResult(result, {
497
- operationId: binding.operationId,
498
- operationVersion: binding.operationVersion,
499
- input
500
- });
511
+ let projected = offersCatalogApps ? void 0 : catalogAppRefusal(binding, selection.profile, input);
512
+ if (projected === void 0) {
513
+ await selection.beforeOperation?.();
514
+ const result = await invokeOperation(
515
+ binding.operationId,
516
+ binding.operationVersion,
517
+ invocationTargetForMcp(selection),
518
+ input,
519
+ metrics
520
+ );
521
+ projected = selection.transformOperationResult === void 0 ? result : await selection.transformOperationResult(result, {
522
+ operationId: binding.operationId,
523
+ operationVersion: binding.operationVersion,
524
+ input
525
+ });
526
+ }
501
527
  const response = toMcpToolResult(projected, bindings, {
502
528
  surface: selection.surface === "local" ? "local" : "hosted",
503
529
  readOnly: binding.readOnlyHint,
@@ -529,7 +555,7 @@ function outcomeCode(result) {
529
555
  // package.json
530
556
  var package_default = {
531
557
  name: "@tinycloud/mcp",
532
- version: "0.10.0-beta.5",
558
+ version: "0.10.0-beta.51",
533
559
  description: "TinyCloud delegated operations MCP server",
534
560
  keywords: [
535
561
  "tinycloud",
@@ -600,9 +626,10 @@ var package_default = {
600
626
  dependencies: {
601
627
  "@modelcontextprotocol/node": "2.0.0-beta.5",
602
628
  "@modelcontextprotocol/server": "2.0.0-beta.5",
603
- "@tinycloud/node-sdk": "3.12.0-beta.2",
604
- "@tinycloud/node-sdk-wasm": "1.7.8",
605
- "@tinycloud/operations": "0.9.0-beta.4",
629
+ "@tinycloud/node-sdk": "3.12.0-beta.38",
630
+ "@tinycloud/sdk-core": "3.12.0-beta.37",
631
+ "@tinycloud/node-sdk-wasm": "1.7.9-beta.0",
632
+ "@tinycloud/operations": "0.9.0-beta.45",
606
633
  jose: "6.2.4"
607
634
  },
608
635
  devDependencies: {
@@ -991,6 +1018,7 @@ function claims(token) {
991
1018
  }
992
1019
 
993
1020
  // src/remote-store.ts
1021
+ import { sameTinyCloudNode } from "@tinycloud/sdk-core";
994
1022
  import { createHmac, randomBytes, timingSafeEqual as timingSafeEqual2 } from "crypto";
995
1023
  import { chmod, mkdir, readFile, readdir, rename, rm, writeFile } from "fs/promises";
996
1024
  import { dirname, join as join2 } from "path";
@@ -1004,6 +1032,7 @@ import {
1004
1032
  UnsupportedSessionRestoreError,
1005
1033
  isCapabilitySubset,
1006
1034
  principalDidEquals,
1035
+ publicJwk,
1007
1036
  siweRuntimeDelegation,
1008
1037
  signedCompactUcanExpiry
1009
1038
  } from "@tinycloud/node-sdk";
@@ -1082,7 +1111,7 @@ var NATIVE_GRANT_IMPORT_REJECTION_CODES = /* @__PURE__ */ new Set([
1082
1111
  "DELEGATION_HOST_MISMATCH",
1083
1112
  "DELEGATION_REJECTED"
1084
1113
  ]);
1085
- var LEGACY_DEFAULT_NODE_HOST = "https://node.tinycloud.xyz";
1114
+ var PRODUCTION_NODE_HOSTS = /* @__PURE__ */ new Set(["https://node.tinycloud.xyz", "https://tee.node.tinycloud.xyz"]);
1086
1115
  var BOOTSTRAP_PERMISSIONS = [
1087
1116
  {
1088
1117
  service: "tinycloud.kv",
@@ -1505,14 +1534,16 @@ var RemoteTenantStore = class {
1505
1534
  did: tenant.sessionDid,
1506
1535
  callback: callback.toString(),
1507
1536
  host: this.#config.nodeHost,
1537
+ requesterOrigin: this.#config.publicUrl.origin,
1508
1538
  jwk: Buffer.from(JSON.stringify(publicJwk(tenant.jwk))).toString("base64url"),
1509
1539
  permissions: Buffer.from(JSON.stringify({
1510
1540
  permissions: pending.permissions,
1511
1541
  reason: [
1512
1542
  pending.kind === "bootstrap" ? "Connect this TinyCloud account to the hosted MCP delegate." : tcAppsApprovalReason(pending.permissions) ?? "Approve the exact capabilities requested by the TinyCloud MCP operation.",
1513
1543
  // Owner DIDs come from the verified OpenKey access token of the MCP
1514
- // client that created this link, never from the link itself.
1515
- ...pending.ownerDids.length === 0 ? [] : [`Requested by TinyCloud account ${pending.ownerDids.join(", ")}; approve only if that is you.`]
1544
+ // client that created this link, never from the link itself. The
1545
+ // callback refuses a signer outside them, so the approver isn't asked to check.
1546
+ ...pending.ownerDids.length === 0 ? [] : [`Requested by TinyCloud account ${pending.ownerDids.join(", ")}.`]
1516
1547
  ].join(" ")
1517
1548
  })).toString("base64url"),
1518
1549
  expiry: this.#config.delegationExpiry
@@ -1811,10 +1842,10 @@ var RemoteTenantStore = class {
1811
1842
  authMethod: "openkey",
1812
1843
  openkeyHost: this.#config.openkeyHost
1813
1844
  });
1814
- } else if (typeof profile.host === "string" && profile.host.replace(/\/+$/, "") === LEGACY_DEFAULT_NODE_HOST && this.#config.nodeHost.replace(/\/+$/, "") !== LEGACY_DEFAULT_NODE_HOST) {
1845
+ } 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(/\/+$/, "")) {
1815
1846
  await secureWrite(profilePath, { ...profile, host: this.#config.nodeHost });
1816
1847
  process.stderr.write(
1817
- `[tinycloud-mcp-http] tenant node host migrated: from=${LEGACY_DEFAULT_NODE_HOST} to=${new URL(this.#config.nodeHost).origin}
1848
+ `[tinycloud-mcp-http] tenant node host migrated: from=${profile.host.replace(/\/+$/, "")} to=${new URL(this.#config.nodeHost).origin}
1818
1849
  `
1819
1850
  );
1820
1851
  }
@@ -2120,11 +2151,6 @@ function sessionFromCallback(data, privateJwk) {
2120
2151
  signature: data.signature
2121
2152
  };
2122
2153
  }
2123
- function publicJwk(jwk) {
2124
- const copy = { ...jwk };
2125
- for (const field of ["d", "p", "q", "dp", "dq", "qi", "oth", "k"]) delete copy[field];
2126
- return copy;
2127
- }
2128
2154
  function samePrincipal(left, right) {
2129
2155
  if (typeof left !== "string") return false;
2130
2156
  try {
@@ -2137,6 +2163,7 @@ function normalizeDid(value) {
2137
2163
  return value.split("#", 1)[0];
2138
2164
  }
2139
2165
  function sameNodeHost(left, right) {
2166
+ if (PRODUCTION_NODE_HOSTS.has(left) && sameTinyCloudNode(left, right)) return true;
2140
2167
  try {
2141
2168
  const normalize = (value) => {
2142
2169
  const url = new URL(value);
@@ -2231,36 +2258,47 @@ function samePendingRequest(pending, expected) {
2231
2258
  // src/http.ts
2232
2259
  var REQUIRED_SCOPE = "tinycloud:mcp";
2233
2260
  var MCP_CORS_ALLOWED_HEADERS = "Authorization, Content-Type, Accept, Mcp-Protocol-Version, Mcp-Session-Id, Last-Event-ID, Mcp-Method, Mcp-Name";
2261
+ var MCP_CORS_EXPOSED_HEADERS = "WWW-Authenticate, Mcp-Session-Id, Mcp-Protocol-Version";
2234
2262
  var LOCAL_CLI_PACKAGE = ["@tinycloud", "cli"].join("/");
2235
2263
  var LOCAL_MCP_PACKAGE = ["@tinycloud", "mcp"].join("/");
2264
+ var RESTRICTED_ADDRESS_PREFIXES = ["chatgpt", "claude", "grok", "muse"];
2265
+ var ANNOTATION_TITLE_PREFIXES = /* @__PURE__ */ new Set(["claude"]);
2236
2266
  function createHostedMcpApp(config) {
2237
2267
  if (config.nativeServiceCredential !== void 0 && Buffer.byteLength(config.nativeServiceCredential, "utf8") < 32) {
2238
2268
  throw new Error("TC_MCP_NATIVE_SERVICE_CREDENTIAL must contain at least 32 bytes.");
2239
2269
  }
2240
2270
  const resourceUrl = canonicalResourceUrl(config.publicUrl);
2241
- const pluginUrl = new URL("./chatgpt/mcp", resourceUrl);
2242
2271
  const statusFor = (resource) => config.introspection === void 0 ? void 0 : createTokenStatusChecker({ ...config.introspection, resourceUrl: resource.toString() });
2243
2272
  const hosted = createHostedSurface(config, resourceUrl, "hosted", statusFor(resourceUrl));
2244
- const plugin = createHostedSurface({
2245
- ...config,
2246
- nativeServiceCredential: void 0,
2247
- stateDir: join3(config.stateDir, "chatgpt"),
2248
- approvalPath: new URL("./connect", pluginUrl).pathname
2249
- }, pluginUrl, "public", statusFor(pluginUrl));
2250
- const pluginPaths = {
2251
- [pluginUrl.pathname]: true,
2252
- [new URL("./connect", pluginUrl).pathname]: true,
2253
- [new URL("./connect/callback", pluginUrl).pathname]: true,
2254
- [new URL(getOAuthProtectedResourceMetadataUrl(pluginUrl)).pathname]: true
2255
- };
2273
+ const surfaces = [hosted];
2274
+ const restrictedByPath = /* @__PURE__ */ new Map();
2275
+ for (const prefix of RESTRICTED_ADDRESS_PREFIXES) {
2276
+ const restrictedUrl = new URL(`./${prefix}/mcp`, resourceUrl);
2277
+ const connectUrl = new URL("./connect", restrictedUrl);
2278
+ const restricted = createHostedSurface({
2279
+ ...config,
2280
+ nativeServiceCredential: void 0,
2281
+ stateDir: join3(config.stateDir, prefix),
2282
+ approvalPath: connectUrl.pathname
2283
+ }, restrictedUrl, "public", statusFor(restrictedUrl), ANNOTATION_TITLE_PREFIXES.has(prefix));
2284
+ surfaces.push(restricted);
2285
+ for (const owned of [
2286
+ restrictedUrl,
2287
+ connectUrl,
2288
+ new URL("./connect/callback", restrictedUrl),
2289
+ new URL(getOAuthProtectedResourceMetadataUrl(restrictedUrl))
2290
+ ]) {
2291
+ restrictedByPath.set(owned.pathname, restricted);
2292
+ }
2293
+ }
2256
2294
  return {
2257
- fetch: (request) => (pluginPaths[new URL(request.url).pathname] === true ? plugin : hosted).fetch(request),
2295
+ fetch: (request) => (restrictedByPath.get(new URL(request.url).pathname) ?? hosted).fetch(request),
2258
2296
  close: async () => {
2259
- await Promise.all([hosted.close(), plugin.close()]);
2297
+ await Promise.all(surfaces.map((surface) => surface.close()));
2260
2298
  }
2261
2299
  };
2262
2300
  }
2263
- function createHostedSurface(config, resourceUrl, surface, tokenStatus) {
2301
+ function createHostedSurface(config, resourceUrl, surface, tokenStatus, annotationTitles = false) {
2264
2302
  const connectPath = config.approvalPath ?? "/connect";
2265
2303
  const callbackPath = `${connectPath}/callback`;
2266
2304
  const issuer = String(config.oauthMetadata.issuer);
@@ -2300,6 +2338,7 @@ function createHostedSurface(config, resourceUrl, surface, tokenStatus) {
2300
2338
  explicitProfile: true,
2301
2339
  allowOwnerProfile: false,
2302
2340
  stateRoot,
2341
+ annotationTitles,
2303
2342
  ...nativeOwner === void 0 ? {} : {
2304
2343
  allowedTools: ["tinycloud_sql_query", "tinycloud_kv_get", "tinycloud_read"]
2305
2344
  },
@@ -2308,7 +2347,7 @@ function createHostedSurface(config, resourceUrl, surface, tokenStatus) {
2308
2347
  transformOperationResult: (result, invocation) => store.decorateAuthorityResult(subject, ownerDids, result, invocation)
2309
2348
  } : {}
2310
2349
  }, validator);
2311
- if (nativeOwner === void 0) registerConnectTool(server, validator, store, identity, surface);
2350
+ if (nativeOwner === void 0) registerConnectTool(server, validator, store, identity, surface, annotationTitles);
2312
2351
  return server;
2313
2352
  }, {
2314
2353
  legacy: "stateless",
@@ -2528,10 +2567,12 @@ Local alternative: install \`${LOCAL_CLI_PACKAGE}\` and \`${LOCAL_MCP_PACKAGE}\`
2528
2567
  try {
2529
2568
  const destination = await store.approvalRedirect(requiredState(url));
2530
2569
  return Response.redirect(destination, 302);
2531
- } catch {
2570
+ } catch (error) {
2571
+ const reason = error instanceof ApprovalRequestError ? error.detail : "unknown";
2572
+ writeDiagnostic(`connect rejected: reason=${reason} path=${connectPath}`);
2532
2573
  if (request.headers.get("accept")?.includes("text/html")) {
2533
2574
  return new Response(
2534
- '<!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>',
2575
+ '<!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>',
2535
2576
  {
2536
2577
  status: 400,
2537
2578
  headers: {
@@ -2653,7 +2694,8 @@ Local alternative: install \`${LOCAL_CLI_PACKAGE}\` and \`${LOCAL_MCP_PACKAGE}\`
2653
2694
  close: () => handler.close()
2654
2695
  };
2655
2696
  }
2656
- function registerConnectTool(server, validator, store, identity, surface) {
2697
+ function registerConnectTool(server, validator, store, identity, surface, annotationTitles) {
2698
+ const title = "Connect TinyCloud";
2657
2699
  const inputSchema = fromJsonSchema2({ type: "object", properties: {}, additionalProperties: false }, validator);
2658
2700
  const outputSchema = fromJsonSchema2({
2659
2701
  type: "object",
@@ -2669,11 +2711,12 @@ function registerConnectTool(server, validator, store, identity, surface) {
2669
2711
  server.registerTool(
2670
2712
  "tinycloud_connect",
2671
2713
  {
2672
- title: "Connect TinyCloud",
2714
+ title,
2673
2715
  description: "Check the hosted delegate connection and return a one-time OpenKey approval URL when setup is required.",
2674
2716
  inputSchema,
2675
2717
  outputSchema,
2676
2718
  annotations: {
2719
+ ...annotationTitles ? { title } : {},
2677
2720
  readOnlyHint: false,
2678
2721
  idempotentHint: true,
2679
2722
  destructiveHint: false,
@@ -2742,7 +2785,7 @@ function mcpCors(response, request) {
2742
2785
  if (request.headers.has("origin")) {
2743
2786
  headers.set("access-control-allow-origin", "*");
2744
2787
  headers.set("access-control-allow-methods", "GET, POST, DELETE, OPTIONS");
2745
- headers.set("access-control-expose-headers", "WWW-Authenticate");
2788
+ headers.set("access-control-expose-headers", MCP_CORS_EXPOSED_HEADERS);
2746
2789
  if (request.method === "OPTIONS") headers.set("access-control-allow-headers", MCP_CORS_ALLOWED_HEADERS);
2747
2790
  }
2748
2791
  return new Response(response.body, { status: response.status, statusText: response.statusText, headers });