pms-analysis-reports-mcp-server
Version:
PMS analysis reports server handling maintenance reports, equipment analysis, compliance tracking, and performance metrics with ERP access for data extraction
77 lines (73 loc) • 2.95 kB
JavaScript
import OpenAI from 'openai';
import { config } from './config.js';
import { logger } from './logger.js';
let openaiClient = null;
export function getOpenAIClient() {
if (!openaiClient && config.openaiApiKey) {
openaiClient = new OpenAI({
apiKey: config.openaiApiKey
});
}
if (!openaiClient) {
throw new Error('OpenAI API key not configured');
}
return openaiClient;
}
export async function processWithLLM(prompt, systemMessage = "You are a helpful assistant for PMS analysis and maintenance reports.", model = "gpt-4") {
try {
const client = getOpenAIClient();
const response = await client.chat.completions.create({
model: model,
messages: [
{ role: "system", content: systemMessage },
{ role: "user", content: prompt }
],
temperature: 0.7,
max_tokens: 2000
});
const content = response.choices[0]?.message?.content || '';
return {
content,
usage: response.usage ? {
prompt_tokens: response.usage.prompt_tokens,
completion_tokens: response.usage.completion_tokens,
total_tokens: response.usage.total_tokens
} : undefined
};
}
catch (error) {
logger.error('Error processing with LLM:', error);
throw error;
}
}
export async function analyzeMaintenanceData(data, analysisType = "general") {
const prompt = `Analyze the following PMS maintenance data and provide insights:
Analysis Type: ${analysisType}
Data: ${JSON.stringify(data, null, 2)}
Please provide:
1. Key findings and patterns
2. Potential issues or concerns
3. Recommendations for improvement
4. Risk assessment if applicable`;
const systemMessage = `You are an expert marine engineer specializing in Planned Maintenance System (PMS) analysis.
Provide detailed, actionable insights based on maintenance data, equipment performance, and compliance requirements.`;
const response = await processWithLLM(prompt, systemMessage);
return response.content;
}
export async function generateMaintenanceReport(reportData, reportType = "summary") {
const prompt = `Generate a comprehensive PMS maintenance report based on the following data:
Report Type: ${reportType}
Data: ${JSON.stringify(reportData, null, 2)}
Please structure the report with:
1. Executive Summary
2. Equipment Status Overview
3. Maintenance Activities Completed
4. Outstanding Issues
5. Compliance Status
6. Recommendations and Next Steps`;
const systemMessage = `You are a technical report writer specializing in marine maintenance systems.
Create professional, detailed reports that comply with maritime industry standards and regulations.`;
const response = await processWithLLM(prompt, systemMessage);
return response.content;
}
//# sourceMappingURL=llm.js.map