Skip to content

Python API

The modules behind the server, rendered from their docstrings. The MCP tools themselves are listed on the tools reference; this page is for reading or extending the code.

Server

The MCP server: endoflife.date queries exposed as read-only MCP tools.

build_server

build_server(
    settings: Settings, service: EndOfLife | None = None
) -> MCPServer

Create the MCP server and register its tools.

Parameters:

Name Type Description Default
settings Settings

Resolved settings.

required
service EndOfLife | None

The endoflife.date service to use. By default one is built from settings and closed when the server shuts down.

None

Returns:

Type Description
MCPServer

The server, ready to run.

Configuration

Settings, resolved from CLI options, environment variables and a TOML config file.

Precedence, highest first: CLI option > ENDOFLIFE_MCP_* environment variable > config file > default. The config file is $XDG_CONFIG_HOME/endoflife-mcp-server/config.toml (~/.config/endoflife-mcp-server/config.toml when XDG_CONFIG_HOME is unset), or the file passed with --config.

ConfigFileNotFoundError

Bases: FileNotFoundError

The config file passed with --config does not exist.

Settings

Bases: BaseSettings

Runtime settings for the server.

settings_customise_sources classmethod

settings_customise_sources(
    settings_cls: type[BaseSettings],
    init_settings: PydanticBaseSettingsSource,
    env_settings: PydanticBaseSettingsSource,
    dotenv_settings: PydanticBaseSettingsSource,
    file_secret_settings: PydanticBaseSettingsSource,
) -> tuple[PydanticBaseSettingsSource, ...]

Read CLI values, then the environment, then the TOML config file.

Parameters:

Name Type Description Default
settings_cls type[BaseSettings]

The settings class being built.

required
init_settings PydanticBaseSettingsSource

Values passed to the constructor (the CLI options).

required
env_settings PydanticBaseSettingsSource

ENDOFLIFE_MCP_* environment variables.

required
dotenv_settings PydanticBaseSettingsSource

Unused; .env files are not read.

required
file_secret_settings PydanticBaseSettingsSource

Unused; secret files are not read.

required

Returns:

Type Description
tuple[PydanticBaseSettingsSource, ...]

The sources in precedence order.

default_config_file

default_config_file() -> Path

Return where the config file lives when --config is not given.

Returns:

Type Description
Path

$XDG_CONFIG_HOME/endoflife-mcp-server/config.toml, falling back to

Path

~/.config when XDG_CONFIG_HOME is unset or empty.

load_settings

load_settings(
    config_file: Path | None = None, **overrides: Any
) -> Settings

Resolve settings from every source.

Parameters:

Name Type Description Default
config_file Path | None

An explicit config file. It must exist. When None, the default file is read if it exists.

None
**overrides Any

Values given on the command line. None values are ignored, so unset options fall through to the environment and the file.

{}

Returns:

Type Description
Settings

The resolved settings.

Raises:

Type Description
ConfigFileNotFoundError

If config_file is given but does not exist.

ValidationError

If any source holds an invalid value.

Service

The endoflife.date service: typed, validated calls to the endoflife.date v1 API.

Requests go through the client generated from api/external/endoflife.yaml; this module adds name validation, error mapping and the shapes the MCP tools return.

DEFAULT_API_URL module-attribute

DEFAULT_API_URL = 'https://endoflife.date/api/v1'

The public endoflife.date v1 API.

USER_AGENT module-attribute

USER_AGENT = f"endoflife-mcp-server/{__version__} (+https://github.com/rossedman/endoflife-mcp-server)"

Sent with every request so endoflife.date can tell where traffic comes from.

EndOfLife

EndOfLife(
    api_url: str = DEFAULT_API_URL,
    timeout: float = 10.0,
    *,
    transport: AsyncBaseTransport | None = None,
)

An async client for the endoflife.date API that returns plain JSON-ready data.

Use it as an async context manager, or call :meth:aclose when done, so the underlying HTTP connection pool is released.

Create the service.

Parameters:

Name Type Description Default
api_url str

Base URL of the endoflife.date v1 API.

DEFAULT_API_URL
timeout float

Seconds to wait for each request before giving up.

10.0
transport AsyncBaseTransport | None

An httpx transport to send requests through instead of the network, used by tests.

None

aclose async

aclose() -> None

Close the underlying HTTP client.

product_summaries async

product_summaries() -> list[ProductSummary]

Fetch the summary of every product endoflife.date tracks.

Returns:

Type Description
list[ProductSummary]

One summary per product, in the API's order.

Raises:

Type Description
EndOfLifeError

If the request fails.

product_names async

product_names() -> list[str]

List the canonical name of every product endoflife.date tracks.

Returns:

Type Description
list[str]

Product names such as python or amazon-eks, in the API's order.

Raises:

Type Description
EndOfLifeError

If the request fails.

product async

product(name: str) -> dict[str, Any]

Fetch everything endoflife.date knows about a product, including all releases.

Aliases (k8s) are resolved to the canonical product (kubernetes).

Parameters:

Name Type Description Default
name str

The product name or alias.

required

Returns:

Type Description
dict[str, Any]

The product details, as JSON-ready data.

Raises:

Type Description
InvalidNameError

If name cannot be a product name.

NotFoundError

If there is no such product; the message suggests close names.

EndOfLifeError

If the request fails for another reason.

release async

