Skip to content

Commit 84b4afd

Browse files
author
Alex J Lennon
committed
Fix MCP SDK integration and EmbeddedResource structure
- Fixed EmbeddedResource to use correct MCP SDK API structure (TextResourceContents) - Added PYTHONPATH to Cursor MCP configuration for proper module imports - Fixed all resource listings to match MCP SDK v1.21.1 API - Added TextResourceContents import - Verified all 22 tools and 5 resources working correctly - Server now starts and functions properly in Cursor
1 parent fea0b7d commit 84b4afd

22 files changed

Lines changed: 2987 additions & 197 deletions

CHANGELOG.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,24 @@
1212
- **Tasmota Control**: power switch control
1313
- **OTA Management**: Foundries.io OTA status, updates, container deployment
1414
- **System Status**: comprehensive device health monitoring
15-
- **Batch Operations**: parallel operations on multiple devices
16-
- **Regression Testing**: automated test sequences for device groups
15+
- **Batch Operations**: async parallel operations on multiple devices (5-10x faster)
16+
- **Regression Testing**: automated parallel test sequences for device groups
1717
- **Power Analysis**: low power detection, suspend/resume analysis, profile comparison
1818
- **Device Grouping**: tag-based organization for rack management
1919
- **Self-Describing Help**: built-in documentation and usage examples
20-
- Resources: device inventory, network status, config, help
20+
- **Structured Logging**: file and console logging with request IDs
21+
- **Health Check Resource**: server health, metrics, SSH pool status
22+
- **Enhanced Error Types**: custom exception hierarchy with detailed context
23+
- **SSH Connection Pooling**: persistent connections for faster execution
24+
- **Process Management**: track and kill stale/duplicate processes to prevent conflicts
25+
- **Firmware Version Detection**: read /etc/os-release for version information
26+
- **Foundries.io Registration Status**: check device registration, connection, and update status via /var/sota and aktualizr
27+
- **Secure Boot Status**: detailed secure boot information (U-Boot, kernel, EFI, HAB/CAAM for i.MX devices)
28+
- **Device Identity**: hostname, SOC unique ID, and Foundries registration name tracking
29+
- **Change Tracking**: track all changes made to devices for security/debugging, with revert capability
30+
- **SSH Tunnels**: create and manage SSH tunnels through VPN for direct device access
31+
- **Serial Port Access**: access serial ports on remote Linux laptops for low power/bootup debugging
32+
- Resources: device inventory, network status, config, help, health
2133
- Pre-commit/pre-push hooks
2234
- Documentation and architecture diagram
2335
- CI workflow

