Skip to content

πŸš€ The fast, Pythonic way to build MCP servers and clients.

dead branch

zzstoatzz988f3b52a582
diff --git a/examples/smart_home/pyproject.toml b/examples/smart_home/pyproject.toml
index 367bd8da0..68509092b 100644
--- a/examples/smart_home/pyproject.toml
+++ b/examples/smart_home/pyproject.toml
@@ -5,10 +5,7 @@ description = "Add your description here"
readme = "README.md"
authors = [{ name = "zzstoatzz", email = "[email protected]" }]
requires-python = ">=3.12"
-dependencies = [
- "fastmcp@git+https://github.com/jlowin/[email protected]",
- "phue2",
-]
+dependencies = ["fastmcp@git+https://github.com/jlowin/fastmcp.git", "phue2"]
[project.scripts]
smart-home = "smart_home.__main__:main"
diff --git a/examples/smart_home/src/smart_home/hub.py b/examples/smart_home/src/smart_home/hub.py
index ac011c3c1..b3bc84b9d 100644
--- a/examples/smart_home/src/smart_home/hub.py
+++ b/examples/smart_home/src/smart_home/hub.py
@@ -1,5 +1,7 @@
+from phue2 import Bridge
+
from fastmcp import FastMCP
-from smart_home.lights.server import bridge, lights_mcp
+from smart_home.settings import settings
hub_mcp = FastMCP(
"Smart Home Hub (phue2)",
@@ -9,14 +11,14 @@ hub_mcp = FastMCP(
)
# Mount the lights service under the 'hue' prefix
-hub_mcp.mount("hue", lights_mcp)
+# hub_mcp.mount("hue", lights_mcp)
# Add a status check for the hub
@hub_mcp.tool()
def hub_status() -> str:
"""Checks the status of the main hub and connections."""
- if bridge:
+ if Bridge(settings.hue_bridge_ip).connect():
# Access the bridge instance directly
return "Hub OK. Hue Bridge Connected (via phue2)."
else:
diff --git a/examples/smart_home/src/smart_home/lights/server.py b/examples/smart_home/src/smart_home/lights/server.py
index 9bf976fe8..3d65207b0 100644
--- a/examples/smart_home/src/smart_home/lights/server.py
+++ b/examples/smart_home/src/smart_home/lights/server.py
@@ -11,7 +11,6 @@ from phue2.exceptions import (
from fastmcp import FastMCP
from smart_home.settings import settings
-bridge: Bridge | None = None
BRIDGE_IP = str(settings.hue_bridge_ip)
try:
@@ -66,31 +65,6 @@ def list_lights() -> list[str]:
return [f"Unexpected error listing lights: {e}"]
-@lights_mcp.resource("hue://light/{light_name}/status")
-def get_light_status(light_name: str) -> dict[str, Any]:
- """Gets the current status of a specific light using phue2."""
- if not bridge:
- return {"error": "Bridge not connected"}
- try:
- light_state = bridge.get_light(light_name, "state")
- if light_state and isinstance(light_state, dict):
- return {
- "name": light_name,
- "on": light_state.get("on"),
- "brightness": light_state.get("bri"),
- "reachable": light_state.get("reachable"),
- "raw_state": light_state,
- }
- else:
- return {"error": f"Light '{light_name}' not found or state unavailable."}
- except KeyError:
- return {"error": f"Light '{light_name}' not found (KeyError)."}
- except PhueException as e:
- return {"error": f"phue2 error getting status for '{light_name}': {e}"}
- except Exception as e:
- return {"error": f"Unexpected error getting status for '{light_name}': {e}"}
-
-
# --- Tools ---
diff --git a/examples/smart_home/src/smart_home/settings.py b/examples/smart_home/src/smart_home/settings.py
index 517be5330..ed78cef15 100644
--- a/examples/smart_home/src/smart_home/settings.py
+++ b/examples/smart_home/src/smart_home/settings.py
@@ -3,7 +3,7 @@ from pydantic_settings import BaseSettings, SettingsConfigDict
class Settings(BaseSettings):
- model_config = SettingsConfigDict(env_file=".env")
+ model_config = SettingsConfigDict(env_file=".env", extra="ignore")
hue_bridge_ip: IPvAnyAddress = Field(default=...)
diff --git a/justfile b/justfile
new file mode 100644
index 000000000..9fd3b0651
--- /dev/null
+++ b/justfile
@@ -0,0 +1,9 @@
+build:
+ uv sync
+
+test: build
+ uv run --frozen pytest -xvs tests
+
+# Run pyright on all files
+typecheck:
+ uv run pyright
\ No newline at end of file