Skip to content

fix(server-info): trust installed metadata over foreign pyproject + version guard#42

Merged
heznpc merged 1 commit into
mainfrom
fix/quality-audit
Jun 4, 2026
Merged

fix(server-info): trust installed metadata over foreign pyproject + version guard#42
heznpc merged 1 commit into
mainfrom
fix/quality-audit

Conversation

@heznpc
Copy link
Copy Markdown
Member

@heznpc heznpc commented Jun 4, 2026

What

Make distribution identity (dist name + version) a single source of truth in the package root (`my_mcp_server/init.py`) and route the `server-info` MCP resource through it.

Resolution order (now metadata-first)

  1. `importlib.metadata` — authoritative for an installed distribution (wheel or `pip install -e .`). This is what the running server actually is, regardless of files on disk above it.
  2. The package's own `pyproject.toml` — dev fallback for a source checkout, accepted only when `[project].name` matches `DIST_NAME`. A foreign / monorepo-parent `pyproject.toml` found on the walk-up is skipped (the version guard), so a parent project can never masquerade as this server's identity.
  3. `FALLBACK_VERSION` (`0.0.0`) — last resort (renamed clone, neither source usable).

Why

Previously `server_info.py` re-derived identity on its own, pyproject-first and unguarded: a monorepo-parent `pyproject.toml` encountered on the walk-up would be served as this server's version. It also duplicated the name/version logic, so the two could drift. Now `server_info` consumes `resolve_version()` / `DIST_NAME` from the package root — the reported version can't drift from what the package is, and the foreign-pyproject case is correctly skipped.

`PKG_NAME` is retained in `server_info` as a back-compat alias of `DIST_NAME`.

Tests

  • New `tests/test_version_resolution.py` covers each resolution branch, with explicit cases for the guard (foreign pyproject nearer on the walk-up is skipped; foreign-only walk exhausts to `None`; `[project]` without a `name` is skipped).
  • `tests/test_server_info.py` reworked to assert the resource consumes the single source of truth.
  • Local: ruff check + format, mypy `src/`, 33/33 pytest. Coverage 79.56% -> 97.17% (`init.py` 32% -> 100%).

@heznpc heznpc enabled auto-merge (squash) June 4, 2026 12:25
@heznpc heznpc merged commit 8e39dd6 into main Jun 4, 2026
9 checks passed
@heznpc heznpc deleted the fix/quality-audit branch June 4, 2026 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant