@tinycloud/mcp 0.10.0-beta.9 → 0.10.0

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,6 +776,7 @@ 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,
@@ -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) && sameTinyCloudNode(left, right)) return true;
1410
1409
  try {
1411
1410
  const normalize = (value) => {
1412
1411
  const url = new URL(value);
@@ -1508,6 +1507,7 @@ import { join as join2 } from "path";
1508
1507
  import { fromJsonSchema } from "@modelcontextprotocol/server";
1509
1508
  import { AjvJsonSchemaValidator } from "@modelcontextprotocol/server/validators/ajv";
1510
1509
  import { invokeOperation as invokeOperation2 } from "@tinycloud/operations";
1510
+ import { TC_APPS_CATALOG_APPS } from "@tinycloud/operations/tc-apps";
1511
1511
 
1512
1512
  // src/results.ts
1513
1513
  function toMcpToolResult(result, bindings = [], options = {}) {
@@ -1848,7 +1848,7 @@ var TOOL_BINDINGS = [
1848
1848
  operationVersion: 1,
1849
1849
  readOnlyHint: false,
1850
1850
  idempotentHint: true,
1851
- destructiveHint: true,
1851
+ destructiveHint: false,
1852
1852
  openWorldHint: false,
1853
1853
  surfaces: ["hosted", "public"]
1854
1854
  },
@@ -1878,19 +1878,9 @@ var TOOL_BINDINGS = [
1878
1878
  operationVersion: 1,
1879
1879
  readOnlyHint: false,
1880
1880
  idempotentHint: true,
1881
- destructiveHint: true,
1882
- openWorldHint: false,
1883
- surfaces: ["hosted", "public"]
1884
- },
1885
- {
1886
- name: "tinycloud_apps_move",
1887
- operationId: "tinycloud.apps.move",
1888
- operationVersion: 1,
1889
- readOnlyHint: false,
1890
- idempotentHint: true,
1891
1881
  destructiveHint: false,
1892
1882
  openWorldHint: false,
1893
- surfaces: ["hosted"]
1883
+ surfaces: ["hosted", "public"]
1894
1884
  }
1895
1885
  ];
1896
1886
  var definitions = new Map(generatedCatalog.operations.map((operation) => [
@@ -1901,18 +1891,50 @@ var definitions = new Map(generatedCatalog.operations.map((operation) => [
1901
1891
  result: toMcpJsonSchema(operation.result)
1902
1892
  }
1903
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
+ }
1904
1923
  function createJsonSchemaValidator() {
1905
1924
  return new AjvJsonSchemaValidator();
1906
1925
  }
1907
1926
  function registerTinyCloudTools(server, selection, validator) {
1908
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));
1909
1929
  for (const binding of bindings) {
1910
1930
  const operation = definitions.get(`${binding.operationId}@${binding.operationVersion}`);
1911
1931
  if (operation === void 0) {
1912
1932
  throw new Error(`Generated operations catalog is missing ${binding.operationId}@${binding.operationVersion}.`);
1913
1933
  }
1934
+ const offersCatalogApps = servesCatalogApps || binding.operationId !== "tinycloud.apps.context";
1935
+ const inputJsonSchema = offersCatalogApps ? operation.input : withPropertyDescription(operation.input, "app", APP_WITHOUT_CATALOG_APPS);
1914
1936
  const inputSchema = fromJsonSchema(
1915
- operation.input,
1937
+ inputJsonSchema,
1916
1938
  validator
1917
1939
  );
1918
1940
  const outputSchema = fromJsonSchema(
@@ -1920,6 +1942,7 @@ function registerTinyCloudTools(server, selection, validator) {
1920
1942
  validator
1921
1943
  );
1922
1944
  const annotations = {
1945
+ ...selection.annotationTitles === true ? { title: operation.title } : {},
1923
1946
  readOnlyHint: binding.readOnlyHint,
1924
1947
  idempotentHint: binding.idempotentHint,
1925
1948
  destructiveHint: binding.destructiveHint,
@@ -1939,19 +1962,22 @@ function registerTinyCloudTools(server, selection, validator) {
1939
1962
  const metrics = { replayedGrants: 0 };
1940
1963
  let code = "INTERNAL_ERROR";
1941
1964
  try {
1942
- await selection.beforeOperation?.();
1943
- const result = await invokeOperation2(
1944
- binding.operationId,
1945
- binding.operationVersion,
1946
- invocationTargetForMcp(selection),
1947
- input,
1948
- metrics
1949
- );
1950
- const projected = selection.transformOperationResult === void 0 ? result : await selection.transformOperationResult(result, {
1951
- operationId: binding.operationId,
1952
- operationVersion: binding.operationVersion,
1953
- input
1954
- });
1965
+ let projected = offersCatalogApps ? void 0 : catalogAppRefusal(binding, selection.profile, input);
1966
+ if (projected === void 0) {
1967
+ await selection.beforeOperation?.();
1968
+ const result = await invokeOperation2(
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
+ }
1955
1981
  const response = toMcpToolResult(projected, bindings, {
1956
1982
  surface: selection.surface === "local" ? "local" : "hosted",
1957
1983
  readOnly: binding.readOnlyHint,
@@ -1983,7 +2009,7 @@ function outcomeCode(result) {
1983
2009
  // package.json
1984
2010
  var package_default = {
1985
2011
  name: "@tinycloud/mcp",
1986
- version: "0.10.0-beta.9",
2012
+ version: "0.10.0",
1987
2013
  description: "TinyCloud delegated operations MCP server",
1988
2014
  keywords: [
1989
2015
  "tinycloud",
@@ -2054,9 +2080,10 @@ var package_default = {
2054
2080
  dependencies: {
2055
2081
  "@modelcontextprotocol/node": "2.0.0-beta.5",
2056
2082
  "@modelcontextprotocol/server": "2.0.0-beta.5",
2057
- "@tinycloud/node-sdk": "3.12.0-beta.4",
2058
- "@tinycloud/node-sdk-wasm": "1.7.8",
2059
- "@tinycloud/operations": "0.9.0-beta.6",
2083
+ "@tinycloud/node-sdk": "3.12.0",
2084
+ "@tinycloud/sdk-core": "3.12.0",
2085
+ "@tinycloud/node-sdk-wasm": "1.7.9",
2086
+ "@tinycloud/operations": "0.9.0",
2060
2087
  jose: "6.2.4"
2061
2088
  },
2062
2089
  devDependencies: {
@@ -2081,36 +2108,47 @@ var MCP_SERVER_NAME = "tinycloud-mcp";
2081
2108
  // src/http.ts
2082
2109
  var REQUIRED_SCOPE = "tinycloud:mcp";
2083
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";
2084
2112
  var LOCAL_CLI_PACKAGE = ["@tinycloud", "cli"].join("/");
2085
2113
  var LOCAL_MCP_PACKAGE = ["@tinycloud", "mcp"].join("/");
2114
+ var RESTRICTED_ADDRESS_PREFIXES = ["chatgpt", "claude", "grok", "muse"];
2115
+ var ANNOTATION_TITLE_PREFIXES = /* @__PURE__ */ new Set(["claude"]);
2086
2116
  function createHostedMcpApp(config) {
2087
2117
  if (config.nativeServiceCredential !== void 0 && Buffer.byteLength(config.nativeServiceCredential, "utf8") < 32) {
2088
2118
  throw new Error("TC_MCP_NATIVE_SERVICE_CREDENTIAL must contain at least 32 bytes.");
2089
2119
  }
2090
2120
  const resourceUrl = canonicalResourceUrl(config.publicUrl);
2091
- const pluginUrl = new URL("./chatgpt/mcp", resourceUrl);
2092
2121
  const statusFor = (resource) => config.introspection === void 0 ? void 0 : createTokenStatusChecker({ ...config.introspection, resourceUrl: resource.toString() });
2093
2122
  const hosted = createHostedSurface(config, resourceUrl, "hosted", statusFor(resourceUrl));
2094
- const plugin = createHostedSurface({
2095
- ...config,
2096
- nativeServiceCredential: void 0,
2097
- stateDir: join3(config.stateDir, "chatgpt"),
2098
- approvalPath: new URL("./connect", pluginUrl).pathname
2099
- }, pluginUrl, "public", statusFor(pluginUrl));
2100
- const pluginPaths = {
2101
- [pluginUrl.pathname]: true,
2102
- [new URL("./connect", pluginUrl).pathname]: true,
2103
- [new URL("./connect/callback", pluginUrl).pathname]: true,
2104
- [new URL(getOAuthProtectedResourceMetadataUrl(pluginUrl)).pathname]: true
2105
- };
2123
+ const surfaces = [hosted];
2124
+ const restrictedByPath = /* @__PURE__ */ new Map();
2125
+ for (const prefix of RESTRICTED_ADDRESS_PREFIXES) {
2126
+ const restrictedUrl = new URL(`./${prefix}/mcp`, resourceUrl);
2127
+ const connectUrl = new URL("./connect", restrictedUrl);
2128
+ const restricted = createHostedSurface({
2129
+ ...config,
2130
+ nativeServiceCredential: void 0,
2131
+ stateDir: join3(config.stateDir, prefix),
2132
+ approvalPath: connectUrl.pathname
2133
+ }, restrictedUrl, "public", statusFor(restrictedUrl), ANNOTATION_TITLE_PREFIXES.has(prefix));
2134
+ surfaces.push(restricted);
2135
+ for (const owned of [
2136
+ restrictedUrl,
2137
+ connectUrl,
2138
+ new URL("./connect/callback", restrictedUrl),
2139
+ new URL(getOAuthProtectedResourceMetadataUrl(restrictedUrl))
2140
+ ]) {
2141
+ restrictedByPath.set(owned.pathname, restricted);
2142
+ }
2143
+ }
2106
2144
  return {
2107
- fetch: (request) => (pluginPaths[new URL(request.url).pathname] === true ? plugin : hosted).fetch(request),
2145
+ fetch: (request) => (restrictedByPath.get(new URL(request.url).pathname) ?? hosted).fetch(request),
2108
2146
  close: async () => {
2109
- await Promise.all([hosted.close(), plugin.close()]);
2147
+ await Promise.all(surfaces.map((surface) => surface.close()));
2110
2148
  }
2111
2149
  };
2112
2150
  }
2113
- function createHostedSurface(config, resourceUrl, surface, tokenStatus) {
2151
+ function createHostedSurface(config, resourceUrl, surface, tokenStatus, annotationTitles = false) {
2114
2152
  const connectPath = config.approvalPath ?? "/connect";
2115
2153
  const callbackPath = `${connectPath}/callback`;
2116
2154
  const issuer = String(config.oauthMetadata.issuer);
@@ -2150,6 +2188,7 @@ function createHostedSurface(config, resourceUrl, surface, tokenStatus) {
2150
2188
  explicitProfile: true,
2151
2189
  allowOwnerProfile: false,
2152
2190
  stateRoot,
2191
+ annotationTitles,
2153
2192
  ...nativeOwner === void 0 ? {} : {
2154
2193
  allowedTools: ["tinycloud_sql_query", "tinycloud_kv_get", "tinycloud_read"]
2155
2194
  },
@@ -2158,7 +2197,7 @@ function createHostedSurface(config, resourceUrl, surface, tokenStatus) {
2158
2197
  transformOperationResult: (result, invocation) => store.decorateAuthorityResult(subject, ownerDids, result, invocation)
2159
2198
  } : {}
2160
2199
  }, validator);
2161
- if (nativeOwner === void 0) registerConnectTool(server, validator, store, identity, surface);
2200
+ if (nativeOwner === void 0) registerConnectTool(server, validator, store, identity, surface, annotationTitles);
2162
2201
  return server;
2163
2202
  }, {
2164
2203
  legacy: "stateless",
@@ -2505,7 +2544,8 @@ Local alternative: install \`${LOCAL_CLI_PACKAGE}\` and \`${LOCAL_MCP_PACKAGE}\`
2505
2544
  close: () => handler.close()
2506
2545
  };
2507
2546
  }
2508
- function registerConnectTool(server, validator, store, identity, surface) {
2547
+ function registerConnectTool(server, validator, store, identity, surface, annotationTitles) {
2548
+ const title = "Connect TinyCloud";
2509
2549
  const inputSchema = fromJsonSchema2({ type: "object", properties: {}, additionalProperties: false }, validator);
2510
2550
  const outputSchema = fromJsonSchema2({
2511
2551
  type: "object",
@@ -2521,11 +2561,12 @@ function registerConnectTool(server, validator, store, identity, surface) {
2521
2561
  server.registerTool(
2522
2562
  "tinycloud_connect",
2523
2563
  {
2524
- title: "Connect TinyCloud",
2564
+ title,
2525
2565
  description: "Check the hosted delegate connection and return a one-time OpenKey approval URL when setup is required.",
2526
2566
  inputSchema,
2527
2567
  outputSchema,
2528
2568
  annotations: {
2569
+ ...annotationTitles ? { title } : {},
2529
2570
  readOnlyHint: false,
2530
2571
  idempotentHint: true,
2531
2572
  destructiveHint: false,
@@ -2594,7 +2635,7 @@ function mcpCors(response, request) {
2594
2635
  if (request.headers.has("origin")) {
2595
2636
  headers.set("access-control-allow-origin", "*");
2596
2637
  headers.set("access-control-allow-methods", "GET, POST, DELETE, OPTIONS");
2597
- headers.set("access-control-expose-headers", "WWW-Authenticate");
2638
+ headers.set("access-control-expose-headers", MCP_CORS_EXPOSED_HEADERS);
2598
2639
  if (request.method === "OPTIONS") headers.set("access-control-allow-headers", MCP_CORS_ALLOWED_HEADERS);
2599
2640
  }
2600
2641
  return new Response(response.body, { status: response.status, statusText: response.statusText, headers });