@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/http.js CHANGED
@@ -1533,7 +1533,7 @@ function outcomeCode(result) {
1533
1533
  // package.json
1534
1534
  var package_default = {
1535
1535
  name: "@tinycloud/mcp",
1536
- version: "0.8.3-beta.15",
1536
+ version: "0.8.3-beta.16",
1537
1537
  description: "TinyCloud delegated operations MCP server",
1538
1538
  keywords: [
1539
1539
  "tinycloud",
@@ -1630,6 +1630,8 @@ var MCP_SERVER_NAME = "tinycloud-mcp";
1630
1630
 
1631
1631
  // src/http.ts
1632
1632
  var REQUIRED_SCOPE = "tinycloud:mcp";
1633
+ var LOCAL_CLI_PACKAGE = ["@tinycloud", "cli"].join("/");
1634
+ var LOCAL_MCP_PACKAGE = ["@tinycloud", "mcp"].join("/");
1633
1635
  function createHostedMcpApp(config) {
1634
1636
  const resourceUrl = canonicalResourceUrl(config.publicUrl);
1635
1637
  const pluginUrl = new URL("./chatgpt/mcp", resourceUrl);
@@ -1709,14 +1711,173 @@ function createHostedSurface(config, resourceUrl, surface, tokenStatus) {
1709
1711
  const allowedHosts = [resourceUrl.hostname];
1710
1712
  return {
1711
1713
  async fetch(request) {
1712
- const metadata = oauthMetadataResponse(request, metadataOptions);
1713
- if (metadata !== void 0) return metadata;
1714
1714
  const url = new URL(request.url);
1715
+ if (url.pathname !== "/healthz") {
1716
+ const hostFailure = hostHeaderValidationResponse(request, allowedHosts);
1717
+ if (hostFailure !== void 0) return hostFailure;
1718
+ }
1719
+ if (url.pathname === "/.well-known/oauth-protected-resource" && surface === "hosted") {
1720
+ const metadataUrl = new URL(getOAuthProtectedResourceMetadataUrl(resourceUrl));
1721
+ const metadataRequest = new Request(metadataUrl.toString(), {
1722
+ method: request.method,
1723
+ headers: request.headers
1724
+ });
1725
+ const response = oauthMetadataResponse(metadataRequest, metadataOptions);
1726
+ if (response !== void 0) return withBearerMethodsSupported(response);
1727
+ }
1728
+ const metadata = oauthMetadataResponse(request, metadataOptions);
1729
+ if (metadata !== void 0) {
1730
+ return surface === "hosted" ? withBearerMethodsSupported(metadata) : metadata;
1731
+ }
1732
+ if (url.pathname === "/.well-known/ai-catalog.json" && surface === "hosted") {
1733
+ if (request.method === "OPTIONS") {
1734
+ return publicMetadataCors(new Response(null, { status: 204 }), request);
1735
+ }
1736
+ if (request.method !== "GET") return methodNotAllowed("GET");
1737
+ return publicMetadataCors(Response.json({
1738
+ specVersion: "1.0",
1739
+ host: {
1740
+ displayName: "TinyCloud, Inc.",
1741
+ identifier: "https://mcp.tinycloud.xyz",
1742
+ documentationUrl: "https://docs.tinycloud.xyz/cli/mcp"
1743
+ },
1744
+ entries: [{
1745
+ identifier: "urn:air:tinycloud.xyz:mcp:tinycloud-mcp",
1746
+ displayName: "TinyCloud MCP",
1747
+ type: "application/json",
1748
+ description: "Hosted Streamable HTTP MCP server for delegated TinyCloud operations.",
1749
+ url: new URL("/.well-known/mcp/server-card.json", resourceUrl).toString(),
1750
+ representativeQueries: [
1751
+ "How do I connect to TinyCloud's hosted MCP server?",
1752
+ "Which endpoint provides TinyCloud's delegated MCP operations?",
1753
+ "How can I connect to TinyCloud MCP using local stdio?"
1754
+ ]
1755
+ }]
1756
+ }, {
1757
+ headers: {
1758
+ "cache-control": "public, max-age=300",
1759
+ "content-type": "application/json; charset=utf-8"
1760
+ }
1761
+ }), request);
1762
+ }
1763
+ if (url.pathname === "/.well-known/poppy.json" && surface === "hosted") {
1764
+ if (request.method === "OPTIONS") {
1765
+ return publicMetadataCors(new Response(null, { status: 204 }), request);
1766
+ }
1767
+ if (request.method !== "GET") return methodNotAllowed("GET");
1768
+ return publicMetadataCors(Response.json({
1769
+ protocol_version: "0.1",
1770
+ organization: {
1771
+ name: "TinyCloud, Inc.",
1772
+ domain: resourceUrl.hostname
1773
+ },
1774
+ web: {}
1775
+ }, {
1776
+ headers: {
1777
+ "cache-control": "public, max-age=300",
1778
+ "content-type": "application/json; charset=utf-8"
1779
+ }
1780
+ }), request);
1781
+ }
1782
+ if (url.pathname === "/auth.md" && surface === "hosted") {
1783
+ if (request.method === "OPTIONS") {
1784
+ return publicMetadataCors(new Response(null, { status: 204 }), request);
1785
+ }
1786
+ if (request.method !== "GET") return methodNotAllowed("GET");
1787
+ const issuerUrl = new URL(issuer);
1788
+ const authorizationServerMetadataUrl = new URL(
1789
+ `/.well-known/oauth-authorization-server${issuerUrl.pathname}`,
1790
+ issuerUrl.origin
1791
+ );
1792
+ const registrationEndpoint = config.oauthMetadata.registration_endpoint;
1793
+ 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.";
1794
+ const authDoc = [
1795
+ "# TinyCloud MCP auth.md",
1796
+ "",
1797
+ `Protected resource: ${resourceUrl}.`,
1798
+ "",
1799
+ "Send an OAuth access token in the `Authorization: Bearer` header.",
1800
+ "",
1801
+ `Protected Resource Metadata: ${new URL("/.well-known/oauth-protected-resource", resourceUrl)}.`,
1802
+ `Authorization server issuer: ${issuer}.`,
1803
+ `Authorization server metadata: ${authorizationServerMetadataUrl}.`,
1804
+ `Scope: \`${REQUIRED_SCOPE}\`.`,
1805
+ "",
1806
+ "Hosted access uses OpenKey OAuth.",
1807
+ registrationNote,
1808
+ "TinyCloud does not host an Auth.md agent-enrollment or user-registration endpoint for this service.",
1809
+ "No `agent_auth` registration block is published because no agent-registration endpoint is available.",
1810
+ "",
1811
+ `Local stdio is a separate option configured with \`${LOCAL_CLI_PACKAGE}\` and \`${LOCAL_MCP_PACKAGE}\`.`,
1812
+ "",
1813
+ "Connection steps: https://docs.tinycloud.xyz/cli/mcp"
1814
+ ].join("\n") + "\n";
1815
+ return publicMetadataCors(publicText(authDoc, "text/markdown; charset=utf-8"), request);
1816
+ }
1817
+ if (url.pathname === "/robots.txt" && surface === "hosted") {
1818
+ return request.method === "GET" ? publicText(`User-agent: *
1819
+ Allow: /
1820
+ Sitemap: ${new URL("/sitemap.xml", resourceUrl)}
1821
+ Agentmap: ${new URL("/.well-known/ai-catalog.json", resourceUrl)}
1822
+ `, "text/plain; charset=utf-8") : methodNotAllowed("GET");
1823
+ }
1824
+ if ((url.pathname === "/mcp/server-card" || url.pathname === "/.well-known/mcp/server-card.json") && surface === "hosted") {
1825
+ if (request.method === "OPTIONS") {
1826
+ return publicMetadataCors(new Response(null, { status: 204 }), request);
1827
+ }
1828
+ if (request.method !== "GET") return methodNotAllowed("GET");
1829
+ return publicMetadataCors(Response.json({
1830
+ $schema: "https://static.modelcontextprotocol.io/schemas/v1/server-card.schema.json",
1831
+ name: `xyz.tinycloud/${MCP_SERVER_NAME}`,
1832
+ title: "TinyCloud MCP",
1833
+ version: MCP_VERSION,
1834
+ description: "MCP server for delegated TinyCloud operations.",
1835
+ websiteUrl: "https://docs.tinycloud.xyz/cli/mcp",
1836
+ repository: { source: "github", url: "https://github.com/TinyCloudLabs/js-sdk", subfolder: "packages/mcp" },
1837
+ remotes: [{ type: "streamable-http", url: resourceUrl.toString() }]
1838
+ }, { headers: { "cache-control": "public, max-age=300" } }), request);
1839
+ }
1840
+ if (url.pathname === "/llms.txt" && surface === "hosted") {
1841
+ return request.method === "GET" ? publicText(`# TinyCloud MCP
1842
+
1843
+ Hosted Streamable HTTP endpoint: https://mcp.tinycloud.xyz/mcp (OpenKey OAuth).
1844
+
1845
+ Connection documentation: https://docs.tinycloud.xyz/cli/mcp
1846
+
1847
+ Local alternative: install ${LOCAL_CLI_PACKAGE} and ${LOCAL_MCP_PACKAGE}, then set up tinycloud-mcp as a stdio server in your MCP client.
1848
+ `, "text/plain; charset=utf-8") : methodNotAllowed("GET");
1849
+ }
1850
+ if (url.pathname === "/sitemap.xml" && surface === "hosted") {
1851
+ 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>`;
1852
+ return request.method === "GET" ? publicText(sitemap, "application/xml; charset=utf-8") : methodNotAllowed("GET");
1853
+ }
1854
+ if (url.pathname === "/" && surface === "hosted") {
1855
+ if (request.method !== "GET" && request.method !== "HEAD") return methodNotAllowed("GET, HEAD");
1856
+ const markdown = request.headers.get("accept")?.includes("text/markdown") ?? false;
1857
+ const content = markdown ? `# TinyCloud MCP
1858
+
1859
+ Hosted endpoint: <https://mcp.tinycloud.xyz/mcp> (Streamable HTTP, OpenKey OAuth).
1860
+
1861
+ [Connection documentation](https://docs.tinycloud.xyz/cli/mcp).
1862
+
1863
+ Local alternative: install \`${LOCAL_CLI_PACKAGE}\` and \`${LOCAL_MCP_PACKAGE}\` and connect the \`tinycloud-mcp\` stdio server.
1864
+ ` : `<!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>`;
1865
+ const headers = new Headers({
1866
+ "content-type": markdown ? "text/markdown; charset=utf-8" : "text/html; charset=utf-8",
1867
+ "cache-control": "public, max-age=300",
1868
+ "content-security-policy": "default-src 'none'; base-uri 'none'; frame-ancestors 'none'",
1869
+ "x-content-type-options": "nosniff",
1870
+ vary: "Accept"
1871
+ });
1872
+ headers.set(
1873
+ "link",
1874
+ `<${new URL("/mcp/server-card", resourceUrl)}>; rel="describedby"; type="application/json", <https://docs.tinycloud.xyz/cli/mcp>; rel="service-doc"`
1875
+ );
1876
+ return new Response(request.method === "HEAD" ? null : content, { headers });
1877
+ }
1715
1878
  if (url.pathname === "/healthz") {
1716
1879
  return request.method === "GET" ? json({ ok: true }) : methodNotAllowed("GET");
1717
1880
  }
1718
- const hostFailure = hostHeaderValidationResponse(request, allowedHosts);
1719
- if (hostFailure !== void 0) return hostFailure;
1720
1881
  if (url.pathname === connectPath) {
1721
1882
  if (request.method !== "GET") return methodNotAllowed("GET");
1722
1883
  try {
@@ -1886,6 +2047,41 @@ function callbackCors(response, openkeyHost) {
1886
2047
  function json(value, status = 200) {
1887
2048
  return Response.json(value, { status, headers: { "cache-control": "no-store" } });
1888
2049
  }
2050
+ async function withBearerMethodsSupported(response) {
2051
+ if (response.status === 204 || response.body === null) return response;
2052
+ const metadata = await response.json();
2053
+ const headers = new Headers(response.headers);
2054
+ headers.delete("content-length");
2055
+ headers.delete("content-encoding");
2056
+ return new Response(JSON.stringify({ ...metadata, bearer_methods_supported: ["header"] }), {
2057
+ status: response.status,
2058
+ statusText: response.statusText,
2059
+ headers
2060
+ });
2061
+ }
2062
+ function publicMetadataCors(response, request) {
2063
+ const headers = new Headers(response.headers);
2064
+ headers.set("access-control-allow-origin", "*");
2065
+ headers.set("access-control-allow-methods", "GET, OPTIONS");
2066
+ const requestedHeaders = request.method === "OPTIONS" ? request.headers.get("access-control-request-headers") : null;
2067
+ if (requestedHeaders !== null) {
2068
+ headers.set("access-control-allow-headers", requestedHeaders);
2069
+ }
2070
+ headers.set(
2071
+ "vary",
2072
+ requestedHeaders === null ? "Origin" : "Origin, Access-Control-Request-Headers"
2073
+ );
2074
+ return new Response(response.body, { status: response.status, headers });
2075
+ }
2076
+ function publicText(text, contentType) {
2077
+ return new Response(text, {
2078
+ headers: {
2079
+ "content-type": contentType,
2080
+ "cache-control": "public, max-age=300",
2081
+ "x-content-type-options": "nosniff"
2082
+ }
2083
+ });
2084
+ }
1889
2085
  function methodNotAllowed(allow) {
1890
2086
  return new Response("Method not allowed", { status: 405, headers: { allow } });
1891
2087
  }