Skip to main content

Crate turul_ai_catalog_client

Crate turul_ai_catalog_client 

Source
Expand description

§turul-ai-catalog-client

Create AI Catalog files, and load catalogs from files or HTTPS (under the specification’s Safe Fetching rules), following nested catalogs into one resolved tree. Built on turul-ai-catalog.

Part of turul-agent-card.

§Features

This crate has no Cargo feature flags.

HTTPS requests are blocking; from async code call load and fetch through tokio::task::spawn_blocking.

§Quick start

cargo add turul-ai-catalog-client

Create a catalog file and add an MCP server to it. Every change is validated, and only a document without errors is written, as canonical JSON:

use turul_ai_catalog_client::{Change, Content, EntryInput, HostInput, produce};

let dir = std::env::temp_dir().join(format!("ai-catalog-readme-{}", std::process::id()));
std::fs::create_dir_all(&dir)?;
let file = dir.join("ai-catalog.json");

let mut host = HostInput::new("Example Corp".into());
host.identifier = Some("did:web:example.com".into());
produce(&file, &Change::Init { host: Some(host) })?;

let mut server = EntryInput::new(
    "urn:air:example.com:mcp:weather".into(),
    "application/mcp-server-card+json".into(),
    Content::Url("https://mcp.example.com/mcp/server-card".into()),
);
server.display_name = Some("Weather".into());
produce(&file, &Change::Add(server))?;

Load a catalog and list its entries. Source::File reads locally; Source::Url and Source::WellKnown fetch over HTTPS with private addresses, redirects, size, time and request count all bounded by FetchPolicy:

use turul_ai_catalog_client::{FetchPolicy, Source, load};

let tree = load(&Source::File(file), &FetchPolicy::default())?;
for row in &tree.rows {
    println!("{}", row.name);
}
for warning in &tree.warnings {
    eprintln!("warning: {warning:?}");
}
assert_eq!(tree.rows[0].name, "weather");

§Licence

Apache-2.0.

Structs§

Accepted
A response that passed accept_response.
DisplayText
Catalog text for a text rendering: every Unicode Cc character is replaced by U+FFFD and every other character is kept.
EntryInput
Unchecked add flags.
EntryRow
Display values of one entry, resolved without fetching its artifact.
FetchPolicy
Limits for one fetch call or one load. Defaults: 4 MiB, 10 s, 5 redirects, loopback off, 256 requests.
Fetched
An HTTP response received by fetch.
Filter
Criteria that must all hold; an unset criterion matches everything.
HostInput
Unchecked host flags; display_name is required because host.displayName MUST be present.
InvalidHost
The text given to WellKnownHost::new is not a host with an optional port.
Nested
A nested catalog entry and what loading it produced.
ResolvedCatalog
A loaded catalog with its validation report and the nested catalogs resolved from it.
Unresolvable
A URL reference that cannot be resolved to an absolute URL.
WellKnownHost
A host with an optional port and nothing else, resolved to its /.well-known/ai-catalog.json URL.

Enums§

AcceptError
Why accept_response refused a response.
Change
What a producer command asks for.
Child
The outcome of loading one nested catalog.
Content
Where an entry’s artifact content comes from.
FetchError
Why fetch refused or failed a request.
LoadError
Why load could not load the root catalog.
LoadWarning
A non-fatal retrieval outcome; it describes how a catalog was obtained, not what it contains.
ProduceError
Why produce refused a change.
SkipReason
Why a nested catalog was not loaded.
Source
Where load reads a root catalog from.

Functions§

accept_response
Accepts a fetched response as a catalog.
fetch
Sends one GET under Safe Fetching, following redirects itself.
load
Loads a catalog and the catalogs nested in it by url.
media_type_essence
Returns the media type of a raw Content-Type value: everything before the first ;, trimmed.
produce
Applies change to the catalog file at path and writes the canonical bytes back.
resolve_reference
Resolves reference against the optional base URL.