release(product_name: str, release: str) -> dict[str, Any]

Fetch one release cycle of a product, such as Python 3.12.

Parameters:

Name Type Description Default
product_name str

The product name or alias.

required
release str

The release cycle name, as listed in the product's releases.

required

Returns:

Type Description
dict[str, Any]

The release cycle, as JSON-ready data.

Raises:

Type Description
InvalidNameError

If either name is invalid.

NotFoundError

If the product or the release cycle does not exist.

EndOfLifeError

If the request fails for another reason.

latest_release async

latest_release(product_name: str) -> dict[str, Any]

Fetch the newest release cycle of a product.

Parameters:

Name Type Description Default
product_name str

The product name or alias.

required

Returns:

Type Description
dict[str, Any]

The latest release cycle, as JSON-ready data.

Raises:

Type Description
InvalidNameError

If the name is invalid.

NotFoundError

If the product does not exist.

EndOfLifeError

If the request fails for another reason.

categories async

categories() -> list[str]

List the product categories, such as lang, os or database.

Returns:

Type Description
list[str]

Category names.

Raises:

Type Description
EndOfLifeError

If the request fails.

category_products async

category_products(category: str) -> list[dict[str, Any]]

List the products in a category.

Parameters:

Name Type Description Default
category str

A category name from :meth:categories.

required

Returns:

Type Description
list[dict[str, Any]]

A summary of each product in the category.

Raises:

Type Description
InvalidNameError

If the name is invalid.

NotFoundError

If the category does not exist.

EndOfLifeError

If the request fails for another reason.

tags async

tags() -> list[str]

List the product tags, such as linux-distribution or amazon.

Returns:

Type Description
list[str]

Tag names.

Raises:

Type Description
EndOfLifeError

If the request fails.

tag_products async

tag_products(tag: str) -> list[dict[str, Any]]

List the products with a tag.

Parameters:

Name Type Description Default
tag str

A tag name from :meth:tags.

required

Returns:

Type Description
list[dict[str, Any]]

A summary of each product with the tag.

Raises:

Type Description
InvalidNameError

If the name is invalid.

NotFoundError

If the tag does not exist.

EndOfLifeError

If the request fails for another reason.

Product names

Validation for the names that end up in endoflife.date URL paths.

Names come from a model, so they can be anything: mixed case, padded with spaces, or crafted to escape the path segment they are placed in. Normalizing and checking them here keeps every request on the endpoint it was meant for.

MAX_NAME_LENGTH module-attribute

MAX_NAME_LENGTH = 100

Longest name accepted. Real endoflife.date names are well under 50 characters.

normalize_slug

normalize_slug(value: str, kind: str = 'product') -> str

Normalize a product, category or tag name and check it is a valid slug.

endoflife.date names are lowercase slugs such as python, amazon-eks or linux-distribution. Surrounding whitespace is stripped and the name is lowercased, so " Python " becomes "python".

Parameters:

Name Type Description Default
value str

The name as given by the caller.

required
kind str

What the name identifies, used in error messages.

'product'

Returns:

Type Description
str

The normalized name.

Raises:

Type Description
InvalidNameError

If the name is empty, too long, or contains characters that never appear in endoflife.date names.

normalize_release

normalize_release(value: str) -> str

Normalize a release cycle name and check it is safe to put in a URL path.

Release cycles keep their case (some products use names like R2 or SP1), so only surrounding whitespace is stripped.

Parameters:

Name Type Description Default
value str

The release cycle name as given by the caller, such as "3.12".

required

Returns:

Type Description
str

The normalized release cycle name.

Raises:

Type Description
InvalidNameError

If the name is empty, too long, or contains characters that never appear in release cycle names.

Suggestions

Suggest product names for a name endoflife.date doesn't know.

suggest_products

suggest_products(
    name: str,
    products: Iterable[ProductSummary],
    limit: int = 5,
    cutoff: float = 0.6,
) -> list[str]

Return the canonical names of the products closest to name.

Both canonical names and aliases are matched, so "postgres" finds postgresql and a typo such as "pyhton" finds python. Each product is listed at most once, by its canonical name, closest match first.

Parameters:

Name Type Description Default
name str

The normalized product name that was not found.

required
products Iterable[ProductSummary]

Product summaries from the products list endpoint.

required
limit int

The most suggestions to return.

5
cutoff float

The minimum similarity ratio (0 to 1) for a suggestion.

0.6

Returns:

Type Description
list[str]

Up to limit canonical product names, best match first.

Errors

Errors raised by the endoflife.date service.

Every failure the service anticipates is an :class:EndOfLifeError, so callers (the MCP tools) can turn it into a message for the model without catching unrelated exceptions.

EndOfLifeError

Bases: Exception

Base class for every error the service raises on purpose.

InvalidNameError

Bases: EndOfLifeError, ValueError

A product, release, category or tag name cannot be a valid endoflife.date name.

NotFoundError

Bases: EndOfLifeError

endoflife.date has no entry for the requested name.

RateLimitedError

RateLimitedError(retry_after: str | None)

Bases: EndOfLifeError

endoflife.date asked the client to slow down (HTTP 429).

Build the error from the response's Retry-After header.

Parameters:

Name Type Description Default
retry_after str | None

The raw Retry-After header value, if the API sent one.

required

UpstreamError

Bases: EndOfLifeError

endoflife.date could not be reached, or answered with something unexpected.