""" Pydantic data models for the Fabric Config Oracle MCP server. These models define the canonical shape of: * A Minecraft version entry parsed from the Mojang version manifest. * A fully-resolved Fabric mod build configuration. All MCP tool return values are validated against these models before being serialized to JSON, ensuring callers always receive well-formed payloads. """ from __future__ import annotations from datetime import datetime from typing import Literal, Optional from pydantic import BaseModel, ConfigDict, Field # --------------------------------------------------------------------------- # Manifest-level model # --------------------------------------------------------------------------- class MinecraftVersion(BaseModel): """ A single Minecraft version entry extracted from the Mojang manifest. Mojang's manifest exposes every released version (stable releases, snapshots, pre-releases, release candidates) along with an ISO-8601 `releaseTime`. We use `releaseTime` for sorting because version strings alone are ambiguous across the dual versioning schemes (legacy `1.21.x` vs year-based `26.x`). """ model_config = ConfigDict(frozen=True) id: str = Field( ..., description="The version identifier as published by Mojang, e.g. " "'1.21.4', '26.2', or '26.3 Snapshot 2'.", ) type: Literal["release", "snapshot"] = Field( ..., description="Mojang-declared type. Snapshots, pre-releases and " "release candidates are all bucketed under 'snapshot' for our " "fallback purposes.", ) release_time: datetime = Field( ..., description="ISO-8601 timestamp at which Mojang published the version. " "Used for newest-first sorting.", ) url: Optional[str] = Field( default=None, description="Optional URL to the per-version manifest JSON. " "Currently unused but kept for diagnostics.", ) # --------------------------------------------------------------------------- # Resolved configuration model # --------------------------------------------------------------------------- class FabricConfig(BaseModel): """ The fully-resolved Fabric mod build configuration for one Minecraft version. This is the canonical return type of the `get_optimal_fabric_config` MCP tool. Every field is populated by the `VersionResolver` after consulting the Mojang manifest, Fabric Meta, and Modrinth APIs. """ minecraft_version: str = Field( ..., description="The resolved Minecraft version string. May differ from " "the requested version when the requested version was 'latest' and " "the resolver had to fall back to a Fabric-supported version.", ) version_type: Literal["release", "snapshot"] = Field( ..., description="Whether the resolved minecraft_version is a stable " "release or a snapshot.", ) yarn_mappings: str = Field( default="", description="Yarn mappings build string (e.g. '26.2+build.1'). " "Empty string when no Yarn build exists for this MC version.", ) loader_version: str = Field( default="", description="Fabric Loader version (e.g. '0.16.0').", ) fabric_api_version: str = Field( default="", description="Fabric API mod version from Modrinth " "(e.g. '0.100.0+1.21.4'). Empty when Modrinth has no compatible build.", ) loom_version: str = Field( default="1.7-SNAPSHOT", description="Fabric Loom Gradle plugin version. Not currently fetched " "from a remote source — a sensible default is provided and may be " "overridden by the caller.", ) gradle_wrapper_version: str = Field( default="8.8", description="Recommended Gradle wrapper version. Not currently fetched " "from a remote source — a sensible default is provided.", ) message: str = Field( default="", description="Human-readable status message describing the resolution " "outcome, including any missing components.", )