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-clientCreate 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. - Display
Text - Catalog text for a text rendering: every Unicode
Cccharacter is replaced by U+FFFD and every other character is kept. - Entry
Input - Unchecked
addflags. - Entry
Row - Display values of one entry, resolved without fetching its artifact.
- Fetch
Policy - Limits for one
fetchcall or oneload. 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.
- Host
Input - Unchecked host flags;
display_nameis required becausehost.displayNameMUST be present. - Invalid
Host - The text given to
WellKnownHost::newis not a host with an optional port. - Nested
- A nested catalog entry and what loading it produced.
- Resolved
Catalog - 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.
- Well
Known Host - A host with an optional port and nothing else, resolved to its
/.well-known/ai-catalog.jsonURL.
Enums§
- Accept
Error - Why
accept_responserefused 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.
- Fetch
Error - Why
fetchrefused or failed a request. - Load
Error - Why
loadcould not load the root catalog. - Load
Warning - A non-fatal retrieval outcome; it describes how a catalog was obtained, not what it contains.
- Produce
Error - Why
producerefused a change. - Skip
Reason - Why a nested catalog was not loaded.
- Source
- Where
loadreads 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-Typevalue: everything before the first;, trimmed. - produce
- Applies
changeto the catalog file atpathand writes the canonical bytes back. - resolve_
reference - Resolves
referenceagainst the optionalbaseURL.