diff --git a/src/late/mcp/http_server.py b/src/late/mcp/http_server.py index c5f775d6..6085dc12 100644 --- a/src/late/mcp/http_server.py +++ b/src/late/mcp/http_server.py @@ -15,16 +15,27 @@ """ import argparse +import base64 +import hashlib +import json import logging import os +import re import sys +import urllib.parse from contextlib import asynccontextmanager +from pathlib import Path import anyio import uvicorn from starlette.applications import Starlette from starlette.requests import ClientDisconnect, Request -from starlette.responses import JSONResponse, PlainTextResponse, RedirectResponse +from starlette.responses import ( + HTMLResponse, + JSONResponse, + PlainTextResponse, + RedirectResponse, +) from starlette.types import ASGIApp, Receive, Scope, Send from late.mcp.auth import is_allowed_origin @@ -97,9 +108,58 @@ def filter(self, record: logging.LogRecord) -> bool: logging.getLogger(_logger_name).addFilter(_disconnect_filter) +def _render_landing_page() -> str: + """The landing page at /, with this deployment's URL filled in.""" + logo = (Path(__file__).parent / "logo.svg").read_text() + url = f"{MCP_PUBLIC_URL}{ENDPOINT_MCP}" + cursor_config = base64.b64encode(json.dumps({"url": url}).encode()).decode() + vscode_config = urllib.parse.quote(json.dumps({"type": "http", "url": url})) + return ( + (Path(__file__).parent / "landing.html") + .read_text() + .replace("{{LOGO}}", logo) + .replace("{{MCP_URL}}", MCP_PUBLIC_URL) + .replace("{{CURSOR_CONFIG}}", cursor_config) + .replace("{{VSCODE_CONFIG}}", vscode_config) + .replace("{{CLAUDE_CONNECTOR_URL}}", urllib.parse.quote(url, safe="")) + ) + + +_LANDING_PAGE = _render_landing_page() + +# The page's one inline script is allowed by its hash, so nothing else can run. +_LANDING_SCRIPT_HASH = base64.b64encode( + hashlib.sha256( + re.search(r"", _LANDING_PAGE, re.S).group(1).encode() + ).digest() +).decode() +_LANDING_HEADERS = { + "Content-Security-Policy": ( + "default-src 'none'; " + f"script-src 'sha256-{_LANDING_SCRIPT_HASH}'; " + "style-src 'unsafe-inline'; " + "font-src https://cdn.jsdelivr.net; " + "img-src https://zernio.com data:; " + "base-uri 'none'; form-action 'none'; frame-ancestors 'none'" + ), + "X-Content-Type-Options": "nosniff", + "X-Frame-Options": "DENY", + "Referrer-Policy": "strict-origin-when-cross-origin", + "Permissions-Policy": "camera=(), microphone=(), geolocation=()", + "Strict-Transport-Security": "max-age=31536000", + # Revalidate every load, like zernio.com, so a deploy shows up at once. + "Cache-Control": "public, max-age=0, must-revalidate", + # / answers HTML or JSON by Accept, so caches must key on it. + "Vary": "Accept", +} + + @mcp.custom_route(ENDPOINT_ROOT, methods=["GET"]) -async def handle_root(_request: Request) -> JSONResponse: - """Root endpoint with server information (public, no auth).""" +async def handle_root(request: Request) -> HTMLResponse | JSONResponse: + """Root endpoint (public, no auth): the landing page for browsers, server + information as JSON for everything else.""" + if "text/html" in request.headers.get("accept", ""): + return HTMLResponse(_LANDING_PAGE, headers=_LANDING_HEADERS) return JSONResponse( { "service": SERVICE_NAME, @@ -113,7 +173,8 @@ async def handle_root(_request: Request) -> JSONResponse: }, "documentation": DOCS_URL, "authentication": "Required: 'Authorization: Bearer YOUR_API_KEY'", - } + }, + headers={"Vary": "Accept"}, ) diff --git a/src/late/mcp/landing.html b/src/late/mcp/landing.html new file mode 100644 index 00000000..fe2af424 --- /dev/null +++ b/src/late/mcp/landing.html @@ -0,0 +1,415 @@ + + + + + +Zernio MCP Server: connect Claude, ChatGPT, Cursor and Codex + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ {{LOGO}} + +
+ +
+ MCP server +

Zernio MCP Server. The whole API in your AI client.

+

Connect Claude, ChatGPT, Codex, Cursor or any MCP client, then sign in with your Zernio account. The server is hosted, so there is nothing to install.

+ +
+ {{MCP_URL}}/mcp + +
+ +

Connect your client

+
+ + + + + + + +
+ +
+

Cursor

+ Install in Cursor +

The install link opens Cursor and adds the server. To add it by hand instead, put this in ~/.cursor/mcp.json:

+
{
+  "mcpServers": {
+    "zernio": {
+      "url": "{{MCP_URL}}/mcp"
+    }
+  }
+}
+

Cursor prompts you to sign in with your Zernio account.

+
+ +
+

Claude Code

+

Add the server:

+
claude mcp add --transport http zernio {{MCP_URL}}/mcp
+

Then sign in with your Zernio account:

+
claude /mcp
+
+ +
+

Codex

+

Add the server:

+
codex mcp add zernio --url {{MCP_URL}}/mcp
+

Then sign in with your Zernio account:

+
codex mcp login zernio
+
+ +
+

ChatGPT

+

MCP servers are available on ChatGPT Pro, Plus, Business, Enterprise and Education accounts. Follow the OpenAI documentation to enable developer mode, then create a custom connector with:

+
    +
  • Server URL: {{MCP_URL}}/mcp
  • +
  • Authentication: OAuth
  • +
+

ChatGPT redirects you to sign in with your Zernio account, and the connector activates.

+
+ +
+

Claude

+ Add to Claude +

The link opens Claude with the connector filled in. Click Add, then sign in with your Zernio account.

+

To add it by hand instead, open Settings, then Connectors, then Add custom connector:

+
    +
  • Name: Zernio
  • +
  • URL: {{MCP_URL}}/mcp
  • +
+
+ +
+

VS Code

+ Install in VS Code +

The install link opens VS Code and adds the server. To add it by hand instead, put this in the project's .vscode/mcp.json:

+
{
+  "servers": {
+    "zernio": {
+      "type": "http",
+      "url": "{{MCP_URL}}/mcp"
+    }
+  }
+}
+
+ +
+

Other clients

+

Use the server URL {{MCP_URL}}/mcp and OAuth when your client supports it. Otherwise pass an API key in the Authorization header:

+
{
+  "zernio": {
+    "url": "{{MCP_URL}}/mcp",
+    "headers": {
+      "Authorization": "Bearer $ZERNIO_API_KEY"
+    }
+  }
+}
+

If your client only runs local commands, bridge to the hosted server with mcp-remote. It opens a browser to sign in:

+
{
+  "mcpServers": {
+    "zernio": {
+      "command": "npx",
+      "args": [
+        "-y",
+        "mcp-remote@latest",
+        "{{MCP_URL}}/mcp"
+      ]
+    }
+  }
+}
+
+ +

To check it works, ask the assistant to list your connected Zernio accounts.

+ +

API keys for agents

+

An autonomous agent has nobody at a browser to sign in. Send an API key as a bearer token instead:

+
Authorization: Bearer $ZERNIO_API_KEY
+
+ + +
+ + + + + + diff --git a/src/late/mcp/logo.svg b/src/late/mcp/logo.svg new file mode 100644 index 00000000..790fa007 --- /dev/null +++ b/src/late/mcp/logo.svg @@ -0,0 +1,9 @@ + + + + + + + + +