@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.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(
@@ -1938,19 +1961,22 @@ function registerTinyCloudTools(server, selection, validator) {
1938
1961
  const metrics = { replayedGrants: 0 };
1939
1962
  let code = "INTERNAL_ERROR";
1940
1963
  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
- });
1964
+ let projected = offersCatalogApps ? void 0 : catalogAppRefusal(binding, selection.profile, input);
1965
+ if (projected === void 0) {
1966
+ await selection.beforeOperation?.();
1967
+ const result = await invokeOperation2(
1968
+ binding.operationId,
1969
+ binding.operationVersion,
1970
+ invocationTargetForMcp(selection),
1971
+ input,
1972
+ metrics
1973
+ );
1974
+ projected = selection.transformOperationResult === void 0 ? result : await selection.transformOperationResult(result, {
1975
+ operationId: binding.operationId,
1976
+ operationVersion: binding.operationVersion,
1977
+ input
1978
+ });
1979
+ }
1954
1980
  const response = toMcpToolResult(projected, bindings, {
1955
1981
  surface: selection.surface === "local" ? "local" : "hosted",
1956
1982
  readOnly: binding.readOnlyHint,
@@ -1982,7 +2008,7 @@ function outcomeCode(result) {
1982
2008
  // package.json
1983
2009
  var package_default = {
1984
2010
  name: "@tinycloud/mcp",
1985
- version: "0.10.0-beta.5",
2011
+ version: "0.10.0-beta.50",
1986
2012
  description: "TinyCloud delegated operations MCP server",
1987
2013
  keywords: [
1988
2014
  "tinycloud",
@@ -2053,9 +2079,10 @@ var package_default = {
2053
2079
  dependencies: {
2054
2080
  "@modelcontextprotocol/node": "2.0.0-beta.5",
2055
2081
  "@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",
2082
+ "@tinycloud/node-sdk": "3.12.0-beta.38",
2083
+ "@tinycloud/sdk-core": "3.12.0-beta.37",
2084
+ "@tinycloud/node-sdk-wasm": "1.7.9-beta.0",
2085
+ "@tinycloud/operations": "0.9.0-beta.45",
2059
2086
  jose: "6.2.4"
2060
2087
  },
2061
2088
  devDependencies: {
@@ -2080,32 +2107,42 @@ var MCP_SERVER_NAME = "tinycloud-mcp";
2080
2107
  // src/http.ts
2081
2108
  var REQUIRED_SCOPE = "tinycloud:mcp";
2082
2109
  var MCP_CORS_ALLOWED_HEADERS = "Authorization, Content-Type, Accept, Mcp-Protocol-Version, Mcp-Session-Id, Last-Event-ID, Mcp-Method, Mcp-Name";
2110
+ var MCP_CORS_EXPOSED_HEADERS = "WWW-Authenticate, Mcp-Session-Id, Mcp-Protocol-Version";
2083
2111
  var LOCAL_CLI_PACKAGE = ["@tinycloud", "cli"].join("/");
2084
2112
  var LOCAL_MCP_PACKAGE = ["@tinycloud", "mcp"].join("/");
2113
+ var RESTRICTED_ADDRESS_PREFIXES = ["chatgpt", "claude", "grok", "muse"];
2085
2114
  function createHostedMcpApp(config) {
2086
2115
  if (config.nativeServiceCredential !== void 0 && Buffer.byteLength(config.nativeServiceCredential, "utf8") < 32) {
2087
2116
  throw new Error("TC_MCP_NATIVE_SERVICE_CREDENTIAL must contain at least 32 bytes.");
2088
2117
  }
2089
2118
  const resourceUrl = canonicalResourceUrl(config.publicUrl);
2090
- const pluginUrl = new URL("./chatgpt/mcp", resourceUrl);
2091
2119
  const statusFor = (resource) => config.introspection === void 0 ? void 0 : createTokenStatusChecker({ ...config.introspection, resourceUrl: resource.toString() });
2092
2120
  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
- };
2121
+ const surfaces = [hosted];
2122
+ const restrictedByPath = /* @__PURE__ */ new Map();
2123
+ for (const prefix of RESTRICTED_ADDRESS_PREFIXES) {
2124
+ const restrictedUrl = new URL(`./${prefix}/mcp`, resourceUrl);
2125
+ const connectUrl = new URL("./connect", restrictedUrl);
2126
+ const restricted = createHostedSurface({
2127
+ ...config,
2128
+ nativeServiceCredential: void 0,
2129
+ stateDir: join3(config.stateDir, prefix),
2130
+ approvalPath: connectUrl.pathname
2131
+ }, restrictedUrl, "public", statusFor(restrictedUrl));
2132
+ surfaces.push(restricted);
2133
+ for (const owned of [
2134
+ restrictedUrl,
2135
+ connectUrl,
2136
+ new URL("./connect/callback", restrictedUrl),
2137
+ new URL(getOAuthProtectedResourceMetadataUrl(restrictedUrl))
2138
+ ]) {
2139
+ restrictedByPath.set(owned.pathname, restricted);
2140
+ }
2141
+ }
2105
2142
  return {
2106
- fetch: (request) => (pluginPaths[new URL(request.url).pathname] === true ? plugin : hosted).fetch(request),
2143
+ fetch: (request) => (restrictedByPath.get(new URL(request.url).pathname) ?? hosted).fetch(request),
2107
2144
  close: async () => {
2108
- await Promise.all([hosted.close(), plugin.close()]);
2145
+ await Promise.all(surfaces.map((surface) => surface.close()));
2109
2146
  }
2110
2147
  };
2111
2148
  }
@@ -2377,10 +2414,12 @@ Local alternative: install \`${LOCAL_CLI_PACKAGE}\` and \`${LOCAL_MCP_PACKAGE}\`
2377
2414
  try {
2378
2415
  const destination = await store.approvalRedirect(requiredState(url));
2379
2416
  return Response.redirect(destination, 302);
2380
- } catch {
2417
+ } catch (error) {
2418
+ const reason = error instanceof ApprovalRequestError ? error.detail : "unknown";
2419
+ writeDiagnostic(`connect rejected: reason=${reason} path=${connectPath}`);
2381
2420
  if (request.headers.get("accept")?.includes("text/html")) {
2382
2421
  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>',
2422
+ '<!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
2423
  {
2385
2424
  status: 400,
2386
2425
  headers: {
@@ -2591,7 +2630,7 @@ function mcpCors(response, request) {
2591
2630
  if (request.headers.has("origin")) {
2592
2631
  headers.set("access-control-allow-origin", "*");
2593
2632
  headers.set("access-control-allow-methods", "GET, POST, DELETE, OPTIONS");
2594
- headers.set("access-control-expose-headers", "WWW-Authenticate");
2633
+ headers.set("access-control-expose-headers", MCP_CORS_EXPOSED_HEADERS);
2595
2634
  if (request.method === "OPTIONS") headers.set("access-control-allow-headers", MCP_CORS_ALLOWED_HEADERS);
2596
2635
  }
2597
2636
  return new Response(response.body, { status: response.status, statusText: response.statusText, headers });