Google Home MCP Server
by jmagar
Verified
Google Home MCP Server
An MCP server implementation for controlling Google Home smart plugs through the Smart Home API.
Features
- List all available smart plugs and their states
- Control smart plugs (turn on/off)
- Get real-time state of specific smart plugs
- Automatic device state refresh
- OAuth2 authentication with Smart Home API
Prerequisites
- Google Cloud Project with Smart Home API enabled
- Actions on Google Smart Home Action project
- OAuth 2.0 Client credentials for Smart Home Action
- Node.js 18 or higher
- Access to Google Home smart plugs
Setup
- Create a Smart Home Action:
- Go to Actions on Google Console
- Create a new project
- Choose "Smart Home" as the project type
- Configure Account Linking:
- OAuth Client ID
- OAuth Client Secret
- Authorization URL
- Token URL
- Set up OAuth 2.0:
- Configure your OAuth server endpoints
- Set up user authentication flow
- Implement token generation/validation
- Install dependencies:
Copy
pnpm install
- Configure the server:
- Copy
config.json.example
toconfig.json
- Fill in your:
- OAuth Client ID
- OAuth Client Secret
- Copy
- Build the server:
Copy
pnpm build
- Start the server:
Copy
pnpm start
Available Tools
1. List Smart Plugs
Copy
{
name: "list_smart_plugs",
description: "List all available smart plugs and their current states",
response: Array<{
id: string;
name: string;
state: {
on: boolean;
online: boolean;
}
}>
}
2. Control Smart Plug
Copy
{
name: "control_smart_plug",
description: "Turn a smart plug on or off",
parameters: {
deviceId: string; // Device ID from list_smart_plugs
state: boolean; // true for on, false for off
},
response: {
success: boolean;
device: {
id: string;
name: string;
state: {
on: boolean;
online: boolean;
}
}
}
}
3. Get Smart Plug State
Copy
{
name: "get_smart_plug_state",
description: "Get the current state of a specific smart plug",
parameters: {
deviceId: string; // Device ID from list_smart_plugs
},
response: {
id: string;
name: string;
state: {
on: boolean;
online: boolean;
}
}
}
API Details
The server implements the Smart Home API intents:
- SYNC Intent
- Called when users link their account
- Reports available devices and capabilities
- Handles device discovery
- QUERY Intent
- Reports current state of devices
- Handles state queries from Google Assistant
- Returns online/offline status
- EXECUTE Intent
- Handles device control commands
- Executes on/off operations
- Reports command success/failure
Error Handling
The server implements comprehensive error handling with specific error codes:
CONFIG_ERROR
: Configuration loading or validation errorsAPI_ERROR
: Errors from Smart Home APIDEVICE_NOT_FOUND
: Device ID not found in available devicesCOMMAND_ERROR
: Error executing device command
Each error includes:
- Error message
- Error code
- Detailed error information when available
Security
- OAuth 2.0 authentication flow
- Secure token handling
- Request validation
- Command authorization
- HTTPS communication
- Input sanitization
Development
- Start in development mode:
Copy
pnpm dev
- Run tests:
Copy
pnpm test
- Debug logs:
- All API calls are logged
- Error details are captured
- Device state changes are tracked
Contributing
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
License
MIT
ghome-mcp-server
Enables users to control Google Home smart plugs using the Smart Home API with OAuth2 authentication, offering real-time device state management and control operations.