API Documentation 📚
Welcome to the MCP Server API documentation. This guide covers all available endpoints, authentication methods, and integration patterns.
API Overview
The MCP Server provides several API categories:
- Core API - Basic device control and state management
- SSE API - Real-time event subscriptions
- Scene API - Scene management and automation
- Voice API - Natural language command processing
Authentication
All API endpoints require authentication using JWT tokens:
# Include the token in your requests
curl -H "Authorization: Bearer YOUR_JWT_TOKEN" http://localhost:3000/api/state
To obtain a token:
curl -X POST http://localhost:3000/auth/token \
-H "Content-Type: application/json" \
-d '{"username": "your_username", "password": "your_password"}'
Core Endpoints
Device State
Retrieve the current state of all devices:
Response:
{
"devices": [
{
"id": "light.living_room",
"state": "on",
"attributes": {
"brightness": 255,
"color_temp": 370
}
}
]
}
Command Execution
Execute a natural language command:
curl -X POST http://localhost:3000/api/command \
-H "Content-Type: application/json" \
-d '{"command": "Turn on the kitchen lights"}'
Response:
{
"success": true,
"action": "turn_on",
"device": "light.kitchen",
"message": "Kitchen lights turned on"
}
Real-Time Events
Event Subscription
Subscribe to device state changes:
const eventSource = new EventSource('http://localhost:3000/subscribe_events?token=YOUR_TOKEN');
eventSource.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log('State changed:', data);
};
Filtered Subscriptions
Subscribe to specific device types:
Scene Management
Create Scene
Create a new scene:
curl -X POST http://localhost:3000/api/scene \
-H "Content-Type: application/json" \
-d '{
"name": "Movie Night",
"actions": [
{"device": "light.living_room", "action": "dim", "value": 20},
{"device": "media_player.tv", "action": "on"}
]
}'
Activate Scene
Activate an existing scene:
curl -X POST http://localhost:3000/api/scene/activate \
-H "Content-Type: application/json" \
-d '{"name": "Movie Night"}'
Error Handling
The API uses standard HTTP status codes:
200
- Success400
- Bad Request401
- Unauthorized404
- Not Found500
- Server Error
Error responses include detailed messages:
{
"error": true,
"message": "Device not found",
"code": "DEVICE_NOT_FOUND",
"details": {
"device_id": "light.nonexistent"
}
}
Rate Limiting
API requests are rate-limited to prevent abuse:
When exceeded, returns 429 Too Many Requests
:
WebSocket API
For bi-directional communication:
const ws = new WebSocket('ws://localhost:3000/ws');
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
console.log('Received:', data);
};
ws.send(JSON.stringify({
type: 'command',
payload: {
command: 'Turn on lights'
}
}));
API Versioning
The current API version is v1. Include the version in the URL:
Further Reading
- SSE API Details - In-depth SSE documentation
- Core Functions - Detailed endpoint documentation
- Architecture Overview - System design details
- Troubleshooting - Common issues and solutions
API Reference
The Advanced Home Assistant MCP provides several APIs for integration and automation:
- Core API - Primary interface for system control
- SSE API - Server-Sent Events for real-time updates
- Core Functions - Essential system functions