@tinycloud/mcp 0.8.3-beta.15 → 0.8.3-beta.16

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/index.js CHANGED
@@ -485,7 +485,7 @@ function outcomeCode(result) {
485
485
  // package.json
486
486
  var package_default = {
487
487
  name: "@tinycloud/mcp",
488
- version: "0.8.3-beta.15",
488
+ version: "0.8.3-beta.16",
489
489
  description: "TinyCloud delegated operations MCP server",
490
490
  keywords: [
491
491
  "tinycloud",
@@ -1778,6 +1778,8 @@ function samePendingRequest(pending, expected) {
1778
1778
 
1779
1779
  // src/http.ts
1780
1780
  var REQUIRED_SCOPE = "tinycloud:mcp";
1781
+ var LOCAL_CLI_PACKAGE = ["@tinycloud", "cli"].join("/");
1782
+ var LOCAL_MCP_PACKAGE = ["@tinycloud", "mcp"].join("/");
1781
1783
  function createHostedMcpApp(config) {
1782
1784
  const resourceUrl = canonicalResourceUrl(config.publicUrl);
1783
1785
  const pluginUrl = new URL("./chatgpt/mcp", resourceUrl);
@@ -1857,14 +1859,173 @@ function createHostedSurface(config, resourceUrl, surface, tokenStatus) {
1857
1859
  const allowedHosts = [resourceUrl.hostname];
1858
1860
  return {
1859
1861
  async fetch(request) {
1860
- const metadata = oauthMetadataResponse(request, metadataOptions);
1861
- if (metadata !== void 0) return metadata;
1862
1862
  const url = new URL(request.url);
1863
+ if (url.pathname !== "/healthz") {
1864
+ const hostFailure = hostHeaderValidationResponse(request, allowedHosts);
1865
+ if (hostFailure !== void 0) return hostFailure;
1866
+ }
1867
+ if (url.pathname === "/.well-known/oauth-protected-resource" && surface === "hosted") {
1868
+ const metadataUrl = new URL(getOAuthProtectedResourceMetadataUrl(resourceUrl));
1869
+ const metadataRequest = new Request(metadataUrl.toString(), {
1870
+ method: request.method,
1871
+ headers: request.headers
1872
+ });
1873
+ const response = oauthMetadataResponse(metadataRequest, metadataOptions);
1874
+ if (response !== void 0) return withBearerMethodsSupported(response);
1875
+ }
1876
+ const metadata = oauthMetadataResponse(request, metadataOptions);
1877
+ if (metadata !== void 0) {
1878
+ return surface === "hosted" ? withBearerMethodsSupported(metadata) : metadata;
1879
+ }
1880
+ if (url.pathname === "/.well-known/ai-catalog.json" && surface === "hosted") {
1881
+ if (request.method === "OPTIONS") {
1882
+ return publicMetadataCors(new Response(null, { status: 204 }), request);
1883
+ }
1884
+ if (request.method !== "GET") return methodNotAllowed("GET");
1885
+ return publicMetadataCors(Response.json({
1886
+ specVersion: "1.0",
1887
+ host: {
1888
+ displayName: "TinyCloud, Inc.",
1889
+ identifier: "https://mcp.tinycloud.xyz",
1890
+ documentationUrl: "https://docs.tinycloud.xyz/cli/mcp"
1891
+ },
1892
+ entries: [{
1893
+ identifier: "urn:air:tinycloud.xyz:mcp:tinycloud-mcp",
1894
+ displayName: "TinyCloud MCP",
1895
+ type: "application/json",
1896
+ description: "Hosted Streamable HTTP MCP server for delegated TinyCloud operations.",
1897
+ url: new URL("/.well-known/mcp/server-card.json", resourceUrl).toString(),
1898
+ representativeQueries: [
1899
+ "How do I connect to TinyCloud's hosted MCP server?",
1900
+ "Which endpoint provides TinyCloud's delegated MCP operations?",
1901
+ "How can I connect to TinyCloud MCP using local stdio?"
1902
+ ]
1903
+ }]
1904
+ }, {
1905
+ headers: {
1906
+ "cache-control": "public, max-age=300",
1907
+ "content-type": "application/json; charset=utf-8"
1908
+ }
1909
+ }), request);
1910
+ }
1911
+ if (url.pathname === "/.well-known/poppy.json" && surface === "hosted") {
1912
+ if (request.method === "OPTIONS") {
1913
+ return publicMetadataCors(new Response(null, { status: 204 }), request);
1914
+ }
1915
+ if (request.method !== "GET") return methodNotAllowed("GET");
1916
+ return publicMetadataCors(Response.json({
1917
+ protocol_version: "0.1",
1918
+ organization: {
1919
+ name: "TinyCloud, Inc.",
1920
+ domain: resourceUrl.hostname
1921
+ },
1922
+ web: {}
1923
+ }, {
1924
+ headers: {
1925
+ "cache-control": "public, max-age=300",
1926
+ "content-type": "application/json; charset=utf-8"
1927
+ }
1928
+ }), request);
1929
+ }
1930
+ if (url.pathname === "/auth.md" && surface === "hosted") {
1931
+ if (request.method === "OPTIONS") {
1932
+ return publicMetadataCors(new Response(null, { status: 204 }), request);
1933
+ }
1934
+ if (request.method !== "GET") return methodNotAllowed("GET");
1935
+ const issuerUrl = new URL(issuer);
1936
+ const authorizationServerMetadataUrl = new URL(
1937
+ `/.well-known/oauth-authorization-server${issuerUrl.pathname}`,
1938
+ issuerUrl.origin
1939
+ );
1940
+ const registrationEndpoint = config.oauthMetadata.registration_endpoint;
1941
+ const registrationNote = typeof registrationEndpoint === "string" ? `OpenKey's OAuth \`registration_endpoint\` is ${registrationEndpoint}; it registers OAuth clients, not TinyCloud users or agents.` : "The authorization server does not advertise an OAuth client registration endpoint.";
1942
+ const authDoc = [
1943
+ "# TinyCloud MCP auth.md",
1944
+ "",
1945
+ `Protected resource: ${resourceUrl}.`,
1946
+ "",
1947
+ "Send an OAuth access token in the `Authorization: Bearer` header.",
1948
+ "",
1949
+ `Protected Resource Metadata: ${new URL("/.well-known/oauth-protected-resource", resourceUrl)}.`,
1950
+ `Authorization server issuer: ${issuer}.`,
1951
+ `Authorization server metadata: ${authorizationServerMetadataUrl}.`,
1952
+ `Scope: \`${REQUIRED_SCOPE}\`.`,
1953
+ "",
1954
+ "Hosted access uses OpenKey OAuth.",
1955
+ registrationNote,
1956
+ "TinyCloud does not host an Auth.md agent-enrollment or user-registration endpoint for this service.",
1957
+ "No `agent_auth` registration block is published because no agent-registration endpoint is available.",
1958
+ "",
1959
+ `Local stdio is a separate option configured with \`${LOCAL_CLI_PACKAGE}\` and \`${LOCAL_MCP_PACKAGE}\`.`,
1960
+ "",
1961
+ "Connection steps: https://docs.tinycloud.xyz/cli/mcp"
1962
+ ].join("\n") + "\n";
1963
+ return publicMetadataCors(publicText(authDoc, "text/markdown; charset=utf-8"), request);
1964
+ }
1965
+ if (url.pathname === "/robots.txt" && surface === "hosted") {
1966
+ return request.method === "GET" ? publicText(`User-agent: *
1967
+ Allow: /
1968
+ Sitemap: ${new URL("/sitemap.xml", resourceUrl)}
1969
+ Agentmap: ${new URL("/.well-known/ai-catalog.json", resourceUrl)}
1970
+ `, "text/plain; charset=utf-8") : methodNotAllowed("GET");
1971
+ }
1972
+ if ((url.pathname === "/mcp/server-card" || url.pathname === "/.well-known/mcp/server-card.json") && surface === "hosted") {
1973
+ if (request.method === "OPTIONS") {
1974
+ return publicMetadataCors(new Response(null, { status: 204 }), request);
1975
+ }
1976
+ if (request.method !== "GET") return methodNotAllowed("GET");
1977
+ return publicMetadataCors(Response.json({
1978
+ $schema: "https://static.modelcontextprotocol.io/schemas/v1/server-card.schema.json",
1979
+ name: `xyz.tinycloud/${MCP_SERVER_NAME}`,
1980
+ title: "TinyCloud MCP",
1981
+ version: MCP_VERSION,
1982
+ description: "MCP server for delegated TinyCloud operations.",
1983
+ websiteUrl: "https://docs.tinycloud.xyz/cli/mcp",
1984
+ repository: { source: "github", url: "https://github.com/TinyCloudLabs/js-sdk", subfolder: "packages/mcp" },
1985
+ remotes: [{ type: "streamable-http", url: resourceUrl.toString() }]
1986
+ }, { headers: { "cache-control": "public, max-age=300" } }), request);
1987
+ }
1988
+ if (url.pathname === "/llms.txt" && surface === "hosted") {
1989
+ return request.method === "GET" ? publicText(`# TinyCloud MCP
1990
+
1991
+ Hosted Streamable HTTP endpoint: https://mcp.tinycloud.xyz/mcp (OpenKey OAuth).
1992
+
1993
+ Connection documentation: https://docs.tinycloud.xyz/cli/mcp
1994
+
1995
+ Local alternative: install ${LOCAL_CLI_PACKAGE} and ${LOCAL_MCP_PACKAGE}, then set up tinycloud-mcp as a stdio server in your MCP client.
1996
+ `, "text/plain; charset=utf-8") : methodNotAllowed("GET");
1997
+ }
1998
+ if (url.pathname === "/sitemap.xml" && surface === "hosted") {
1999
+ const sitemap = `<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><url><loc>${new URL("/", resourceUrl)}</loc></url></urlset>`;
2000
+ return request.method === "GET" ? publicText(sitemap, "application/xml; charset=utf-8") : methodNotAllowed("GET");
2001
+ }
2002
+ if (url.pathname === "/" && surface === "hosted") {
2003
+ if (request.method !== "GET" && request.method !== "HEAD") return methodNotAllowed("GET, HEAD");
2004
+ const markdown = request.headers.get("accept")?.includes("text/markdown") ?? false;
2005
+ const content = markdown ? `# TinyCloud MCP
2006
+
2007
+ Hosted endpoint: <https://mcp.tinycloud.xyz/mcp> (Streamable HTTP, OpenKey OAuth).
2008
+
2009
+ [Connection documentation](https://docs.tinycloud.xyz/cli/mcp).
2010
+
2011
+ Local alternative: install \`${LOCAL_CLI_PACKAGE}\` and \`${LOCAL_MCP_PACKAGE}\` and connect the \`tinycloud-mcp\` stdio server.
2012
+ ` : `<!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>`;
2013
+ const headers = new Headers({
2014
+ "content-type": markdown ? "text/markdown; charset=utf-8" : "text/html; charset=utf-8",
2015
+ "cache-control": "public, max-age=300",
2016
+ "content-security-policy": "default-src 'none'; base-uri 'none'; frame-ancestors 'none'",
2017
+ "x-content-type-options": "nosniff",
2018
+ vary: "Accept"
2019
+ });
2020
+ headers.set(
2021
+ "link",
2022
+ `<${new URL("/mcp/server-card", resourceUrl)}>; rel="describedby"; type="application/json", <https://docs.tinycloud.xyz/cli/mcp>; rel="service-doc"`
2023
+ );
2024
+ return new Response(request.method === "HEAD" ? null : content, { headers });
2025
+ }
1863
2026
  if (url.pathname === "/healthz") {
1864
2027
  return request.method === "GET" ? json({ ok: true }) : methodNotAllowed("GET");
1865
2028
  }
1866
- const hostFailure = hostHeaderValidationResponse(request, allowedHosts);
1867
- if (hostFailure !== void 0) return hostFailure;
1868
2029
  if (url.pathname === connectPath) {
1869
2030
  if (request.method !== "GET") return methodNotAllowed("GET");
1870
2031
  try {
@@ -2034,6 +2195,41 @@ function callbackCors(response, openkeyHost) {
2034
2195
  function json(value, status = 200) {
2035
2196
  return Response.json(value, { status, headers: { "cache-control": "no-store" } });
2036
2197
  }
2198
+ async function withBearerMethodsSupported(response) {
2199
+ if (response.status === 204 || response.body === null) return response;
2200
+ const metadata = await response.json();
2201
+ const headers = new Headers(response.headers);
2202
+ headers.delete("content-length");
2203
+ headers.delete("content-encoding");
2204
+ return new Response(JSON.stringify({ ...metadata, bearer_methods_supported: ["header"] }), {
2205
+ status: response.status,
2206
+ statusText: response.statusText,
2207
+ headers
2208
+ });
2209
+ }
2210
+ function publicMetadataCors(response, request) {
2211
+ const headers = new Headers(response.headers);
2212
+ headers.set("access-control-allow-origin", "*");
2213
+ headers.set("access-control-allow-methods", "GET, OPTIONS");
2214
+ const requestedHeaders = request.method === "OPTIONS" ? request.headers.get("access-control-request-headers") : null;
2215
+ if (requestedHeaders !== null) {
2216
+ headers.set("access-control-allow-headers", requestedHeaders);
2217
+ }
2218
+ headers.set(
2219
+ "vary",
2220
+ requestedHeaders === null ? "Origin" : "Origin, Access-Control-Request-Headers"
2221
+ );
2222
+ return new Response(response.body, { status: response.status, headers });
2223
+ }
2224
+ function publicText(text, contentType) {
2225
+ return new Response(text, {
2226
+ headers: {
2227
+ "content-type": contentType,
2228
+ "cache-control": "public, max-age=300",
2229
+ "x-content-type-options": "nosniff"
2230
+ }
2231
+ });
2232
+ }
2037
2233
  function methodNotAllowed(allow) {
2038
2234
  return new Response("Method not allowed", { status: 405, headers: { allow } });
2039
2235
  }