Skip to content

Commit cfce352

Browse files
julienldclaude
andauthored
feat: add server icon to FastMCP configuration (#236)
Add Home Assistant icons to the MCP server configuration for improved visual identification in MCP clients that support server icons. Changes: - Add SERVER_ICONS constant with SVG and PNG icon references - Pass icons to FastMCP constructor for client UI display - Add comprehensive tests for icon configuration validation Closes #224 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com>
1 parent af3a169 commit cfce352

2 files changed

Lines changed: 83 additions & 2 deletions

File tree

src/ha_mcp/server.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from typing import Any
77

88
from fastmcp import FastMCP
9+
from mcp.types import Icon
910

1011
from .client.rest_client import HomeAssistantClient
1112
from .config import get_global_settings
@@ -17,6 +18,20 @@
1718

1819
logger = logging.getLogger(__name__)
1920

21+
# Server icon configuration using GitHub-hosted images
22+
# These icons are bundled in packaging/mcpb/ and also available via GitHub raw URLs
23+
SERVER_ICONS = [
24+
Icon(
25+
src="https://raw.githubusercontent.com/homeassistant-ai/ha-mcp/master/packaging/mcpb/icon.svg",
26+
mimeType="image/svg+xml",
27+
),
28+
Icon(
29+
src="https://raw.githubusercontent.com/homeassistant-ai/ha-mcp/master/packaging/mcpb/icon-128.png",
30+
mimeType="image/png",
31+
sizes=["128x128"],
32+
),
33+
]
34+
2035

2136
class HomeAssistantSmartMCPServer(EnhancedToolsMixin, EnhancedPromptsMixin):
2237
"""Home Assistant MCP Server with smart tools and fuzzy search."""
@@ -38,8 +53,8 @@ def __init__(
3853
self.settings = None # type: ignore[assignment]
3954
self.client = client
4055

41-
# Create FastMCP server
42-
self.mcp = FastMCP(name=server_name, version=server_version)
56+
# Create FastMCP server with Home Assistant icons for client UI display
57+
self.mcp = FastMCP(name=server_name, version=server_version, icons=SERVER_ICONS)
4358

4459
# Initialize smart tools
4560
self.smart_tools = create_smart_search_tools(self.client)

tests/addon/test_server_config.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
"""Test MCP server configuration and metadata."""
2+
3+
from mcp.types import Icon
4+
5+
6+
class TestServerIcons:
7+
"""Verify server icon configuration meets MCP requirements."""
8+
9+
def test_server_icons_defined(self):
10+
"""Check that SERVER_ICONS is defined and properly structured."""
11+
from ha_mcp.server import SERVER_ICONS
12+
13+
assert SERVER_ICONS is not None, "SERVER_ICONS must be defined"
14+
assert isinstance(SERVER_ICONS, list), "SERVER_ICONS must be a list"
15+
assert len(SERVER_ICONS) > 0, "SERVER_ICONS must contain at least one icon"
16+
17+
def test_icons_are_valid_mcp_icon_types(self):
18+
"""Check that all icons are valid MCP Icon objects."""
19+
from ha_mcp.server import SERVER_ICONS
20+
21+
for i, icon in enumerate(SERVER_ICONS):
22+
assert isinstance(icon, Icon), f"Icon at index {i} must be an mcp.types.Icon"
23+
24+
def test_icons_have_required_fields(self):
25+
"""Check that all icons have required 'src' field."""
26+
from ha_mcp.server import SERVER_ICONS
27+
28+
for i, icon in enumerate(SERVER_ICONS):
29+
assert icon.src, f"Icon at index {i} must have a non-empty 'src' field"
30+
# src should be a URL pointing to GitHub raw content
31+
assert icon.src.startswith("https://"), "Icon src must be an HTTPS URL"
32+
33+
def test_icons_have_valid_mime_types(self):
34+
"""Check that icons have valid MIME types when specified."""
35+
from ha_mcp.server import SERVER_ICONS
36+
37+
valid_image_types = {"image/png", "image/svg+xml", "image/jpeg", "image/webp"}
38+
for i, icon in enumerate(SERVER_ICONS):
39+
if icon.mimeType:
40+
assert icon.mimeType in valid_image_types, (
41+
f"Icon at index {i} has invalid mimeType: {icon.mimeType}"
42+
)
43+
44+
def test_icons_include_svg_format(self):
45+
"""Check that at least one SVG icon is included for scalability."""
46+
from ha_mcp.server import SERVER_ICONS
47+
48+
svg_icons = [icon for icon in SERVER_ICONS if icon.mimeType == "image/svg+xml"]
49+
assert len(svg_icons) > 0, "Should include at least one SVG icon for scalability"
50+
51+
def test_icons_include_raster_format(self):
52+
"""Check that at least one raster icon (PNG) is included for compatibility."""
53+
from ha_mcp.server import SERVER_ICONS
54+
55+
raster_icons = [icon for icon in SERVER_ICONS if icon.mimeType == "image/png"]
56+
assert len(raster_icons) > 0, "Should include at least one PNG icon for compatibility"
57+
58+
def test_icon_urls_point_to_correct_repository(self):
59+
"""Check that icon URLs point to the ha-mcp repository."""
60+
from ha_mcp.server import SERVER_ICONS
61+
62+
expected_base = "https://raw.githubusercontent.com/homeassistant-ai/ha-mcp/"
63+
for i, icon in enumerate(SERVER_ICONS):
64+
assert icon.src.startswith(expected_base), (
65+
f"Icon at index {i} should point to homeassistant-ai/ha-mcp repository"
66+
)

0 commit comments

Comments
 (0)