@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.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,7 +776,8 @@ 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: [
@@ -1082,10 +1084,10 @@ var RemoteTenantStore = class {
1082
1084
  authMethod: "openkey",
1083
1085
  openkeyHost: this.#config.openkeyHost
1084
1086
  });
1085
- } 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(/\/+$/, "")) {
1086
1088
  await secureWrite(profilePath, { ...profile, host: this.#config.nodeHost });
1087
1089
  process.stderr.write(
1088
- `[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}
1089
1091
  `
1090
1092
  );
1091
1093
  }
@@ -1391,11 +1393,6 @@ function sessionFromCallback(data, privateJwk) {
1391
1393
  signature: data.signature
1392
1394
  };
1393
1395
  }
1394
- function publicJwk(jwk) {
1395
- const copy = { ...jwk };
1396
- for (const field of ["d", "p", "q", "dp", "dq", "qi", "oth", "k"]) delete copy[field];
1397
- return copy;
1398
- }
1399
1396
  function samePrincipal(left, right) {
1400
1397
  if (typeof left !== "string") return false;
1401
1398
  try {
@@ -1408,6 +1405,7 @@ function normalizeDid(value) {
1408
1405
  return value.split("#", 1)[0];
1409
1406
  }
1410
1407
  function sameNodeHost(left, right) {
1408
+ if (PRODUCTION_NODE_HOSTS.has(left) && (0, import_sdk_core.sameTinyCloudNode)(left, right)) return true;
1411
1409
  try {
1412
1410
  const normalize = (value) => {
1413
1411
  const url = new URL(value);
@@ -1509,6 +1507,7 @@ var import_node_path2 = require("path");
1509
1507
  var import_server2 = require("@modelcontextprotocol/server");
1510
1508
  var import_ajv = require("@modelcontextprotocol/server/validators/ajv");
1511
1509
  var import_operations2 = require("@tinycloud/operations");
1510
+ var import_tc_apps2 = require("@tinycloud/operations/tc-apps");
1512
1511
 
1513
1512
  // src/results.ts
1514
1513
  function toMcpToolResult(result, bindings = [], options = {}) {
@@ -1850,7 +1849,7 @@ var TOOL_BINDINGS = [
1850
1849
  operationVersion: 1,
1851
1850
  readOnlyHint: false,
1852
1851
  idempotentHint: true,
1853
- destructiveHint: true,
1852
+ destructiveHint: false,
1854
1853
  openWorldHint: false,
1855
1854
  surfaces: ["hosted", "public"]
1856
1855
  },
@@ -1880,19 +1879,9 @@ var TOOL_BINDINGS = [
1880
1879
  operationVersion: 1,
1881
1880
  readOnlyHint: false,
1882
1881
  idempotentHint: true,
1883
- destructiveHint: true,
1884
- openWorldHint: false,
1885
- surfaces: ["hosted", "public"]
1886
- },
1887
- {
1888
- name: "tinycloud_apps_move",
1889
- operationId: "tinycloud.apps.move",
1890
- operationVersion: 1,
1891
- readOnlyHint: false,
1892
- idempotentHint: true,
1893
1882
  destructiveHint: false,
1894
1883
  openWorldHint: false,
1895
- surfaces: ["hosted"]
1884
+ surfaces: ["hosted", "public"]
1896
1885
  }
1897
1886
  ];
1898
1887
  var definitions = new Map(generatedCatalog.operations.map((operation) => [
@@ -1903,18 +1892,50 @@ var definitions = new Map(generatedCatalog.operations.map((operation) => [
1903
1892
  result: toMcpJsonSchema(operation.result)
1904
1893
  }
1905
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
+ }
1906
1924
  function createJsonSchemaValidator() {
1907
1925
  return new import_ajv.AjvJsonSchemaValidator();
1908
1926
  }
1909
1927
  function registerTinyCloudTools(server, selection, validator) {
1910
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));
1911
1930
  for (const binding of bindings) {
1912
1931
  const operation = definitions.get(`${binding.operationId}@${binding.operationVersion}`);
1913
1932
  if (operation === void 0) {
1914
1933
  throw new Error(`Generated operations catalog is missing ${binding.operationId}@${binding.operationVersion}.`);
1915
1934
  }
1935
+ const offersCatalogApps = servesCatalogApps || binding.operationId !== "tinycloud.apps.context";
1936
+ const inputJsonSchema = offersCatalogApps ? operation.input : withPropertyDescription(operation.input, "app", APP_WITHOUT_CATALOG_APPS);
1916
1937
  const inputSchema = (0, import_server2.fromJsonSchema)(
1917
- operation.input,
1938
+ inputJsonSchema,
1918
1939
  validator
1919
1940
  );
1920
1941
  const outputSchema = (0, import_server2.fromJsonSchema)(
@@ -1922,6 +1943,7 @@ function registerTinyCloudTools(server, selection, validator) {
1922
1943
  validator
1923
1944
  );
1924
1945
  const annotations = {
1946
+ ...selection.annotationTitles === true ? { title: operation.title } : {},
1925
1947
  readOnlyHint: binding.readOnlyHint,
1926
1948
  idempotentHint: binding.idempotentHint,
1927
1949
  destructiveHint: binding.destructiveHint,
@@ -1941,19 +1963,22 @@ function registerTinyCloudTools(server, selection, validator) {
1941
1963
  const metrics = { replayedGrants: 0 };
1942
1964
  let code = "INTERNAL_ERROR";
1943
1965
  try {
1944
- await selection.beforeOperation?.();
1945
- const result = await (0, import_operations2.invokeOperation)(
1946
- binding.operationId,
1947
- binding.operationVersion,
1948
- invocationTargetForMcp(selection),
1949
- input,
1950
- metrics
1951
- );
1952
- const projected = selection.transformOperationResult === void 0 ? result : await selection.transformOperationResult(result, {
1953
- operationId: binding.operationId,
1954
- operationVersion: binding.operationVersion,
1955
- input
1956
- });
1966
+ let projected = offersCatalogApps ? void 0 : catalogAppRefusal(binding, selection.profile, input);
1967
+ if (projected === void 0) {
1968
+ await selection.beforeOperation?.();
1969
+ const result = await (0, import_operations2.invokeOperation)(
1970
+ binding.operationId,
1971
+ binding.operationVersion,
1972
+ invocationTargetForMcp(selection),
1973
+ input,
1974
+ metrics
1975
+ );
1976
+ projected = selection.transformOperationResult === void 0 ? result : await selection.transformOperationResult(result, {
1977
+ operationId: binding.operationId,
1978
+ operationVersion: binding.operationVersion,
1979
+ input
1980
+ });
1981
+ }
1957
1982
  const response = toMcpToolResult(projected, bindings, {
1958
1983
  surface: selection.surface === "local" ? "local" : "hosted",
1959
1984
  readOnly: binding.readOnlyHint,
@@ -1985,7 +2010,7 @@ function outcomeCode(result) {
1985
2010
  // package.json
1986
2011
  var package_default = {
1987
2012
  name: "@tinycloud/mcp",
1988
- version: "0.10.0-beta.9",
2013
+ version: "0.10.0",
1989
2014
  description: "TinyCloud delegated operations MCP server",
1990
2015
  keywords: [
1991
2016
  "tinycloud",
@@ -2056,9 +2081,10 @@ var package_default = {
2056
2081
  dependencies: {
2057
2082
  "@modelcontextprotocol/node": "2.0.0-beta.5",
2058
2083
  "@modelcontextprotocol/server": "2.0.0-beta.5",
2059
- "@tinycloud/node-sdk": "3.12.0-beta.4",
2060
- "@tinycloud/node-sdk-wasm": "1.7.8",
2061
- "@tinycloud/operations": "0.9.0-beta.6",
2084
+ "@tinycloud/node-sdk": "3.12.0",
2085
+ "@tinycloud/sdk-core": "3.12.0",
2086
+ "@tinycloud/node-sdk-wasm": "1.7.9",
2087
+ "@tinycloud/operations": "0.9.0",
2062
2088
  jose: "6.2.4"
2063
2089
  },
2064
2090
  devDependencies: {
@@ -2083,36 +2109,47 @@ var MCP_SERVER_NAME = "tinycloud-mcp";
2083
2109
  // src/http.ts
2084
2110
  var REQUIRED_SCOPE = "tinycloud:mcp";
2085
2111
  var MCP_CORS_ALLOWED_HEADERS = "Authorization, Content-Type, Accept, Mcp-Protocol-Version, Mcp-Session-Id, Last-Event-ID, Mcp-Method, Mcp-Name";
2112
+ var MCP_CORS_EXPOSED_HEADERS = "WWW-Authenticate, Mcp-Session-Id, Mcp-Protocol-Version";
2086
2113
  var LOCAL_CLI_PACKAGE = ["@tinycloud", "cli"].join("/");
2087
2114
  var LOCAL_MCP_PACKAGE = ["@tinycloud", "mcp"].join("/");
2115
+ var RESTRICTED_ADDRESS_PREFIXES = ["chatgpt", "claude", "grok", "muse"];
2116
+ var ANNOTATION_TITLE_PREFIXES = /* @__PURE__ */ new Set(["claude"]);
2088
2117
  function createHostedMcpApp(config) {
2089
2118
  if (config.nativeServiceCredential !== void 0 && Buffer.byteLength(config.nativeServiceCredential, "utf8") < 32) {
2090
2119
  throw new Error("TC_MCP_NATIVE_SERVICE_CREDENTIAL must contain at least 32 bytes.");
2091
2120
  }
2092
2121
  const resourceUrl = canonicalResourceUrl(config.publicUrl);
2093
- const pluginUrl = new URL("./chatgpt/mcp", resourceUrl);
2094
2122
  const statusFor = (resource) => config.introspection === void 0 ? void 0 : createTokenStatusChecker({ ...config.introspection, resourceUrl: resource.toString() });
2095
2123
  const hosted = createHostedSurface(config, resourceUrl, "hosted", statusFor(resourceUrl));
2096
- const plugin = createHostedSurface({
2097
- ...config,
2098
- nativeServiceCredential: void 0,
2099
- stateDir: (0, import_node_path3.join)(config.stateDir, "chatgpt"),
2100
- approvalPath: new URL("./connect", pluginUrl).pathname
2101
- }, pluginUrl, "public", statusFor(pluginUrl));
2102
- const pluginPaths = {
2103
- [pluginUrl.pathname]: true,
2104
- [new URL("./connect", pluginUrl).pathname]: true,
2105
- [new URL("./connect/callback", pluginUrl).pathname]: true,
2106
- [new URL((0, import_server4.getOAuthProtectedResourceMetadataUrl)(pluginUrl)).pathname]: true
2107
- };
2124
+ const surfaces = [hosted];
2125
+ const restrictedByPath = /* @__PURE__ */ new Map();
2126
+ for (const prefix of RESTRICTED_ADDRESS_PREFIXES) {
2127
+ const restrictedUrl = new URL(`./${prefix}/mcp`, resourceUrl);
2128
+ const connectUrl = new URL("./connect", restrictedUrl);
2129
+ const restricted = createHostedSurface({
2130
+ ...config,
2131
+ nativeServiceCredential: void 0,
2132
+ stateDir: (0, import_node_path3.join)(config.stateDir, prefix),
2133
+ approvalPath: connectUrl.pathname
2134
+ }, restrictedUrl, "public", statusFor(restrictedUrl), ANNOTATION_TITLE_PREFIXES.has(prefix));
2135
+ surfaces.push(restricted);
2136
+ for (const owned of [
2137
+ restrictedUrl,
2138
+ connectUrl,
2139
+ new URL("./connect/callback", restrictedUrl),
2140
+ new URL((0, import_server4.getOAuthProtectedResourceMetadataUrl)(restrictedUrl))
2141
+ ]) {
2142
+ restrictedByPath.set(owned.pathname, restricted);
2143
+ }
2144
+ }
2108
2145
  return {
2109
- fetch: (request) => (pluginPaths[new URL(request.url).pathname] === true ? plugin : hosted).fetch(request),
2146
+ fetch: (request) => (restrictedByPath.get(new URL(request.url).pathname) ?? hosted).fetch(request),
2110
2147
  close: async () => {
2111
- await Promise.all([hosted.close(), plugin.close()]);
2148
+ await Promise.all(surfaces.map((surface) => surface.close()));
2112
2149
  }
2113
2150
  };
2114
2151
  }
2115
- function createHostedSurface(config, resourceUrl, surface, tokenStatus) {
2152
+ function createHostedSurface(config, resourceUrl, surface, tokenStatus, annotationTitles = false) {
2116
2153
  const connectPath = config.approvalPath ?? "/connect";
2117
2154
  const callbackPath = `${connectPath}/callback`;
2118
2155
  const issuer = String(config.oauthMetadata.issuer);
@@ -2152,6 +2189,7 @@ function createHostedSurface(config, resourceUrl, surface, tokenStatus) {
2152
2189
  explicitProfile: true,
2153
2190
  allowOwnerProfile: false,
2154
2191
  stateRoot,
2192
+ annotationTitles,
2155
2193
  ...nativeOwner === void 0 ? {} : {
2156
2194
  allowedTools: ["tinycloud_sql_query", "tinycloud_kv_get", "tinycloud_read"]
2157
2195
  },
@@ -2160,7 +2198,7 @@ function createHostedSurface(config, resourceUrl, surface, tokenStatus) {
2160
2198
  transformOperationResult: (result, invocation) => store.decorateAuthorityResult(subject, ownerDids, result, invocation)
2161
2199
  } : {}
2162
2200
  }, validator);
2163
- if (nativeOwner === void 0) registerConnectTool(server, validator, store, identity, surface);
2201
+ if (nativeOwner === void 0) registerConnectTool(server, validator, store, identity, surface, annotationTitles);
2164
2202
  return server;
2165
2203
  }, {
2166
2204
  legacy: "stateless",
@@ -2507,7 +2545,8 @@ Local alternative: install \`${LOCAL_CLI_PACKAGE}\` and \`${LOCAL_MCP_PACKAGE}\`
2507
2545
  close: () => handler.close()
2508
2546
  };
2509
2547
  }
2510
- function registerConnectTool(server, validator, store, identity, surface) {
2548
+ function registerConnectTool(server, validator, store, identity, surface, annotationTitles) {
2549
+ const title = "Connect TinyCloud";
2511
2550
  const inputSchema = (0, import_server4.fromJsonSchema)({ type: "object", properties: {}, additionalProperties: false }, validator);
2512
2551
  const outputSchema = (0, import_server4.fromJsonSchema)({
2513
2552
  type: "object",
@@ -2523,11 +2562,12 @@ function registerConnectTool(server, validator, store, identity, surface) {
2523
2562
  server.registerTool(
2524
2563
  "tinycloud_connect",
2525
2564
  {
2526
- title: "Connect TinyCloud",
2565
+ title,
2527
2566
  description: "Check the hosted delegate connection and return a one-time OpenKey approval URL when setup is required.",
2528
2567
  inputSchema,
2529
2568
  outputSchema,
2530
2569
  annotations: {
2570
+ ...annotationTitles ? { title } : {},
2531
2571
  readOnlyHint: false,
2532
2572
  idempotentHint: true,
2533
2573
  destructiveHint: false,
@@ -2596,7 +2636,7 @@ function mcpCors(response, request) {
2596
2636
  if (request.headers.has("origin")) {
2597
2637
  headers.set("access-control-allow-origin", "*");
2598
2638
  headers.set("access-control-allow-methods", "GET, POST, DELETE, OPTIONS");
2599
- headers.set("access-control-expose-headers", "WWW-Authenticate");
2639
+ headers.set("access-control-expose-headers", MCP_CORS_EXPOSED_HEADERS);
2600
2640
  if (request.method === "OPTIONS") headers.set("access-control-allow-headers", MCP_CORS_ALLOWED_HEADERS);
2601
2641
  }
2602
2642
  return new Response(response.body, { status: response.status, statusText: response.statusText, headers });