Expand description
§turul-ai-catalog
Parse, validate, build and canonically serialise AI Catalog documents
(application/ai-catalog+json). No async runtime, network or other runtime dependency.
Part of turul-agent-card.
§Quick start
cargo add turul-ai-catalogBuild a catalog that lists an A2A agent and an MCP server, check it against the specification, and write it out:
use turul_ai_catalog::canonical::to_canonical_vec;
use turul_ai_catalog::identity::{ArtifactType, EntryIdentifier, HostIdentifier};
use turul_ai_catalog::model::{AiCatalog, ArtifactSource, CatalogEntry, HostInfo};
use turul_ai_catalog::validate::{Conformance, ConformanceLevel, validate};
let agent = CatalogEntry::new(
EntryIdentifier::new("urn:air:example.com:a2a:research"),
ArtifactType::A2A_AGENT_CARD,
ArtifactSource::Url("https://agents.example.com/.well-known/agent-card.json".into()),
);
let server = CatalogEntry::new(
EntryIdentifier::new("urn:air:example.com:mcp:weather"),
ArtifactType::MCP_SERVER_CARD,
ArtifactSource::Url("https://mcp.example.com/mcp/server-card".into()),
);
let mut catalog = AiCatalog::new(vec![agent, server]);
let mut host = HostInfo::new("Example Corp".into());
host.identifier = Some(HostIdentifier::new("did:web:example.com"));
catalog.host = Some(host);
let report = validate(&catalog);
assert!(!report.has_errors());
assert_eq!(report.conformance(), Conformance::Met(ConformanceLevel::Discoverable));
// RFC 8785 canonical JSON: the same catalog always gives the same bytes.
// Numbers take their RFC 8785 form; only a number that is not a finite double (1e400) is refused.
let bytes = to_canonical_vec(&catalog).expect("every value is I-JSON");
assert!(bytes.starts_with(br#"{"entries":"#));Read a catalog and report what is wrong with it. Parsing is strict (duplicate member names, missing required members and unsupported major versions are errors); validation reports every remaining finding with its JSON Pointer:
use turul_ai_catalog::parse::parse;
use turul_ai_catalog::validate::validate;
let input = br#"{"specVersion":"1.0","entries":[
{"identifier":"urn:air:example.com:mcp:weather","type":"application/mcp-server-card+json",
"url":"https://mcp.example.com/mcp/server-card"}]}"#;
let catalog = parse(input).expect("a well-formed catalog");
for d in validate(&catalog).diagnostics() {
println!("{:?} {} at {}", d.severity, d.code, d.path);
}
assert!(parse(br#"{"specVersion":"1.0"}"#).is_err()); // `entries` is requiredA catalog does not parse or model the artifacts it lists: an A2A Agent Card or MCP Server Card is
referenced by url, or embedded as opaque JSON in data, and declared by its type.
§Feature flags
None. The crate has no dependencies and no optional features.
§Licence
Apache-2.0.
§Modules
parse: strict bytes-to-model reading (parse::parse).model: the document types (model::AiCatalog,model::CatalogEntry, …).validate: content rules the schema cannot express (validate::validate).canonical: RFC 8785 serialisation (canonical::to_canonical_vec).identity: identifiers, artifact types and entry keys.resolve: display-name, description, version and latest-entry resolution.error: rendering an error with its cause chain (error::chain).digest,timestamp,uri,extensionsandjson: the value parsers the other modules share.
Modules§
- canonical
- RFC 8785 (JCS) serialisation: the only code in the workspace that emits JSON text.
- digest
- The one digest parser, for the
algorithm:hex-valueform of #digest-format. - error
- Rendering an error together with its causes.
- extensions
- Extension keys and the policy-urls extension (#format-and-key-naming, #policy-urls-extension).
- identity
- Identity values of the format: spec constants, identifiers, artifact types and entry keys.
- json
- The strict RFC 8259 reader (
read) and its value type (Json). - model
- The AI Catalog document model. Field names are the spec names in snake case.
- parse
- Bytes to model: the
specVersiongate, then the mapping of the CDDL shape (#cddl-schema). - resolve
- Display-name, description, version and latest-entry resolution (#resolving-an-artifact-s-display-name, #resolving-an-artifact-s-description, #resolving-an-artifact-s-version, #multi-version-entries).
- timestamp
- The one RFC 3339 instant (#catalog-entry
updatedAt). - uri
- RFC 3986 grammar, as far as a caller needs it.
- validate
- The one document validator: content rules the CDDL cannot express.