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