@tinycloud/mcp 0.10.0-beta.5 → 0.10.0-beta.50
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/README.md +49 -31
- package/dist/cli.cjs +57 -30
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +57 -30
- package/dist/cli.js.map +1 -1
- package/dist/http-cli.cjs +97 -59
- package/dist/http-cli.cjs.map +1 -1
- package/dist/http-cli.js +97 -58
- package/dist/http-cli.js.map +1 -1
- package/dist/http.cjs +97 -59
- package/dist/http.cjs.map +1 -1
- package/dist/http.js +97 -58
- package/dist/http.js.map +1 -1
- package/dist/index.cjs +102 -65
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +98 -60
- package/dist/index.js.map +1 -1
- package/dist/server.cjs +57 -30
- package/dist/server.cjs.map +1 -1
- package/dist/server.js +57 -30
- package/dist/server.js.map +1 -1
- package/dist/tools.cjs +53 -28
- package/dist/tools.cjs.map +1 -1
- package/dist/tools.d.cts +1 -1
- package/dist/tools.d.ts +1 -1
- package/dist/tools.js +53 -28
- package/dist/tools.js.map +1 -1
- package/generated/mcp-facts.json +16 -18
- package/package.json +5 -4
- package/skills/tinycloud-delegated-secrets/SKILL.md +4 -3
package/dist/index.js
CHANGED
|
@@ -12,6 +12,7 @@ import { join } from "path";
|
|
|
12
12
|
import { fromJsonSchema } from "@modelcontextprotocol/server";
|
|
13
13
|
import { AjvJsonSchemaValidator } from "@modelcontextprotocol/server/validators/ajv";
|
|
14
14
|
import { invokeOperation } from "@tinycloud/operations";
|
|
15
|
+
import { TC_APPS_CATALOG_APPS } from "@tinycloud/operations/tc-apps";
|
|
15
16
|
|
|
16
17
|
// src/results.ts
|
|
17
18
|
function toMcpToolResult(result, bindings = [], options = {}) {
|
|
@@ -169,8 +170,7 @@ var TOOL_NAMES = [
|
|
|
169
170
|
"tinycloud_apps_context",
|
|
170
171
|
"tinycloud_apps_read",
|
|
171
172
|
"tinycloud_apps_write",
|
|
172
|
-
"tinycloud_apps_query"
|
|
173
|
-
"tinycloud_apps_move"
|
|
173
|
+
"tinycloud_apps_query"
|
|
174
174
|
];
|
|
175
175
|
function invocationTargetForMcp(selection) {
|
|
176
176
|
return {
|
|
@@ -394,7 +394,7 @@ var TOOL_BINDINGS = [
|
|
|
394
394
|
operationVersion: 1,
|
|
395
395
|
readOnlyHint: false,
|
|
396
396
|
idempotentHint: true,
|
|
397
|
-
destructiveHint:
|
|
397
|
+
destructiveHint: false,
|
|
398
398
|
openWorldHint: false,
|
|
399
399
|
surfaces: ["hosted", "public"]
|
|
400
400
|
},
|
|
@@ -424,19 +424,9 @@ var TOOL_BINDINGS = [
|
|
|
424
424
|
operationVersion: 1,
|
|
425
425
|
readOnlyHint: false,
|
|
426
426
|
idempotentHint: true,
|
|
427
|
-
destructiveHint: true,
|
|
428
|
-
openWorldHint: false,
|
|
429
|
-
surfaces: ["hosted", "public"]
|
|
430
|
-
},
|
|
431
|
-
{
|
|
432
|
-
name: "tinycloud_apps_move",
|
|
433
|
-
operationId: "tinycloud.apps.move",
|
|
434
|
-
operationVersion: 1,
|
|
435
|
-
readOnlyHint: false,
|
|
436
|
-
idempotentHint: true,
|
|
437
427
|
destructiveHint: false,
|
|
438
428
|
openWorldHint: false,
|
|
439
|
-
surfaces: ["hosted"]
|
|
429
|
+
surfaces: ["hosted", "public"]
|
|
440
430
|
}
|
|
441
431
|
];
|
|
442
432
|
var definitions = new Map(generatedCatalog.operations.map((operation) => [
|
|
@@ -447,18 +437,50 @@ var definitions = new Map(generatedCatalog.operations.map((operation) => [
|
|
|
447
437
|
result: toMcpJsonSchema(operation.result)
|
|
448
438
|
}
|
|
449
439
|
]));
|
|
440
|
+
var CATALOG_APP_TOOLS = [
|
|
441
|
+
"tinycloud_knowledge_list",
|
|
442
|
+
"tinycloud_knowledge_read",
|
|
443
|
+
"tinycloud_sql_query",
|
|
444
|
+
"tinycloud_sql_execute"
|
|
445
|
+
];
|
|
446
|
+
var APP_WITHOUT_CATALOG_APPS = "Pass one existing personal app id to request its task access together.";
|
|
447
|
+
function withPropertyDescription(schema, property, description) {
|
|
448
|
+
const properties = schema.properties;
|
|
449
|
+
const current = properties?.[property];
|
|
450
|
+
if (current === void 0) throw new Error(`Generated operations catalog has no ${property} input to describe.`);
|
|
451
|
+
return { ...schema, properties: { ...properties, [property]: { ...current, description } } };
|
|
452
|
+
}
|
|
453
|
+
function catalogAppRefusal(binding, profile, input) {
|
|
454
|
+
const app = typeof input === "object" && input !== null ? input.app : void 0;
|
|
455
|
+
if (typeof app !== "string" || !Object.hasOwn(TC_APPS_CATALOG_APPS, app)) return void 0;
|
|
456
|
+
const { title, link } = TC_APPS_CATALOG_APPS[app];
|
|
457
|
+
return {
|
|
458
|
+
status: "error",
|
|
459
|
+
operation: { operationId: binding.operationId, operationVersion: binding.operationVersion },
|
|
460
|
+
context: { profile, host: "unresolved", posture: "unauthenticated" },
|
|
461
|
+
error: {
|
|
462
|
+
code: "INPUT_INVALID",
|
|
463
|
+
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.`,
|
|
464
|
+
retryable: false,
|
|
465
|
+
details: { reason: "catalog_app_unavailable", app, link }
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
}
|
|
450
469
|
function createJsonSchemaValidator() {
|
|
451
470
|
return new AjvJsonSchemaValidator();
|
|
452
471
|
}
|
|
453
472
|
function registerTinyCloudTools(server, selection, validator) {
|
|
454
473
|
const bindings = TOOL_BINDINGS.filter((binding) => bindingSurfaces(binding).includes(selection.surface) && (selection.allowedTools === void 0 || selection.allowedTools.includes(binding.name)));
|
|
474
|
+
const servesCatalogApps = CATALOG_APP_TOOLS.every((name) => bindings.some((binding) => binding.name === name));
|
|
455
475
|
for (const binding of bindings) {
|
|
456
476
|
const operation = definitions.get(`${binding.operationId}@${binding.operationVersion}`);
|
|
457
477
|
if (operation === void 0) {
|
|
458
478
|
throw new Error(`Generated operations catalog is missing ${binding.operationId}@${binding.operationVersion}.`);
|
|
459
479
|
}
|
|
480
|
+
const offersCatalogApps = servesCatalogApps || binding.operationId !== "tinycloud.apps.context";
|
|
481
|
+
const inputJsonSchema = offersCatalogApps ? operation.input : withPropertyDescription(operation.input, "app", APP_WITHOUT_CATALOG_APPS);
|
|
460
482
|
const inputSchema = fromJsonSchema(
|
|
461
|
-
|
|
483
|
+
inputJsonSchema,
|
|
462
484
|
validator
|
|
463
485
|
);
|
|
464
486
|
const outputSchema = fromJsonSchema(
|
|
@@ -485,19 +507,22 @@ function registerTinyCloudTools(server, selection, validator) {
|
|
|
485
507
|
const metrics = { replayedGrants: 0 };
|
|
486
508
|
let code = "INTERNAL_ERROR";
|
|
487
509
|
try {
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
510
|
+
let projected = offersCatalogApps ? void 0 : catalogAppRefusal(binding, selection.profile, input);
|
|
511
|
+
if (projected === void 0) {
|
|
512
|
+
await selection.beforeOperation?.();
|
|
513
|
+
const result = await invokeOperation(
|
|
514
|
+
binding.operationId,
|
|
515
|
+
binding.operationVersion,
|
|
516
|
+
invocationTargetForMcp(selection),
|
|
517
|
+
input,
|
|
518
|
+
metrics
|
|
519
|
+
);
|
|
520
|
+
projected = selection.transformOperationResult === void 0 ? result : await selection.transformOperationResult(result, {
|
|
521
|
+
operationId: binding.operationId,
|
|
522
|
+
operationVersion: binding.operationVersion,
|
|
523
|
+
input
|
|
524
|
+
});
|
|
525
|
+
}
|
|
501
526
|
const response = toMcpToolResult(projected, bindings, {
|
|
502
527
|
surface: selection.surface === "local" ? "local" : "hosted",
|
|
503
528
|
readOnly: binding.readOnlyHint,
|
|
@@ -529,7 +554,7 @@ function outcomeCode(result) {
|
|
|
529
554
|
// package.json
|
|
530
555
|
var package_default = {
|
|
531
556
|
name: "@tinycloud/mcp",
|
|
532
|
-
version: "0.10.0-beta.
|
|
557
|
+
version: "0.10.0-beta.50",
|
|
533
558
|
description: "TinyCloud delegated operations MCP server",
|
|
534
559
|
keywords: [
|
|
535
560
|
"tinycloud",
|
|
@@ -600,9 +625,10 @@ var package_default = {
|
|
|
600
625
|
dependencies: {
|
|
601
626
|
"@modelcontextprotocol/node": "2.0.0-beta.5",
|
|
602
627
|
"@modelcontextprotocol/server": "2.0.0-beta.5",
|
|
603
|
-
"@tinycloud/node-sdk": "3.12.0-beta.
|
|
604
|
-
"@tinycloud/
|
|
605
|
-
"@tinycloud/
|
|
628
|
+
"@tinycloud/node-sdk": "3.12.0-beta.38",
|
|
629
|
+
"@tinycloud/sdk-core": "3.12.0-beta.37",
|
|
630
|
+
"@tinycloud/node-sdk-wasm": "1.7.9-beta.0",
|
|
631
|
+
"@tinycloud/operations": "0.9.0-beta.45",
|
|
606
632
|
jose: "6.2.4"
|
|
607
633
|
},
|
|
608
634
|
devDependencies: {
|
|
@@ -991,6 +1017,7 @@ function claims(token) {
|
|
|
991
1017
|
}
|
|
992
1018
|
|
|
993
1019
|
// src/remote-store.ts
|
|
1020
|
+
import { sameTinyCloudNode } from "@tinycloud/sdk-core";
|
|
994
1021
|
import { createHmac, randomBytes, timingSafeEqual as timingSafeEqual2 } from "crypto";
|
|
995
1022
|
import { chmod, mkdir, readFile, readdir, rename, rm, writeFile } from "fs/promises";
|
|
996
1023
|
import { dirname, join as join2 } from "path";
|
|
@@ -1004,6 +1031,7 @@ import {
|
|
|
1004
1031
|
UnsupportedSessionRestoreError,
|
|
1005
1032
|
isCapabilitySubset,
|
|
1006
1033
|
principalDidEquals,
|
|
1034
|
+
publicJwk,
|
|
1007
1035
|
siweRuntimeDelegation,
|
|
1008
1036
|
signedCompactUcanExpiry
|
|
1009
1037
|
} from "@tinycloud/node-sdk";
|
|
@@ -1082,7 +1110,7 @@ var NATIVE_GRANT_IMPORT_REJECTION_CODES = /* @__PURE__ */ new Set([
|
|
|
1082
1110
|
"DELEGATION_HOST_MISMATCH",
|
|
1083
1111
|
"DELEGATION_REJECTED"
|
|
1084
1112
|
]);
|
|
1085
|
-
var
|
|
1113
|
+
var PRODUCTION_NODE_HOSTS = /* @__PURE__ */ new Set(["https://node.tinycloud.xyz", "https://tee.node.tinycloud.xyz"]);
|
|
1086
1114
|
var BOOTSTRAP_PERMISSIONS = [
|
|
1087
1115
|
{
|
|
1088
1116
|
service: "tinycloud.kv",
|
|
@@ -1505,14 +1533,16 @@ var RemoteTenantStore = class {
|
|
|
1505
1533
|
did: tenant.sessionDid,
|
|
1506
1534
|
callback: callback.toString(),
|
|
1507
1535
|
host: this.#config.nodeHost,
|
|
1536
|
+
requesterOrigin: this.#config.publicUrl.origin,
|
|
1508
1537
|
jwk: Buffer.from(JSON.stringify(publicJwk(tenant.jwk))).toString("base64url"),
|
|
1509
1538
|
permissions: Buffer.from(JSON.stringify({
|
|
1510
1539
|
permissions: pending.permissions,
|
|
1511
1540
|
reason: [
|
|
1512
1541
|
pending.kind === "bootstrap" ? "Connect this TinyCloud account to the hosted MCP delegate." : tcAppsApprovalReason(pending.permissions) ?? "Approve the exact capabilities requested by the TinyCloud MCP operation.",
|
|
1513
1542
|
// Owner DIDs come from the verified OpenKey access token of the MCP
|
|
1514
|
-
// client that created this link, never from the link itself.
|
|
1515
|
-
|
|
1543
|
+
// client that created this link, never from the link itself. The
|
|
1544
|
+
// callback refuses a signer outside them, so the approver isn't asked to check.
|
|
1545
|
+
...pending.ownerDids.length === 0 ? [] : [`Requested by TinyCloud account ${pending.ownerDids.join(", ")}.`]
|
|
1516
1546
|
].join(" ")
|
|
1517
1547
|
})).toString("base64url"),
|
|
1518
1548
|
expiry: this.#config.delegationExpiry
|
|
@@ -1811,10 +1841,10 @@ var RemoteTenantStore = class {
|
|
|
1811
1841
|
authMethod: "openkey",
|
|
1812
1842
|
openkeyHost: this.#config.openkeyHost
|
|
1813
1843
|
});
|
|
1814
|
-
} else if (typeof profile.host === "string" && profile.host.replace(/\/+$/, "")
|
|
1844
|
+
} 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(/\/+$/, "")) {
|
|
1815
1845
|
await secureWrite(profilePath, { ...profile, host: this.#config.nodeHost });
|
|
1816
1846
|
process.stderr.write(
|
|
1817
|
-
`[tinycloud-mcp-http] tenant node host migrated: from=${
|
|
1847
|
+
`[tinycloud-mcp-http] tenant node host migrated: from=${profile.host.replace(/\/+$/, "")} to=${new URL(this.#config.nodeHost).origin}
|
|
1818
1848
|
`
|
|
1819
1849
|
);
|
|
1820
1850
|
}
|
|
@@ -2120,11 +2150,6 @@ function sessionFromCallback(data, privateJwk) {
|
|
|
2120
2150
|
signature: data.signature
|
|
2121
2151
|
};
|
|
2122
2152
|
}
|
|
2123
|
-
function publicJwk(jwk) {
|
|
2124
|
-
const copy = { ...jwk };
|
|
2125
|
-
for (const field of ["d", "p", "q", "dp", "dq", "qi", "oth", "k"]) delete copy[field];
|
|
2126
|
-
return copy;
|
|
2127
|
-
}
|
|
2128
2153
|
function samePrincipal(left, right) {
|
|
2129
2154
|
if (typeof left !== "string") return false;
|
|
2130
2155
|
try {
|
|
@@ -2137,6 +2162,7 @@ function normalizeDid(value) {
|
|
|
2137
2162
|
return value.split("#", 1)[0];
|
|
2138
2163
|
}
|
|
2139
2164
|
function sameNodeHost(left, right) {
|
|
2165
|
+
if (PRODUCTION_NODE_HOSTS.has(left) && sameTinyCloudNode(left, right)) return true;
|
|
2140
2166
|
try {
|
|
2141
2167
|
const normalize = (value) => {
|
|
2142
2168
|
const url = new URL(value);
|
|
@@ -2231,32 +2257,42 @@ function samePendingRequest(pending, expected) {
|
|
|
2231
2257
|
// src/http.ts
|
|
2232
2258
|
var REQUIRED_SCOPE = "tinycloud:mcp";
|
|
2233
2259
|
var MCP_CORS_ALLOWED_HEADERS = "Authorization, Content-Type, Accept, Mcp-Protocol-Version, Mcp-Session-Id, Last-Event-ID, Mcp-Method, Mcp-Name";
|
|
2260
|
+
var MCP_CORS_EXPOSED_HEADERS = "WWW-Authenticate, Mcp-Session-Id, Mcp-Protocol-Version";
|
|
2234
2261
|
var LOCAL_CLI_PACKAGE = ["@tinycloud", "cli"].join("/");
|
|
2235
2262
|
var LOCAL_MCP_PACKAGE = ["@tinycloud", "mcp"].join("/");
|
|
2263
|
+
var RESTRICTED_ADDRESS_PREFIXES = ["chatgpt", "claude", "grok", "muse"];
|
|
2236
2264
|
function createHostedMcpApp(config) {
|
|
2237
2265
|
if (config.nativeServiceCredential !== void 0 && Buffer.byteLength(config.nativeServiceCredential, "utf8") < 32) {
|
|
2238
2266
|
throw new Error("TC_MCP_NATIVE_SERVICE_CREDENTIAL must contain at least 32 bytes.");
|
|
2239
2267
|
}
|
|
2240
2268
|
const resourceUrl = canonicalResourceUrl(config.publicUrl);
|
|
2241
|
-
const pluginUrl = new URL("./chatgpt/mcp", resourceUrl);
|
|
2242
2269
|
const statusFor = (resource) => config.introspection === void 0 ? void 0 : createTokenStatusChecker({ ...config.introspection, resourceUrl: resource.toString() });
|
|
2243
2270
|
const hosted = createHostedSurface(config, resourceUrl, "hosted", statusFor(resourceUrl));
|
|
2244
|
-
const
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2271
|
+
const surfaces = [hosted];
|
|
2272
|
+
const restrictedByPath = /* @__PURE__ */ new Map();
|
|
2273
|
+
for (const prefix of RESTRICTED_ADDRESS_PREFIXES) {
|
|
2274
|
+
const restrictedUrl = new URL(`./${prefix}/mcp`, resourceUrl);
|
|
2275
|
+
const connectUrl = new URL("./connect", restrictedUrl);
|
|
2276
|
+
const restricted = createHostedSurface({
|
|
2277
|
+
...config,
|
|
2278
|
+
nativeServiceCredential: void 0,
|
|
2279
|
+
stateDir: join3(config.stateDir, prefix),
|
|
2280
|
+
approvalPath: connectUrl.pathname
|
|
2281
|
+
}, restrictedUrl, "public", statusFor(restrictedUrl));
|
|
2282
|
+
surfaces.push(restricted);
|
|
2283
|
+
for (const owned of [
|
|
2284
|
+
restrictedUrl,
|
|
2285
|
+
connectUrl,
|
|
2286
|
+
new URL("./connect/callback", restrictedUrl),
|
|
2287
|
+
new URL(getOAuthProtectedResourceMetadataUrl(restrictedUrl))
|
|
2288
|
+
]) {
|
|
2289
|
+
restrictedByPath.set(owned.pathname, restricted);
|
|
2290
|
+
}
|
|
2291
|
+
}
|
|
2256
2292
|
return {
|
|
2257
|
-
fetch: (request) => (
|
|
2293
|
+
fetch: (request) => (restrictedByPath.get(new URL(request.url).pathname) ?? hosted).fetch(request),
|
|
2258
2294
|
close: async () => {
|
|
2259
|
-
await Promise.all(
|
|
2295
|
+
await Promise.all(surfaces.map((surface) => surface.close()));
|
|
2260
2296
|
}
|
|
2261
2297
|
};
|
|
2262
2298
|
}
|
|
@@ -2528,10 +2564,12 @@ Local alternative: install \`${LOCAL_CLI_PACKAGE}\` and \`${LOCAL_MCP_PACKAGE}\`
|
|
|
2528
2564
|
try {
|
|
2529
2565
|
const destination = await store.approvalRedirect(requiredState(url));
|
|
2530
2566
|
return Response.redirect(destination, 302);
|
|
2531
|
-
} catch {
|
|
2567
|
+
} catch (error) {
|
|
2568
|
+
const reason = error instanceof ApprovalRequestError ? error.detail : "unknown";
|
|
2569
|
+
writeDiagnostic(`connect rejected: reason=${reason} path=${connectPath}`);
|
|
2532
2570
|
if (request.headers.get("accept")?.includes("text/html")) {
|
|
2533
2571
|
return new Response(
|
|
2534
|
-
'<!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.
|
|
2572
|
+
'<!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>',
|
|
2535
2573
|
{
|
|
2536
2574
|
status: 400,
|
|
2537
2575
|
headers: {
|
|
@@ -2742,7 +2780,7 @@ function mcpCors(response, request) {
|
|
|
2742
2780
|
if (request.headers.has("origin")) {
|
|
2743
2781
|
headers.set("access-control-allow-origin", "*");
|
|
2744
2782
|
headers.set("access-control-allow-methods", "GET, POST, DELETE, OPTIONS");
|
|
2745
|
-
headers.set("access-control-expose-headers",
|
|
2783
|
+
headers.set("access-control-expose-headers", MCP_CORS_EXPOSED_HEADERS);
|
|
2746
2784
|
if (request.method === "OPTIONS") headers.set("access-control-allow-headers", MCP_CORS_ALLOWED_HEADERS);
|
|
2747
2785
|
}
|
|
2748
2786
|
return new Response(response.body, { status: response.status, statusText: response.statusText, headers });
|