@tinycloud/mcp 0.10.1-beta.4 → 0.11.0-beta.6
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/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 +154 -50
- package/dist/http-cli.cjs.map +1 -1
- package/dist/http-cli.js +140 -37
- 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.js
CHANGED
|
@@ -555,7 +555,7 @@ function outcomeCode(result) {
|
|
|
555
555
|
// package.json
|
|
556
556
|
var package_default = {
|
|
557
557
|
name: "@tinycloud/mcp",
|
|
558
|
-
version: "0.
|
|
558
|
+
version: "0.11.0-beta.6",
|
|
559
559
|
description: "TinyCloud delegated operations MCP server",
|
|
560
560
|
keywords: [
|
|
561
561
|
"tinycloud",
|
|
@@ -626,10 +626,10 @@ var package_default = {
|
|
|
626
626
|
dependencies: {
|
|
627
627
|
"@modelcontextprotocol/node": "2.0.0-beta.5",
|
|
628
628
|
"@modelcontextprotocol/server": "2.0.0-beta.5",
|
|
629
|
-
"@tinycloud/node-sdk": "3.13.0-beta.
|
|
630
|
-
"@tinycloud/sdk-core": "3.13.0-beta.
|
|
629
|
+
"@tinycloud/node-sdk": "3.13.0-beta.5",
|
|
630
|
+
"@tinycloud/sdk-core": "3.13.0-beta.5",
|
|
631
631
|
"@tinycloud/node-sdk-wasm": "1.7.9",
|
|
632
|
-
"@tinycloud/operations": "0.9.1-beta.
|
|
632
|
+
"@tinycloud/operations": "0.9.1-beta.6",
|
|
633
633
|
jose: "6.2.4"
|
|
634
634
|
},
|
|
635
635
|
devDependencies: {
|
|
@@ -768,7 +768,7 @@ if (isDirectInvocation()) {
|
|
|
768
768
|
}
|
|
769
769
|
|
|
770
770
|
// src/http.ts
|
|
771
|
-
import { join as
|
|
771
|
+
import { join as join4 } from "path";
|
|
772
772
|
import {
|
|
773
773
|
McpServer as McpServer2,
|
|
774
774
|
createMcpHandler,
|
|
@@ -780,6 +780,95 @@ import {
|
|
|
780
780
|
} from "@modelcontextprotocol/server";
|
|
781
781
|
import { RUNTIME_DELEGATION_REJECTIONS } from "@tinycloud/node-sdk";
|
|
782
782
|
|
|
783
|
+
// src/agent-discovery.ts
|
|
784
|
+
import { createHash } from "crypto";
|
|
785
|
+
import { readFileSync } from "fs";
|
|
786
|
+
import { dirname, join as join2 } from "path";
|
|
787
|
+
import { fileURLToPath } from "url";
|
|
788
|
+
var DOCUMENTATION_URL = "https://docs.tinycloud.xyz/cli/mcp";
|
|
789
|
+
var SKILL_NAME = "tinycloud-delegated-secrets";
|
|
790
|
+
var LOCAL_PACKAGES = [["@tinycloud", "cli"].join("/"), ["@tinycloud", "mcp"].join("/")];
|
|
791
|
+
var WEBMCP_SCRIPT_PATH = "/webmcp.js";
|
|
792
|
+
var WEBMCP_TOOL_NAME = "get_tinycloud_mcp_connection";
|
|
793
|
+
var A2A_AGENT_CARD_URL = "https://tinycloud.xyz/.well-known/agent-card.json";
|
|
794
|
+
var moduleDirectory = typeof __dirname === "string" ? __dirname : dirname(fileURLToPath(import.meta.url));
|
|
795
|
+
var skillPath = join2(moduleDirectory, "..", "skills", SKILL_NAME, "SKILL.md");
|
|
796
|
+
function agentDiscoveryRoutes(resourceUrl, issuer, requiredScope) {
|
|
797
|
+
const at = (path) => new URL(path, resourceUrl).toString();
|
|
798
|
+
const serverCardUrl = at("/.well-known/mcp/server-card.json");
|
|
799
|
+
const skillUrlPath = `/.well-known/agent-skills/${SKILL_NAME}/SKILL.md`;
|
|
800
|
+
const skill = readFileSync(skillPath);
|
|
801
|
+
const apiCatalog = JSON.stringify({
|
|
802
|
+
linkset: [{
|
|
803
|
+
anchor: resourceUrl.toString(),
|
|
804
|
+
"service-desc": [{ href: serverCardUrl, type: "application/json" }],
|
|
805
|
+
"service-doc": [{ href: DOCUMENTATION_URL, type: "text/html" }],
|
|
806
|
+
status: [{ href: at("/healthz"), type: "application/json" }]
|
|
807
|
+
}]
|
|
808
|
+
});
|
|
809
|
+
const skillsIndex = JSON.stringify({
|
|
810
|
+
$schema: "https://schemas.agentskills.io/discovery/0.2.0/schema.json",
|
|
811
|
+
skills: [{
|
|
812
|
+
name: SKILL_NAME,
|
|
813
|
+
type: "skill-md",
|
|
814
|
+
description: skillDescription(skill.toString("utf8")),
|
|
815
|
+
url: at(skillUrlPath),
|
|
816
|
+
digest: `sha256:${createHash("sha256").update(skill).digest("hex")}`
|
|
817
|
+
}]
|
|
818
|
+
});
|
|
819
|
+
const connection = {
|
|
820
|
+
endpoint: resourceUrl.toString(),
|
|
821
|
+
transport: "streamable-http",
|
|
822
|
+
authorization: {
|
|
823
|
+
type: "oauth2",
|
|
824
|
+
authorizationServer: issuer,
|
|
825
|
+
protectedResourceMetadata: at(`/.well-known/oauth-protected-resource${resourceUrl.pathname}`),
|
|
826
|
+
scope: requiredScope
|
|
827
|
+
},
|
|
828
|
+
serverCard: serverCardUrl,
|
|
829
|
+
documentation: DOCUMENTATION_URL,
|
|
830
|
+
localAlternative: { packages: LOCAL_PACKAGES, stdioServer: "tinycloud-mcp" }
|
|
831
|
+
};
|
|
832
|
+
const webMcpScript = `(() => {
|
|
833
|
+
const modelContext = (typeof document !== "undefined" && document.modelContext) ||
|
|
834
|
+
(typeof navigator !== "undefined" && navigator.modelContext);
|
|
835
|
+
if (!modelContext || typeof modelContext.registerTool !== "function") return;
|
|
836
|
+
const connection = ${JSON.stringify(connection)};
|
|
837
|
+
modelContext.registerTool({
|
|
838
|
+
name: ${JSON.stringify(WEBMCP_TOOL_NAME)},
|
|
839
|
+
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.",
|
|
840
|
+
inputSchema: { type: "object", properties: {}, additionalProperties: false },
|
|
841
|
+
annotations: { readOnlyHint: true },
|
|
842
|
+
execute() {
|
|
843
|
+
return { content: [{ type: "text", text: JSON.stringify(connection) }], structuredContent: connection };
|
|
844
|
+
},
|
|
845
|
+
});
|
|
846
|
+
})();
|
|
847
|
+
`;
|
|
848
|
+
const cached = (body, contentType) => () => new Response(body, {
|
|
849
|
+
headers: {
|
|
850
|
+
"content-type": contentType,
|
|
851
|
+
"cache-control": "public, max-age=300",
|
|
852
|
+
"x-content-type-options": "nosniff"
|
|
853
|
+
}
|
|
854
|
+
});
|
|
855
|
+
return /* @__PURE__ */ new Map([
|
|
856
|
+
["/.well-known/api-catalog", cached(apiCatalog, 'application/linkset+json; profile="https://www.rfc-editor.org/info/rfc9727"')],
|
|
857
|
+
["/.well-known/agent-skills/index.json", cached(skillsIndex, "application/json; charset=utf-8")],
|
|
858
|
+
[skillUrlPath, cached(skill, "text/markdown; charset=utf-8")],
|
|
859
|
+
["/.well-known/agent-card.json", () => new Response(null, {
|
|
860
|
+
status: 302,
|
|
861
|
+
headers: { location: A2A_AGENT_CARD_URL, "cache-control": "public, max-age=300" }
|
|
862
|
+
})],
|
|
863
|
+
[WEBMCP_SCRIPT_PATH, cached(webMcpScript, "text/javascript; charset=utf-8")]
|
|
864
|
+
]);
|
|
865
|
+
}
|
|
866
|
+
function skillDescription(skill) {
|
|
867
|
+
const description = /^---\n(?:.*\n)*?description: (.+)\n(?:.*\n)*?---\n/.exec(skill)?.[1];
|
|
868
|
+
if (description === void 0) throw new Error(`${SKILL_NAME}/SKILL.md must declare a frontmatter description.`);
|
|
869
|
+
return description;
|
|
870
|
+
}
|
|
871
|
+
|
|
783
872
|
// src/oauth.ts
|
|
784
873
|
import {
|
|
785
874
|
OAuthError,
|
|
@@ -873,7 +962,7 @@ function firstString(...values) {
|
|
|
873
962
|
}
|
|
874
963
|
|
|
875
964
|
// src/token-status.ts
|
|
876
|
-
import { createHash } from "crypto";
|
|
965
|
+
import { createHash as createHash2 } from "crypto";
|
|
877
966
|
import { decodeJwt } from "jose";
|
|
878
967
|
var ACTIVE_CACHE_MS = 3e4;
|
|
879
968
|
var UNKNOWN_TOLERANCE_MS = 6e4;
|
|
@@ -970,7 +1059,7 @@ function createTokenStatusChecker(config) {
|
|
|
970
1059
|
}
|
|
971
1060
|
return {
|
|
972
1061
|
async tokenStatus(token) {
|
|
973
|
-
const key =
|
|
1062
|
+
const key = createHash2("sha256").update(token).digest("hex");
|
|
974
1063
|
const now = clock();
|
|
975
1064
|
const elapsed = monotonic();
|
|
976
1065
|
const inactiveUntil = inactive.get(key);
|
|
@@ -985,7 +1074,7 @@ function createTokenStatusChecker(config) {
|
|
|
985
1074
|
},
|
|
986
1075
|
toleratesUnknown(token) {
|
|
987
1076
|
if (credentialsRefused) return false;
|
|
988
|
-
const confirmed = confirmedActive.get(
|
|
1077
|
+
const confirmed = confirmedActive.get(createHash2("sha256").update(token).digest("hex"));
|
|
989
1078
|
if (confirmed === void 0) return false;
|
|
990
1079
|
return confirmed.expiresAt > clock() && monotonic() - confirmed.at < UNKNOWN_TOLERANCE_MS;
|
|
991
1080
|
}
|
|
@@ -1021,7 +1110,7 @@ function claims(token) {
|
|
|
1021
1110
|
import { sameTinyCloudNode } from "@tinycloud/sdk-core";
|
|
1022
1111
|
import { createHmac, randomBytes, timingSafeEqual as timingSafeEqual2 } from "crypto";
|
|
1023
1112
|
import { chmod, mkdir, readFile, readdir, rename, rm, writeFile } from "fs/promises";
|
|
1024
|
-
import { dirname, join as
|
|
1113
|
+
import { dirname as dirname2, join as join3 } from "path";
|
|
1025
1114
|
import {
|
|
1026
1115
|
activateValidatedRuntimeDelegation,
|
|
1027
1116
|
deserializeDelegation,
|
|
@@ -1186,7 +1275,7 @@ var RemoteTenantStore = class {
|
|
|
1186
1275
|
const canonical = canonicalOwnerDid(ownerDid);
|
|
1187
1276
|
if (canonical === void 0) throw new NativeGrantValidationError("rejected");
|
|
1188
1277
|
const tenant = createHmac("sha256", this.#config.stateSecret).update(`native-tenant:${canonical}`).digest("hex");
|
|
1189
|
-
return
|
|
1278
|
+
return join3(this.#config.stateDir, "native-tenants", tenant);
|
|
1190
1279
|
}
|
|
1191
1280
|
async acceptNativeGrant(serializedDelegation) {
|
|
1192
1281
|
if (Buffer.byteLength(serializedDelegation) > MAX_CALLBACK_BYTES) {
|
|
@@ -1354,7 +1443,7 @@ var RemoteTenantStore = class {
|
|
|
1354
1443
|
if (Date.parse(stored.expiresAt) <= Date.now()) throw new NativeGrantValidationError("expired");
|
|
1355
1444
|
}
|
|
1356
1445
|
tenantStateRoot(subject) {
|
|
1357
|
-
return
|
|
1446
|
+
return join3(this.#config.stateDir, "tenants", this.#tenantId(subject));
|
|
1358
1447
|
}
|
|
1359
1448
|
/** Prepare only this authenticated account's profile before its first operation. */
|
|
1360
1449
|
async initializeTenant(subject) {
|
|
@@ -1567,7 +1656,7 @@ var RemoteTenantStore = class {
|
|
|
1567
1656
|
}
|
|
1568
1657
|
if (!isRecord(data)) throw new ApprovalRequestError("body_invalid", "Callback body is invalid.");
|
|
1569
1658
|
const pending = await this.#readPending(state, true);
|
|
1570
|
-
const stateRoot =
|
|
1659
|
+
const stateRoot = join3(this.#config.stateDir, "tenants", pending.tenantId);
|
|
1571
1660
|
const prior = this.#approvalProcessing.get(stateRoot);
|
|
1572
1661
|
const processing = (async () => {
|
|
1573
1662
|
if (prior) await prior.catch(() => void 0);
|
|
@@ -1805,7 +1894,7 @@ var RemoteTenantStore = class {
|
|
|
1805
1894
|
approvalEpoch: this.#approvalEpochs.get(tenant.stateRoot)
|
|
1806
1895
|
});
|
|
1807
1896
|
await rm(this.#additionalPath(tenant.stateRoot), { force: true });
|
|
1808
|
-
await rm(
|
|
1897
|
+
await rm(join3(tenant.stateRoot, ".tinycloud", "profiles", PROFILE, "auth-requests.json"), { force: true });
|
|
1809
1898
|
await rm(this.#pendingDirectory(tenant.stateRoot), { recursive: true, force: true });
|
|
1810
1899
|
await rm(this.#sessionPath(tenant.stateRoot), { force: true });
|
|
1811
1900
|
})().finally(() => this.#clearing.delete(tenant.stateRoot));
|
|
@@ -1813,9 +1902,9 @@ var RemoteTenantStore = class {
|
|
|
1813
1902
|
await clearing;
|
|
1814
1903
|
}
|
|
1815
1904
|
async #initializeTenant(tenantId) {
|
|
1816
|
-
const stateRoot =
|
|
1905
|
+
const stateRoot = join3(this.#config.stateDir, "tenants", tenantId);
|
|
1817
1906
|
const keyPath = this.#keyPath(stateRoot);
|
|
1818
|
-
await secureDirectory(
|
|
1907
|
+
await secureDirectory(join3(stateRoot, ".tinycloud", "profiles", PROFILE));
|
|
1819
1908
|
let jwk = await readJson(keyPath);
|
|
1820
1909
|
let sessionDid;
|
|
1821
1910
|
if (jwk === null) {
|
|
@@ -1855,7 +1944,7 @@ var RemoteTenantStore = class {
|
|
|
1855
1944
|
}
|
|
1856
1945
|
async #readTenant(tenantId) {
|
|
1857
1946
|
if (!/^[a-f0-9]{64}$/.test(tenantId)) throw new ApprovalRequestError("state_invalid", "Approval state is invalid.");
|
|
1858
|
-
const stateRoot =
|
|
1947
|
+
const stateRoot = join3(this.#config.stateDir, "tenants", tenantId);
|
|
1859
1948
|
const jwk = await readJson(this.#keyPath(stateRoot));
|
|
1860
1949
|
if (jwk === null) throw new ApprovalRequestError("tenant_missing", "The TinyCloud delegate no longer exists.");
|
|
1861
1950
|
const profile = await readJson(this.#profilePath(stateRoot));
|
|
@@ -1909,7 +1998,7 @@ var RemoteTenantStore = class {
|
|
|
1909
1998
|
if (supplied.length !== expectedBytes.length || !timingSafeEqual2(supplied, expectedBytes)) {
|
|
1910
1999
|
throw new ApprovalRequestError("state_invalid", "Approval state is invalid.");
|
|
1911
2000
|
}
|
|
1912
|
-
const stateRoot =
|
|
2001
|
+
const stateRoot = join3(this.#config.stateDir, "tenants", tenantId);
|
|
1913
2002
|
const path = this.#pendingPath(stateRoot, nonce);
|
|
1914
2003
|
const claimed = `${path}.processing`;
|
|
1915
2004
|
if (consume) {
|
|
@@ -1948,7 +2037,7 @@ var RemoteTenantStore = class {
|
|
|
1948
2037
|
}
|
|
1949
2038
|
}
|
|
1950
2039
|
async #restorePending(pending) {
|
|
1951
|
-
const stateRoot =
|
|
2040
|
+
const stateRoot = join3(this.#config.stateDir, "tenants", pending.tenantId);
|
|
1952
2041
|
const path = this.#pendingPath(stateRoot, pending.nonce);
|
|
1953
2042
|
await rename(`${path}.processing`, path);
|
|
1954
2043
|
}
|
|
@@ -1983,8 +2072,8 @@ var RemoteTenantStore = class {
|
|
|
1983
2072
|
return this.#nativeIdentity;
|
|
1984
2073
|
}
|
|
1985
2074
|
async #readOrCreateNativeServiceKey() {
|
|
1986
|
-
const path =
|
|
1987
|
-
await secureDirectory(
|
|
2075
|
+
const path = join3(this.#config.stateDir, ".tinycloud", "native-service-key.json");
|
|
2076
|
+
await secureDirectory(dirname2(path));
|
|
1988
2077
|
let stored = await readJson(path);
|
|
1989
2078
|
if (stored === null) {
|
|
1990
2079
|
const generated = generateSessionKey();
|
|
@@ -2072,7 +2161,7 @@ var RemoteTenantStore = class {
|
|
|
2072
2161
|
}
|
|
2073
2162
|
}
|
|
2074
2163
|
#nativeGrantPath(stateRoot) {
|
|
2075
|
-
return
|
|
2164
|
+
return join3(stateRoot, ".tinycloud", "native-grant.json");
|
|
2076
2165
|
}
|
|
2077
2166
|
#tenantId(subject) {
|
|
2078
2167
|
return createHmac("sha256", this.#config.stateSecret).update(`tenant:${subject}`).digest("hex");
|
|
@@ -2081,22 +2170,22 @@ var RemoteTenantStore = class {
|
|
|
2081
2170
|
return createHmac("sha256", this.#config.stateSecret).update(`approval:${tenantId}:${nonce}`).digest("base64url");
|
|
2082
2171
|
}
|
|
2083
2172
|
#profilePath(stateRoot) {
|
|
2084
|
-
return
|
|
2173
|
+
return join3(stateRoot, ".tinycloud", "profiles", PROFILE, "profile.json");
|
|
2085
2174
|
}
|
|
2086
2175
|
#keyPath(stateRoot) {
|
|
2087
|
-
return
|
|
2176
|
+
return join3(stateRoot, ".tinycloud", "profiles", PROFILE, "key.json");
|
|
2088
2177
|
}
|
|
2089
2178
|
#sessionPath(stateRoot) {
|
|
2090
|
-
return
|
|
2179
|
+
return join3(stateRoot, ".tinycloud", "profiles", PROFILE, "session.json");
|
|
2091
2180
|
}
|
|
2092
2181
|
#additionalPath(stateRoot) {
|
|
2093
|
-
return
|
|
2182
|
+
return join3(stateRoot, ".tinycloud", "profiles", PROFILE, "additional-delegations.json");
|
|
2094
2183
|
}
|
|
2095
2184
|
#pendingPath(stateRoot, nonce) {
|
|
2096
|
-
return
|
|
2185
|
+
return join3(this.#pendingDirectory(stateRoot), `${nonce}.json`);
|
|
2097
2186
|
}
|
|
2098
2187
|
#pendingDirectory(stateRoot) {
|
|
2099
|
-
return
|
|
2188
|
+
return join3(stateRoot, ".tinycloud", "profiles", PROFILE, "pending");
|
|
2100
2189
|
}
|
|
2101
2190
|
};
|
|
2102
2191
|
var wasmInitialized = false;
|
|
@@ -2189,7 +2278,7 @@ async function secureDirectory(path) {
|
|
|
2189
2278
|
await chmod(path, 448);
|
|
2190
2279
|
}
|
|
2191
2280
|
async function secureWrite(path, value) {
|
|
2192
|
-
const directory =
|
|
2281
|
+
const directory = dirname2(path);
|
|
2193
2282
|
await secureDirectory(directory);
|
|
2194
2283
|
const temporary = `${path}.${process.pid}.${randomBytes(8).toString("hex")}.tmp`;
|
|
2195
2284
|
await writeFile(temporary, `${JSON.stringify(value, jsonReplacer, 2)}
|
|
@@ -2221,7 +2310,7 @@ async function restoreOptionalText(path, contents) {
|
|
|
2221
2310
|
await rm(path, { force: true });
|
|
2222
2311
|
return;
|
|
2223
2312
|
}
|
|
2224
|
-
await secureDirectory(
|
|
2313
|
+
await secureDirectory(dirname2(path));
|
|
2225
2314
|
await writeFile(path, contents, { mode: 384 });
|
|
2226
2315
|
await chmod(path, 384);
|
|
2227
2316
|
}
|
|
@@ -2236,7 +2325,7 @@ async function reusablePending(directory, expected) {
|
|
|
2236
2325
|
const active = [];
|
|
2237
2326
|
for (const name of names) {
|
|
2238
2327
|
if (!name.endsWith(".json")) continue;
|
|
2239
|
-
const path =
|
|
2328
|
+
const path = join3(directory, name);
|
|
2240
2329
|
const pending = await readJson(path).catch(() => null);
|
|
2241
2330
|
if (pending === null || new Date(pending.expiresAt).getTime() <= Date.now()) {
|
|
2242
2331
|
await rm(path, { force: true });
|
|
@@ -2247,7 +2336,7 @@ async function reusablePending(directory, expected) {
|
|
|
2247
2336
|
}
|
|
2248
2337
|
if (active.length >= 64) {
|
|
2249
2338
|
active.sort((left, right) => Date.parse(left.createdAt) - Date.parse(right.createdAt));
|
|
2250
|
-
await rm(
|
|
2339
|
+
await rm(join3(directory, `${active[0].nonce}.json`), { force: true });
|
|
2251
2340
|
}
|
|
2252
2341
|
return void 0;
|
|
2253
2342
|
}
|
|
@@ -2278,7 +2367,7 @@ function createHostedMcpApp(config) {
|
|
|
2278
2367
|
const restricted = createHostedSurface({
|
|
2279
2368
|
...config,
|
|
2280
2369
|
nativeServiceCredential: void 0,
|
|
2281
|
-
stateDir:
|
|
2370
|
+
stateDir: join4(config.stateDir, prefix),
|
|
2282
2371
|
approvalPath: connectUrl.pathname
|
|
2283
2372
|
}, restrictedUrl, "public", statusFor(restrictedUrl), ANNOTATION_TITLE_PREFIXES.has(prefix));
|
|
2284
2373
|
surfaces.push(restricted);
|
|
@@ -2360,6 +2449,7 @@ function createHostedSurface(config, resourceUrl, surface, tokenStatus, annotati
|
|
|
2360
2449
|
scopesSupported: [REQUIRED_SCOPE],
|
|
2361
2450
|
resourceName: surface === "public" ? "TinyCloud personal records" : "TinyCloud hosted MCP"
|
|
2362
2451
|
};
|
|
2452
|
+
const discoveryRoutes = surface === "hosted" ? agentDiscoveryRoutes(resourceUrl, issuer, REQUIRED_SCOPE) : /* @__PURE__ */ new Map();
|
|
2363
2453
|
const allowedHosts = [resourceUrl.hostname];
|
|
2364
2454
|
return {
|
|
2365
2455
|
async fetch(request) {
|
|
@@ -2466,9 +2556,22 @@ function createHostedSurface(config, resourceUrl, surface, tokenStatus, annotati
|
|
|
2466
2556
|
].join("\n") + "\n";
|
|
2467
2557
|
return publicMetadataCors(publicText(authDoc, "text/markdown; charset=utf-8"), request);
|
|
2468
2558
|
}
|
|
2559
|
+
const discoveryRoute = discoveryRoutes.get(url.pathname);
|
|
2560
|
+
if (discoveryRoute !== void 0) {
|
|
2561
|
+
if (request.method === "OPTIONS") {
|
|
2562
|
+
return publicMetadataCors(new Response(null, { status: 204 }), request);
|
|
2563
|
+
}
|
|
2564
|
+
if (request.method !== "GET" && request.method !== "HEAD") return methodNotAllowed("GET, HEAD");
|
|
2565
|
+
const response = discoveryRoute();
|
|
2566
|
+
return publicMetadataCors(
|
|
2567
|
+
request.method === "HEAD" ? new Response(null, { status: response.status, headers: response.headers }) : response,
|
|
2568
|
+
request
|
|
2569
|
+
);
|
|
2570
|
+
}
|
|
2469
2571
|
if (url.pathname === "/robots.txt" && surface === "hosted") {
|
|
2470
2572
|
return request.method === "GET" ? publicText(`User-agent: *
|
|
2471
2573
|
Allow: /
|
|
2574
|
+
Content-Signal: search=yes, ai-input=yes, ai-train=no
|
|
2472
2575
|
Sitemap: ${new URL("/sitemap.xml", resourceUrl)}
|
|
2473
2576
|
Agentmap: ${new URL("/.well-known/ai-catalog.json", resourceUrl)}
|
|
2474
2577
|
`, "text/plain; charset=utf-8") : methodNotAllowed("GET");
|
|
@@ -2545,17 +2648,17 @@ Hosted endpoint: <https://mcp.tinycloud.xyz/mcp> (Streamable HTTP, OpenKey OAuth
|
|
|
2545
2648
|
[Connection documentation](https://docs.tinycloud.xyz/cli/mcp).
|
|
2546
2649
|
|
|
2547
2650
|
Local alternative: install \`${LOCAL_CLI_PACKAGE}\` and \`${LOCAL_MCP_PACKAGE}\` and connect the \`tinycloud-mcp\` stdio server.
|
|
2548
|
-
` : `<!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>`;
|
|
2651
|
+
` : `<!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>`;
|
|
2549
2652
|
const headers = new Headers({
|
|
2550
2653
|
"content-type": markdown ? "text/markdown; charset=utf-8" : "text/html; charset=utf-8",
|
|
2551
2654
|
"cache-control": "public, max-age=300",
|
|
2552
|
-
"content-security-policy": "default-src 'none'; base-uri 'none'; frame-ancestors 'none'",
|
|
2655
|
+
"content-security-policy": "default-src 'none'; script-src 'self'; base-uri 'none'; frame-ancestors 'none'",
|
|
2553
2656
|
"x-content-type-options": "nosniff",
|
|
2554
2657
|
vary: "Accept"
|
|
2555
2658
|
});
|
|
2556
2659
|
headers.set(
|
|
2557
2660
|
"link",
|
|
2558
|
-
`<${new URL("/mcp/server-card", resourceUrl)}>; rel="describedby"; type="application/json", <https://docs.tinycloud.xyz/cli/mcp>; rel="service-doc"`
|
|
2661
|
+
`<${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"`
|
|
2559
2662
|
);
|
|
2560
2663
|
return new Response(request.method === "HEAD" ? null : content, { headers });
|
|
2561
2664
|
}
|