@tinycloud/mcp 0.10.1-beta.5 → 0.11.0-beta.11
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 +1 -1
- package/dist/cli.cjs +4 -4
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +4 -4
- package/dist/cli.js.map +1 -1
- package/dist/http-cli.cjs +155 -51
- package/dist/http-cli.cjs.map +1 -1
- package/dist/http-cli.js +141 -38
- package/dist/http-cli.js.map +1 -1
- package/dist/http.cjs +151 -47
- package/dist/http.cjs.map +1 -1
- package/dist/http.js +140 -37
- package/dist/http.js.map +1 -1
- package/dist/index.cjs +148 -44
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +138 -35
- package/dist/index.js.map +1 -1
- package/dist/server.cjs +4 -4
- package/dist/server.cjs.map +1 -1
- package/dist/server.js +4 -4
- package/dist/server.js.map +1 -1
- package/package.json +4 -4
- package/skills/tinycloud-delegated-secrets/SKILL.md +6 -1
package/dist/index.cjs
CHANGED
|
@@ -592,7 +592,7 @@ function outcomeCode(result) {
|
|
|
592
592
|
// package.json
|
|
593
593
|
var package_default = {
|
|
594
594
|
name: "@tinycloud/mcp",
|
|
595
|
-
version: "0.
|
|
595
|
+
version: "0.11.0-beta.11",
|
|
596
596
|
description: "TinyCloud delegated operations MCP server",
|
|
597
597
|
keywords: [
|
|
598
598
|
"tinycloud",
|
|
@@ -663,10 +663,10 @@ var package_default = {
|
|
|
663
663
|
dependencies: {
|
|
664
664
|
"@modelcontextprotocol/node": "2.0.0-beta.5",
|
|
665
665
|
"@modelcontextprotocol/server": "2.0.0-beta.5",
|
|
666
|
-
"@tinycloud/node-sdk": "3.13.0-beta.
|
|
667
|
-
"@tinycloud/sdk-core": "3.13.0-beta.
|
|
666
|
+
"@tinycloud/node-sdk": "3.13.0-beta.9",
|
|
667
|
+
"@tinycloud/sdk-core": "3.13.0-beta.9",
|
|
668
668
|
"@tinycloud/node-sdk-wasm": "1.7.9",
|
|
669
|
-
"@tinycloud/operations": "0.9.1-beta.
|
|
669
|
+
"@tinycloud/operations": "0.9.1-beta.11",
|
|
670
670
|
jose: "6.2.4"
|
|
671
671
|
},
|
|
672
672
|
devDependencies: {
|
|
@@ -805,10 +805,100 @@ if (isDirectInvocation()) {
|
|
|
805
805
|
}
|
|
806
806
|
|
|
807
807
|
// src/http.ts
|
|
808
|
-
var
|
|
808
|
+
var import_node_path5 = require("path");
|
|
809
809
|
var import_server5 = require("@modelcontextprotocol/server");
|
|
810
810
|
var import_node_sdk3 = require("@tinycloud/node-sdk");
|
|
811
811
|
|
|
812
|
+
// src/agent-discovery.ts
|
|
813
|
+
var import_node_crypto = require("crypto");
|
|
814
|
+
var import_node_fs = require("fs");
|
|
815
|
+
var import_node_path3 = require("path");
|
|
816
|
+
var import_node_url = require("url");
|
|
817
|
+
var import_meta2 = {};
|
|
818
|
+
var DOCUMENTATION_URL = "https://docs.tinycloud.xyz/cli/mcp";
|
|
819
|
+
var SKILL_NAME = "tinycloud-delegated-secrets";
|
|
820
|
+
var LOCAL_PACKAGES = [["@tinycloud", "cli"].join("/"), ["@tinycloud", "mcp"].join("/")];
|
|
821
|
+
var WEBMCP_SCRIPT_PATH = "/webmcp.js";
|
|
822
|
+
var WEBMCP_TOOL_NAME = "get_tinycloud_mcp_connection";
|
|
823
|
+
var A2A_AGENT_CARD_URL = "https://tinycloud.xyz/.well-known/agent-card.json";
|
|
824
|
+
var moduleDirectory = typeof __dirname === "string" ? __dirname : (0, import_node_path3.dirname)((0, import_node_url.fileURLToPath)(import_meta2.url));
|
|
825
|
+
var skillPath = (0, import_node_path3.join)(moduleDirectory, "..", "skills", SKILL_NAME, "SKILL.md");
|
|
826
|
+
function agentDiscoveryRoutes(resourceUrl, issuer, requiredScope) {
|
|
827
|
+
const at = (path) => new URL(path, resourceUrl).toString();
|
|
828
|
+
const serverCardUrl = at("/.well-known/mcp/server-card.json");
|
|
829
|
+
const skillUrlPath = `/.well-known/agent-skills/${SKILL_NAME}/SKILL.md`;
|
|
830
|
+
const skill = (0, import_node_fs.readFileSync)(skillPath);
|
|
831
|
+
const apiCatalog = JSON.stringify({
|
|
832
|
+
linkset: [{
|
|
833
|
+
anchor: resourceUrl.toString(),
|
|
834
|
+
"service-desc": [{ href: serverCardUrl, type: "application/json" }],
|
|
835
|
+
"service-doc": [{ href: DOCUMENTATION_URL, type: "text/html" }],
|
|
836
|
+
status: [{ href: at("/healthz"), type: "application/json" }]
|
|
837
|
+
}]
|
|
838
|
+
});
|
|
839
|
+
const skillsIndex = JSON.stringify({
|
|
840
|
+
$schema: "https://schemas.agentskills.io/discovery/0.2.0/schema.json",
|
|
841
|
+
skills: [{
|
|
842
|
+
name: SKILL_NAME,
|
|
843
|
+
type: "skill-md",
|
|
844
|
+
description: skillDescription(skill.toString("utf8")),
|
|
845
|
+
url: at(skillUrlPath),
|
|
846
|
+
digest: `sha256:${(0, import_node_crypto.createHash)("sha256").update(skill).digest("hex")}`
|
|
847
|
+
}]
|
|
848
|
+
});
|
|
849
|
+
const connection = {
|
|
850
|
+
endpoint: resourceUrl.toString(),
|
|
851
|
+
transport: "streamable-http",
|
|
852
|
+
authorization: {
|
|
853
|
+
type: "oauth2",
|
|
854
|
+
authorizationServer: issuer,
|
|
855
|
+
protectedResourceMetadata: at(`/.well-known/oauth-protected-resource${resourceUrl.pathname}`),
|
|
856
|
+
scope: requiredScope
|
|
857
|
+
},
|
|
858
|
+
serverCard: serverCardUrl,
|
|
859
|
+
documentation: DOCUMENTATION_URL,
|
|
860
|
+
localAlternative: { packages: LOCAL_PACKAGES, stdioServer: "tinycloud-mcp" }
|
|
861
|
+
};
|
|
862
|
+
const webMcpScript = `(() => {
|
|
863
|
+
const modelContext = (typeof document !== "undefined" && document.modelContext) ||
|
|
864
|
+
(typeof navigator !== "undefined" && navigator.modelContext);
|
|
865
|
+
if (!modelContext || typeof modelContext.registerTool !== "function") return;
|
|
866
|
+
const connection = ${JSON.stringify(connection)};
|
|
867
|
+
modelContext.registerTool({
|
|
868
|
+
name: ${JSON.stringify(WEBMCP_TOOL_NAME)},
|
|
869
|
+
description: "Returns how to connect to TinyCloud MCP: the hosted endpoint, its transport, OAuth discovery, the documentation link and the local stdio option shown on this page.",
|
|
870
|
+
inputSchema: { type: "object", properties: {}, additionalProperties: false },
|
|
871
|
+
annotations: { readOnlyHint: true },
|
|
872
|
+
execute() {
|
|
873
|
+
return { content: [{ type: "text", text: JSON.stringify(connection) }], structuredContent: connection };
|
|
874
|
+
},
|
|
875
|
+
});
|
|
876
|
+
})();
|
|
877
|
+
`;
|
|
878
|
+
const cached = (body, contentType) => () => new Response(body, {
|
|
879
|
+
headers: {
|
|
880
|
+
"content-type": contentType,
|
|
881
|
+
"cache-control": "public, max-age=300",
|
|
882
|
+
"x-content-type-options": "nosniff"
|
|
883
|
+
}
|
|
884
|
+
});
|
|
885
|
+
return /* @__PURE__ */ new Map([
|
|
886
|
+
["/.well-known/api-catalog", cached(apiCatalog, 'application/linkset+json; profile="https://www.rfc-editor.org/info/rfc9727"')],
|
|
887
|
+
["/.well-known/agent-skills/index.json", cached(skillsIndex, "application/json; charset=utf-8")],
|
|
888
|
+
[skillUrlPath, cached(skill, "text/markdown; charset=utf-8")],
|
|
889
|
+
["/.well-known/agent-card.json", () => new Response(null, {
|
|
890
|
+
status: 302,
|
|
891
|
+
headers: { location: A2A_AGENT_CARD_URL, "cache-control": "public, max-age=300" }
|
|
892
|
+
})],
|
|
893
|
+
[WEBMCP_SCRIPT_PATH, cached(webMcpScript, "text/javascript; charset=utf-8")]
|
|
894
|
+
]);
|
|
895
|
+
}
|
|
896
|
+
function skillDescription(skill) {
|
|
897
|
+
const description = /^---\n(?:.*\n)*?description: (.+)\n(?:.*\n)*?---\n/.exec(skill)?.[1];
|
|
898
|
+
if (description === void 0) throw new Error(`${SKILL_NAME}/SKILL.md must declare a frontmatter description.`);
|
|
899
|
+
return description;
|
|
900
|
+
}
|
|
901
|
+
|
|
812
902
|
// src/oauth.ts
|
|
813
903
|
var import_server4 = require("@modelcontextprotocol/server");
|
|
814
904
|
var import_node_sdk = require("@tinycloud/node-sdk");
|
|
@@ -899,7 +989,7 @@ function firstString(...values) {
|
|
|
899
989
|
}
|
|
900
990
|
|
|
901
991
|
// src/token-status.ts
|
|
902
|
-
var
|
|
992
|
+
var import_node_crypto2 = require("crypto");
|
|
903
993
|
var import_jose2 = require("jose");
|
|
904
994
|
var ACTIVE_CACHE_MS = 3e4;
|
|
905
995
|
var UNKNOWN_TOLERANCE_MS = 6e4;
|
|
@@ -996,7 +1086,7 @@ function createTokenStatusChecker(config) {
|
|
|
996
1086
|
}
|
|
997
1087
|
return {
|
|
998
1088
|
async tokenStatus(token) {
|
|
999
|
-
const key = (0,
|
|
1089
|
+
const key = (0, import_node_crypto2.createHash)("sha256").update(token).digest("hex");
|
|
1000
1090
|
const now = clock();
|
|
1001
1091
|
const elapsed = monotonic();
|
|
1002
1092
|
const inactiveUntil = inactive.get(key);
|
|
@@ -1011,7 +1101,7 @@ function createTokenStatusChecker(config) {
|
|
|
1011
1101
|
},
|
|
1012
1102
|
toleratesUnknown(token) {
|
|
1013
1103
|
if (credentialsRefused) return false;
|
|
1014
|
-
const confirmed = confirmedActive.get((0,
|
|
1104
|
+
const confirmed = confirmedActive.get((0, import_node_crypto2.createHash)("sha256").update(token).digest("hex"));
|
|
1015
1105
|
if (confirmed === void 0) return false;
|
|
1016
1106
|
return confirmed.expiresAt > clock() && monotonic() - confirmed.at < UNKNOWN_TOLERANCE_MS;
|
|
1017
1107
|
}
|
|
@@ -1045,9 +1135,9 @@ function claims(token) {
|
|
|
1045
1135
|
|
|
1046
1136
|
// src/remote-store.ts
|
|
1047
1137
|
var import_sdk_core = require("@tinycloud/sdk-core");
|
|
1048
|
-
var
|
|
1138
|
+
var import_node_crypto4 = require("crypto");
|
|
1049
1139
|
var import_promises = require("fs/promises");
|
|
1050
|
-
var
|
|
1140
|
+
var import_node_path4 = require("path");
|
|
1051
1141
|
var import_node_sdk2 = require("@tinycloud/node-sdk");
|
|
1052
1142
|
var import_node_sdk_wasm = require("@tinycloud/node-sdk-wasm");
|
|
1053
1143
|
var import_artifacts = require("@tinycloud/operations/artifacts");
|
|
@@ -1057,7 +1147,7 @@ var import_mcp_authority = require("@tinycloud/operations/mcp-authority");
|
|
|
1057
1147
|
var import_tc_apps2 = require("@tinycloud/operations/tc-apps");
|
|
1058
1148
|
|
|
1059
1149
|
// src/native-auth.ts
|
|
1060
|
-
var
|
|
1150
|
+
var import_node_crypto3 = require("crypto");
|
|
1061
1151
|
var NATIVE_SERVICE_CREDENTIAL_HEADER = "X-TinyCloud-Service-Credential";
|
|
1062
1152
|
var NATIVE_OWNER_DID_HEADER = "X-TinyCloud-Owner-DID";
|
|
1063
1153
|
var NATIVE_GRANT_MAX_LIFETIME_SECONDS = 30 * 24 * 60 * 60;
|
|
@@ -1072,7 +1162,7 @@ function serviceCredentialMatches(supplied, configured) {
|
|
|
1072
1162
|
if (supplied === null || configured === void 0) return false;
|
|
1073
1163
|
const suppliedBytes = Buffer.from(supplied, "utf8");
|
|
1074
1164
|
const configuredBytes = Buffer.from(configured, "utf8");
|
|
1075
|
-
return suppliedBytes.byteLength === configuredBytes.byteLength && (0,
|
|
1165
|
+
return suppliedBytes.byteLength === configuredBytes.byteLength && (0, import_node_crypto3.timingSafeEqual)(suppliedBytes, configuredBytes);
|
|
1076
1166
|
}
|
|
1077
1167
|
var OWNER_APPLICATIONS_SPACE = /^tinycloud:pkh:eip155:([1-9][0-9]*):(0x[0-9a-f]{40}):applications$/i;
|
|
1078
1168
|
var SQL_PATH = "xyz.tinycloud.tinychat/connectors";
|
|
@@ -1198,8 +1288,8 @@ var RemoteTenantStore = class {
|
|
|
1198
1288
|
nativeTenantStateRoot(ownerDid) {
|
|
1199
1289
|
const canonical = canonicalOwnerDid(ownerDid);
|
|
1200
1290
|
if (canonical === void 0) throw new NativeGrantValidationError("rejected");
|
|
1201
|
-
const tenant = (0,
|
|
1202
|
-
return (0,
|
|
1291
|
+
const tenant = (0, import_node_crypto4.createHmac)("sha256", this.#config.stateSecret).update(`native-tenant:${canonical}`).digest("hex");
|
|
1292
|
+
return (0, import_node_path4.join)(this.#config.stateDir, "native-tenants", tenant);
|
|
1203
1293
|
}
|
|
1204
1294
|
async acceptNativeGrant(serializedDelegation) {
|
|
1205
1295
|
if (Buffer.byteLength(serializedDelegation) > MAX_CALLBACK_BYTES) {
|
|
@@ -1367,7 +1457,7 @@ var RemoteTenantStore = class {
|
|
|
1367
1457
|
if (Date.parse(stored.expiresAt) <= Date.now()) throw new NativeGrantValidationError("expired");
|
|
1368
1458
|
}
|
|
1369
1459
|
tenantStateRoot(subject) {
|
|
1370
|
-
return (0,
|
|
1460
|
+
return (0, import_node_path4.join)(this.#config.stateDir, "tenants", this.#tenantId(subject));
|
|
1371
1461
|
}
|
|
1372
1462
|
/** Prepare only this authenticated account's profile before its first operation. */
|
|
1373
1463
|
async initializeTenant(subject) {
|
|
@@ -1580,7 +1670,7 @@ var RemoteTenantStore = class {
|
|
|
1580
1670
|
}
|
|
1581
1671
|
if (!isRecord(data)) throw new ApprovalRequestError("body_invalid", "Callback body is invalid.");
|
|
1582
1672
|
const pending = await this.#readPending(state, true);
|
|
1583
|
-
const stateRoot = (0,
|
|
1673
|
+
const stateRoot = (0, import_node_path4.join)(this.#config.stateDir, "tenants", pending.tenantId);
|
|
1584
1674
|
const prior = this.#approvalProcessing.get(stateRoot);
|
|
1585
1675
|
const processing = (async () => {
|
|
1586
1676
|
if (prior) await prior.catch(() => void 0);
|
|
@@ -1818,7 +1908,7 @@ var RemoteTenantStore = class {
|
|
|
1818
1908
|
approvalEpoch: this.#approvalEpochs.get(tenant.stateRoot)
|
|
1819
1909
|
});
|
|
1820
1910
|
await (0, import_promises.rm)(this.#additionalPath(tenant.stateRoot), { force: true });
|
|
1821
|
-
await (0, import_promises.rm)((0,
|
|
1911
|
+
await (0, import_promises.rm)((0, import_node_path4.join)(tenant.stateRoot, ".tinycloud", "profiles", PROFILE, "auth-requests.json"), { force: true });
|
|
1822
1912
|
await (0, import_promises.rm)(this.#pendingDirectory(tenant.stateRoot), { recursive: true, force: true });
|
|
1823
1913
|
await (0, import_promises.rm)(this.#sessionPath(tenant.stateRoot), { force: true });
|
|
1824
1914
|
})().finally(() => this.#clearing.delete(tenant.stateRoot));
|
|
@@ -1826,9 +1916,9 @@ var RemoteTenantStore = class {
|
|
|
1826
1916
|
await clearing;
|
|
1827
1917
|
}
|
|
1828
1918
|
async #initializeTenant(tenantId) {
|
|
1829
|
-
const stateRoot = (0,
|
|
1919
|
+
const stateRoot = (0, import_node_path4.join)(this.#config.stateDir, "tenants", tenantId);
|
|
1830
1920
|
const keyPath = this.#keyPath(stateRoot);
|
|
1831
|
-
await secureDirectory((0,
|
|
1921
|
+
await secureDirectory((0, import_node_path4.join)(stateRoot, ".tinycloud", "profiles", PROFILE));
|
|
1832
1922
|
let jwk = await readJson(keyPath);
|
|
1833
1923
|
let sessionDid;
|
|
1834
1924
|
if (jwk === null) {
|
|
@@ -1868,7 +1958,7 @@ var RemoteTenantStore = class {
|
|
|
1868
1958
|
}
|
|
1869
1959
|
async #readTenant(tenantId) {
|
|
1870
1960
|
if (!/^[a-f0-9]{64}$/.test(tenantId)) throw new ApprovalRequestError("state_invalid", "Approval state is invalid.");
|
|
1871
|
-
const stateRoot = (0,
|
|
1961
|
+
const stateRoot = (0, import_node_path4.join)(this.#config.stateDir, "tenants", tenantId);
|
|
1872
1962
|
const jwk = await readJson(this.#keyPath(stateRoot));
|
|
1873
1963
|
if (jwk === null) throw new ApprovalRequestError("tenant_missing", "The TinyCloud delegate no longer exists.");
|
|
1874
1964
|
const profile = await readJson(this.#profilePath(stateRoot));
|
|
@@ -1894,7 +1984,7 @@ var RemoteTenantStore = class {
|
|
|
1894
1984
|
{ tenantId, approvalEpoch: tenant.approvalEpoch, kind, requestId, permissions, ownerDids }
|
|
1895
1985
|
);
|
|
1896
1986
|
if (reusable !== void 0) return reusable;
|
|
1897
|
-
const nonce = (0,
|
|
1987
|
+
const nonce = (0, import_node_crypto4.randomBytes)(24).toString("base64url");
|
|
1898
1988
|
const created = Date.now();
|
|
1899
1989
|
const pending = {
|
|
1900
1990
|
version: 1,
|
|
@@ -1919,10 +2009,10 @@ var RemoteTenantStore = class {
|
|
|
1919
2009
|
const expected = this.#signState(tenantId, nonce);
|
|
1920
2010
|
const supplied = Buffer.from(signature, "base64url");
|
|
1921
2011
|
const expectedBytes = Buffer.from(expected, "base64url");
|
|
1922
|
-
if (supplied.length !== expectedBytes.length || !(0,
|
|
2012
|
+
if (supplied.length !== expectedBytes.length || !(0, import_node_crypto4.timingSafeEqual)(supplied, expectedBytes)) {
|
|
1923
2013
|
throw new ApprovalRequestError("state_invalid", "Approval state is invalid.");
|
|
1924
2014
|
}
|
|
1925
|
-
const stateRoot = (0,
|
|
2015
|
+
const stateRoot = (0, import_node_path4.join)(this.#config.stateDir, "tenants", tenantId);
|
|
1926
2016
|
const path = this.#pendingPath(stateRoot, nonce);
|
|
1927
2017
|
const claimed = `${path}.processing`;
|
|
1928
2018
|
if (consume) {
|
|
@@ -1961,7 +2051,7 @@ var RemoteTenantStore = class {
|
|
|
1961
2051
|
}
|
|
1962
2052
|
}
|
|
1963
2053
|
async #restorePending(pending) {
|
|
1964
|
-
const stateRoot = (0,
|
|
2054
|
+
const stateRoot = (0, import_node_path4.join)(this.#config.stateDir, "tenants", pending.tenantId);
|
|
1965
2055
|
const path = this.#pendingPath(stateRoot, pending.nonce);
|
|
1966
2056
|
await (0, import_promises.rename)(`${path}.processing`, path);
|
|
1967
2057
|
}
|
|
@@ -1996,8 +2086,8 @@ var RemoteTenantStore = class {
|
|
|
1996
2086
|
return this.#nativeIdentity;
|
|
1997
2087
|
}
|
|
1998
2088
|
async #readOrCreateNativeServiceKey() {
|
|
1999
|
-
const path = (0,
|
|
2000
|
-
await secureDirectory((0,
|
|
2089
|
+
const path = (0, import_node_path4.join)(this.#config.stateDir, ".tinycloud", "native-service-key.json");
|
|
2090
|
+
await secureDirectory((0, import_node_path4.dirname)(path));
|
|
2001
2091
|
let stored = await readJson(path);
|
|
2002
2092
|
if (stored === null) {
|
|
2003
2093
|
const generated = generateSessionKey();
|
|
@@ -2085,31 +2175,31 @@ var RemoteTenantStore = class {
|
|
|
2085
2175
|
}
|
|
2086
2176
|
}
|
|
2087
2177
|
#nativeGrantPath(stateRoot) {
|
|
2088
|
-
return (0,
|
|
2178
|
+
return (0, import_node_path4.join)(stateRoot, ".tinycloud", "native-grant.json");
|
|
2089
2179
|
}
|
|
2090
2180
|
#tenantId(subject) {
|
|
2091
|
-
return (0,
|
|
2181
|
+
return (0, import_node_crypto4.createHmac)("sha256", this.#config.stateSecret).update(`tenant:${subject}`).digest("hex");
|
|
2092
2182
|
}
|
|
2093
2183
|
#signState(tenantId, nonce) {
|
|
2094
|
-
return (0,
|
|
2184
|
+
return (0, import_node_crypto4.createHmac)("sha256", this.#config.stateSecret).update(`approval:${tenantId}:${nonce}`).digest("base64url");
|
|
2095
2185
|
}
|
|
2096
2186
|
#profilePath(stateRoot) {
|
|
2097
|
-
return (0,
|
|
2187
|
+
return (0, import_node_path4.join)(stateRoot, ".tinycloud", "profiles", PROFILE, "profile.json");
|
|
2098
2188
|
}
|
|
2099
2189
|
#keyPath(stateRoot) {
|
|
2100
|
-
return (0,
|
|
2190
|
+
return (0, import_node_path4.join)(stateRoot, ".tinycloud", "profiles", PROFILE, "key.json");
|
|
2101
2191
|
}
|
|
2102
2192
|
#sessionPath(stateRoot) {
|
|
2103
|
-
return (0,
|
|
2193
|
+
return (0, import_node_path4.join)(stateRoot, ".tinycloud", "profiles", PROFILE, "session.json");
|
|
2104
2194
|
}
|
|
2105
2195
|
#additionalPath(stateRoot) {
|
|
2106
|
-
return (0,
|
|
2196
|
+
return (0, import_node_path4.join)(stateRoot, ".tinycloud", "profiles", PROFILE, "additional-delegations.json");
|
|
2107
2197
|
}
|
|
2108
2198
|
#pendingPath(stateRoot, nonce) {
|
|
2109
|
-
return (0,
|
|
2199
|
+
return (0, import_node_path4.join)(this.#pendingDirectory(stateRoot), `${nonce}.json`);
|
|
2110
2200
|
}
|
|
2111
2201
|
#pendingDirectory(stateRoot) {
|
|
2112
|
-
return (0,
|
|
2202
|
+
return (0, import_node_path4.join)(stateRoot, ".tinycloud", "profiles", PROFILE, "pending");
|
|
2113
2203
|
}
|
|
2114
2204
|
};
|
|
2115
2205
|
var wasmInitialized = false;
|
|
@@ -2202,9 +2292,9 @@ async function secureDirectory(path) {
|
|
|
2202
2292
|
await (0, import_promises.chmod)(path, 448);
|
|
2203
2293
|
}
|
|
2204
2294
|
async function secureWrite(path, value) {
|
|
2205
|
-
const directory = (0,
|
|
2295
|
+
const directory = (0, import_node_path4.dirname)(path);
|
|
2206
2296
|
await secureDirectory(directory);
|
|
2207
|
-
const temporary = `${path}.${process.pid}.${(0,
|
|
2297
|
+
const temporary = `${path}.${process.pid}.${(0, import_node_crypto4.randomBytes)(8).toString("hex")}.tmp`;
|
|
2208
2298
|
await (0, import_promises.writeFile)(temporary, `${JSON.stringify(value, jsonReplacer, 2)}
|
|
2209
2299
|
`, { mode: 384 });
|
|
2210
2300
|
await (0, import_promises.rename)(temporary, path);
|
|
@@ -2234,7 +2324,7 @@ async function restoreOptionalText(path, contents) {
|
|
|
2234
2324
|
await (0, import_promises.rm)(path, { force: true });
|
|
2235
2325
|
return;
|
|
2236
2326
|
}
|
|
2237
|
-
await secureDirectory((0,
|
|
2327
|
+
await secureDirectory((0, import_node_path4.dirname)(path));
|
|
2238
2328
|
await (0, import_promises.writeFile)(path, contents, { mode: 384 });
|
|
2239
2329
|
await (0, import_promises.chmod)(path, 384);
|
|
2240
2330
|
}
|
|
@@ -2249,7 +2339,7 @@ async function reusablePending(directory, expected) {
|
|
|
2249
2339
|
const active = [];
|
|
2250
2340
|
for (const name of names) {
|
|
2251
2341
|
if (!name.endsWith(".json")) continue;
|
|
2252
|
-
const path = (0,
|
|
2342
|
+
const path = (0, import_node_path4.join)(directory, name);
|
|
2253
2343
|
const pending = await readJson(path).catch(() => null);
|
|
2254
2344
|
if (pending === null || new Date(pending.expiresAt).getTime() <= Date.now()) {
|
|
2255
2345
|
await (0, import_promises.rm)(path, { force: true });
|
|
@@ -2260,7 +2350,7 @@ async function reusablePending(directory, expected) {
|
|
|
2260
2350
|
}
|
|
2261
2351
|
if (active.length >= 64) {
|
|
2262
2352
|
active.sort((left, right) => Date.parse(left.createdAt) - Date.parse(right.createdAt));
|
|
2263
|
-
await (0, import_promises.rm)((0,
|
|
2353
|
+
await (0, import_promises.rm)((0, import_node_path4.join)(directory, `${active[0].nonce}.json`), { force: true });
|
|
2264
2354
|
}
|
|
2265
2355
|
return void 0;
|
|
2266
2356
|
}
|
|
@@ -2291,7 +2381,7 @@ function createHostedMcpApp(config) {
|
|
|
2291
2381
|
const restricted = createHostedSurface({
|
|
2292
2382
|
...config,
|
|
2293
2383
|
nativeServiceCredential: void 0,
|
|
2294
|
-
stateDir: (0,
|
|
2384
|
+
stateDir: (0, import_node_path5.join)(config.stateDir, prefix),
|
|
2295
2385
|
approvalPath: connectUrl.pathname
|
|
2296
2386
|
}, restrictedUrl, "public", statusFor(restrictedUrl), ANNOTATION_TITLE_PREFIXES.has(prefix));
|
|
2297
2387
|
surfaces.push(restricted);
|
|
@@ -2373,6 +2463,7 @@ function createHostedSurface(config, resourceUrl, surface, tokenStatus, annotati
|
|
|
2373
2463
|
scopesSupported: [REQUIRED_SCOPE],
|
|
2374
2464
|
resourceName: surface === "public" ? "TinyCloud personal records" : "TinyCloud hosted MCP"
|
|
2375
2465
|
};
|
|
2466
|
+
const discoveryRoutes = surface === "hosted" ? agentDiscoveryRoutes(resourceUrl, issuer, REQUIRED_SCOPE) : /* @__PURE__ */ new Map();
|
|
2376
2467
|
const allowedHosts = [resourceUrl.hostname];
|
|
2377
2468
|
return {
|
|
2378
2469
|
async fetch(request) {
|
|
@@ -2479,9 +2570,22 @@ function createHostedSurface(config, resourceUrl, surface, tokenStatus, annotati
|
|
|
2479
2570
|
].join("\n") + "\n";
|
|
2480
2571
|
return publicMetadataCors(publicText(authDoc, "text/markdown; charset=utf-8"), request);
|
|
2481
2572
|
}
|
|
2573
|
+
const discoveryRoute = discoveryRoutes.get(url.pathname);
|
|
2574
|
+
if (discoveryRoute !== void 0) {
|
|
2575
|
+
if (request.method === "OPTIONS") {
|
|
2576
|
+
return publicMetadataCors(new Response(null, { status: 204 }), request);
|
|
2577
|
+
}
|
|
2578
|
+
if (request.method !== "GET" && request.method !== "HEAD") return methodNotAllowed("GET, HEAD");
|
|
2579
|
+
const response = discoveryRoute();
|
|
2580
|
+
return publicMetadataCors(
|
|
2581
|
+
request.method === "HEAD" ? new Response(null, { status: response.status, headers: response.headers }) : response,
|
|
2582
|
+
request
|
|
2583
|
+
);
|
|
2584
|
+
}
|
|
2482
2585
|
if (url.pathname === "/robots.txt" && surface === "hosted") {
|
|
2483
2586
|
return request.method === "GET" ? publicText(`User-agent: *
|
|
2484
2587
|
Allow: /
|
|
2588
|
+
Content-Signal: search=yes, ai-input=yes, ai-train=no
|
|
2485
2589
|
Sitemap: ${new URL("/sitemap.xml", resourceUrl)}
|
|
2486
2590
|
Agentmap: ${new URL("/.well-known/ai-catalog.json", resourceUrl)}
|
|
2487
2591
|
`, "text/plain; charset=utf-8") : methodNotAllowed("GET");
|
|
@@ -2558,17 +2662,17 @@ Hosted endpoint: <https://mcp.tinycloud.xyz/mcp> (Streamable HTTP, OpenKey OAuth
|
|
|
2558
2662
|
[Connection documentation](https://docs.tinycloud.xyz/cli/mcp).
|
|
2559
2663
|
|
|
2560
2664
|
Local alternative: install \`${LOCAL_CLI_PACKAGE}\` and \`${LOCAL_MCP_PACKAGE}\` and connect the \`tinycloud-mcp\` stdio server.
|
|
2561
|
-
` : `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="ai-catalog" href="/.well-known/ai-catalog.json"><title>TinyCloud MCP</title></head><main><h1>TinyCloud MCP</h1><p>Hosted MCP endpoint: <code>https://mcp.tinycloud.xyz/mcp</code> (Streamable HTTP, OpenKey OAuth).</p><p><a href="https://docs.tinycloud.xyz/cli/mcp">Connection documentation</a></p><p>Local alternative: install <code>${LOCAL_CLI_PACKAGE}</code> and <code>${LOCAL_MCP_PACKAGE}</code> and connect the <code>tinycloud-mcp</code> stdio server.</p></main></html>`;
|
|
2665
|
+
` : `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="ai-catalog" href="/.well-known/ai-catalog.json"><script src="${WEBMCP_SCRIPT_PATH}" defer></script><title>TinyCloud MCP</title></head><main><h1>TinyCloud MCP</h1><p>Hosted MCP endpoint: <code>https://mcp.tinycloud.xyz/mcp</code> (Streamable HTTP, OpenKey OAuth).</p><p><a href="https://docs.tinycloud.xyz/cli/mcp">Connection documentation</a></p><p>Local alternative: install <code>${LOCAL_CLI_PACKAGE}</code> and <code>${LOCAL_MCP_PACKAGE}</code> and connect the <code>tinycloud-mcp</code> stdio server.</p></main></html>`;
|
|
2562
2666
|
const headers = new Headers({
|
|
2563
2667
|
"content-type": markdown ? "text/markdown; charset=utf-8" : "text/html; charset=utf-8",
|
|
2564
2668
|
"cache-control": "public, max-age=300",
|
|
2565
|
-
"content-security-policy": "default-src 'none'; base-uri 'none'; frame-ancestors 'none'",
|
|
2669
|
+
"content-security-policy": "default-src 'none'; script-src 'self'; base-uri 'none'; frame-ancestors 'none'",
|
|
2566
2670
|
"x-content-type-options": "nosniff",
|
|
2567
2671
|
vary: "Accept"
|
|
2568
2672
|
});
|
|
2569
2673
|
headers.set(
|
|
2570
2674
|
"link",
|
|
2571
|
-
`<${new URL("/mcp/server-card", resourceUrl)}>; rel="describedby"; type="application/json", <https://docs.tinycloud.xyz/cli/mcp>; rel="service-doc"`
|
|
2675
|
+
`<${new URL("/mcp/server-card", resourceUrl)}>; rel="describedby"; type="application/json", <https://docs.tinycloud.xyz/cli/mcp>; rel="service-doc", <${new URL("/.well-known/api-catalog", resourceUrl)}>; rel="api-catalog"`
|
|
2572
2676
|
);
|
|
2573
2677
|
return new Response(request.method === "HEAD" ? null : content, { headers });
|
|
2574
2678
|
}
|