- Revamp README.md with improved project overview, architecture diagram, and badges - Create new development and tools documentation with detailed guides - Update API documentation with enhanced examples, rate limiting, and security information - Refactor and consolidate documentation files for better navigation and clarity - Add emojis and visual improvements to make documentation more engaging
7.9 KiB
Troubleshooting Guide
This guide provides solutions to common issues encountered with the Home Assistant MCP Server.
Common Issues
-
Server Not Starting:
- Verify that all required environment variables are correctly set.
- Check for port conflicts or missing dependencies.
- Review the server logs for error details.
-
Connection Problems:
- Ensure your Home Assistant instance is reachable.
- Confirm that the authentication token is valid.
- Check network configurations and firewalls.
Tool Issues
Tool Not Found
Symptoms:
- "Tool not found" errors or 404 responses.
Solutions:
- Double-check the tool name spelling.
- Verify that the tool is correctly registered.
- Review tool imports and documentation.
Tool Execution Failures
Symptoms:
- Execution errors or timeouts.
Solutions:
- Validate input parameters.
- Check and review error logs.
- Debug the tool implementation.
- Ensure proper permissions in Home Assistant.
Debugging Steps
Server Logs
- Enable debug logging by setting:
LOG_LEVEL=debug - Check logs:
npm run logs - Filter errors:
npm run logs | grep "error"
Network Debugging
- Test API endpoints:
curl -v http://localhost:3000/api/health - Monitor SSE connections:
curl -N http://localhost:3000/api/sse/stats - Test WebSocket connectivity:
wscat -c ws://localhost:3000
Performance Issues
- Monitor memory usage with:
npm run stats
Security Middleware Troubleshooting
Rate Limiting Problems
Symptoms: Receiving 429 (Too Many Requests) errors.
Solutions:
- Adjust and fine-tune rate limit settings.
- Consider different limits for critical versus non-critical endpoints.
Request Validation Failures
Symptoms: 400 or 415 errors on valid requests.
Solutions:
- Verify that the
Content-Typeheader is set correctly. - Inspect request payload size and format.
Input Sanitization Issues
Symptoms: Unexpected data transformation or loss.
Solutions:
- Test sanitization with various input types.
- Implement custom sanitization for complex data if needed.
Security Header Configuration
Symptoms: Missing or improper security headers.
Solutions:
- Review and update security header configurations (e.g., Helmet settings).
- Ensure environment-specific header settings are in place.
Error Handling and Logging
Symptoms: Inconsistent error responses.
Solutions:
- Enhance logging for detailed error tracking.
- Adjust error handlers for production and development differences.
Additional Resources
Getting Help
If issues persist:
- Review detailed logs.
- Verify your configuration and environment.
- Consult the GitHub issue tracker or community forums.
FAQ
Q: How do I reset my configuration?
A: Delete .env and copy .env.example to start fresh.
Q: Why are my events delayed?
A: Check network latency and server load. Consider adjusting buffer sizes.
Q: How do I update my token?
A: Generate a new token in Home Assistant and update HASS_TOKEN.
Q: Why do I get "Maximum clients reached"?
A: Adjust SSE_MAX_CLIENTS in configuration or clean up stale connections.
Error Codes
E001: Connection ErrorE002: Authentication ErrorE003: Rate Limit ErrorE004: Tool ErrorE005: Configuration Error
Support Resources
-
Documentation
-
Community
- GitHub Issues
- Discussion Forums
- Stack Overflow
-
Tools
- Diagnostic Scripts
- Testing Tools
- Monitoring Tools
Still Need Help?
-
Create a detailed issue:
- Error messages
- Steps to reproduce
- Environment details
- Logs
-
Contact support:
- GitHub Issues
- Email Support
- Community Forums
Security Middleware Troubleshooting
Common Issues and Solutions
Rate Limiting Problems
Symptom: Unexpected 429 (Too Many Requests) errors
Possible Causes:
- Misconfigured rate limit settings
- Shared IP addresses (e.g., behind NAT)
- Aggressive client-side retry mechanisms
Solutions:
-
Adjust rate limit parameters
// Customize rate limit for specific scenarios checkRateLimit(ip, maxRequests = 200, windowMs = 30 * 60 * 1000) -
Implement more granular rate limiting
- Use different limits for different endpoints
- Consider user authentication level
Request Validation Failures
Symptom: 400 or 415 status codes on valid requests
Possible Causes:
- Incorrect
Content-Typeheader - Large request payloads
- Malformed authorization headers
Debugging Steps:
-
Verify request headers
// Check content type and size validateRequestHeaders(request, 'application/json') -
Log detailed validation errors
try { validateRequestHeaders(request); } catch (error) { console.error('Request validation failed:', error.message); }
Input Sanitization Issues
Symptom: Unexpected data transformation or loss
Possible Causes:
- Complex nested objects
- Non-standard input formats
- Overly aggressive sanitization
Troubleshooting:
-
Test sanitization with various input types
const input = { text: '<script>alert("xss")</script>', nested: { html: '<img src="x" onerror="alert(1)">World' } }; const sanitized = sanitizeValue(input); -
Custom sanitization for specific use cases
function customSanitize(value) { // Add custom sanitization logic return sanitizeValue(value); }
Security Header Configuration
Symptom: Missing or incorrect security headers
Possible Causes:
- Misconfigured Helmet options
- Environment-specific header requirements
Solutions:
- Custom security header configuration
const customHelmetConfig = { contentSecurityPolicy: { directives: { defaultSrc: ["'self'"], scriptSrc: ["'self'", 'trusted-cdn.com'] } } }; applySecurityHeaders(request, customHelmetConfig);
Error Handling and Logging
Symptom: Inconsistent error responses
Possible Causes:
- Incorrect environment configuration
- Unhandled error types
Debugging Techniques:
-
Verify environment settings
const errorResponse = handleError(error, process.env.NODE_ENV); -
Add custom error handling
function enhancedErrorHandler(error, env) { // Add custom logging or monitoring console.error('Security error:', error); return handleError(error, env); }
Performance and Security Monitoring
-
Logging
- Enable debug logging for security events
- Monitor rate limit and validation logs
-
Metrics
- Track rate limit hit rates
- Monitor request validation success/failure ratios
-
Continuous Improvement
- Regularly review and update security configurations
- Conduct periodic security audits
Environment-Specific Considerations
Development
- More verbose error messages
- Relaxed rate limiting
- Detailed security logs
Production
- Minimal error details
- Strict rate limiting
- Comprehensive security headers
External Resources
Getting Help
If you encounter persistent issues:
- Check application logs
- Verify environment configurations
- Consult the project's issue tracker
- Reach out to the development team with detailed error information