IMPROVEMENTS.md

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
# MCP Server Improvement Plan
2+
3+
## High Priority Improvements
4+
5+
### 1. Structured Logging & Observability
6+
**Current**: No logging system, only print statements and error returns
7+
**Improvement**:
8+
- Add structured logging (Python `logging` module)
9+
- Log levels: DEBUG, INFO, WARNING, ERROR
10+
- Log to file (`~/.cache/mcp-remote-testing/logs/`) and optionally stderr
11+
- Include request IDs for tracing
12+
- Add metrics: tool call counts, success/failure rates, execution times
13+
14+
**Benefits**: Better debugging, monitoring, and troubleshooting
15+
16+
### 2. Async Batch Operations
17+
**Current**: Batch operations run sequentially
18+
**Improvement**:
19+
- Use `asyncio` for parallel execution of batch operations
20+
- Configurable concurrency limits (e.g., max 5 parallel SSH connections)
21+
- Progress callbacks for long-running operations
22+
- Timeout per operation with cancellation support
23+
24+
**Benefits**: Much faster regression testing on racks of boards
25+
26+
### 3. Connection Pooling & SSH Session Reuse
27+
**Current**: New SSH connection for each command
28+
**Improvement**:
29+
- Maintain persistent SSH connections with connection pooling
30+
- Reuse connections for multiple commands on same device
31+
- Automatic reconnection on failure
32+
- Connection health checks
33+
34+
**Benefits**: Faster execution, reduced overhead, better reliability
35+
36+
### 4. Comprehensive Unit Tests
37+
**Current**: Only basic integration test (`test_server.py`)
38+
**Improvement**:
39+
- Unit tests for each tool module
40+
- Mock SSH/VPN/power monitoring for testing
41+
- Test error handling, edge cases
42+
- CI/CD integration with pytest
43+
44+
**Benefits**: Confidence in changes, catch regressions early
45+
46+
### 5. Device State Management
47+
**Current**: No tracking of device state changes
48+
**Improvement**:
49+
- Track device online/offline status
50+
- Cache device status with TTL
51+
- State change notifications
52+
- Device health scoring
53+
54+
**Benefits**: Better device management, proactive issue detection
55+
56+
### 6. Enhanced Error Handling
57+
**Current**: Basic try/except with error dicts
58+
**Improvement**:
59+
- Custom exception hierarchy
60+
- Retry logic with exponential backoff
61+
- Error categorization (network, auth, device, config)
62+
- Detailed error context for debugging
63+
64+
**Benefits**: More robust, better error messages
65+
66+
### 7. Health Check & Metrics Resource
67+
**Current**: No health check capability
68+
**Improvement**:
69+
- `health://status` resource showing server health
70+
- `metrics://usage` resource with usage statistics
71+
- Tool execution time tracking
72+
- Error rate monitoring
73+
74+
**Benefits**: Monitoring, debugging, performance insights
75+
76+
### 8. Configuration Validation & Auto-fix
77+
**Current**: Basic validation
78+
**Improvement**:
79+
- Comprehensive config schema validation (JSON Schema)
80+
- Auto-detect and suggest fixes for common issues
81+
- Validate device connectivity on config load
82+
- Config diff tool for changes
83+
84+
**Benefits**: Catch config issues early, easier setup
85+
86+
## Medium Priority Improvements
87+
88+
### 9. Progress Tracking for Long Operations
89+
**Current**: No progress feedback for long-running operations
90+
**Improvement**:
91+
- Progress callbacks for OTA updates, power monitoring
92+
- Estimated time remaining
93+
- Operation cancellation support
94+
- Status resource: `status://<operation_id>`
95+
96+
**Benefits**: Better UX, know what's happening
97+
98+
### 10. Rate Limiting & Throttling
99+
**Current**: No protection against too many requests
100+
**Improvement**:
101+
- Rate limiting per tool type
102+
- Throttling for device operations
103+
- Queue management for batch operations
104+
- Configurable limits
105+
106+
**Benefits**: Prevent overload, fair resource usage
107+
108+
### 11. Caching Layer
109+
**Current**: No caching of results
110+
**Improvement**:
111+
- Cache device status (TTL: 30s)
112+
- Cache device inventory (TTL: 5min)
113+
- Cache power log metadata
114+
- Invalidate on updates
115+
116+
**Benefits**: Faster responses, reduced load
117+
118+
### 12. Webhook/Event System
119+
**Current**: No event notifications
120+
**Improvement**:
121+
- Event bus for device state changes
122+
- Webhook support for external integrations
123+
- Event history resource
124+
- Configurable event filters
125+
126+
**Benefits**: Integration with other systems, automation
127+
128+
### 13. Device Discovery & Auto-configuration
129+
**Current**: Manual device configuration
130+
**Improvement**:
131+
- Network scanning for new devices
132+
- Auto-detect device type (Foundries.io, etc.)
133+
- Auto-generate device config entries
134+
- Device fingerprinting
135+
136+
**Benefits**: Easier setup, less manual work
137+
138+
### 14. Advanced Power Analysis
139+
**Current**: Basic power log analysis
140+
**Improvement**:
141+
- Statistical analysis (mean, std dev, percentiles)
142+
- Anomaly detection
143+
- Power trend analysis over time
144+
- Export to CSV/JSON for external analysis
145+
146+
**Benefits**: Better insights, data export
147+
148+
### 15. OTA Update Management
149+
**Current**: Basic OTA status/trigger
150+
**Improvement**:
151+
- OTA update queue management
152+
- Rollback capability
153+
- Update verification (checksums, signatures)
154+
- Update history tracking
155+
156+
**Benefits**: Safer updates, better control
157+
158+
## Low Priority / Future Enhancements
159+
160+
### 16. Web UI Dashboard
161+
- Real-time device status dashboard
162+
- Power monitoring graphs
163+
- OTA update management interface
164+
- Historical data visualization
165+
166+
### 17. Multi-user Support
167+
- User authentication
168+
- Permission system
169+
- Audit logging
170+
- User-specific device access
171+
172+
### 18. Plugin System
173+
- Extensible tool system
174+
- Custom tool registration
175+
- Third-party integrations
176+
177+
### 19. Device Templates
178+
- Device configuration templates
179+
- Quick setup for common board types
180+
- Template library
181+
182+
### 20. Backup & Restore
183+
- Config backup/restore
184+
- Device state snapshots
185+
- Disaster recovery
186+
187+
## Implementation Priority
188+
189+
**Phase 1 (Immediate)**:
190+
1. Structured logging
191+
2. Async batch operations
192+
3. Unit tests
193+
4. Enhanced error handling
194+
195+
**Phase 2 (Short-term)**:
196+
5. Connection pooling
197+
6. Device state management
198+
7. Health check resource
199+
8. Configuration validation
200+
201+
**Phase 3 (Medium-term)**:
202+
9. Progress tracking
203+
10. Rate limiting
204+
11. Caching
205+
12. Advanced power analysis
206+
207+
**Phase 4 (Long-term)**:
208+
13. Webhook system
209+
14. Device discovery
210+
15. OTA management enhancements
211+

