@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.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)(
@@ -1940,19 +1962,22 @@ function registerTinyCloudTools(server, selection, validator) {
1940
1962
  const metrics = { replayedGrants: 0 };
1941
1963
  let code = "INTERNAL_ERROR";
1942
1964
  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
- });
1965
+ let projected = offersCatalogApps ? void 0 : catalogAppRefusal(binding, selection.profile, input);
1966
+ if (projected === void 0) {
1967
+ await selection.beforeOperation?.();
1968
+ const result = await (0, import_operations2.invokeOperation)(
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
+ }
1956
1981
  const response = toMcpToolResult(projected, bindings, {
1957
1982
  surface: selection.surface === "local" ? "local" : "hosted",
1958
1983
  readOnly: binding.readOnlyHint,
@@ -1984,7 +2009,7 @@ function outcomeCode(result) {
1984
2009
  // package.json
1985
2010
  var package_default = {
1986
2011
  name: "@tinycloud/mcp",
1987
- version: "0.10.0-beta.5",
2012
+ version: "0.10.0-beta.50",
1988
2013
  description: "TinyCloud delegated operations MCP server",
1989
2014
  keywords: [
1990
2015
  "tinycloud",
@@ -2055,9 +2080,10 @@ var package_default = {
2055
2080
  dependencies: {
2056
2081
  "@modelcontextprotocol/node": "2.0.0-beta.5",
2057
2082
  "@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",
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",
2061
2087
  jose: "6.2.4"
2062
2088
  },
2063
2089
  devDependencies: {
@@ -2082,32 +2108,42 @@ var MCP_SERVER_NAME = "tinycloud-mcp";
2082
2108
  // src/http.ts
2083
2109
  var REQUIRED_SCOPE = "tinycloud:mcp";
2084
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";
2085
2112
  var LOCAL_CLI_PACKAGE = ["@tinycloud", "cli"].join("/");
2086
2113
  var LOCAL_MCP_PACKAGE = ["@tinycloud", "mcp"].join("/");
2114
+ var RESTRICTED_ADDRESS_PREFIXES = ["chatgpt", "claude", "grok", "muse"];
2087
2115
  function createHostedMcpApp(config) {
2088
2116
  if (config.nativeServiceCredential !== void 0 && Buffer.byteLength(config.nativeServiceCredential, "utf8") < 32) {
2089
2117
  throw new Error("TC_MCP_NATIVE_SERVICE_CREDENTIAL must contain at least 32 bytes.");
2090
2118
  }
2091
2119
  const resourceUrl = canonicalResourceUrl(config.publicUrl);
2092
- const pluginUrl = new URL("./chatgpt/mcp", resourceUrl);
2093
2120
  const statusFor = (resource) => config.introspection === void 0 ? void 0 : createTokenStatusChecker({ ...config.introspection, resourceUrl: resource.toString() });
2094
2121
  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
- };
2122
+ const surfaces = [hosted];
2123
+ const restrictedByPath = /* @__PURE__ */ new Map();
2124
+ for (const prefix of RESTRICTED_ADDRESS_PREFIXES) {
2125
+ const restrictedUrl = new URL(`./${prefix}/mcp`, resourceUrl);
2126
+ const connectUrl = new URL("./connect", restrictedUrl);
2127
+ const restricted = createHostedSurface({
2128
+ ...config,
2129
+ nativeServiceCredential: void 0,
2130
+ stateDir: (0, import_node_path3.join)(config.stateDir, prefix),
2131
+ approvalPath: connectUrl.pathname
2132
+ }, restrictedUrl, "public", statusFor(restrictedUrl));
2133
+ surfaces.push(restricted);
2134
+ for (const owned of [
2135
+ restrictedUrl,
2136
+ connectUrl,
2137
+ new URL("./connect/callback", restrictedUrl),
2138
+ new URL((0, import_server4.getOAuthProtectedResourceMetadataUrl)(restrictedUrl))
2139
+ ]) {
2140
+ restrictedByPath.set(owned.pathname, restricted);
2141
+ }
2142
+ }
2107
2143
  return {
2108
- fetch: (request) => (pluginPaths[new URL(request.url).pathname] === true ? plugin : hosted).fetch(request),
2144
+ fetch: (request) => (restrictedByPath.get(new URL(request.url).pathname) ?? hosted).fetch(request),
2109
2145
  close: async () => {
2110
- await Promise.all([hosted.close(), plugin.close()]);
2146
+ await Promise.all(surfaces.map((surface) => surface.close()));
2111
2147
  }
2112
2148
  };
2113
2149
  }
@@ -2379,10 +2415,12 @@ Local alternative: install \`${LOCAL_CLI_PACKAGE}\` and \`${LOCAL_MCP_PACKAGE}\`
2379
2415
  try {
2380
2416
  const destination = await store.approvalRedirect(requiredState(url));
2381
2417
  return Response.redirect(destination, 302);
2382
- } catch {
2418
+ } catch (error) {
2419
+ const reason = error instanceof ApprovalRequestError ? error.detail : "unknown";
2420
+ writeDiagnostic(`connect rejected: reason=${reason} path=${connectPath}`);
2383
2421
  if (request.headers.get("accept")?.includes("text/html")) {
2384
2422
  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>',
2423
+ '<!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
2424
  {
2387
2425
  status: 400,
2388
2426
  headers: {
@@ -2593,7 +2631,7 @@ function mcpCors(response, request) {
2593
2631
  if (request.headers.has("origin")) {
2594
2632
  headers.set("access-control-allow-origin", "*");
2595
2633
  headers.set("access-control-allow-methods", "GET, POST, DELETE, OPTIONS");
2596
- headers.set("access-control-expose-headers", "WWW-Authenticate");
2634
+ headers.set("access-control-expose-headers", MCP_CORS_EXPOSED_HEADERS);
2597
2635
  if (request.method === "OPTIONS") headers.set("access-control-allow-headers", MCP_CORS_ALLOWED_HEADERS);
2598
2636
  }
2599
2637
  return new Response(response.body, { status: response.status, statusText: response.statusText, headers });