Skip to content

Commit 66dd3ed

Browse files
julienldclaude
andauthored
fix: add --version/-V flag to CLI (#309)
The CLI previously crashed when running `ha-mcp --version` because it would attempt to create the server, which requires HOMEASSISTANT_URL and HOMEASSISTANT_TOKEN environment variables. Now the --version and -V flags are handled early, before any server initialization, allowing users to check their installed version without configuration. Fixes #290 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent d95c5e7 commit 66dd3ed

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

src/ha_mcp/__main__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,12 @@ async def _run_with_graceful_shutdown() -> None:
255255
# CLI entry point (for pyproject.toml) - use FastMCP's built-in runner
256256
def main() -> None:
257257
"""Run server via CLI using FastMCP's stdio transport."""
258+
# Handle --version flag early, before server creation requires config
259+
if "--version" in sys.argv or "-V" in sys.argv:
260+
from importlib.metadata import version
261+
print(f"ha-mcp {version('ha-mcp')}")
262+
sys.exit(0)
263+
258264
# Check for smoke test flag
259265
if "--smoke-test" in sys.argv:
260266
from ha_mcp.smoke_test import main as smoke_test_main

0 commit comments

Comments
 (0)