mcapi 0.2.0

Unified async Rust client for the Minecraft ecosystem (Mojang, Modrinth, CurseForge, Yggdrasil, Blessing Skin, Loaders, Java Runtimes, and SLP)
Documentation

mcapi

License Rust

A unified, clean-room async Rust client for the Minecraft ecosystem — covering Mojang / Microsoft Auth, Modrinth, CurseForge, Yggdrasil / authlib-injector, Blessing Skin / CSL, Mod Loaders, Java Runtimes, and Server List Ping (SLP) in a single feature-gated crate.

Highlights

  • Single Crate, Pay Only for What You Use: Pick exact modules via Cargo features. Enabling only slp compiles with zero HTTP (reqwest) dependencies.
  • One Shared HttpCore (Arc-backed): Configure connection pooling, User-Agent, timeout, mirror routing, and retry policies once via McApi (or HttpCore) and clone zero-cost across every platform client.
  • Unified mcapi::Error: One error enum and mcapi::Result<T> across all modules — no double-wrapping or per-client error conversion boilerplate.
  • Built-in Mirror Routing & Credential Isolation: First-class Mirror::Bmclapi, Mirror::Mcim, Mirror::China, and Mirror::Custom prefix rewriting with optional fallback to official origins. Authenticated and mutating calls (client.authed(token)) always bypass mirrors so tokens and API keys are never leaked to third-party hosts.
  • Resilient & Forward-Compatible: Automatic Retry-After / X-Ratelimit-* parsing, opt-in 429/5xx backoff retries, forward-compatible Unknown enum variants, and [REDACTED] Debug formatting for all tokens and credentials.

Installation

Default (full + tls-aws-lc):

[dependencies]
mcapi = "0.2"

Selective modules (e.g. a launcher needing Mojang, Modrinth, Loaders, and Java Runtimes):

[dependencies]
mcapi = { version = "0.2", default-features = false, features = ["mojang", "modrinth", "loaders", "java", "tls-aws-lc"] }

Zero-HTTP Server List Ping only (with optional DNS SRV):

[dependencies]
mcapi = { version = "0.2", default-features = false, features = ["slp", "slp-srv"] }

Quick Start

1. Shared McApi Entry Point

Share one reqwest::Client connection pool, mirror configuration, and retry policy across all clients:

use std::time::Duration;

use mcapi::modrinth::models::{Facet, FacetBuilder, ProjectType, SearchQuery};
use mcapi::{McApi, Mirror, ResiliencePolicy};

#[tokio::main]
async fn main() -> mcapi::Result<()> {
    let api = McApi::builder()
        .user_agent("my-launcher/1.0 (contact@example.com)")
        .mirror(Mirror::China)
        .resilience(ResiliencePolicy {
            auto_retry_rate_limit: true,
            fallback_to_official: true,
            ..Default::default()
        })
        .timeout(Duration::from_secs(20))
        .build()?;

    // Mojang Piston Meta
    let manifest = api.mojang().version_manifest().await?;
    println!("Latest Minecraft: {}", manifest.latest.release);

    // Modrinth CNF facet search
    let query = SearchQuery::new()
        .query("sodium")
        .facets(FacetBuilder::new().and(Facet::ProjectType(ProjectType::Mod)))
        .limit(5);
    let results = api.modrinth().search(&query).await?;
    println!("Modrinth hits: {}", results.hits.len());

    // Mod Loaders (Fabric / Quilt / Forge / NeoForge) & Java Runtimes
    let fabric = api.loaders().fabric_loaders_for_game("1.21.1").await?;
    let adoptium = api.java().adoptium_available_releases().await?;
    println!("Fabric loaders: {}, Adoptium LTS: Java {}", fabric.len(), adoptium.most_recent_lts);

    Ok(())
}

2. Authenticated Operations (client.authed(token))

