HomeOps: Safe, Autonomous Smart Home Operations via Model Context Protocol Inspiration

Modern smart homes are filled with connected devices, but interacting with them remains surprisingly fragmented and brittle. Users are still forced to speak in rigid, pre-programmed syntax: "Alexa, turn off kitchen light 1," followed by "Alexa, set temperature to 72," followed by "Alexa, lock the front door."

When generative AI and Large Language Models (LLMs) emerged, many early systems made a critical mistake: they granted models direct tool execution access to physical environments. In a smart home, giving a non-deterministic model direct actuation over door locks, high-voltage heaters, and physical security is dangerous. A single model hallucination or parameter glitch could leave a front door unlocked overnight or overheat a room.

We built HomeOps to bridge this divide. Our vision was to give Alexa+ users an intelligent, conversational operator that understands compound natural human intentions while maintaining an uncompromising, deterministic safety boundary: "LLM proposes, backend disposes."

What it does

HomeOps is an AI-native smart home operator that transforms high-level natural language requests into safely validated, multi-step execution routines over the Model Context Protocol (MCP) with Streamable HTTP.

Key capabilities include:

Compound Intent Parsing: Handles multi-action, multi-device natural language requests in a single turn (such as "Create a Goodnight routine that turns off the kitchen light, sets the living room temperature to 72, and checks the front door").

Device Grounding: Maps fuzzy natural language references to physical, cataloged devices in the home state database (such as resolving "kitchen light" to dev_003).

The "LLM Proposes, Backend Disposes" Safety Boundary: The AI planner generates a proposed plan as structured JSON, but has zero direct hardware execution privileges.

Human-in-the-Loop Confirmation Gate: Every synthesized multi-step routine halts at a verification checkpoint, presenting the user with an exact breakdown of proposed actions before any physical state is modified. Deterministic Execution & Policy Validation: The backend independently validates device IDs, supported capability verbs, and safe parameter boundaries (such as temperature limits between 60°F and 85°F) before execution.

Auditable SQLite Persistence: Complete state persistence across device power states, custom routine definitions, and an immutable activity audit log. How we built it

HomeOps is architected as an enterprise-grade MCP server integrated with the Alexa+ ecosystem, structured into five clean decoupled layers:

  1. System Architecture & Request Lifecycle Client & Transport Layer: The user interacts via the Alexa+ client or voice interface, which connects over Streamable HTTP using Server-Sent Events (SSE) to our MCP server. Security & Authentication Layer: All incoming requests pass through an OAuth 2.1 authentication gate supporting PKCE (S256) and Bearer token verification, backed by standard Protected Resource Metadata (PRM) endpoints.

MCP Server & Intent Planning Layer: When a compound natural language request is received, the FastMCP endpoint triggers the plan_routine tool. The Gemini LLM intent planner analyzes the request and grounds it against known physical devices, outputting a candidate action plan as structured JSON. The LLM has zero direct execution capability.

Human Confirmation & Execution Boundary: The system halts at a human verification checkpoint, presenting the proposed plan to the user. Upon explicit user confirmation, the execute_plan tool passes the actions to our deterministic backend policy engine.

Validation & Persistence Layer: The backend independently re-validates device IDs, capability verbs, and numerical parameter bounds before altering state. Approved actions are dispatched to the device layer and recorded in an auditable SQLite activity log.

  1. The MCP Tool Suite

The server exposes seven atomic tools conforming to the official Model Context Protocol specifications:

get_home_status: Queries current device states and health. get_routines: Lists saved automated routines. create_routine: Persists user-defined routines to the database. run_routine: Re-executes existing validated routines. get_activity_log: Surfaces tamper-resistant operational history. plan_routine: Interfaces with the Gemini LLM to synthesize high-level intent into a structured plan without executing. execute_plan: The strictly guarded backend executor that re-validates and carries out confirmed actions.

  1. Mathematical Formalization of the Safety Model

