UNPKG

math-mcp

Version:

MCP server for mathematical expression evaluation with strict grammar validation

62 lines 2.28 kB
export class ResourceHandlers { evaluator; constructor(evaluator) { this.evaluator = evaluator; } async handleResourceRead(uri) { switch (uri) { case 'math://grammar': return { contents: [ { uri: 'math://grammar', mimeType: 'text/plain', text: await this.getGrammarSpec(), }, ], }; case 'math://functions': return { contents: [ { uri: 'math://functions', mimeType: 'application/json', text: JSON.stringify({ functions: this.evaluator.listFunctions(), description: 'List of supported mathematical functions', }, null, 2), }, ], }; case 'math://constants': return { contents: [ { uri: 'math://constants', mimeType: 'application/json', text: JSON.stringify({ constants: this.evaluator.listConstants(), description: 'List of predefined mathematical constants', }, null, 2), }, ], }; default: throw new Error(`Unknown resource: ${uri}`); } } async getGrammarSpec() { try { const fs = await import('fs/promises'); const path = await import('path'); const url = await import('url'); const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); const grammarPath = path.resolve(__dirname, '../../grammar.txt'); return await fs.readFile(grammarPath, 'utf-8'); } catch { return 'Grammar specification not available'; } } } //# sourceMappingURL=handlers.js.map