Skip to main content

hyperdb_mcp/
version.rs

1// Copyright (c) 2026, Salesforce, Inc. All rights reserved.
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3
4//! Version reporting for the `HyperDB` MCP server.
5//!
6//! Exposes two version strings used by `status` and the
7//! `hyper://workspace` resource so LLMs and humans alike can correlate
8//! a running server with a specific point in source control:
9//!
10//! * [`mcp_version_string`] — the `hyperdb-mcp` crate's own version.
11//! * [`hyper_api_version_string`] — the `hyperdb-api` pure-Rust Hyper
12//!   client library version (pulled from [`hyperdb_api::VERSION`]).
13//!
14//! Both are postfixed with the short git commit hash of the workspace
15//! they were built from, formatted as `.r<8-char-hash>`. When the
16//! working tree had uncommitted changes at build time the suffix is
17//! extended to `.r<hash>-dirty-<YYYYMMDDTHHMMSSZ>` — a literal
18//! `-dirty` marker plus an ISO 8601 basic UTC build timestamp, so
19//! iterative dirty rebuilds of the same commit can still be told
20//! apart by their version string alone. The hash and timestamp are
21//! captured by `build.rs` at compile time. For source trees without a
22//! working `git` binary the suffix falls back to `.runknown`.
23
24/// Semantic version of this crate, from `Cargo.toml`.
25pub const MCP_VERSION: &str = env!("CARGO_PKG_VERSION");
26
27/// Short git hash of the workspace HEAD at build time. When the tree
28/// was dirty at build time the value is extended to
29/// `<hash>-dirty-<YYYYMMDDTHHMMSSZ>` (ISO 8601 basic UTC). Falls back
30/// to `"unknown"` when git is unavailable.
31pub const GIT_HASH: &str = env!("HYPERDB_GIT_HASH");
32
33/// Version string reported for the `HyperDB` MCP server.
34///
35/// Example clean build: `"0.1.0.ra1b2c3d4"`.
36/// Example dirty build: `"0.1.0.ra1b2c3d4-dirty-20260423T184900Z"`.
37#[must_use]
38pub fn mcp_version_string() -> String {
39    format!("{MCP_VERSION}.r{GIT_HASH}")
40}
41
42/// Version string reported for the underlying pure-Rust Hyper API
43/// (the `hyperdb-api` crate). Shares the same git hash suffix as the MCP
44/// crate because both live in the same workspace.
45///
46/// Example: `"0.1.0.ra1b2c3d4"`.
47#[must_use]
48pub fn hyper_api_version_string() -> String {
49    format!("{}.r{GIT_HASH}", hyperdb_api::VERSION)
50}