@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/http.js CHANGED
@@ -260,6 +260,7 @@ function logToolCall(tool, code, startedAt, replayedGrants) {
260
260
  }
261
261
 
262
262
  // src/remote-store.ts
263
+ import { sameTinyCloudNode } from "@tinycloud/sdk-core";
263
264
  import { createHmac, randomBytes, timingSafeEqual as timingSafeEqual2 } from "crypto";
264
265
  import { chmod, mkdir, readFile, readdir, rename, rm, writeFile } from "fs/promises";
265
266
  import { dirname, join } from "path";
@@ -273,6 +274,7 @@ import {
273
274
  UnsupportedSessionRestoreError,
274
275
  isCapabilitySubset,
275
276
  principalDidEquals,
277
+ publicJwk,
276
278
  siweRuntimeDelegation,
277
279
  signedCompactUcanExpiry
278
280
  } from "@tinycloud/node-sdk";
@@ -351,7 +353,7 @@ var NATIVE_GRANT_IMPORT_REJECTION_CODES = /* @__PURE__ */ new Set([
351
353
  "DELEGATION_HOST_MISMATCH",
352
354
  "DELEGATION_REJECTED"
353
355
  ]);
354
- var LEGACY_DEFAULT_NODE_HOST = "https://node.tinycloud.xyz";
356
+ var PRODUCTION_NODE_HOSTS = /* @__PURE__ */ new Set(["https://node.tinycloud.xyz", "https://tee.node.tinycloud.xyz"]);
355
357
  var BOOTSTRAP_PERMISSIONS = [
356
358
  {
357
359
  service: "tinycloud.kv",
@@ -774,14 +776,16 @@ var RemoteTenantStore = class {
774
776
  did: tenant.sessionDid,
775
777
  callback: callback.toString(),
776
778
  host: this.#config.nodeHost,
779
+ requesterOrigin: this.#config.publicUrl.origin,
777
780
  jwk: Buffer.from(JSON.stringify(publicJwk(tenant.jwk))).toString("base64url"),
778
781
  permissions: Buffer.from(JSON.stringify({
779
782
  permissions: pending.permissions,
780
783
  reason: [
781
784
  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.",
782
785
  // Owner DIDs come from the verified OpenKey access token of the MCP
783
- // client that created this link, never from the link itself.
784
- ...pending.ownerDids.length === 0 ? [] : [`Requested by TinyCloud account ${pending.ownerDids.join(", ")}; approve only if that is you.`]
786
+ // client that created this link, never from the link itself. The
787
+ // callback refuses a signer outside them, so the approver isn't asked to check.
788
+ ...pending.ownerDids.length === 0 ? [] : [`Requested by TinyCloud account ${pending.ownerDids.join(", ")}.`]
785
789
  ].join(" ")
786
790
  })).toString("base64url"),
787
791
  expiry: this.#config.delegationExpiry
@@ -1080,10 +1084,10 @@ var RemoteTenantStore = class {
1080
1084
  authMethod: "openkey",
1081
1085
  openkeyHost: this.#config.openkeyHost
1082
1086
  });
1083
- } else if (typeof profile.host === "string" && profile.host.replace(/\/+$/, "") === LEGACY_DEFAULT_NODE_HOST && this.#config.nodeHost.replace(/\/+$/, "") !== LEGACY_DEFAULT_NODE_HOST) {
1087
+ } 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(/\/+$/, "")) {
1084
1088
  await secureWrite(profilePath, { ...profile, host: this.#config.nodeHost });
1085
1089
  process.stderr.write(
1086
- `[tinycloud-mcp-http] tenant node host migrated: from=${LEGACY_DEFAULT_NODE_HOST} to=${new URL(this.#config.nodeHost).origin}
1090
+ `[tinycloud-mcp-http] tenant node host migrated: from=${profile.host.replace(/\/+$/, "")} to=${new URL(this.#config.nodeHost).origin}
1087
1091
  `
1088
1092
  );
1089
1093
  }
@@ -1389,11 +1393,6 @@ function sessionFromCallback(data, privateJwk) {
1389
1393
  signature: data.signature
1390
1394
  };
1391
1395
  }
1392
- function publicJwk(jwk) {
1393
- const copy = { ...jwk };
1394
- for (const field of ["d", "p", "q", "dp", "dq", "qi", "oth", "k"]) delete copy[field];
1395
- return copy;
1396
- }
1397
1396
  function samePrincipal(left, right) {
1398
1397
  if (typeof left !== "string") return false;
1399
1398
  try {
@@ -1406,6 +1405,7 @@ function normalizeDid(value) {
1406
1405
  return value.split("#", 1)[0];
1407
1406
  }
1408
1407
  function sameNodeHost(left, right) {
1408
+ if (PRODUCTION_NODE_HOSTS.has(left) && sameTinyCloudNode(left, right)) return true;
1409
1409
  try {
1410
1410
  const normalize = (value) => {
1411
1411
  const url = new URL(value);
@@ -1507,6 +1507,7 @@ import { join as join2 } from "path";
1507
1507
  import { fromJsonSchema } from "@modelcontextprotocol/server";
1508
1508
  import { AjvJsonSchemaValidator } from "@modelcontextprotocol/server/validators/ajv";
1509
1509
  import { invokeOperation as invokeOperation2 } from "@tinycloud/operations";
1510
+ import { TC_APPS_CATALOG_APPS } from "@tinycloud/operations/tc-apps";
1510
1511
 
1511
1512
  // src/results.ts
1512
1513
  function toMcpToolResult(result, bindings = [], options = {}) {
@@ -1847,7 +1848,7 @@ var TOOL_BINDINGS = [
1847
1848
  operationVersion: 1,
1848
1849
  readOnlyHint: false,
1849
1850
  idempotentHint: true,
1850
- destructiveHint: true,
1851
+ destructiveHint: false,
1851
1852
  openWorldHint: false,
1852
1853
  surfaces: ["hosted", "public"]
1853
1854
  },
@@ -1877,19 +1878,9 @@ var TOOL_BINDINGS = [
1877
1878
  operationVersion: 1,
1878
1879
  readOnlyHint: false,
1879
1880
  idempotentHint: true,
1880
- destructiveHint: true,
1881
- openWorldHint: false,
1882
- surfaces: ["hosted", "public"]
1883
- },
1884
- {
1885
- name: "tinycloud_apps_move",
1886
- operationId: "tinycloud.apps.move",
1887
- operationVersion: 1,
1888
- readOnlyHint: false,
1889
- idempotentHint: true,
1890
1881
  destructiveHint: false,
1891
1882
  openWorldHint: false,
1892
- surfaces: ["hosted"]
1883
+ surfaces: ["hosted", "public"]
1893
1884
  }
1894
1885
  ];
1895
1886
  var definitions = new Map(generatedCatalog.operations.map((operation) => [
@@ -1900,18 +1891,50 @@ var definitions = new Map(generatedCatalog.operations.map((operation) => [
1900
1891
  result: toMcpJsonSchema(operation.result)
1901
1892
  }
1902
1893
  ]));
1894
+ var CATALOG_APP_TOOLS = [
1895
+ "tinycloud_knowledge_list",
1896
+ "tinycloud_knowledge_read",
1897
+ "tinycloud_sql_query",
1898
+ "tinycloud_sql_execute"
1899
+ ];
1900
+ var APP_WITHOUT_CATALOG_APPS = "Pass one existing personal app id to request its task access together.";
1901
+ function withPropertyDescription(schema, property, description) {
1902
+ const properties = schema.properties;
1903
+ const current = properties?.[property];
1904
+ if (current === void 0) throw new Error(`Generated operations catalog has no ${property} input to describe.`);
1905
+ return { ...schema, properties: { ...properties, [property]: { ...current, description } } };
1906
+ }
1907
+ function catalogAppRefusal(binding, profile, input) {
1908
+ const app = typeof input === "object" && input !== null ? input.app : void 0;
1909
+ if (typeof app !== "string" || !Object.hasOwn(TC_APPS_CATALOG_APPS, app)) return void 0;
1910
+ const { title, link } = TC_APPS_CATALOG_APPS[app];
1911
+ return {
1912
+ status: "error",
1913
+ operation: { operationId: binding.operationId, operationVersion: binding.operationVersion },
1914
+ context: { profile, host: "unresolved", posture: "unauthenticated" },
1915
+ error: {
1916
+ code: "INPUT_INVALID",
1917
+ 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.`,
1918
+ retryable: false,
1919
+ details: { reason: "catalog_app_unavailable", app, link }
1920
+ }
1921
+ };
1922
+ }
1903
1923
  function createJsonSchemaValidator() {
1904
1924
  return new AjvJsonSchemaValidator();
1905
1925
  }
1906
1926
  function registerTinyCloudTools(server, selection, validator) {
1907
1927
  const bindings = TOOL_BINDINGS.filter((binding) => bindingSurfaces(binding).includes(selection.surface) && (selection.allowedTools === void 0 || selection.allowedTools.includes(binding.name)));
1928
+ const servesCatalogApps = CATALOG_APP_TOOLS.every((name) => bindings.some((binding) => binding.name === name));
1908
1929
  for (const binding of bindings) {
1909
1930
  const operation = definitions.get(`${binding.operationId}@${binding.operationVersion}`);
1910
1931
  if (operation === void 0) {
1911
1932
  throw new Error(`Generated operations catalog is missing ${binding.operationId}@${binding.operationVersion}.`);
1912
1933
  }
1934
+ const offersCatalogApps = servesCatalogApps || binding.operationId !== "tinycloud.apps.context";
1935
+ const inputJsonSchema = offersCatalogApps ? operation.input : withPropertyDescription(operation.input, "app", APP_WITHOUT_CATALOG_APPS);
1913
1936
  const inputSchema = fromJsonSchema(
1914
- operation.input,
1937
+ inputJsonSchema,
1915
1938
  validator
1916
1939
  );
1917
1940
  const outputSchema = fromJsonSchema(
@@ -1919,6 +1942,7 @@ function registerTinyCloudTools(server, selection, validator) {
1919
1942
  validator
1920
1943
  );
1921
1944
  const annotations = {
1945
+ ...selection.annotationTitles === true ? { title: operation.title } : {},
1922
1946
  readOnlyHint: binding.readOnlyHint,
1923
1947
  idempotentHint: binding.idempotentHint,
1924
1948
  destructiveHint: binding.destructiveHint,
@@ -1938,19 +1962,22 @@ function registerTinyCloudTools(server, selection, validator) {
1938
1962
  const metrics = { replayedGrants: 0 };
1939
1963
  let code = "INTERNAL_ERROR";
1940
1964
  try {
1941
- await selection.beforeOperation?.();
1942
- const result = await invokeOperation2(
1943
- binding.operationId,
1944
- binding.operationVersion,
1945
- invocationTargetForMcp(selection),
1946
- input,
1947
- metrics
1948
- );
1949
- const projected = selection.transformOperationResult === void 0 ? result : await selection.transformOperationResult(result, {
1950
- operationId: binding.operationId,
1951
- operationVersion: binding.operationVersion,
1952
- input
1953
- });
1965
+ let projected = offersCatalogApps ? void 0 : catalogAppRefusal(binding, selection.profile, input);
1966
+ if (projected === void 0) {
1967
+ await selection.beforeOperation?.();
1968
+ const result = await invokeOperation2(
1969
+ binding.operationId,
1970
+ binding.operationVersion,
1971
+ invocationTargetForMcp(selection),
1972
+ input,
1973
+ metrics
1974
+ );
1975
+ projected = selection.transformOperationResult === void 0 ? result : await selection.transformOperationResult(result, {
1976
+ operationId: binding.operationId,
1977
+ operationVersion: binding.operationVersion,
1978
+ input
1979
+ });
1980
+ }
1954
1981
  const response = toMcpToolResult(projected, bindings, {
1955
1982
  surface: selection.surface === "local" ? "local" : "hosted",
1956
1983
  readOnly: binding.readOnlyHint,
@@ -1982,7 +2009,7 @@ function outcomeCode(result) {
1982
2009
  // package.json
1983
2010
  var package_default = {
1984
2011
  name: "@tinycloud/mcp",
1985
- version: "0.10.0-beta.5",
2012
+ version: "0.10.0-beta.51",
1986
2013
  description: "TinyCloud delegated operations MCP server",
1987
2014
  keywords: [
1988
2015
  "tinycloud",
@@ -2053,9 +2080,10 @@ var package_default = {
2053
2080
  dependencies: {
2054
2081
  "@modelcontextprotocol/node": "2.0.0-beta.5",
2055
2082
  "@modelcontextprotocol/server": "2.0.0-beta.5",
2056
- "@tinycloud/node-sdk": "3.12.0-beta.2",
2057
- "@tinycloud/node-sdk-wasm": "1.7.8",
2058
- "@tinycloud/operations": "0.9.0-beta.4",
2083
+ "@tinycloud/node-sdk": "3.12.0-beta.38",
2084
+ "@tinycloud/sdk-core": "3.12.0-beta.37",
2085
+ "@tinycloud/node-sdk-wasm": "1.7.9-beta.0",
2086
+ "@tinycloud/operations": "0.9.0-beta.45",
2059
2087
  jose: "6.2.4"
2060
2088
  },
2061
2089
  devDependencies: {
@@ -2080,36 +2108,47 @@ var MCP_SERVER_NAME = "tinycloud-mcp";
2080
2108
  // src/http.ts
2081
2109
  var REQUIRED_SCOPE = "tinycloud:mcp";
2082
2110
  var MCP_CORS_ALLOWED_HEADERS = "Authorization, Content-Type, Accept, Mcp-Protocol-Version, Mcp-Session-Id, Last-Event-ID, Mcp-Method, Mcp-Name";
2111
+ var MCP_CORS_EXPOSED_HEADERS = "WWW-Authenticate, Mcp-Session-Id, Mcp-Protocol-Version";
2083
2112
  var LOCAL_CLI_PACKAGE = ["@tinycloud", "cli"].join("/");
2084
2113
  var LOCAL_MCP_PACKAGE = ["@tinycloud", "mcp"].join("/");
2114
+ var RESTRICTED_ADDRESS_PREFIXES = ["chatgpt", "claude", "grok", "muse"];
2115
+ var ANNOTATION_TITLE_PREFIXES = /* @__PURE__ */ new Set(["claude"]);
2085
2116
  function createHostedMcpApp(config) {
2086
2117
  if (config.nativeServiceCredential !== void 0 && Buffer.byteLength(config.nativeServiceCredential, "utf8") < 32) {
2087
2118
  throw new Error("TC_MCP_NATIVE_SERVICE_CREDENTIAL must contain at least 32 bytes.");
2088
2119
  }
2089
2120
  const resourceUrl = canonicalResourceUrl(config.publicUrl);
2090
- const pluginUrl = new URL("./chatgpt/mcp", resourceUrl);
2091
2121
  const statusFor = (resource) => config.introspection === void 0 ? void 0 : createTokenStatusChecker({ ...config.introspection, resourceUrl: resource.toString() });
2092
2122
  const hosted = createHostedSurface(config, resourceUrl, "hosted", statusFor(resourceUrl));
2093
- const plugin = createHostedSurface({
2094
- ...config,
2095
- nativeServiceCredential: void 0,
2096
- stateDir: join3(config.stateDir, "chatgpt"),
2097
- approvalPath: new URL("./connect", pluginUrl).pathname
2098
- }, pluginUrl, "public", statusFor(pluginUrl));
2099
- const pluginPaths = {
2100
- [pluginUrl.pathname]: true,
2101
- [new URL("./connect", pluginUrl).pathname]: true,
2102
- [new URL("./connect/callback", pluginUrl).pathname]: true,
2103
- [new URL(getOAuthProtectedResourceMetadataUrl(pluginUrl)).pathname]: true
2104
- };
2123
+ const surfaces = [hosted];
2124
+ const restrictedByPath = /* @__PURE__ */ new Map();
2125
+ for (const prefix of RESTRICTED_ADDRESS_PREFIXES) {
2126
+ const restrictedUrl = new URL(`./${prefix}/mcp`, resourceUrl);
2127
+ const connectUrl = new URL("./connect", restrictedUrl);
2128
+ const restricted = createHostedSurface({
2129
+ ...config,
2130
+ nativeServiceCredential: void 0,
2131
+ stateDir: join3(config.stateDir, prefix),
2132
+ approvalPath: connectUrl.pathname
2133
+ }, restrictedUrl, "public", statusFor(restrictedUrl), ANNOTATION_TITLE_PREFIXES.has(prefix));
2134
+ surfaces.push(restricted);
2135
+ for (const owned of [
2136
+ restrictedUrl,
2137
+ connectUrl,
2138
+ new URL("./connect/callback", restrictedUrl),
2139
+ new URL(getOAuthProtectedResourceMetadataUrl(restrictedUrl))
2140
+ ]) {
2141
+ restrictedByPath.set(owned.pathname, restricted);
2142
+ }
2143
+ }
2105
2144
  return {
2106
- fetch: (request) => (pluginPaths[new URL(request.url).pathname] === true ? plugin : hosted).fetch(request),
2145
+ fetch: (request) => (restrictedByPath.get(new URL(request.url).pathname) ?? hosted).fetch(request),
2107
2146
  close: async () => {
2108
- await Promise.all([hosted.close(), plugin.close()]);
2147
+ await Promise.all(surfaces.map((surface) => surface.close()));
2109
2148
  }
2110
2149
  };
2111
2150
  }
2112
- function createHostedSurface(config, resourceUrl, surface, tokenStatus) {
2151
+ function createHostedSurface(config, resourceUrl, surface, tokenStatus, annotationTitles = false) {
2113
2152
  const connectPath = config.approvalPath ?? "/connect";
2114
2153
  const callbackPath = `${connectPath}/callback`;
2115
2154
  const issuer = String(config.oauthMetadata.issuer);
@@ -2149,6 +2188,7 @@ function createHostedSurface(config, resourceUrl, surface, tokenStatus) {
2149
2188
  explicitProfile: true,
2150
2189
  allowOwnerProfile: false,
2151
2190
  stateRoot,
2191
+ annotationTitles,
2152
2192
  ...nativeOwner === void 0 ? {} : {
2153
2193
  allowedTools: ["tinycloud_sql_query", "tinycloud_kv_get", "tinycloud_read"]
2154
2194
  },
@@ -2157,7 +2197,7 @@ function createHostedSurface(config, resourceUrl, surface, tokenStatus) {
2157
2197
  transformOperationResult: (result, invocation) => store.decorateAuthorityResult(subject, ownerDids, result, invocation)
2158
2198
  } : {}
2159
2199
  }, validator);
2160
- if (nativeOwner === void 0) registerConnectTool(server, validator, store, identity, surface);
2200
+ if (nativeOwner === void 0) registerConnectTool(server, validator, store, identity, surface, annotationTitles);
2161
2201
  return server;
2162
2202
  }, {
2163
2203
  legacy: "stateless",
@@ -2377,10 +2417,12 @@ Local alternative: install \`${LOCAL_CLI_PACKAGE}\` and \`${LOCAL_MCP_PACKAGE}\`
2377
2417
  try {
2378
2418
  const destination = await store.approvalRedirect(requiredState(url));
2379
2419
  return Response.redirect(destination, 302);
2380
- } catch {
2420
+ } catch (error) {
2421
+ const reason = error instanceof ApprovalRequestError ? error.detail : "unknown";
2422
+ writeDiagnostic(`connect rejected: reason=${reason} path=${connectPath}`);
2381
2423
  if (request.headers.get("accept")?.includes("text/html")) {
2382
2424
  return new Response(
2383
- '<!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>',
2425
+ '<!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>',
2384
2426
  {
2385
2427
  status: 400,
2386
2428
  headers: {
@@ -2502,7 +2544,8 @@ Local alternative: install \`${LOCAL_CLI_PACKAGE}\` and \`${LOCAL_MCP_PACKAGE}\`
2502
2544
  close: () => handler.close()
2503
2545
  };
2504
2546
  }
2505
- function registerConnectTool(server, validator, store, identity, surface) {
2547
+ function registerConnectTool(server, validator, store, identity, surface, annotationTitles) {
2548
+ const title = "Connect TinyCloud";
2506
2549
  const inputSchema = fromJsonSchema2({ type: "object", properties: {}, additionalProperties: false }, validator);
2507
2550
  const outputSchema = fromJsonSchema2({
2508
2551
  type: "object",
@@ -2518,11 +2561,12 @@ function registerConnectTool(server, validator, store, identity, surface) {
2518
2561
  server.registerTool(
2519
2562
  "tinycloud_connect",
2520
2563
  {
2521
- title: "Connect TinyCloud",
2564
+ title,
2522
2565
  description: "Check the hosted delegate connection and return a one-time OpenKey approval URL when setup is required.",
2523
2566
  inputSchema,
2524
2567
  outputSchema,
2525
2568
  annotations: {
2569
+ ...annotationTitles ? { title } : {},
2526
2570
  readOnlyHint: false,
2527
2571
  idempotentHint: true,
2528
2572
  destructiveHint: false,
@@ -2591,7 +2635,7 @@ function mcpCors(response, request) {
2591
2635
  if (request.headers.has("origin")) {
2592
2636
  headers.set("access-control-allow-origin", "*");
2593
2637
  headers.set("access-control-allow-methods", "GET, POST, DELETE, OPTIONS");
2594
- headers.set("access-control-expose-headers", "WWW-Authenticate");
2638
+ headers.set("access-control-expose-headers", MCP_CORS_EXPOSED_HEADERS);
2595
2639
  if (request.method === "OPTIONS") headers.set("access-control-allow-headers", MCP_CORS_ALLOWED_HEADERS);
2596
2640
  }
2597
2641
  return new Response(response.body, { status: response.status, statusText: response.statusText, headers });