leshan-mcp-server
Version:
A standards-compliant MCP server for Leshan LwM2M, exposing Leshan as Model Context Protocol tools.
114 lines (93 loc) • 3.91 kB
JavaScript
import logger from "../utils/loggerConfig.js";
/**
* Device diagnostics prompt for comprehensive device analysis
* @param {Object} params - Prompt parameters
* @param {string} params.deviceId - Device endpoint to diagnose
* @returns {Promise<Object>} MCP prompt response
*/
export async function deviceDiagnosticsPrompt({ deviceId }) {
const operationId = `device-diagnostics-${Date.now()}`;
try {
logger.info("Device diagnostics prompt requested", { operationId, deviceId });
const prompt = `# LwM2M Device Diagnostics Analysis
You are an expert LwM2M (Lightweight M2M) device management specialist. Perform a comprehensive diagnostic analysis of device: **${deviceId || '[DEVICE_ID]'}**
## Diagnostic Checklist
### 1. Device Connectivity & Registration
- Check device registration status and last update time
- Verify device lifetime and binding mode
- Analyze registration parameters and endpoint configuration
- Review network connectivity (IP address, port)
### 2. Object Model Analysis
- List all available LwM2M objects and instances
- Identify standard vs. custom objects
- Check for missing mandatory objects (Security, Server, Device)
- Validate object instance configurations
### 3. Device Information Assessment
- Read Device Object (3) resources:
- Manufacturer (0), Model Number (1), Serial Number (2)
- Firmware Version (3), Available Power Sources (6)
- Power Source Voltage (7), Battery Level (9)
- Memory Free (10), Error Code (11)
- Current Time (13), UTC Offset (14)
### 4. Server Configuration Review
- Check Server Object (1) configuration
- Verify server URI, lifetime, and binding preferences
- Review notification settings and observation parameters
### 5. Security Assessment
- Validate Security Object (0) configuration (without exposing sensitive data)
- Check security mode and certificate status
- Review bootstrap configuration if applicable
### 6. Connectivity Monitoring
- Analyze Connectivity Monitoring Object (4) if present
- Check network bearer, IP addresses, router IP
- Review link quality and utilization metrics
### 7. Performance Metrics
- Monitor resource read/write response times
- Check for any error patterns or timeouts
- Analyze observation and notification behavior
## Available Tools
Use these MCP tools for the diagnostic analysis:
- \`list-devices\`: Get overview of all devices
- \`get-device-info\`: Get detailed device information
- \`read-resource\`: Read specific resource values
- \`observe-resource\`: Monitor resource changes
- \`execute-resource\`: Execute device functions for testing
## Analysis Format
Provide your analysis in this structure:
1. **Executive Summary**: Overall device health status
2. **Connectivity Status**: Registration and network details
3. **Object Model Review**: Available objects and their status
4. **Critical Issues**: Any problems requiring immediate attention
5. **Recommendations**: Suggested actions for optimization
6. **Monitoring Setup**: Recommended ongoing monitoring strategy
## Device Context
${deviceId ? `Target Device: ${deviceId}` : 'Please specify the device endpoint ID to analyze.'}
Begin the diagnostic analysis by first listing all devices to confirm the target device exists, then proceed with the comprehensive assessment.`;
logger.info("Device diagnostics prompt generated", { operationId, deviceId });
return {
messages: [{
role: "user",
content: {
type: "text",
text: prompt
}
}]
};
} catch (error) {
logger.error("Device diagnostics prompt failed", {
operationId,
deviceId,
error: error.message
});
return {
messages: [{
role: "user",
content: {
type: "text",
text: `Error generating device diagnostics prompt: ${error.message}`
}
}]
};
}
}
export default deviceDiagnosticsPrompt;