Skip to content

Commit efaf8ac

Browse files
fix: use package version for MCP server version instead of hardcoded 0.1.0 (#744)
* fix: use package version for MCP server version instead of hardcoded 0.1.0 The server reported version "0.1.0" to MCP clients regardless of the actual package version. This reads the version from package metadata (managed by semantic-release) so the server correctly identifies itself as e.g. "6.7.2". The MCP_SERVER_VERSION env var still works as an override. Closes #741 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: use 'unknown' fallback instead of '0.0.0-dev' Avoids confusion with the dev server addon. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: kingpanther13 <kingpanther13@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 66c9b24 commit efaf8ac

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ LOG_LEVEL=INFO
2525

2626
# Optional: MCP Server Configuration
2727
MCP_SERVER_NAME=ha-mcp
28-
MCP_SERVER_VERSION=0.1.0
28+
# MCP_SERVER_VERSION defaults to the package version (e.g. 6.7.2)

src/ha_mcp/config.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22
Configuration management for Home Assistant MCP Server.
33
"""
44

5+
import importlib.metadata
56
import os
67

78
# Load environment variables from .env file with HAMCP_ENV_FILE support
89
# Use absolute path to ensure .env is found regardless of cwd
910
from pathlib import Path
1011

12+
try:
13+
_PACKAGE_VERSION = importlib.metadata.version("ha-mcp")
14+
except importlib.metadata.PackageNotFoundError:
15+
_PACKAGE_VERSION = "unknown"
16+
1117
from dotenv import load_dotenv
1218
from pydantic import Field, field_validator
1319
from pydantic_settings import BaseSettings, SettingsConfigDict
@@ -64,7 +70,7 @@ class Settings(BaseSettings):
6470

6571
# MCP Server configuration
6672
mcp_server_name: str = Field("ha-mcp", alias="MCP_SERVER_NAME")
67-
mcp_server_version: str = Field("0.1.0", alias="MCP_SERVER_VERSION")
73+
mcp_server_version: str = Field(default=_PACKAGE_VERSION, alias="MCP_SERVER_VERSION")
6874

6975
# Environment configuration
7076
environment: str = Field("development", alias="ENVIRONMENT")

src/ha_mcp/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from fastmcp import FastMCP
1818
from mcp.types import Icon
1919

20-
from .config import get_global_settings
20+
from .config import _PACKAGE_VERSION, get_global_settings
2121
from .tools.enhanced import EnhancedToolsMixin
2222

2323
if TYPE_CHECKING:
@@ -53,7 +53,7 @@ def __init__(
5353
self,
5454
client: HomeAssistantClient | None = None,
5555
server_name: str = "ha-mcp",
56-
server_version: str = "0.1.0",
56+
server_version: str = _PACKAGE_VERSION,
5757
):
5858
"""Initialize the smart MCP server with lazy loading support."""
5959
# Load settings first (fast operation)

0 commit comments

Comments
 (0)