purchase-mcp-server
Version:
Purchase and budget management server handling requisitions, purchase orders, expenses, budgets, and vendor management with ERP access for data extraction
38 lines • 1.45 kB
JavaScript
import { GeneralHandler } from './handlers/generalHandler.js';
import { resources } from './resources.js';
// 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