ms-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
52 lines • 1.96 kB
JavaScript
import * as yaml from 'js-yaml';
import * as fs from 'fs';
import * as path from 'path';
import { fileURLToPath } from 'url';
import { GeneralHandler } from './handlers/generalHandler.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Load resources from YAML file
function loadResources() {
const resourcesPath = path.resolve(__dirname, './resources.yaml');
const fileContents = fs.readFileSync(resourcesPath, 'utf8');
const config = yaml.load(fileContents);
return config.resources;
}
// Cache loaded resources
const resources = loadResources();
// Initialize single handler
const handler = new GeneralHandler();
// Export resource list for MCP (metadata only)
export const resourceList = resources.map(resource => ({
uri: resource.uri,
name: resource.name,
description: resource.description,
mimeType: resource.mimeType
}));
// Read specific resource content
export async function readResource(uri) {
const url = new URL(uri);
const resourceType = url.hostname;
const identifier = url.pathname.substring(1); // Remove leading slash
// Find matching resource definition
const resourceDef = resources.find(r => {
const resourceUrl = new URL(r.uri);
return resourceUrl.hostname === resourceType;
});
if (!resourceDef) {
return JSON.stringify({ error: `Resource not found for uri: ${uri}` }, null, 2);
}
try {
// Call method on single handler
const handlerMethod = handler[resourceDef.method];
if (typeof handlerMethod !== 'function') {
return JSON.stringify({ error: `Handler method not found: ${resourceDef.method}` }, null, 2);
}
const result = await handlerMethod(identifier);
return JSON.stringify(result, null, 2);
}
catch (error) {
return JSON.stringify({ error: String(error) }, null, 2);
}
}
//# sourceMappingURL=index.js.map