@tinycloud/mcp 0.10.0-beta.8 → 0.10.0

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.8",
558
+ version: "0.10.0",
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.3",
604
- "@tinycloud/node-sdk-wasm": "1.7.8",
605
- "@tinycloud/operations": "0.9.0-beta.5",
629
+ "@tinycloud/node-sdk": "3.12.0",
630
+ "@tinycloud/sdk-core": "3.12.0",
631
+ "@tinycloud/node-sdk-wasm": "1.7.9",
632
+ "@tinycloud/operations": "0.9.0",
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,6 +1534,7 @@ 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,
@@ -1812,10 +1842,10 @@ var RemoteTenantStore = class {
1812
1842
  authMethod: "openkey",
1813
1843
  openkeyHost: this.#config.openkeyHost
1814
1844
  });
1815
- } 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(/\/+$/, "")) {
1816
1846
  await secureWrite(profilePath, { ...profile, host: this.#config.nodeHost });
1817
1847
  process.stderr.write(
1818
- `[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}
1819
1849
  `
1820
1850
  );
1821
1851
  }
@@ -2121,11 +2151,6 @@ function sessionFromCallback(data, privateJwk) {
2121
2151
  signature: data.signature
2122
2152
  };
2123
2153
  }
2124
- function publicJwk(jwk) {
2125
- const copy = { ...jwk };
2126
- for (const field of ["d", "p", "q", "dp", "dq", "qi", "oth", "k"]) delete copy[field];
2127
- return copy;
2128
- }
2129
2154
  function samePrincipal(left, right) {
2130
2155
  if (typeof left !== "string") return false;
2131
2156
  try {
@@ -2138,6 +2163,7 @@ function normalizeDid(value) {
2138
2163
  return value.split("#", 1)[0];
2139
2164
  }
2140
2165
  function sameNodeHost(left, right) {
2166
+ if (PRODUCTION_NODE_HOSTS.has(left) && sameTinyCloudNode(left, right)) return true;
2141
2167
  try {
2142
2168
  const normalize = (value) => {
2143
2169
  const url = new URL(value);
@@ -2232,36 +2258,47 @@ function samePendingRequest(pending, expected) {
2232
2258
  // src/http.ts
2233
2259
  var REQUIRED_SCOPE = "tinycloud:mcp";
2234
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";
2235
2262
  var LOCAL_CLI_PACKAGE = ["@tinycloud", "cli"].join("/");
2236
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"]);
2237
2266
  function createHostedMcpApp(config) {
2238
2267
  if (config.nativeServiceCredential !== void 0 && Buffer.byteLength(config.nativeServiceCredential, "utf8") < 32) {
2239
2268
  throw new Error("TC_MCP_NATIVE_SERVICE_CREDENTIAL must contain at least 32 bytes.");
2240
2269
  }
2241
2270
  const resourceUrl = canonicalResourceUrl(config.publicUrl);
2242
- const pluginUrl = new URL("./chatgpt/mcp", resourceUrl);
2243
2271
  const statusFor = (resource) => config.introspection === void 0 ? void 0 : createTokenStatusChecker({ ...config.introspection, resourceUrl: resource.toString() });
2244
2272
  const hosted = createHostedSurface(config, resourceUrl, "hosted", statusFor(resourceUrl));
2245
- const plugin = createHostedSurface({
2246
- ...config,
2247
- nativeServiceCredential: void 0,
2248
- stateDir: join3(config.stateDir, "chatgpt"),
2249
- approvalPath: new URL("./connect", pluginUrl).pathname
2250
- }, pluginUrl, "public", statusFor(pluginUrl));
2251
- const pluginPaths = {
2252
- [pluginUrl.pathname]: true,
2253
- [new URL("./connect", pluginUrl).pathname]: true,
2254
- [new URL("./connect/callback", pluginUrl).pathname]: true,
2255
- [new URL(getOAuthProtectedResourceMetadataUrl(pluginUrl)).pathname]: true
2256
- };
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
+ }
2257
2294
  return {
2258
- 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),
2259
2296
  close: async () => {
2260
- await Promise.all([hosted.close(), plugin.close()]);
2297
+ await Promise.all(surfaces.map((surface) => surface.close()));
2261
2298
  }
2262
2299
  };
2263
2300
  }
2264
- function createHostedSurface(config, resourceUrl, surface, tokenStatus) {
2301
+ function createHostedSurface(config, resourceUrl, surface, tokenStatus, annotationTitles = false) {
2265
2302
  const connectPath = config.approvalPath ?? "/connect";
2266
2303
  const callbackPath = `${connectPath}/callback`;
2267
2304
  const issuer = String(config.oauthMetadata.issuer);
@@ -2301,6 +2338,7 @@ function createHostedSurface(config, resourceUrl, surface, tokenStatus) {
2301
2338
  explicitProfile: true,
2302
2339
  allowOwnerProfile: false,
2303
2340
  stateRoot,
2341
+ annotationTitles,
2304
2342
  ...nativeOwner === void 0 ? {} : {
2305
2343
  allowedTools: ["tinycloud_sql_query", "tinycloud_kv_get", "tinycloud_read"]
2306
2344
  },
@@ -2309,7 +2347,7 @@ function createHostedSurface(config, resourceUrl, surface, tokenStatus) {
2309
2347
  transformOperationResult: (result, invocation) => store.decorateAuthorityResult(subject, ownerDids, result, invocation)
2310
2348
  } : {}
2311
2349
  }, validator);
2312
- if (nativeOwner === void 0) registerConnectTool(server, validator, store, identity, surface);
2350
+ if (nativeOwner === void 0) registerConnectTool(server, validator, store, identity, surface, annotationTitles);
2313
2351
  return server;
2314
2352
  }, {
2315
2353
  legacy: "stateless",
@@ -2656,7 +2694,8 @@ Local alternative: install \`${LOCAL_CLI_PACKAGE}\` and \`${LOCAL_MCP_PACKAGE}\`
2656
2694
  close: () => handler.close()
2657
2695
  };
2658
2696
  }
2659
- function registerConnectTool(server, validator, store, identity, surface) {
2697
+ function registerConnectTool(server, validator, store, identity, surface, annotationTitles) {
2698
+ const title = "Connect TinyCloud";
2660
2699
  const inputSchema = fromJsonSchema2({ type: "object", properties: {}, additionalProperties: false }, validator);
2661
2700
  const outputSchema = fromJsonSchema2({
2662
2701
  type: "object",
@@ -2672,11 +2711,12 @@ function registerConnectTool(server, validator, store, identity, surface) {
2672
2711
  server.registerTool(
2673
2712
  "tinycloud_connect",
2674
2713
  {
2675
- title: "Connect TinyCloud",
2714
+ title,
2676
2715
  description: "Check the hosted delegate connection and return a one-time OpenKey approval URL when setup is required.",
2677
2716
  inputSchema,
2678
2717
  outputSchema,
2679
2718
  annotations: {
2719
+ ...annotationTitles ? { title } : {},
2680
2720
  readOnlyHint: false,
2681
2721
  idempotentHint: true,
2682
2722
  destructiveHint: false,
@@ -2745,7 +2785,7 @@ function mcpCors(response, request) {
2745
2785
  if (request.headers.has("origin")) {
2746
2786
  headers.set("access-control-allow-origin", "*");
2747
2787
  headers.set("access-control-allow-methods", "GET, POST, DELETE, OPTIONS");
2748
- headers.set("access-control-expose-headers", "WWW-Authenticate");
2788
+ headers.set("access-control-expose-headers", MCP_CORS_EXPOSED_HEADERS);
2749
2789
  if (request.method === "OPTIONS") headers.set("access-control-allow-headers", MCP_CORS_ALLOWED_HEADERS);
2750
2790
  }
2751
2791
  return new Response(response.body, { status: response.status, statusText: response.statusText, headers });