We treat smart home state transitions deterministically. Let the home state at step t be defined as S_t, representing the verified configuration of all connected devices.

When the LLM proposes an action plan, each candidate action is defined as a tuple: Action = (Device_ID, Verb, Parameters)

Before any action is allowed to modify state, it must satisfy our deterministic validation rule:

The Device_ID must exist in the verified device registry. The Verb must be an allowed capability for that specific device. The Parameters must fall within safe operational limits (for example, setting temperature only between 60°F and 85°F).

If any action fails this validation check, execution is halted immediately and rolled back. This ensures physical home integrity can never be compromised by malformed or hallucinated AI output.

  1. Authentication & Security

To comply with the Amazon Alexa+ standard, we implemented an OAuth 2.1 authorization code flow with PKCE (Proof Key for Code Exchange) using S256 verification:

Base64URL(SHA-256(ASCII(code_verifier))) == code_challenge

We implemented the standard metadata discovery endpoints:

Protected Resource Metadata (PRM): /.well-known/oauth-protected-resource Authorization Server Metadata: /.well-known/oauth-authorization-server Bearer Token validation guarding the /mcp transport endpoint.

Challenges I ran into:

Protocol-Level SSE Streaming over Cloud Proxies: The Model Context Protocol's Streamable HTTP transport relies on long-lived Server-Sent Events (SSE) connections. Cloud load balancers and reverse proxies often buffer or terminate idle HTTP streams. We had to ensure session keep-alives and session ID handshakes were strictly maintained without timing out.

Decoupling MCP JSON-RPC Pipeline from ASGI Web Middleware: During the implementation of OAuth 2.1, we encountered an architectural conflict where ASGI/Starlette HTTP middleware collided with FastMCP's internal JSON-RPC protocol dispatch layer. We solved this by separating HTTP transport routing from MCP protocol execution, allowing standard OAuth handshakes while preserving clean JSON-RPC 'initialize' handling.

Grounding Ambiguous Intents: Natural language is imprecise (such as "make it cozy" or "goodnight"). Engineering structured prompts that reliably map conversational speech into concrete database device IDs (dev_001 through dev_003) without hallucinating nonexistent smart appliances required rigorous schema enforcement and structured outputs.

Accomplishments that I am proud of: True Multi-Step Autonomy: Successfully executing compound plans (lighting, climate, and security) from a single sentence in under 2 seconds.

Strict Guardrail Integrity: Achieving zero unauthorized device actuations. The Gemini LLM physically cannot toggle a switch or alter a lock without explicit confirmation and backend policy approval.

Comprehensive Test Suite: Developed and maintained an automated test suite covering SQLite transactions, grounding accuracy, invalid parameter rejection, and safety boundaries.

Production-Grade Compliance: Building an end-to-end MCP server that simultaneously runs locally for high-speed simulation and deploys remotely with full OAuth 2.1 metadata endpoints for Alexa+ add-on registration.

What I learned: MCP is the Future of Agentic Tooling: Working with the Model Context Protocol proved how much cleaner agent-to-tool communication is compared to legacy custom API wrappers. Having standardized schemas, initialization lifecycles, and tool registries radically speeds up agent development. Safety Must Be Architectural, Not Prompt-Based: You cannot rely on prompt engineering alone to keep smart homes safe. System prompts like "please do not unlock doors unless sure" fail under adversarial inputs or edge cases. Hard architectural barriers ("LLM proposes, backend disposes") are essential whenever software interacts with the physical world.

What's next for HomeOps: Proactive & Predictive Routines: Expanding HomeOps from reactive commands to predictive intent (such as detecting irregular schedule deviations and proposing comfort or security optimizations). Matter / Thread Protocol Integration: Expanding beyond the mock device layer to directly control physical Matter-enabled smart home hardware.

Multi-Room Spatial Context: Incorporating spatial awareness so commands like "turn off the lights here" automatically resolve based on which Alexa Echo device heard the prompt.

Built With

Share this project:

Updates

Submission history