@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/http-cli.js CHANGED
@@ -277,6 +277,7 @@ function logToolCall(tool, code, startedAt, replayedGrants) {
277
277
  }
278
278
 
279
279
  // src/remote-store.ts
280
+ import { sameTinyCloudNode } from "@tinycloud/sdk-core";
280
281
  import { createHmac, randomBytes, timingSafeEqual as timingSafeEqual2 } from "crypto";
281
282
  import { chmod, mkdir, readFile, readdir, rename, rm, writeFile } from "fs/promises";
282
283
  import { dirname, join } from "path";
@@ -290,6 +291,7 @@ import {
290
291
  UnsupportedSessionRestoreError,
291
292
  isCapabilitySubset,
292
293
  principalDidEquals,
294
+ publicJwk,
293
295
  siweRuntimeDelegation,
294
296
  signedCompactUcanExpiry
295
297
  } from "@tinycloud/node-sdk";
@@ -368,7 +370,7 @@ var NATIVE_GRANT_IMPORT_REJECTION_CODES = /* @__PURE__ */ new Set([
368
370
  "DELEGATION_HOST_MISMATCH",
369
371
  "DELEGATION_REJECTED"
370
372
  ]);
371
- var LEGACY_DEFAULT_NODE_HOST = "https://node.tinycloud.xyz";
373
+ var PRODUCTION_NODE_HOSTS = /* @__PURE__ */ new Set(["https://node.tinycloud.xyz", "https://tee.node.tinycloud.xyz"]);
372
374
  var BOOTSTRAP_PERMISSIONS = [
373
375
  {
374
376
  service: "tinycloud.kv",
@@ -791,14 +793,16 @@ var RemoteTenantStore = class {
791
793
  did: tenant.sessionDid,
792
794
  callback: callback.toString(),
793
795
  host: this.#config.nodeHost,
796
+ requesterOrigin: this.#config.publicUrl.origin,
794
797
  jwk: Buffer.from(JSON.stringify(publicJwk(tenant.jwk))).toString("base64url"),
795
798
  permissions: Buffer.from(JSON.stringify({
796
799
  permissions: pending.permissions,
797
800
  reason: [
798
801
  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.",
799
802
  // Owner DIDs come from the verified OpenKey access token of the MCP
800
- // client that created this link, never from the link itself.
801
- ...pending.ownerDids.length === 0 ? [] : [`Requested by TinyCloud account ${pending.ownerDids.join(", ")}; approve only if that is you.`]
803
+ // client that created this link, never from the link itself. The
804
+ // callback refuses a signer outside them, so the approver isn't asked to check.
805
+ ...pending.ownerDids.length === 0 ? [] : [`Requested by TinyCloud account ${pending.ownerDids.join(", ")}.`]
802
806
  ].join(" ")
803
807
  })).toString("base64url"),
804
808
  expiry: this.#config.delegationExpiry
@@ -1097,10 +1101,10 @@ var RemoteTenantStore = class {
1097
1101
  authMethod: "openkey",
1098
1102
  openkeyHost: this.#config.openkeyHost
1099
1103
  });
1100
- } else if (typeof profile.host === "string" && profile.host.replace(/\/+$/, "") === LEGACY_DEFAULT_NODE_HOST && this.#config.nodeHost.replace(/\/+$/, "") !== LEGACY_DEFAULT_NODE_HOST) {
1104
+ } 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(/\/+$/, "")) {
1101
1105
  await secureWrite(profilePath, { ...profile, host: this.#config.nodeHost });
1102
1106
  process.stderr.write(
1103
- `[tinycloud-mcp-http] tenant node host migrated: from=${LEGACY_DEFAULT_NODE_HOST} to=${new URL(this.#config.nodeHost).origin}
1107
+ `[tinycloud-mcp-http] tenant node host migrated: from=${profile.host.replace(/\/+$/, "")} to=${new URL(this.#config.nodeHost).origin}
1104
1108
  `
1105
1109
  );
1106
1110
  }
@@ -1406,11 +1410,6 @@ function sessionFromCallback(data, privateJwk) {
1406
1410
  signature: data.signature
1407
1411
  };
1408
1412
  }
1409
- function publicJwk(jwk) {
1410
- const copy = { ...jwk };
1411
- for (const field of ["d", "p", "q", "dp", "dq", "qi", "oth", "k"]) delete copy[field];
1412
- return copy;
1413
- }
1414
1413
  function samePrincipal(left, right) {
1415
1414
  if (typeof left !== "string") return false;
1416
1415
  try {
@@ -1423,6 +1422,7 @@ function normalizeDid(value) {
1423
1422
  return value.split("#", 1)[0];
1424
1423
  }
1425
1424
  function sameNodeHost(left, right) {
1425
+ if (PRODUCTION_NODE_HOSTS.has(left) && sameTinyCloudNode(left, right)) return true;
1426
1426
  try {
1427
1427
  const normalize = (value) => {
1428
1428
  const url = new URL(value);
@@ -1524,6 +1524,7 @@ import { join as join2 } from "path";
1524
1524
  import { fromJsonSchema } from "@modelcontextprotocol/server";
1525
1525
  import { AjvJsonSchemaValidator } from "@modelcontextprotocol/server/validators/ajv";
1526
1526
  import { invokeOperation as invokeOperation2 } from "@tinycloud/operations";
1527
+ import { TC_APPS_CATALOG_APPS } from "@tinycloud/operations/tc-apps";
1527
1528
 
1528
1529
  // src/results.ts
1529
1530
  function toMcpToolResult(result, bindings = [], options = {}) {
@@ -1864,7 +1865,7 @@ var TOOL_BINDINGS = [
1864
1865
  operationVersion: 1,
1865
1866
  readOnlyHint: false,
1866
1867
  idempotentHint: true,
1867
- destructiveHint: true,
1868
+ destructiveHint: false,
1868
1869
  openWorldHint: false,
1869
1870
  surfaces: ["hosted", "public"]
1870
1871
  },
@@ -1894,19 +1895,9 @@ var TOOL_BINDINGS = [
1894
1895
  operationVersion: 1,
1895
1896
  readOnlyHint: false,
1896
1897
  idempotentHint: true,
1897
- destructiveHint: true,
1898
- openWorldHint: false,
1899
- surfaces: ["hosted", "public"]
1900
- },
1901
- {
1902
- name: "tinycloud_apps_move",
1903
- operationId: "tinycloud.apps.move",
1904
- operationVersion: 1,
1905
- readOnlyHint: false,
1906
- idempotentHint: true,
1907
1898
  destructiveHint: false,
1908
1899
  openWorldHint: false,
1909
- surfaces: ["hosted"]
1900
+ surfaces: ["hosted", "public"]
1910
1901
  }
1911
1902
  ];
1912
1903
  var definitions = new Map(generatedCatalog.operations.map((operation) => [
@@ -1917,18 +1908,50 @@ var definitions = new Map(generatedCatalog.operations.map((operation) => [
1917
1908
  result: toMcpJsonSchema(operation.result)
1918
1909
  }
1919
1910
  ]));
1911
+ var CATALOG_APP_TOOLS = [
1912
+ "tinycloud_knowledge_list",
1913
+ "tinycloud_knowledge_read",
1914
+ "tinycloud_sql_query",
1915
+ "tinycloud_sql_execute"
1916
+ ];
1917
+ var APP_WITHOUT_CATALOG_APPS = "Pass one existing personal app id to request its task access together.";
1918
+ function withPropertyDescription(schema, property, description) {
1919
+ const properties = schema.properties;
1920
+ const current = properties?.[property];
1921
+ if (current === void 0) throw new Error(`Generated operations catalog has no ${property} input to describe.`);
1922
+ return { ...schema, properties: { ...properties, [property]: { ...current, description } } };
1923
+ }
1924
+ function catalogAppRefusal(binding, profile, input) {
1925
+ const app = typeof input === "object" && input !== null ? input.app : void 0;
1926
+ if (typeof app !== "string" || !Object.hasOwn(TC_APPS_CATALOG_APPS, app)) return void 0;
1927
+ const { title, link } = TC_APPS_CATALOG_APPS[app];
1928
+ return {
1929
+ status: "error",
1930
+ operation: { operationId: binding.operationId, operationVersion: binding.operationVersion },
1931
+ context: { profile, host: "unresolved", posture: "unauthenticated" },
1932
+ error: {
1933
+ code: "INPUT_INVALID",
1934
+ 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.`,
1935
+ retryable: false,
1936
+ details: { reason: "catalog_app_unavailable", app, link }
1937
+ }
1938
+ };
1939
+ }
1920
1940
  function createJsonSchemaValidator() {
1921
1941
  return new AjvJsonSchemaValidator();
1922
1942
  }
1923
1943
  function registerTinyCloudTools(server, selection, validator) {
1924
1944
  const bindings = TOOL_BINDINGS.filter((binding) => bindingSurfaces(binding).includes(selection.surface) && (selection.allowedTools === void 0 || selection.allowedTools.includes(binding.name)));
1945
+ const servesCatalogApps = CATALOG_APP_TOOLS.every((name) => bindings.some((binding) => binding.name === name));
1925
1946
  for (const binding of bindings) {
1926
1947
  const operation = definitions.get(`${binding.operationId}@${binding.operationVersion}`);
1927
1948
  if (operation === void 0) {
1928
1949
  throw new Error(`Generated operations catalog is missing ${binding.operationId}@${binding.operationVersion}.`);
1929
1950
  }
1951
+ const offersCatalogApps = servesCatalogApps || binding.operationId !== "tinycloud.apps.context";
1952
+ const inputJsonSchema = offersCatalogApps ? operation.input : withPropertyDescription(operation.input, "app", APP_WITHOUT_CATALOG_APPS);
1930
1953
  const inputSchema = fromJsonSchema(
1931
- operation.input,
1954
+ inputJsonSchema,
1932
1955
  validator
1933
1956
  );
1934
1957
  const outputSchema = fromJsonSchema(
@@ -1955,19 +1978,22 @@ function registerTinyCloudTools(server, selection, validator) {
1955
1978
  const metrics = { replayedGrants: 0 };
1956
1979
  let code = "INTERNAL_ERROR";
1957
1980
  try {
1958
- await selection.beforeOperation?.();
1959
- const result = await invokeOperation2(
1960
- binding.operationId,
1961
- binding.operationVersion,
1962
- invocationTargetForMcp(selection),
1963
- input,
1964
- metrics
1965
- );
1966
- const projected = selection.transformOperationResult === void 0 ? result : await selection.transformOperationResult(result, {
1967
- operationId: binding.operationId,
1968
- operationVersion: binding.operationVersion,
1969
- input
1970
- });
1981
+ let projected = offersCatalogApps ? void 0 : catalogAppRefusal(binding, selection.profile, input);
1982
+ if (projected === void 0) {
1983
+ await selection.beforeOperation?.();
1984
+ const result = await invokeOperation2(
1985
+ binding.operationId,
1986
+ binding.operationVersion,
1987
+ invocationTargetForMcp(selection),
1988
+ input,
1989
+ metrics
1990
+ );
1991
+ projected = selection.transformOperationResult === void 0 ? result : await selection.transformOperationResult(result, {
1992
+ operationId: binding.operationId,
1993
+ operationVersion: binding.operationVersion,
1994
+ input
1995
+ });
1996
+ }
1971
1997
  const response = toMcpToolResult(projected, bindings, {
1972
1998
  surface: selection.surface === "local" ? "local" : "hosted",
1973
1999
  readOnly: binding.readOnlyHint,
@@ -1999,7 +2025,7 @@ function outcomeCode(result) {
1999
2025
  // package.json
2000
2026
  var package_default = {
2001
2027
  name: "@tinycloud/mcp",
2002
- version: "0.10.0-beta.5",
2028
+ version: "0.10.0-beta.50",
2003
2029
  description: "TinyCloud delegated operations MCP server",
2004
2030
  keywords: [
2005
2031
  "tinycloud",
@@ -2070,9 +2096,10 @@ var package_default = {
2070
2096
  dependencies: {
2071
2097
  "@modelcontextprotocol/node": "2.0.0-beta.5",
2072
2098
  "@modelcontextprotocol/server": "2.0.0-beta.5",
2073
- "@tinycloud/node-sdk": "3.12.0-beta.2",
2074
- "@tinycloud/node-sdk-wasm": "1.7.8",
2075
- "@tinycloud/operations": "0.9.0-beta.4",
2099
+ "@tinycloud/node-sdk": "3.12.0-beta.38",
2100
+ "@tinycloud/sdk-core": "3.12.0-beta.37",
2101
+ "@tinycloud/node-sdk-wasm": "1.7.9-beta.0",
2102
+ "@tinycloud/operations": "0.9.0-beta.45",
2076
2103
  jose: "6.2.4"
2077
2104
  },
2078
2105
  devDependencies: {
@@ -2097,32 +2124,42 @@ var MCP_SERVER_NAME = "tinycloud-mcp";
2097
2124
  // src/http.ts
2098
2125
  var REQUIRED_SCOPE = "tinycloud:mcp";
2099
2126
  var MCP_CORS_ALLOWED_HEADERS = "Authorization, Content-Type, Accept, Mcp-Protocol-Version, Mcp-Session-Id, Last-Event-ID, Mcp-Method, Mcp-Name";
2127
+ var MCP_CORS_EXPOSED_HEADERS = "WWW-Authenticate, Mcp-Session-Id, Mcp-Protocol-Version";
2100
2128
  var LOCAL_CLI_PACKAGE = ["@tinycloud", "cli"].join("/");
2101
2129
  var LOCAL_MCP_PACKAGE = ["@tinycloud", "mcp"].join("/");
2130
+ var RESTRICTED_ADDRESS_PREFIXES = ["chatgpt", "claude", "grok", "muse"];
2102
2131
  function createHostedMcpApp(config) {
2103
2132
  if (config.nativeServiceCredential !== void 0 && Buffer.byteLength(config.nativeServiceCredential, "utf8") < 32) {
2104
2133
  throw new Error("TC_MCP_NATIVE_SERVICE_CREDENTIAL must contain at least 32 bytes.");
2105
2134
  }
2106
2135
  const resourceUrl = canonicalResourceUrl(config.publicUrl);
2107
- const pluginUrl = new URL("./chatgpt/mcp", resourceUrl);
2108
2136
  const statusFor = (resource) => config.introspection === void 0 ? void 0 : createTokenStatusChecker({ ...config.introspection, resourceUrl: resource.toString() });
2109
2137
  const hosted = createHostedSurface(config, resourceUrl, "hosted", statusFor(resourceUrl));
2110
- const plugin = createHostedSurface({
2111
- ...config,
2112
- nativeServiceCredential: void 0,
2113
- stateDir: join3(config.stateDir, "chatgpt"),
2114
- approvalPath: new URL("./connect", pluginUrl).pathname
2115
- }, pluginUrl, "public", statusFor(pluginUrl));
2116
- const pluginPaths = {
2117
- [pluginUrl.pathname]: true,
2118
- [new URL("./connect", pluginUrl).pathname]: true,
2119
- [new URL("./connect/callback", pluginUrl).pathname]: true,
2120
- [new URL(getOAuthProtectedResourceMetadataUrl(pluginUrl)).pathname]: true
2121
- };
2138
+ const surfaces = [hosted];
2139
+ const restrictedByPath = /* @__PURE__ */ new Map();
2140
+ for (const prefix of RESTRICTED_ADDRESS_PREFIXES) {
2141
+ const restrictedUrl = new URL(`./${prefix}/mcp`, resourceUrl);
2142
+ const connectUrl = new URL("./connect", restrictedUrl);
2143
+ const restricted = createHostedSurface({
2144
+ ...config,
2145
+ nativeServiceCredential: void 0,
2146
+ stateDir: join3(config.stateDir, prefix),
2147
+ approvalPath: connectUrl.pathname
2148
+ }, restrictedUrl, "public", statusFor(restrictedUrl));
2149
+ surfaces.push(restricted);
2150
+ for (const owned of [
2151
+ restrictedUrl,
2152
+ connectUrl,
2153
+ new URL("./connect/callback", restrictedUrl),
2154
+ new URL(getOAuthProtectedResourceMetadataUrl(restrictedUrl))
2155
+ ]) {
2156
+ restrictedByPath.set(owned.pathname, restricted);
2157
+ }
2158
+ }
2122
2159
  return {
2123
- fetch: (request) => (pluginPaths[new URL(request.url).pathname] === true ? plugin : hosted).fetch(request),
2160
+ fetch: (request) => (restrictedByPath.get(new URL(request.url).pathname) ?? hosted).fetch(request),
2124
2161
  close: async () => {
2125
- await Promise.all([hosted.close(), plugin.close()]);
2162
+ await Promise.all(surfaces.map((surface) => surface.close()));
2126
2163
  }
2127
2164
  };
2128
2165
  }
@@ -2394,10 +2431,12 @@ Local alternative: install \`${LOCAL_CLI_PACKAGE}\` and \`${LOCAL_MCP_PACKAGE}\`
2394
2431
  try {
2395
2432
  const destination = await store.approvalRedirect(requiredState(url));
2396
2433
  return Response.redirect(destination, 302);
2397
- } catch {
2434
+ } catch (error) {
2435
+ const reason = error instanceof ApprovalRequestError ? error.detail : "unknown";
2436
+ writeDiagnostic(`connect rejected: reason=${reason} path=${connectPath}`);
2398
2437
  if (request.headers.get("accept")?.includes("text/html")) {
2399
2438
  return new Response(
2400
- '<!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>',
2439
+ '<!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>',
2401
2440
  {
2402
2441
  status: 400,
2403
2442
  headers: {
@@ -2608,7 +2647,7 @@ function mcpCors(response, request) {
2608
2647
  if (request.headers.has("origin")) {
2609
2648
  headers.set("access-control-allow-origin", "*");
2610
2649
  headers.set("access-control-allow-methods", "GET, POST, DELETE, OPTIONS");
2611
- headers.set("access-control-expose-headers", "WWW-Authenticate");
2650
+ headers.set("access-control-expose-headers", MCP_CORS_EXPOSED_HEADERS);
2612
2651
  if (request.method === "OPTIONS") headers.set("access-control-allow-headers", MCP_CORS_ALLOWED_HEADERS);
2613
2652
  }
2614
2653
  return new Response(response.body, { status: response.status, statusText: response.statusText, headers });