atpmcp 0.15.0

AT Protocol MCP server (Model Context Protocol 2026-07-28)
//! `server/discover` — the replacement for the `initialize` handshake.
//!
//! Servers **MUST** implement this. A client may call it before anything else
//! to learn what versions and capabilities are on offer, and a dual-era client
//! uses it on stdio as its backward-compatibility probe: a `DiscoverResult`
//! identifies a modern server, and anything else identifies a legacy one.
//!
//! Unlike `initialize`, this establishes nothing. It is an ordinary cacheable
//! request that happens to describe the server, and a client is free never to
//! send it.

use std::sync::Arc;

use serde_json::Value;

use crate::context::ServerContext;
use crate::proto::PROTOCOL_VERSION;

/// Natural-language guidance for a model using this server.
///
/// The one place to tell a model that blob resources exist and what reading
/// one costs, which is otherwise invisible until it has already asked.
const INSTRUCTIONS: &str = "AT Protocol tools: identity and handle resolution, DAG-CBOR CIDs, \
TIDs, lexicon fetch and validation, XRPC invocation, and blob upload/download. Blobs are also \
exposed as resources under atpmcp://public/blob/{did}/{cid}; reading one fetches it from the \
repository's PDS, verifies the bytes against the CID, and caches them locally. Blobs are \
returned as a file path and a resource link by default; ask for them inline only when they are \
small, because inline bytes are base64 and consume the context window quickly.";

/// The capabilities this server offers.
///
/// `listChanged` and `subscribe` are both false and say so explicitly rather
/// than being omitted: nothing here changes, and a client that knows that can
/// skip opening a subscription it would learn nothing from.
#[must_use]
pub fn capabilities() -> Value {
    serde_json::json!({
        "tools": { "listChanged": false },
        "resources": { "listChanged": false, "subscribe": false },
    })
}

/// Build the `server/discover` payload.
#[must_use]
pub fn payload(ctx: &Arc<ServerContext>) -> Value {
    let _ = ctx;
    serde_json::json!({
        "supportedVersions": [PROTOCOL_VERSION],
        "capabilities": capabilities(),
        "instructions": INSTRUCTIONS,
    })
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn advertises_exactly_the_version_this_server_implements() {
        let capabilities = capabilities();
        assert_eq!(capabilities["tools"]["listChanged"], false);
        assert_eq!(capabilities["resources"]["subscribe"], false);
    }

    #[test]
    fn instructions_name_the_blob_uri_scheme() {
        assert!(INSTRUCTIONS.contains("atpmcp://public/blob/"));
    }
}