Public endpoints live directly on <Platform>Client; protected endpoints live on client.authed(token) (Authed<'_>), which always sends requests directly to the official host (never through third-party mirrors):

use mcapi::mojang::MojangClient;

# async fn example(ms_access_token: &str) -> mcapi::Result<()> {
let mojang = MojangClient::new()?;
let session = mojang.login_full_from_ms_token(ms_access_token, true).await?;

// Authenticated Minecraft Services call
let authed = mojang.authed(&session.minecraft.access_token);
let name_info = authed.name_change_info().await?;
println!("Can change name: {}", name_info.name_change_allowed);
# Ok(())
# }

3. Native Server List Ping (Java & Bedrock)

use std::time::Duration;
use mcapi::slp::SlpClient;

#[tokio::main]
async fn main() -> mcapi::Result<()> {
    let slp = SlpClient::builder().timeout(Duration::from_secs(5)).build();

    let java = slp.ping_java("mc.hypixel.net", None).await?;
    println!(
        "Java: {} ({}/{} players, {} ms)",
        java.status.version.name,
        java.status.players.online,
        java.status.players.max,
        java.latency.as_millis()
    );

    let bedrock = slp.ping_bedrock("play.cubecraft.net", None).await?;
    println!(
        "Bedrock: {} {} ({}/{} players)",
        bedrock.edition, bedrock.version_name, bedrock.online_players, bedrock.max_players
    );
    Ok(())
}

Feature Flags

Module Features

Feature Default Description
full ✅ Enables all standard platform modules (curseforge, modrinth, mojang, yggdrasil, yggdrasil-authlib, blessing, loaders, java, slp)
http via modules Shared Arc-backed HttpCore, Mirror, ResiliencePolicy, McApi
mojang via full MS OAuth2 (Device Code + PKCE) → XBL → XSTS (XErr) → Minecraft login, UUID/session lookup, Minecraft Services, Piston Meta
modrinth via full Modrinth v2 REST API (CNF search, projects, chunked lookups, versions, SHA-1/512 hash lookup & update, tags, statistics, creator APIs)
curseforge via full CurseForge Core API v1/v2 (search, chunked mods/files, Murmur2 cf_fingerprint, Minecraft versions/loaders, keyless mirror mode)
yggdrasil via full Yggdrasil auth/session/profile client and ALI auto-discovery (YggdrasilClient::discover)
yggdrasil-authlib via full authlib-injector build metadata client (AuthlibInjectorClient)
yggdrasil-verify ❌ Opt-in RSA-SHA1 (SHA1withRSA) signature verification (ProfileProperty::verify_signature, GameProfile::decode_and_verify_textures)
blessing via full Blessing Skin v6 REST API (login, /skinlib/list, /skinlib/info/{tid}, upload/manage, closet, players) + CustomSkinLoader endpoints
loaders via full Fabric Meta v2, Quilt Meta v3, Forge (Maven XML / Promotions / BMCLAPI), NeoForge (Maven XML / 1.20.1 legacy / BMCLAPI), LiteLoader, OptiFine
java via full Mojang Official Java Runtimes (all.json + file manifests), Adoptium Temurin v3, Azul Zulu Metadata v1
slp via full Native TCP Java SLP (1.7+ VarInt & 1.4–1.6 Legacy FE 01 FA) and UDP Bedrock RakNet Ping (zero HTTP deps)
slp-srv ❌ Opt-in _minecraft._tcp DNS SRV resolution via hickory-resolver (cached per SlpClient)
stream ❌ Enables reqwest/stream (Response::bytes_stream) for HttpCore::get_stream

TLS Backends

Select one TLS backend when any HTTP module is enabled:

  • tls-aws-lc (default) — reqwest/rustls (aws-lc-rs)
  • tls-native — reqwest/native-tls
  • tls-native-vendored — reqwest/native-tls-vendored
  • tls-rustls-no-provider — reqwest/rustls-no-provider (supply your own rustls crypto provider)

Examples & Development

Run the included Server List Ping CLI example:

cargo run --example server_ping -- mc.hypixel.net

Run the full verification suite:

cargo fmt --all -- --check
cargo clippy --all-targets --all-features -- -D warnings
cargo test --all-features
cargo check --no-default-features
cargo check --no-default-features --features "full,tls-native"
cargo test --no-default-features --features "mojang,modrinth,tls-aws-lc"
cargo test --no-default-features --features "slp"
cargo test --no-default-features --features "yggdrasil,tls-aws-lc"
cargo test --no-default-features --features "yggdrasil-verify,tls-aws-lc"
cargo doc --all-features --no-deps

License

Dual-licensed under either of:

at your option.