~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

The root says what the server is, and how to connect an AI app to it

Merged chadtmiller.com asked to merge into main from chadtmiller.com/monolith:root-page
crates/pds-server/src/lib.rs+1−0
@@ -717,6 +717,7 @@ fn router(svc: Shared) -> Router {
"/xrpc/com.atproto.sync.subscribeRepos",
get(events::subscribe),
)
.route("/", any(ops::root))
.route("/xrpc/_health", any(ops::health))
.route("/xrpc/com.atproto.repo.uploadBlob", any(blobs::upload))
.route("/xrpc/{*method}", any(handle))
crates/pds-server/src/ops.rs+64−2
@@ -380,9 +380,10 @@ pub(crate) async fn fsync<T>(f: impl Future<Output = T>) -> T {
}
/// The routes outside `/xrpc/` the server serves, each its own label: the
/// MCP endpoint, `atproto-did`, OAuth's metadata, endpoints and pages, and
/// the MCP issuer's (`spec/OAUTH-MCP.md`).
/// root, the MCP endpoint, `atproto-did`, OAuth's metadata, endpoints and
/// pages, and the MCP issuer's (`spec/OAUTH-MCP.md`).
const ROUTES: &[&str] = &[
"/",
"/mcp",
"/.well-known/atproto-did",
"/.well-known/oauth-protected-resource",
@@ -599,3 +600,64 @@ pub(crate) async fn health(method: Method) -> Response<Body> {
)
.into_response()
}
// ------------------------------------------------------------ the root
/// What `/` says, `<origin>` standing for the origin of `PDS_PUBLIC_URL`
/// (`spec/OPERATIONS.md`, "The root").
const ROOT: &str = r#"
__ __
/\ \__ /\ \__
__ \ \ ,_\ _____ _ __ ___\ \ ,_\ ___
/'__'\ \ \ \/ /\ '__'\/\''__\/ __'\ \ \/ / __'\
/\ \L\.\_\ \ \_\ \ \L\ \ \ \//\ \L\ \ \ \_/\ \L\ \
\ \__/.\_\\ \__\\ \ ,__/\ \_\\ \____/\ \__\ \____/
\/__/\/_/ \/__/ \ \ \/ \/_/ \/___/ \/__/\/___/
\ \_\
\/_/
This is an AT Protocol Personal Data Server (aka, an atproto PDS):
spec-pds, built from its specification.
Most API routes are under /xrpc/
Connect an AI app
1. Add this address to your AI app as a connector:
<origin>/mcp
In Claude: Settings > Connectors > Add custom connector,
and choose "Sign in when needed".
2. When it asks, sign in here and approve it.
3. Ask it things like:
What have I posted this week?
Post "hello from Claude" to Bluesky
Who have I followed lately?
Set my Bluesky bio to "Software engineer in Seattle"
Code: https://knotless.dev/chadtmiller.com/spec-pds
Protocol: https://atproto.com
"#;
/// `/`: what the server is, and how to connect an AI app to it, to `GET`
/// and `HEAD`, whatever the query; any other method is no route.
pub(crate) async fn root(
axum::extract::State(svc): axum::extract::State<Shared>,
method: Method,
) -> Response<Body> {
use axum::response::IntoResponse;
if method != Method::GET && method != Method::HEAD {
return StatusCode::NOT_FOUND.into_response();
}
(
StatusCode::OK,
[(header::CONTENT_TYPE, "text/plain; charset=utf-8")],
ROOT.replace("<origin>", &svc.oauth.issuer),
)
.into_response()
}
harness/checks/operations.mjs+29−1
@@ -243,6 +243,33 @@ async function checkHealth() {
}
}
/// The text `GET /` answers, as spec/OPERATIONS.md's "The root" writes it,
/// read from that page, with the server's own origin.
function rootText() {
const page = readFileSync(new URL('../../spec/OPERATIONS.md', import.meta.url), 'utf8')
const block = /## The root\n[\s\S]*?```text\n([\s\S]*?)\n```/.exec(page)?.[1]
if (block === undefined) throw new Error('spec/OPERATIONS.md has no "The root" text block')
return `${block.replaceAll('<origin>', new URL(cand.publicUrl).origin)}\n`
}
/// `/`, GET, with a query, HEAD and POST, held to the reference: the status
/// and Content-Type; and the server's text held to the spec, with no
/// RateLimit headers.
async function checkRoot() {
const want = rootText()
const ask = (side, method, path) =>
fetch(`${side.url}${path}`, { method }).then(async (r) => ({ status: r.status, type: r.status < 400 ? r.headers.get('content-type') : null, body: await r.text(), limits: [...r.headers.keys()].filter((k) => k.startsWith('ratelimit')) }))
for (const [method, path] of [['GET', '/'], ['GET', '/?x=1'], ['HEAD', '/'], ['POST', '/']]) {
const [a, b] = await Promise.all([ref, cand].map((side) => ask(side, method, path)))
const [na, nb] = [a, b].map(({ status, type }) => ({ status, type }))
if (JSON.stringify(na) !== JSON.stringify(nb)) await broke('the root', { method, path }, na, nb)
if (b.status === 200 && b.limits.length) await broke('the root', { method, path }, 'no RateLimit headers', b.limits)
const body = method === 'HEAD' ? '' : want
if (b.status === 200 && b.body !== body) await broke('the root', { method, path }, body, b.body)
count(`the root ${method}${path.includes('?') ? ' with a query' : ''}`, b.status < 400)
}
}
/// Routes the server does not serve, each to be `_unknown` in the log and
/// the metrics.
async function unknownRoutes() {
@@ -642,6 +669,7 @@ export async function checkOperations() {
if (ops('health')) await checkHealth()
// The version the spans name, when the health checks did not read it.
else version = await fetch(`${cand.url}${HEALTH}`).then((r) => r.json()).then((b) => b?.version ?? null).catch(() => null)
if (ops('root')) await checkRoot()
if (ops('routes')) await unknownRoutes()
if (ops('traceContext')) await traceContext()
if (ops('metrics')) {
@@ -657,5 +685,5 @@ export async function checkOperations() {
/// The checks at the end of a run, by name: with `--only` naming some of
/// them, only those.
const OPS = ['health', 'routes', 'traceContext', 'metrics', 'lifecycle', 'log']
const OPS = ['health', 'root', 'routes', 'traceContext', 'metrics', 'lifecycle', 'log']
const ops = (name) => !ONLY || !OPS.some((n) => ONLY.has(n)) || ONLY.has(name)
harness/lib/observe.mjs+1−0
@@ -261,6 +261,7 @@ for (const file of readdirSync(new URL('../../spec/lexicons', import.meta.url),
/// The routes outside /xrpc/ the server serves, as spec/OPERATIONS.md lists them.
export const ROUTES = [
'/',
'/mcp',
'/.well-known/atproto-did',
'/.well-known/oauth-protected-resource',
spec/OPERATIONS.md+60−2
@@ -146,6 +146,60 @@ if any, is ignored. `HEAD` answers the same status and headers with no body;
is in no rate limit: past `global` (`LIMITS.md`) it is still `200`, with no
`RateLimit-*` headers. Its route is `_health`.
## The root
`GET /` says what the server is, as the reference's does, and how to
connect an AI app to it (`COMMANDS.md`, `OAUTH-MCP.md`). It answers `200`
with `Content-Type: text/plain; charset=utf-8` and this text, where
`<origin>` is the origin of `PDS_PUBLIC_URL`, every line ending in `\n`,
the first line empty, and none with spaces at its end:
```text
__ __
/\ \__ /\ \__
__ \ \ ,_\ _____ _ __ ___\ \ ,_\ ___
/'__'\ \ \ \/ /\ '__'\/\''__\/ __'\ \ \/ / __'\
/\ \L\.\_\ \ \_\ \ \L\ \ \ \//\ \L\ \ \ \_/\ \L\ \
\ \__/.\_\\ \__\\ \ ,__/\ \_\\ \____/\ \__\ \____/
\/__/\/_/ \/__/ \ \ \/ \/_/ \/___/ \/__/\/___/
\ \_\
\/_/
This is an AT Protocol Personal Data Server (aka, an atproto PDS):
spec-pds, built from its specification.
Most API routes are under /xrpc/
Connect an AI app
1. Add this address to your AI app as a connector:
<origin>/mcp
In Claude: Settings > Connectors > Add custom connector,
and choose "Sign in when needed".
2. When it asks, sign in here and approve it.
3. Ask it things like:
What have I posted this week?
Post "hello from Claude" to Bluesky
Who have I followed lately?
Set my Bluesky bio to "Software engineer in Seattle"
Code: https://knotless.dev/chadtmiller.com/spec-pds
Protocol: https://atproto.com
```
The banner is the reference's; the rest is this server's own, and only the
status and `Content-Type` are compared. Its query, if any, is ignored.
`HEAD` answers the same status and headers with no body; any other method
is `404`, as the reference's. It is in no rate limit and carries no
`RateLimit-*` headers, as the reference's does not. Its route is `/`.
## Metrics
`GET /metrics` on `127.0.0.1:PDS_METRICS_PORT` answers the server's metrics,
@@ -193,8 +247,8 @@ The labels:
- a method the server serves, by its NSID, for `/xrpc/<nsid>`, whatever its
HTTP method;
- `_health`, for `/xrpc/_health`;
- a route outside `/xrpc/` the server serves, as its path: `/mcp`
(`COMMANDS.md`), `/.well-known/atproto-did` (`IDENTITY.md`), and
- a route outside `/xrpc/` the server serves, as its path: `/` ("The
root"), `/mcp` (`COMMANDS.md`), `/.well-known/atproto-did` (`IDENTITY.md`), and
OAuth's (`OAUTH.md`): `/.well-known/oauth-protected-resource`,
`/.well-known/oauth-authorization-server`, `/oauth/jwks`, `/oauth/par`,
`/oauth/token`, `/oauth/revoke`, `/oauth/authorize`,
@@ -361,6 +415,10 @@ is back at two thirds; the steps go on. Then, at the end:
query, against the reference: the status, `Content-Type`, and the body's
form; `/metrics` on the server's own port, `404` on both; with
`--limits`, `_health` past `global` on both.
- **The root**: `GET`, `HEAD` and `POST /`, and `GET` with a query,
against the reference: the status and `Content-Type`; the server's text
held to "The root" above, read from this page, with its own origin; and
no `RateLimit-*` headers on it.
- **Routes**: paths under `/xrpc/` of no method served, one that is no
NSID, and another path, each of route `_unknown`.
- **Trace context**: `_health` with no `traceparent`, ones not valid (no
spec/PDS.md+3−2
@@ -117,8 +117,9 @@ and, besides XRPC, OAuth's metadata, its `/oauth/*` endpoints and pages
(`OAUTH.md`), and OAuth access tokens on every method that takes a token
(`OAUTH-SCOPES.md`).
Besides its methods, it serves `GET /xrpc/_health`, and writes its log,
exports its traces and serves its metrics, as `OPERATIONS.md` says.
Besides its methods, it serves `GET /` and `GET /xrpc/_health`, and writes
its log, exports its traces and serves its metrics, as `OPERATIONS.md`
says.
`repo` parameters name an account by its handle or DID; DIDs and handles
are as `atproto/did.md` and `atproto/handle.md` define them. A session's