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