README.md

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@ MCP server exposing remote embedded hardware testing capabilities to AI assistan
66

77
## Quick Start
88

9+
**Requirements: Python 3.10+** (MCP SDK requires Python 3.10+)
10+
911
```bash
10-
pip3 install -r requirements.txt
11-
pip3 install git+https://github.com/modelcontextprotocol/python-sdk.git
12-
python3 test_server.py
12+
# Install the MCP SDK (requires Python 3.10+)
13+
python3.10 -m pip install git+https://github.com/modelcontextprotocol/python-sdk.git
14+
15+
# Install this package
16+
python3.10 -m pip install -e ".[dev]"
17+
18+
# Verify installation
19+
python3.10 mcp_remote_testing/test_server.py
1320
```
1421

1522
## Configuration
@@ -20,14 +27,18 @@ Add to Cursor MCP config (`~/.cursor/mcp.json`):
2027
{
2128
"mcpServers": {
2229
"lab-testing": {
23-
"command": "python3",
24-
"args": ["/path/to/mcp-remote-testing/server.py"],
30+
"command": "python3.10",
31+
"args": ["/home/ajlennon/data_drive/esl/mcp-remote-testing/mcp_remote_testing/server.py"],
2532
"env": {"LAB_TESTING_ROOT": "/data_drive/esl/lab-testing"}
2633
}
2734
}
2835
}
2936
```
3037

38+
**Important:** Use `python3.10` (or `python3.11+`) since MCP SDK requires Python 3.10+.
39+
40+
See [docs/SETUP.md](docs/SETUP.md) for detailed setup instructions or `mcp.json.example` for a template.
41+
3142
## Architecture
3243

3344
```mermaid
@@ -68,7 +79,10 @@ Data flow: AI → MCP Server → Tools → Lab Framework → Hardware
6879
- **VPN**: `vpn_status`, `connect_vpn`, `disconnect_vpn`
6980
- **Power**: `start_power_monitoring`, `get_power_logs`, `analyze_power_logs`, `monitor_low_power`, `compare_power_profiles`
7081
- **Tasmota**: `tasmota_control`, `list_tasmota_devices`
71-
- **OTA/Containers**: `check_ota_status`, `trigger_ota_update`, `list_containers`, `deploy_container`, `get_system_status`
82+
- **OTA/Containers**: `check_ota_status`, `trigger_ota_update`, `list_containers`, `deploy_container`, `get_system_status`, `get_firmware_version`, `get_foundries_registration_status`, `get_secure_boot_status`, `get_device_identity`
83+
- **Process Management**: `kill_stale_processes` - Kill duplicate processes that might interfere
84+
- **Remote Access**: `create_ssh_tunnel`, `list_ssh_tunnels`, `close_ssh_tunnel`, `access_serial_port`, `list_serial_devices` - SSH tunnels and serial port access
85+
- **Change Tracking**: `get_change_history`, `revert_changes` - Track and revert changes for security/debugging
7286
- **Batch/Regression**: `batch_operation`, `regression_test`, `get_device_groups`
7387
- **Help**: `help` - Get usage documentation and examples
7488

@@ -78,11 +92,13 @@ Data flow: AI → MCP Server → Tools → Lab Framework → Hardware
7892
- `network://status` - Network/VPN status
7993
- `config://lab_devices` - Raw config
8094
- `help://usage` - Help documentation and usage examples
95+
- `health://status` - Server health, metrics, and SSH pool status
8196

8297
## Development
8398

8499
```bash
85-
pip3 install -e ".[dev]"
100+
# Use Python 3.10+ for development
101+
python3.10 -m pip install -e ".[dev]"
86102
pre-commit install
87103
black . && ruff check . --fix
88104
```

0 commit comments

Comments
 (0)