@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-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,7 +793,8 @@ 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: [
@@ -1099,10 +1101,10 @@ var RemoteTenantStore = class {
1099
1101
  authMethod: "openkey",
1100
1102
  openkeyHost: this.#config.openkeyHost
1101
1103
  });
1102
- } 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(/\/+$/, "")) {
1103
1105
  await secureWrite(profilePath, { ...profile, host: this.#config.nodeHost });
1104
1106
  process.stderr.write(
1105
- `[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}
1106
1108
  `
1107
1109
  );
1108
1110
  }
@@ -1408,11 +1410,6 @@ function sessionFromCallback(data, privateJwk) {
1408
1410
  signature: data.signature
1409
1411
  };
1410
1412
  }
1411
- function publicJwk(jwk) {
1412
- const copy = { ...jwk };
1413
- for (const field of ["d", "p", "q", "dp", "dq", "qi", "oth", "k"]) delete copy[field];
1414
- return copy;
1415
- }
1416
1413
  function samePrincipal(left, right) {
1417
1414
  if (typeof left !== "string") return false;
1418
1415
  try {
@@ -1425,6 +1422,7 @@ function normalizeDid(value) {
1425
1422
  return value.split("#", 1)[0];
1426
1423
  }
1427
1424
  function sameNodeHost(left, right) {
1425
+ if (PRODUCTION_NODE_HOSTS.has(left) && (0, import_sdk_core.sameTinyCloudNode)(left, right)) return true;
1428
1426
  try {
1429
1427
  const normalize = (value) => {
1430
1428
  const url = new URL(value);
@@ -1526,6 +1524,7 @@ var import_node_path2 = require("path");
1526
1524
  var import_server2 = require("@modelcontextprotocol/server");
1527
1525
  var import_ajv = require("@modelcontextprotocol/server/validators/ajv");
1528
1526
  var import_operations2 = require("@tinycloud/operations");
1527
+ var import_tc_apps2 = require("@tinycloud/operations/tc-apps");
1529
1528
 
1530
1529
  // src/results.ts
1531
1530
  function toMcpToolResult(result, bindings = [], options = {}) {
@@ -1867,7 +1866,7 @@ var TOOL_BINDINGS = [
1867
1866
  operationVersion: 1,
1868
1867
  readOnlyHint: false,
1869
1868
  idempotentHint: true,
1870
- destructiveHint: true,
1869
+ destructiveHint: false,
1871
1870
  openWorldHint: false,
1872
1871
  surfaces: ["hosted", "public"]
1873
1872
  },
@@ -1897,19 +1896,9 @@ var TOOL_BINDINGS = [
1897
1896
  operationVersion: 1,
1898
1897
  readOnlyHint: false,
1899
1898
  idempotentHint: true,
1900
- destructiveHint: true,
1901
- openWorldHint: false,
1902
- surfaces: ["hosted", "public"]
1903
- },
1904
- {
1905
- name: "tinycloud_apps_move",
1906
- operationId: "tinycloud.apps.move",
1907
- operationVersion: 1,
1908
- readOnlyHint: false,
1909
- idempotentHint: true,
1910
1899
  destructiveHint: false,
1911
1900
  openWorldHint: false,
1912
- surfaces: ["hosted"]
1901
+ surfaces: ["hosted", "public"]
1913
1902
  }
1914
1903
  ];
1915
1904
  var definitions = new Map(generatedCatalog.operations.map((operation) => [
@@ -1920,18 +1909,50 @@ var definitions = new Map(generatedCatalog.operations.map((operation) => [
1920
1909
  result: toMcpJsonSchema(operation.result)
1921
1910
  }
1922
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
+ }
1923
1941
  function createJsonSchemaValidator() {
1924
1942
  return new import_ajv.AjvJsonSchemaValidator();
1925
1943
  }
1926
1944
  function registerTinyCloudTools(server, selection, validator) {
1927
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));
1928
1947
  for (const binding of bindings) {
1929
1948
  const operation = definitions.get(`${binding.operationId}@${binding.operationVersion}`);
1930
1949
  if (operation === void 0) {
1931
1950
  throw new Error(`Generated operations catalog is missing ${binding.operationId}@${binding.operationVersion}.`);
1932
1951
  }
1952
+ const offersCatalogApps = servesCatalogApps || binding.operationId !== "tinycloud.apps.context";
1953
+ const inputJsonSchema = offersCatalogApps ? operation.input : withPropertyDescription(operation.input, "app", APP_WITHOUT_CATALOG_APPS);
1933
1954
  const inputSchema = (0, import_server2.fromJsonSchema)(
1934
- operation.input,
1955
+ inputJsonSchema,
1935
1956
  validator
1936
1957
  );
1937
1958
  const outputSchema = (0, import_server2.fromJsonSchema)(
@@ -1939,6 +1960,7 @@ function registerTinyCloudTools(server, selection, validator) {
1939
1960
  validator
1940
1961
  );
1941
1962
  const annotations = {
1963
+ ...selection.annotationTitles === true ? { title: operation.title } : {},
1942
1964
  readOnlyHint: binding.readOnlyHint,
1943
1965
  idempotentHint: binding.idempotentHint,
1944
1966
  destructiveHint: binding.destructiveHint,
@@ -1958,19 +1980,22 @@ function registerTinyCloudTools(server, selection, validator) {
1958
1980
  const metrics = { replayedGrants: 0 };
1959
1981
  let code = "INTERNAL_ERROR";
1960
1982
  try {
1961
- await selection.beforeOperation?.();
1962
- const result = await (0, import_operations2.invokeOperation)(
1963
- binding.operationId,
1964
- binding.operationVersion,
1965
- invocationTargetForMcp(selection),
1966
- input,
1967
- metrics
1968
- );
1969
- const projected = selection.transformOperationResult === void 0 ? result : await selection.transformOperationResult(result, {
1970
- operationId: binding.operationId,
1971
- operationVersion: binding.operationVersion,
1972
- input
1973
- });
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
+ }
1974
1999
  const response = toMcpToolResult(projected, bindings, {
1975
2000
  surface: selection.surface === "local" ? "local" : "hosted",
1976
2001
  readOnly: binding.readOnlyHint,
@@ -2002,7 +2027,7 @@ function outcomeCode(result) {
2002
2027
  // package.json
2003
2028
  var package_default = {
2004
2029
  name: "@tinycloud/mcp",
2005
- version: "0.10.0-beta.9",
2030
+ version: "0.10.0",
2006
2031
  description: "TinyCloud delegated operations MCP server",
2007
2032
  keywords: [
2008
2033
  "tinycloud",
@@ -2073,9 +2098,10 @@ var package_default = {
2073
2098
  dependencies: {
2074
2099
  "@modelcontextprotocol/node": "2.0.0-beta.5",
2075
2100
  "@modelcontextprotocol/server": "2.0.0-beta.5",
2076
- "@tinycloud/node-sdk": "3.12.0-beta.4",
2077
- "@tinycloud/node-sdk-wasm": "1.7.8",
2078
- "@tinycloud/operations": "0.9.0-beta.6",
2101
+ "@tinycloud/node-sdk": "3.12.0",
2102
+ "@tinycloud/sdk-core": "3.12.0",
2103
+ "@tinycloud/node-sdk-wasm": "1.7.9",
2104
+ "@tinycloud/operations": "0.9.0",
2079
2105
  jose: "6.2.4"
2080
2106
  },
2081
2107
  devDependencies: {
@@ -2100,36 +2126,47 @@ var MCP_SERVER_NAME = "tinycloud-mcp";
2100
2126
  // src/http.ts
2101
2127
  var REQUIRED_SCOPE = "tinycloud:mcp";
2102
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";
2103
2130
  var LOCAL_CLI_PACKAGE = ["@tinycloud", "cli"].join("/");
2104
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"]);
2105
2134
  function createHostedMcpApp(config) {
2106
2135
  if (config.nativeServiceCredential !== void 0 && Buffer.byteLength(config.nativeServiceCredential, "utf8") < 32) {
2107
2136
  throw new Error("TC_MCP_NATIVE_SERVICE_CREDENTIAL must contain at least 32 bytes.");
2108
2137
  }
2109
2138
  const resourceUrl = canonicalResourceUrl(config.publicUrl);
2110
- const pluginUrl = new URL("./chatgpt/mcp", resourceUrl);
2111
2139
  const statusFor = (resource) => config.introspection === void 0 ? void 0 : createTokenStatusChecker({ ...config.introspection, resourceUrl: resource.toString() });
2112
2140
  const hosted = createHostedSurface(config, resourceUrl, "hosted", statusFor(resourceUrl));
2113
- const plugin = createHostedSurface({
2114
- ...config,
2115
- nativeServiceCredential: void 0,
2116
- stateDir: (0, import_node_path3.join)(config.stateDir, "chatgpt"),
2117
- approvalPath: new URL("./connect", pluginUrl).pathname
2118
- }, pluginUrl, "public", statusFor(pluginUrl));
2119
- const pluginPaths = {
2120
- [pluginUrl.pathname]: true,
2121
- [new URL("./connect", pluginUrl).pathname]: true,
2122
- [new URL("./connect/callback", pluginUrl).pathname]: true,
2123
- [new URL((0, import_server4.getOAuthProtectedResourceMetadataUrl)(pluginUrl)).pathname]: true
2124
- };
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
+ }
2125
2162
  return {
2126
- 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),
2127
2164
  close: async () => {
2128
- await Promise.all([hosted.close(), plugin.close()]);
2165
+ await Promise.all(surfaces.map((surface) => surface.close()));
2129
2166
  }
2130
2167
  };
2131
2168
  }
2132
- function createHostedSurface(config, resourceUrl, surface, tokenStatus) {
2169
+ function createHostedSurface(config, resourceUrl, surface, tokenStatus, annotationTitles = false) {
2133
2170
  const connectPath = config.approvalPath ?? "/connect";
2134
2171
  const callbackPath = `${connectPath}/callback`;
2135
2172
  const issuer = String(config.oauthMetadata.issuer);
@@ -2169,6 +2206,7 @@ function createHostedSurface(config, resourceUrl, surface, tokenStatus) {
2169
2206
  explicitProfile: true,
2170
2207
  allowOwnerProfile: false,
2171
2208
  stateRoot,
2209
+ annotationTitles,
2172
2210
  ...nativeOwner === void 0 ? {} : {
2173
2211
  allowedTools: ["tinycloud_sql_query", "tinycloud_kv_get", "tinycloud_read"]
2174
2212
  },
@@ -2177,7 +2215,7 @@ function createHostedSurface(config, resourceUrl, surface, tokenStatus) {
2177
2215
  transformOperationResult: (result, invocation) => store.decorateAuthorityResult(subject, ownerDids, result, invocation)
2178
2216
  } : {}
2179
2217
  }, validator);
2180
- if (nativeOwner === void 0) registerConnectTool(server, validator, store, identity, surface);
2218
+ if (nativeOwner === void 0) registerConnectTool(server, validator, store, identity, surface, annotationTitles);
2181
2219
  return server;
2182
2220
  }, {
2183
2221
  legacy: "stateless",
@@ -2524,7 +2562,8 @@ Local alternative: install \`${LOCAL_CLI_PACKAGE}\` and \`${LOCAL_MCP_PACKAGE}\`
2524
2562
  close: () => handler.close()
2525
2563
  };
2526
2564
  }
2527
- function registerConnectTool(server, validator, store, identity, surface) {
2565
+ function registerConnectTool(server, validator, store, identity, surface, annotationTitles) {
2566
+ const title = "Connect TinyCloud";
2528
2567
  const inputSchema = (0, import_server4.fromJsonSchema)({ type: "object", properties: {}, additionalProperties: false }, validator);
2529
2568
  const outputSchema = (0, import_server4.fromJsonSchema)({
2530
2569
  type: "object",
@@ -2540,11 +2579,12 @@ function registerConnectTool(server, validator, store, identity, surface) {
2540
2579
  server.registerTool(
2541
2580
  "tinycloud_connect",
2542
2581
  {
2543
- title: "Connect TinyCloud",
2582
+ title,
2544
2583
  description: "Check the hosted delegate connection and return a one-time OpenKey approval URL when setup is required.",
2545
2584
  inputSchema,
2546
2585
  outputSchema,
2547
2586
  annotations: {
2587
+ ...annotationTitles ? { title } : {},
2548
2588
  readOnlyHint: false,
2549
2589
  idempotentHint: true,
2550
2590
  destructiveHint: false,
@@ -2613,7 +2653,7 @@ function mcpCors(response, request) {
2613
2653
  if (request.headers.has("origin")) {
2614
2654
  headers.set("access-control-allow-origin", "*");
2615
2655
  headers.set("access-control-allow-methods", "GET, POST, DELETE, OPTIONS");
2616
- headers.set("access-control-expose-headers", "WWW-Authenticate");
2656
+ headers.set("access-control-expose-headers", MCP_CORS_EXPOSED_HEADERS);
2617
2657
  if (request.method === "OPTIONS") headers.set("access-control-allow-headers", MCP_CORS_ALLOWED_HEADERS);
2618
2658
  }
2619
2659
  return new Response(response.body, { status: response.status, statusText: response.statusText, headers });