@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-cli.cjs CHANGED
@@ -290,6 +290,7 @@ function logToolCall(tool, code, startedAt, replayedGrants) {
290
290
  }
291
291
 
292
292
  // src/remote-store.ts
293
+ var import_sdk_core = require("@tinycloud/sdk-core");
293
294
  var import_node_crypto3 = require("crypto");
294
295
  var import_promises = require("fs/promises");
295
296
  var import_node_path = require("path");
@@ -369,7 +370,7 @@ var NATIVE_GRANT_IMPORT_REJECTION_CODES = /* @__PURE__ */ new Set([
369
370
  "DELEGATION_HOST_MISMATCH",
370
371
  "DELEGATION_REJECTED"
371
372
  ]);
372
- 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"]);
373
374
  var BOOTSTRAP_PERMISSIONS = [
374
375
  {
375
376
  service: "tinycloud.kv",
@@ -792,14 +793,16 @@ var RemoteTenantStore = class {
792
793
  did: tenant.sessionDid,
793
794
  callback: callback.toString(),
794
795
  host: this.#config.nodeHost,
795
- jwk: Buffer.from(JSON.stringify(publicJwk(tenant.jwk))).toString("base64url"),
796
+ requesterOrigin: this.#config.publicUrl.origin,
797
+ jwk: Buffer.from(JSON.stringify((0, import_node_sdk2.publicJwk)(tenant.jwk))).toString("base64url"),
796
798
  permissions: Buffer.from(JSON.stringify({
797
799
  permissions: pending.permissions,
798
800
  reason: [
799
801
  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.",
800
802
  // Owner DIDs come from the verified OpenKey access token of the MCP
801
- // client that created this link, never from the link itself.
802
- ...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(", ")}.`]
803
806
  ].join(" ")
804
807
  })).toString("base64url"),
805
808
  expiry: this.#config.delegationExpiry
@@ -1098,10 +1101,10 @@ var RemoteTenantStore = class {
1098
1101
  authMethod: "openkey",
1099
1102
  openkeyHost: this.#config.openkeyHost
1100
1103
  });
1101
- } 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(/\/+$/, "")) {
1102
1105
  await secureWrite(profilePath, { ...profile, host: this.#config.nodeHost });
1103
1106
  process.stderr.write(
1104
- `[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}
1105
1108
  `
1106
1109
  );
1107
1110
  }
@@ -1407,11 +1410,6 @@ function sessionFromCallback(data, privateJwk) {
1407
1410
  signature: data.signature
1408
1411
  };
1409
1412
  }
1410
- function publicJwk(jwk) {
1411
- const copy = { ...jwk };
1412
- for (const field of ["d", "p", "q", "dp", "dq", "qi", "oth", "k"]) delete copy[field];
1413
- return copy;
1414
- }
1415
1413
  function samePrincipal(left, right) {
1416
1414
  if (typeof left !== "string") return false;
1417
1415
  try {
@@ -1424,6 +1422,7 @@ function normalizeDid(value) {
1424
1422
  return value.split("#", 1)[0];
1425
1423
  }
1426
1424
  function sameNodeHost(left, right) {
1425
+ if (PRODUCTION_NODE_HOSTS.has(left) && (0, import_sdk_core.sameTinyCloudNode)(left, right)) return true;
1427
1426
  try {
1428
1427
  const normalize = (value) => {
1429
1428
  const url = new URL(value);
@@ -1525,6 +1524,7 @@ var import_node_path2 = require("path");
1525
1524
  var import_server2 = require("@modelcontextprotocol/server");
1526
1525
  var import_ajv = require("@modelcontextprotocol/server/validators/ajv");
1527
1526
  var import_operations2 = require("@tinycloud/operations");
1527
+ var import_tc_apps2 = require("@tinycloud/operations/tc-apps");
1528
1528
 
1529
1529
  // src/results.ts
1530
1530
  function toMcpToolResult(result, bindings = [], options = {}) {
@@ -1866,7 +1866,7 @@ var TOOL_BINDINGS = [
1866
1866
  operationVersion: 1,
1867
1867
  readOnlyHint: false,
1868
1868
  idempotentHint: true,
1869
- destructiveHint: true,
1869
+ destructiveHint: false,
1870
1870
  openWorldHint: false,
1871
1871
  surfaces: ["hosted", "public"]
1872
1872
  },
@@ -1896,19 +1896,9 @@ var TOOL_BINDINGS = [
1896
1896
  operationVersion: 1,
1897
1897
  readOnlyHint: false,
1898
1898
  idempotentHint: true,
1899
- destructiveHint: true,
1900
- openWorldHint: false,
1901
- surfaces: ["hosted", "public"]
1902
- },
1903
- {
1904
- name: "tinycloud_apps_move",
1905
- operationId: "tinycloud.apps.move",
1906
- operationVersion: 1,
1907
- readOnlyHint: false,
1908
- idempotentHint: true,
1909
1899
  destructiveHint: false,
1910
1900
  openWorldHint: false,
1911
- surfaces: ["hosted"]
1901
+ surfaces: ["hosted", "public"]
1912
1902
  }
1913
1903
  ];
1914
1904
  var definitions = new Map(generatedCatalog.operations.map((operation) => [
@@ -1919,18 +1909,50 @@ var definitions = new Map(generatedCatalog.operations.map((operation) => [
1919
1909
  result: toMcpJsonSchema(operation.result)
1920
1910
  }
1921
1911
  ]));
1912
+ var CATALOG_APP_TOOLS = [
1913
+ "tinycloud_knowledge_list",
1914
+ "tinycloud_knowledge_read",
1915
+ "tinycloud_sql_query",
1916
+ "tinycloud_sql_execute"
1917
+ ];
1918
+ var APP_WITHOUT_CATALOG_APPS = "Pass one existing personal app id to request its task access together.";
1919
+ function withPropertyDescription(schema, property, description) {
1920
+ const properties = schema.properties;
1921
+ const current = properties?.[property];
1922
+ if (current === void 0) throw new Error(`Generated operations catalog has no ${property} input to describe.`);
1923
+ return { ...schema, properties: { ...properties, [property]: { ...current, description } } };
1924
+ }
1925
+ function catalogAppRefusal(binding, profile, input) {
1926
+ const app = typeof input === "object" && input !== null ? input.app : void 0;
1927
+ if (typeof app !== "string" || !Object.hasOwn(import_tc_apps2.TC_APPS_CATALOG_APPS, app)) return void 0;
1928
+ const { title, link } = import_tc_apps2.TC_APPS_CATALOG_APPS[app];
1929
+ return {
1930
+ status: "error",
1931
+ operation: { operationId: binding.operationId, operationVersion: binding.operationVersion },
1932
+ context: { profile, host: "unresolved", posture: "unauthenticated" },
1933
+ error: {
1934
+ code: "INPUT_INVALID",
1935
+ 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.`,
1936
+ retryable: false,
1937
+ details: { reason: "catalog_app_unavailable", app, link }
1938
+ }
1939
+ };
1940
+ }
1922
1941
  function createJsonSchemaValidator() {
1923
1942
  return new import_ajv.AjvJsonSchemaValidator();
1924
1943
  }
1925
1944
  function registerTinyCloudTools(server, selection, validator) {
1926
1945
  const bindings = TOOL_BINDINGS.filter((binding) => bindingSurfaces(binding).includes(selection.surface) && (selection.allowedTools === void 0 || selection.allowedTools.includes(binding.name)));
1946
+ const servesCatalogApps = CATALOG_APP_TOOLS.every((name) => bindings.some((binding) => binding.name === name));
1927
1947
  for (const binding of bindings) {
1928
1948
  const operation = definitions.get(`${binding.operationId}@${binding.operationVersion}`);
1929
1949
  if (operation === void 0) {
1930
1950
  throw new Error(`Generated operations catalog is missing ${binding.operationId}@${binding.operationVersion}.`);
1931
1951
  }
1952
+ const offersCatalogApps = servesCatalogApps || binding.operationId !== "tinycloud.apps.context";
1953
+ const inputJsonSchema = offersCatalogApps ? operation.input : withPropertyDescription(operation.input, "app", APP_WITHOUT_CATALOG_APPS);
1932
1954
  const inputSchema = (0, import_server2.fromJsonSchema)(
1933
- operation.input,
1955
+ inputJsonSchema,
1934
1956
  validator
1935
1957
  );
1936
1958
  const outputSchema = (0, import_server2.fromJsonSchema)(
@@ -1938,6 +1960,7 @@ function registerTinyCloudTools(server, selection, validator) {
1938
1960
  validator
1939
1961
  );
1940
1962
  const annotations = {
1963
+ ...selection.annotationTitles === true ? { title: operation.title } : {},
1941
1964
  readOnlyHint: binding.readOnlyHint,
1942
1965
  idempotentHint: binding.idempotentHint,
1943
1966
  destructiveHint: binding.destructiveHint,
@@ -1957,19 +1980,22 @@ function registerTinyCloudTools(server, selection, validator) {
1957
1980
  const metrics = { replayedGrants: 0 };
1958
1981
  let code = "INTERNAL_ERROR";
1959
1982
  try {
1960
- await selection.beforeOperation?.();
1961
- const result = await (0, import_operations2.invokeOperation)(
1962
- binding.operationId,
1963
- binding.operationVersion,
1964
- invocationTargetForMcp(selection),
1965
- input,
1966
- metrics
1967
- );
1968
- const projected = selection.transformOperationResult === void 0 ? result : await selection.transformOperationResult(result, {
1969
- operationId: binding.operationId,
1970
- operationVersion: binding.operationVersion,
1971
- input
1972
- });
1983
+ let projected = offersCatalogApps ? void 0 : catalogAppRefusal(binding, selection.profile, input);
1984
+ if (projected === void 0) {
1985
+ await selection.beforeOperation?.();
1986
+ const result = await (0, import_operations2.invokeOperation)(
1987
+ binding.operationId,
1988
+ binding.operationVersion,
1989
+ invocationTargetForMcp(selection),
1990
+ input,
1991
+ metrics
1992
+ );
1993
+ projected = selection.transformOperationResult === void 0 ? result : await selection.transformOperationResult(result, {
1994
+ operationId: binding.operationId,
1995
+ operationVersion: binding.operationVersion,
1996
+ input
1997
+ });
1998
+ }
1973
1999
  const response = toMcpToolResult(projected, bindings, {
1974
2000
  surface: selection.surface === "local" ? "local" : "hosted",
1975
2001
  readOnly: binding.readOnlyHint,
@@ -2001,7 +2027,7 @@ function outcomeCode(result) {
2001
2027
  // package.json
2002
2028
  var package_default = {
2003
2029
  name: "@tinycloud/mcp",
2004
- version: "0.10.0-beta.5",
2030
+ version: "0.10.0-beta.51",
2005
2031
  description: "TinyCloud delegated operations MCP server",
2006
2032
  keywords: [
2007
2033
  "tinycloud",
@@ -2072,9 +2098,10 @@ var package_default = {
2072
2098
  dependencies: {
2073
2099
  "@modelcontextprotocol/node": "2.0.0-beta.5",
2074
2100
  "@modelcontextprotocol/server": "2.0.0-beta.5",
2075
- "@tinycloud/node-sdk": "3.12.0-beta.2",
2076
- "@tinycloud/node-sdk-wasm": "1.7.8",
2077
- "@tinycloud/operations": "0.9.0-beta.4",
2101
+ "@tinycloud/node-sdk": "3.12.0-beta.38",
2102
+ "@tinycloud/sdk-core": "3.12.0-beta.37",
2103
+ "@tinycloud/node-sdk-wasm": "1.7.9-beta.0",
2104
+ "@tinycloud/operations": "0.9.0-beta.45",
2078
2105
  jose: "6.2.4"
2079
2106
  },
2080
2107
  devDependencies: {
@@ -2099,36 +2126,47 @@ var MCP_SERVER_NAME = "tinycloud-mcp";
2099
2126
  // src/http.ts
2100
2127
  var REQUIRED_SCOPE = "tinycloud:mcp";
2101
2128
  var MCP_CORS_ALLOWED_HEADERS = "Authorization, Content-Type, Accept, Mcp-Protocol-Version, Mcp-Session-Id, Last-Event-ID, Mcp-Method, Mcp-Name";
2129
+ var MCP_CORS_EXPOSED_HEADERS = "WWW-Authenticate, Mcp-Session-Id, Mcp-Protocol-Version";
2102
2130
  var LOCAL_CLI_PACKAGE = ["@tinycloud", "cli"].join("/");
2103
2131
  var LOCAL_MCP_PACKAGE = ["@tinycloud", "mcp"].join("/");
2132
+ var RESTRICTED_ADDRESS_PREFIXES = ["chatgpt", "claude", "grok", "muse"];
2133
+ var ANNOTATION_TITLE_PREFIXES = /* @__PURE__ */ new Set(["claude"]);
2104
2134
  function createHostedMcpApp(config) {
2105
2135
  if (config.nativeServiceCredential !== void 0 && Buffer.byteLength(config.nativeServiceCredential, "utf8") < 32) {
2106
2136
  throw new Error("TC_MCP_NATIVE_SERVICE_CREDENTIAL must contain at least 32 bytes.");
2107
2137
  }
2108
2138
  const resourceUrl = canonicalResourceUrl(config.publicUrl);
2109
- const pluginUrl = new URL("./chatgpt/mcp", resourceUrl);
2110
2139
  const statusFor = (resource) => config.introspection === void 0 ? void 0 : createTokenStatusChecker({ ...config.introspection, resourceUrl: resource.toString() });
2111
2140
  const hosted = createHostedSurface(config, resourceUrl, "hosted", statusFor(resourceUrl));
2112
- const plugin = createHostedSurface({
2113
- ...config,
2114
- nativeServiceCredential: void 0,
2115
- stateDir: (0, import_node_path3.join)(config.stateDir, "chatgpt"),
2116
- approvalPath: new URL("./connect", pluginUrl).pathname
2117
- }, pluginUrl, "public", statusFor(pluginUrl));
2118
- const pluginPaths = {
2119
- [pluginUrl.pathname]: true,
2120
- [new URL("./connect", pluginUrl).pathname]: true,
2121
- [new URL("./connect/callback", pluginUrl).pathname]: true,
2122
- [new URL((0, import_server4.getOAuthProtectedResourceMetadataUrl)(pluginUrl)).pathname]: true
2123
- };
2141
+ const surfaces = [hosted];
2142
+ const restrictedByPath = /* @__PURE__ */ new Map();
2143
+ for (const prefix of RESTRICTED_ADDRESS_PREFIXES) {
2144
+ const restrictedUrl = new URL(`./${prefix}/mcp`, resourceUrl);
2145
+ const connectUrl = new URL("./connect", restrictedUrl);
2146
+ const restricted = createHostedSurface({
2147
+ ...config,
2148
+ nativeServiceCredential: void 0,
2149
+ stateDir: (0, import_node_path3.join)(config.stateDir, prefix),
2150
+ approvalPath: connectUrl.pathname
2151
+ }, restrictedUrl, "public", statusFor(restrictedUrl), ANNOTATION_TITLE_PREFIXES.has(prefix));
2152
+ surfaces.push(restricted);
2153
+ for (const owned of [
2154
+ restrictedUrl,
2155
+ connectUrl,
2156
+ new URL("./connect/callback", restrictedUrl),
2157
+ new URL((0, import_server4.getOAuthProtectedResourceMetadataUrl)(restrictedUrl))
2158
+ ]) {
2159
+ restrictedByPath.set(owned.pathname, restricted);
2160
+ }
2161
+ }
2124
2162
  return {
2125
- fetch: (request) => (pluginPaths[new URL(request.url).pathname] === true ? plugin : hosted).fetch(request),
2163
+ fetch: (request) => (restrictedByPath.get(new URL(request.url).pathname) ?? hosted).fetch(request),
2126
2164
  close: async () => {
2127
- await Promise.all([hosted.close(), plugin.close()]);
2165
+ await Promise.all(surfaces.map((surface) => surface.close()));
2128
2166
  }
2129
2167
  };
2130
2168
  }
2131
- function createHostedSurface(config, resourceUrl, surface, tokenStatus) {
2169
+ function createHostedSurface(config, resourceUrl, surface, tokenStatus, annotationTitles = false) {
2132
2170
  const connectPath = config.approvalPath ?? "/connect";
2133
2171
  const callbackPath = `${connectPath}/callback`;
2134
2172
  const issuer = String(config.oauthMetadata.issuer);
@@ -2168,6 +2206,7 @@ function createHostedSurface(config, resourceUrl, surface, tokenStatus) {
2168
2206
  explicitProfile: true,
2169
2207
  allowOwnerProfile: false,
2170
2208
  stateRoot,
2209
+ annotationTitles,
2171
2210
  ...nativeOwner === void 0 ? {} : {
2172
2211
  allowedTools: ["tinycloud_sql_query", "tinycloud_kv_get", "tinycloud_read"]
2173
2212
  },
@@ -2176,7 +2215,7 @@ function createHostedSurface(config, resourceUrl, surface, tokenStatus) {
2176
2215
  transformOperationResult: (result, invocation) => store.decorateAuthorityResult(subject, ownerDids, result, invocation)
2177
2216
  } : {}
2178
2217
  }, validator);
2179
- if (nativeOwner === void 0) registerConnectTool(server, validator, store, identity, surface);
2218
+ if (nativeOwner === void 0) registerConnectTool(server, validator, store, identity, surface, annotationTitles);
2180
2219
  return server;
2181
2220
  }, {
2182
2221
  legacy: "stateless",
@@ -2396,10 +2435,12 @@ Local alternative: install \`${LOCAL_CLI_PACKAGE}\` and \`${LOCAL_MCP_PACKAGE}\`
2396
2435
  try {
2397
2436
  const destination = await store.approvalRedirect(requiredState(url));
2398
2437
  return Response.redirect(destination, 302);
2399
- } catch {
2438
+ } catch (error) {
2439
+ const reason = error instanceof ApprovalRequestError ? error.detail : "unknown";
2440
+ writeDiagnostic(`connect rejected: reason=${reason} path=${connectPath}`);
2400
2441
  if (request.headers.get("accept")?.includes("text/html")) {
2401
2442
  return new Response(
2402
- '<!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>',
2443
+ '<!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>',
2403
2444
  {
2404
2445
  status: 400,
2405
2446
  headers: {
@@ -2521,7 +2562,8 @@ Local alternative: install \`${LOCAL_CLI_PACKAGE}\` and \`${LOCAL_MCP_PACKAGE}\`
2521
2562
  close: () => handler.close()
2522
2563
  };
2523
2564
  }
2524
- function registerConnectTool(server, validator, store, identity, surface) {
2565
+ function registerConnectTool(server, validator, store, identity, surface, annotationTitles) {
2566
+ const title = "Connect TinyCloud";
2525
2567
  const inputSchema = (0, import_server4.fromJsonSchema)({ type: "object", properties: {}, additionalProperties: false }, validator);
2526
2568
  const outputSchema = (0, import_server4.fromJsonSchema)({
2527
2569
  type: "object",
@@ -2537,11 +2579,12 @@ function registerConnectTool(server, validator, store, identity, surface) {
2537
2579
  server.registerTool(
2538
2580
  "tinycloud_connect",
2539
2581
  {
2540
- title: "Connect TinyCloud",
2582
+ title,
2541
2583
  description: "Check the hosted delegate connection and return a one-time OpenKey approval URL when setup is required.",
2542
2584
  inputSchema,
2543
2585
  outputSchema,
2544
2586
  annotations: {
2587
+ ...annotationTitles ? { title } : {},
2545
2588
  readOnlyHint: false,
2546
2589
  idempotentHint: true,
2547
2590
  destructiveHint: false,
@@ -2610,7 +2653,7 @@ function mcpCors(response, request) {
2610
2653
  if (request.headers.has("origin")) {
2611
2654
  headers.set("access-control-allow-origin", "*");
2612
2655
  headers.set("access-control-allow-methods", "GET, POST, DELETE, OPTIONS");
2613
- headers.set("access-control-expose-headers", "WWW-Authenticate");
2656
+ headers.set("access-control-expose-headers", MCP_CORS_EXPOSED_HEADERS);
2614
2657
  if (request.method === "OPTIONS") headers.set("access-control-allow-headers", MCP_CORS_ALLOWED_HEADERS);
2615
2658
  }
2616
2659
  return new Response(response.body, { status: response.status, statusText: response.statusText, headers });