@tinycloud/mcp 0.10.0-beta.9 → 0.10.1-beta.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-cli.js CHANGED
@@ -277,6 +277,7 @@ function logToolCall(tool, code, startedAt, replayedGrants) {
277
277
  }
278
278
 
279
279
  // src/remote-store.ts
280
+ import { sameTinyCloudNode } from "@tinycloud/sdk-core";
280
281
  import { createHmac, randomBytes, timingSafeEqual as timingSafeEqual2 } from "crypto";
281
282
  import { chmod, mkdir, readFile, readdir, rename, rm, writeFile } from "fs/promises";
282
283
  import { dirname, join } from "path";
@@ -290,6 +291,7 @@ import {
290
291
  UnsupportedSessionRestoreError,
291
292
  isCapabilitySubset,
292
293
  principalDidEquals,
294
+ publicJwk,
293
295
  siweRuntimeDelegation,
294
296
  signedCompactUcanExpiry
295
297
  } from "@tinycloud/node-sdk";
@@ -368,7 +370,7 @@ var NATIVE_GRANT_IMPORT_REJECTION_CODES = /* @__PURE__ */ new Set([
368
370
  "DELEGATION_HOST_MISMATCH",
369
371
  "DELEGATION_REJECTED"
370
372
  ]);
371
- 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"]);
372
374
  var BOOTSTRAP_PERMISSIONS = [
373
375
  {
374
376
  service: "tinycloud.kv",
@@ -791,6 +793,7 @@ var RemoteTenantStore = class {
791
793
  did: tenant.sessionDid,
792
794
  callback: callback.toString(),
793
795
  host: this.#config.nodeHost,
796
+ requesterOrigin: this.#config.publicUrl.origin,
794
797
  jwk: Buffer.from(JSON.stringify(publicJwk(tenant.jwk))).toString("base64url"),
795
798
  permissions: Buffer.from(JSON.stringify({
796
799
  permissions: pending.permissions,
@@ -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) && sameTinyCloudNode(left, right)) return true;
1427
1426
  try {
1428
1427
  const normalize = (value) => {
1429
1428
  const url = new URL(value);
@@ -1525,6 +1524,7 @@ import { join as join2 } from "path";
1525
1524
  import { fromJsonSchema } from "@modelcontextprotocol/server";
1526
1525
  import { AjvJsonSchemaValidator } from "@modelcontextprotocol/server/validators/ajv";
1527
1526
  import { invokeOperation as invokeOperation2 } from "@tinycloud/operations";
1527
+ import { TC_APPS_CATALOG_APPS } from "@tinycloud/operations/tc-apps";
1528
1528
 
1529
1529
  // src/results.ts
1530
1530
  function toMcpToolResult(result, bindings = [], options = {}) {
@@ -1865,7 +1865,7 @@ var TOOL_BINDINGS = [
1865
1865
  operationVersion: 1,
1866
1866
  readOnlyHint: false,
1867
1867
  idempotentHint: true,
1868
- destructiveHint: true,
1868
+ destructiveHint: false,
1869
1869
  openWorldHint: false,
1870
1870
  surfaces: ["hosted", "public"]
1871
1871
  },
@@ -1895,19 +1895,9 @@ var TOOL_BINDINGS = [
1895
1895
  operationVersion: 1,
1896
1896
  readOnlyHint: false,
1897
1897
  idempotentHint: true,
1898
- destructiveHint: true,
1899
- openWorldHint: false,
1900
- surfaces: ["hosted", "public"]
1901
- },
1902
- {
1903
- name: "tinycloud_apps_move",
1904
- operationId: "tinycloud.apps.move",
1905
- operationVersion: 1,
1906
- readOnlyHint: false,
1907
- idempotentHint: true,
1908
1898
  destructiveHint: false,
1909
1899
  openWorldHint: false,
1910
- surfaces: ["hosted"]
1900
+ surfaces: ["hosted", "public"]
1911
1901
  }
1912
1902
  ];
1913
1903
  var definitions = new Map(generatedCatalog.operations.map((operation) => [
@@ -1918,18 +1908,50 @@ var definitions = new Map(generatedCatalog.operations.map((operation) => [
1918
1908
  result: toMcpJsonSchema(operation.result)
1919
1909
  }
1920
1910
  ]));
1911
+ var CATALOG_APP_TOOLS = [
1912
+ "tinycloud_knowledge_list",
1913
+ "tinycloud_knowledge_read",
1914
+ "tinycloud_sql_query",
1915
+ "tinycloud_sql_execute"
1916
+ ];
1917
+ var APP_WITHOUT_CATALOG_APPS = "Pass one existing personal app id to request its task access together.";
1918
+ function withPropertyDescription(schema, property, description) {
1919
+ const properties = schema.properties;
1920
+ const current = properties?.[property];
1921
+ if (current === void 0) throw new Error(`Generated operations catalog has no ${property} input to describe.`);
1922
+ return { ...schema, properties: { ...properties, [property]: { ...current, description } } };
1923
+ }
1924
+ function catalogAppRefusal(binding, profile, input) {
1925
+ const app = typeof input === "object" && input !== null ? input.app : void 0;
1926
+ if (typeof app !== "string" || !Object.hasOwn(TC_APPS_CATALOG_APPS, app)) return void 0;
1927
+ const { title, link } = TC_APPS_CATALOG_APPS[app];
1928
+ return {
1929
+ status: "error",
1930
+ operation: { operationId: binding.operationId, operationVersion: binding.operationVersion },
1931
+ context: { profile, host: "unresolved", posture: "unauthenticated" },
1932
+ error: {
1933
+ code: "INPUT_INVALID",
1934
+ 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.`,
1935
+ retryable: false,
1936
+ details: { reason: "catalog_app_unavailable", app, link }
1937
+ }
1938
+ };
1939
+ }
1921
1940
  function createJsonSchemaValidator() {
1922
1941
  return new AjvJsonSchemaValidator();
1923
1942
  }
1924
1943
  function registerTinyCloudTools(server, selection, validator) {
1925
1944
  const bindings = TOOL_BINDINGS.filter((binding) => bindingSurfaces(binding).includes(selection.surface) && (selection.allowedTools === void 0 || selection.allowedTools.includes(binding.name)));
1945
+ const servesCatalogApps = CATALOG_APP_TOOLS.every((name) => bindings.some((binding) => binding.name === name));
1926
1946
  for (const binding of bindings) {
1927
1947
  const operation = definitions.get(`${binding.operationId}@${binding.operationVersion}`);
1928
1948
  if (operation === void 0) {
1929
1949
  throw new Error(`Generated operations catalog is missing ${binding.operationId}@${binding.operationVersion}.`);
1930
1950
  }
1951
+ const offersCatalogApps = servesCatalogApps || binding.operationId !== "tinycloud.apps.context";
1952
+ const inputJsonSchema = offersCatalogApps ? operation.input : withPropertyDescription(operation.input, "app", APP_WITHOUT_CATALOG_APPS);
1931
1953
  const inputSchema = fromJsonSchema(
1932
- operation.input,
1954
+ inputJsonSchema,
1933
1955
  validator
1934
1956
  );
1935
1957
  const outputSchema = fromJsonSchema(
@@ -1937,6 +1959,7 @@ function registerTinyCloudTools(server, selection, validator) {
1937
1959
  validator
1938
1960
  );
1939
1961
  const annotations = {
1962
+ ...selection.annotationTitles === true ? { title: operation.title } : {},
1940
1963
  readOnlyHint: binding.readOnlyHint,
1941
1964
  idempotentHint: binding.idempotentHint,
1942
1965
  destructiveHint: binding.destructiveHint,
@@ -1956,19 +1979,22 @@ function registerTinyCloudTools(server, selection, validator) {
1956
1979
  const metrics = { replayedGrants: 0 };
1957
1980
  let code = "INTERNAL_ERROR";
1958
1981
  try {
1959
- await selection.beforeOperation?.();
1960
- const result = await invokeOperation2(
1961
- binding.operationId,
1962
- binding.operationVersion,
1963
- invocationTargetForMcp(selection),
1964
- input,
1965
- metrics
1966
- );
1967
- const projected = selection.transformOperationResult === void 0 ? result : await selection.transformOperationResult(result, {
1968
- operationId: binding.operationId,
1969
- operationVersion: binding.operationVersion,
1970
- input
1971
- });
1982
+ let projected = offersCatalogApps ? void 0 : catalogAppRefusal(binding, selection.profile, input);
1983
+ if (projected === void 0) {
1984
+ await selection.beforeOperation?.();
1985
+ const result = await invokeOperation2(
1986
+ binding.operationId,
1987
+ binding.operationVersion,
1988
+ invocationTargetForMcp(selection),
1989
+ input,
1990
+ metrics
1991
+ );
1992
+ projected = selection.transformOperationResult === void 0 ? result : await selection.transformOperationResult(result, {
1993
+ operationId: binding.operationId,
1994
+ operationVersion: binding.operationVersion,
1995
+ input
1996
+ });
1997
+ }
1972
1998
  const response = toMcpToolResult(projected, bindings, {
1973
1999
  surface: selection.surface === "local" ? "local" : "hosted",
1974
2000
  readOnly: binding.readOnlyHint,
@@ -2000,7 +2026,7 @@ function outcomeCode(result) {
2000
2026
  // package.json
2001
2027
  var package_default = {
2002
2028
  name: "@tinycloud/mcp",
2003
- version: "0.10.0-beta.9",
2029
+ version: "0.10.1-beta.0",
2004
2030
  description: "TinyCloud delegated operations MCP server",
2005
2031
  keywords: [
2006
2032
  "tinycloud",
@@ -2071,9 +2097,10 @@ var package_default = {
2071
2097
  dependencies: {
2072
2098
  "@modelcontextprotocol/node": "2.0.0-beta.5",
2073
2099
  "@modelcontextprotocol/server": "2.0.0-beta.5",
2074
- "@tinycloud/node-sdk": "3.12.0-beta.4",
2075
- "@tinycloud/node-sdk-wasm": "1.7.8",
2076
- "@tinycloud/operations": "0.9.0-beta.6",
2100
+ "@tinycloud/node-sdk": "3.12.0",
2101
+ "@tinycloud/sdk-core": "3.12.0",
2102
+ "@tinycloud/node-sdk-wasm": "1.7.9",
2103
+ "@tinycloud/operations": "0.9.1-beta.0",
2077
2104
  jose: "6.2.4"
2078
2105
  },
2079
2106
  devDependencies: {
@@ -2098,36 +2125,47 @@ var MCP_SERVER_NAME = "tinycloud-mcp";
2098
2125
  // src/http.ts
2099
2126
  var REQUIRED_SCOPE = "tinycloud:mcp";
2100
2127
  var MCP_CORS_ALLOWED_HEADERS = "Authorization, Content-Type, Accept, Mcp-Protocol-Version, Mcp-Session-Id, Last-Event-ID, Mcp-Method, Mcp-Name";
2128
+ var MCP_CORS_EXPOSED_HEADERS = "WWW-Authenticate, Mcp-Session-Id, Mcp-Protocol-Version";
2101
2129
  var LOCAL_CLI_PACKAGE = ["@tinycloud", "cli"].join("/");
2102
2130
  var LOCAL_MCP_PACKAGE = ["@tinycloud", "mcp"].join("/");
2131
+ var RESTRICTED_ADDRESS_PREFIXES = ["chatgpt", "claude", "grok", "muse"];
2132
+ var ANNOTATION_TITLE_PREFIXES = /* @__PURE__ */ new Set(["claude"]);
2103
2133
  function createHostedMcpApp(config) {
2104
2134
  if (config.nativeServiceCredential !== void 0 && Buffer.byteLength(config.nativeServiceCredential, "utf8") < 32) {
2105
2135
  throw new Error("TC_MCP_NATIVE_SERVICE_CREDENTIAL must contain at least 32 bytes.");
2106
2136
  }
2107
2137
  const resourceUrl = canonicalResourceUrl(config.publicUrl);
2108
- const pluginUrl = new URL("./chatgpt/mcp", resourceUrl);
2109
2138
  const statusFor = (resource) => config.introspection === void 0 ? void 0 : createTokenStatusChecker({ ...config.introspection, resourceUrl: resource.toString() });
2110
2139
  const hosted = createHostedSurface(config, resourceUrl, "hosted", statusFor(resourceUrl));
2111
- const plugin = createHostedSurface({
2112
- ...config,
2113
- nativeServiceCredential: void 0,
2114
- stateDir: join3(config.stateDir, "chatgpt"),
2115
- approvalPath: new URL("./connect", pluginUrl).pathname
2116
- }, pluginUrl, "public", statusFor(pluginUrl));
2117
- const pluginPaths = {
2118
- [pluginUrl.pathname]: true,
2119
- [new URL("./connect", pluginUrl).pathname]: true,
2120
- [new URL("./connect/callback", pluginUrl).pathname]: true,
2121
- [new URL(getOAuthProtectedResourceMetadataUrl(pluginUrl)).pathname]: true
2122
- };
2140
+ const surfaces = [hosted];
2141
+ const restrictedByPath = /* @__PURE__ */ new Map();
2142
+ for (const prefix of RESTRICTED_ADDRESS_PREFIXES) {
2143
+ const restrictedUrl = new URL(`./${prefix}/mcp`, resourceUrl);
2144
+ const connectUrl = new URL("./connect", restrictedUrl);
2145
+ const restricted = createHostedSurface({
2146
+ ...config,
2147
+ nativeServiceCredential: void 0,
2148
+ stateDir: join3(config.stateDir, prefix),
2149
+ approvalPath: connectUrl.pathname
2150
+ }, restrictedUrl, "public", statusFor(restrictedUrl), ANNOTATION_TITLE_PREFIXES.has(prefix));
2151
+ surfaces.push(restricted);
2152
+ for (const owned of [
2153
+ restrictedUrl,
2154
+ connectUrl,
2155
+ new URL("./connect/callback", restrictedUrl),
2156
+ new URL(getOAuthProtectedResourceMetadataUrl(restrictedUrl))
2157
+ ]) {
2158
+ restrictedByPath.set(owned.pathname, restricted);
2159
+ }
2160
+ }
2123
2161
  return {
2124
- fetch: (request) => (pluginPaths[new URL(request.url).pathname] === true ? plugin : hosted).fetch(request),
2162
+ fetch: (request) => (restrictedByPath.get(new URL(request.url).pathname) ?? hosted).fetch(request),
2125
2163
  close: async () => {
2126
- await Promise.all([hosted.close(), plugin.close()]);
2164
+ await Promise.all(surfaces.map((surface) => surface.close()));
2127
2165
  }
2128
2166
  };
2129
2167
  }
2130
- function createHostedSurface(config, resourceUrl, surface, tokenStatus) {
2168
+ function createHostedSurface(config, resourceUrl, surface, tokenStatus, annotationTitles = false) {
2131
2169
  const connectPath = config.approvalPath ?? "/connect";
2132
2170
  const callbackPath = `${connectPath}/callback`;
2133
2171
  const issuer = String(config.oauthMetadata.issuer);
@@ -2167,6 +2205,7 @@ function createHostedSurface(config, resourceUrl, surface, tokenStatus) {
2167
2205
  explicitProfile: true,
2168
2206
  allowOwnerProfile: false,
2169
2207
  stateRoot,
2208
+ annotationTitles,
2170
2209
  ...nativeOwner === void 0 ? {} : {
2171
2210
  allowedTools: ["tinycloud_sql_query", "tinycloud_kv_get", "tinycloud_read"]
2172
2211
  },
@@ -2175,7 +2214,7 @@ function createHostedSurface(config, resourceUrl, surface, tokenStatus) {
2175
2214
  transformOperationResult: (result, invocation) => store.decorateAuthorityResult(subject, ownerDids, result, invocation)
2176
2215
  } : {}
2177
2216
  }, validator);
2178
- if (nativeOwner === void 0) registerConnectTool(server, validator, store, identity, surface);
2217
+ if (nativeOwner === void 0) registerConnectTool(server, validator, store, identity, surface, annotationTitles);
2179
2218
  return server;
2180
2219
  }, {
2181
2220
  legacy: "stateless",
@@ -2522,7 +2561,8 @@ Local alternative: install \`${LOCAL_CLI_PACKAGE}\` and \`${LOCAL_MCP_PACKAGE}\`
2522
2561
  close: () => handler.close()
2523
2562
  };
2524
2563
  }
2525
- function registerConnectTool(server, validator, store, identity, surface) {
2564
+ function registerConnectTool(server, validator, store, identity, surface, annotationTitles) {
2565
+ const title = "Connect TinyCloud";
2526
2566
  const inputSchema = fromJsonSchema2({ type: "object", properties: {}, additionalProperties: false }, validator);
2527
2567
  const outputSchema = fromJsonSchema2({
2528
2568
  type: "object",
@@ -2538,11 +2578,12 @@ function registerConnectTool(server, validator, store, identity, surface) {
2538
2578
  server.registerTool(
2539
2579
  "tinycloud_connect",
2540
2580
  {
2541
- title: "Connect TinyCloud",
2581
+ title,
2542
2582
  description: "Check the hosted delegate connection and return a one-time OpenKey approval URL when setup is required.",
2543
2583
  inputSchema,
2544
2584
  outputSchema,
2545
2585
  annotations: {
2586
+ ...annotationTitles ? { title } : {},
2546
2587
  readOnlyHint: false,
2547
2588
  idempotentHint: true,
2548
2589
  destructiveHint: false,
@@ -2611,7 +2652,7 @@ function mcpCors(response, request) {
2611
2652
  if (request.headers.has("origin")) {
2612
2653
  headers.set("access-control-allow-origin", "*");
2613
2654
  headers.set("access-control-allow-methods", "GET, POST, DELETE, OPTIONS");
2614
- headers.set("access-control-expose-headers", "WWW-Authenticate");
2655
+ headers.set("access-control-expose-headers", MCP_CORS_EXPOSED_HEADERS);
2615
2656
  if (request.method === "OPTIONS") headers.set("access-control-allow-headers", MCP_CORS_ALLOWED_HEADERS);
2616
2657
  }
2617
2658
  return new Response(response.body, { status: response.status, statusText: response.statusText, headers });