fastmcp.utilities.versions
Version comparison utilities for component versioning.
This module provides utilities for comparing component versions. Versions are
strings that are first attempted to be parsed as PEP 440 versions (using the
packaging library), falling back to lexicographic string comparison.
Examples:
- “1”, “2”, “10” → parsed as PEP 440, compared semantically (1 < 2 < 10)
- “1.0”, “2.0” → parsed as PEP 440
- “v1.0” → ‘v’ prefix stripped, parsed as “1.0”
- “2025-01-15” → not valid PEP 440, compared as strings
- None → sorts lowest (unversioned components)
Functions
parse_version_key
version: The version string, or None for unversioned.
- A VersionKey suitable for sorting.
version_sort_key
component: The component to get a sort key for.
- A sortable VersionKey.
compare_versions
a: First version string (or None).b: Second version string (or None).
- -1 if a < b, 0 if a == b, 1 if a > b.
is_version_greater
a: First version string (or None).b: Second version string (or None).
- True if a > b, False otherwise.
max_version
a: First version string (or None).b: Second version string (or None).
- The greater version, or None if both are None.
min_version
a: First version string (or None).b: Second version string (or None).
- The lesser version, or None if both are None.
Classes
VersionSpec
Specification for filtering components by version.
Used by transforms and providers to filter components to a specific
version or version range. Unversioned components (version=None) always
match any spec.
Args:
gte: If set, only versions >= this value match.lt: If set, only versions < this value match.eq: If set, only this exact version matches (gte/lt ignored).
matches
version: The version to check, or None for unversioned.
- True if the version matches the spec.
intersect
other: Another spec to intersect with, or None.
- A VersionSpec that matches only versions satisfying both specs.
VersionKey
A comparable version key that handles None, PEP 440 versions, and strings.
Comparison order:
- None (unversioned) sorts lowest
- PEP 440 versions sort by semantic version order
- Invalid versions (strings) sort lexicographically
- When comparing PEP 440 vs string, PEP 440 comes first

