UNPKG

framework-mcp

Version:

Dual-architecture server (MCP + HTTP API) for determining vendor tool capability roles against CIS Controls Framework. Supports Microsoft Copilot custom connectors and DigitalOcean App Services deployment.

201 lines 8.62 kB
#!/usr/bin/env node import { Server } from '@modelcontextprotocol/sdk/server/index.js'; import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'; import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js'; import { CapabilityAnalyzer } from '../../core/capability-analyzer.js'; import { SafeguardManager } from '../../core/safeguard-manager.js'; export class FrameworkMcpServer { constructor() { this.server = new Server({ name: 'framework-analyzer', version: '1.3.7', }); this.capabilityAnalyzer = new CapabilityAnalyzer(); this.safeguardManager = new SafeguardManager(); this.setupHandlers(); } setupHandlers() { // List available tools this.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ { name: 'analyze_vendor_response', description: 'Determine vendor tool capability role for specific safeguard', inputSchema: { type: 'object', properties: { vendor_name: { type: 'string', description: 'Name of the vendor' }, safeguard_id: { type: 'string', description: 'CIS safeguard ID (e.g., "1.1", "5.1")' }, response_text: { type: 'string', description: 'Vendor response text to analyze' } }, required: ['vendor_name', 'safeguard_id', 'response_text'] } }, { name: 'get_safeguard_details', description: 'Get detailed safeguard breakdown', inputSchema: { type: 'object', properties: { safeguard_id: { type: 'string', description: 'CIS safeguard ID (e.g., "1.1", "5.1")' }, include_examples: { type: 'boolean', description: 'Include implementation examples (default: false)' } }, required: ['safeguard_id'] } }, { name: 'list_available_safeguards', description: 'List all available CIS safeguards', inputSchema: { type: 'object', properties: {}, additionalProperties: false } }, ], }; }); // Handle tool calls this.server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; try { switch (name) { case 'analyze_vendor_response': return await this.analyzeVendorResponse(args); case 'get_safeguard_details': return await this.getSafeguardDetails(args); case 'list_available_safeguards': return await this.listAvailableSafeguards(); default: throw new Error(`Unknown tool: ${name}`); } } catch (error) { const errorMessage = this.formatErrorMessage(error, name); console.error(`[Framework MCP] Tool execution error: ${name}`, error); return { content: [ { type: 'text', text: JSON.stringify({ error: errorMessage, timestamp: new Date().toISOString() }, null, 2), }, ], }; } }); } async analyzeVendorResponse(args) { const { vendor_name = 'Unknown Vendor', safeguard_id, response_text } = args; this.validateTextInput(response_text, 'Response text'); this.safeguardManager.validateSafeguardId(safeguard_id); const safeguard = this.safeguardManager.getSafeguardDetails(safeguard_id); if (!safeguard) { throw new Error(`Safeguard ${safeguard_id} not found`); } const analysis = this.capabilityAnalyzer.performCapabilityAnalysis(vendor_name, safeguard, response_text); return { content: [ { type: 'text', text: JSON.stringify(analysis, null, 2), }, ], }; } async getSafeguardDetails(args) { const { safeguard_id, include_examples = false } = args; this.safeguardManager.validateSafeguardId(safeguard_id); const safeguard = this.safeguardManager.getSafeguardDetails(safeguard_id, include_examples); if (!safeguard) { throw new Error(`Safeguard ${safeguard_id} not found`); } return { content: [ { type: 'text', text: JSON.stringify(safeguard, null, 2), }, ], }; } async listAvailableSafeguards() { const safeguards = this.safeguardManager.listAvailableSafeguards(); return { content: [ { type: 'text', text: JSON.stringify({ safeguards, total: safeguards.length, framework: 'CIS Controls v8.1', version: '1.3.7' }, null, 2), }, ], }; } validateTextInput(text, fieldName) { if (typeof text !== 'string') { throw new Error(`${fieldName} must be a string`); } if (text.length < 10) { throw new Error(`${fieldName} must be at least 10 characters long`); } if (text.length > 10000) { throw new Error(`${fieldName} must be less than 10,000 characters`); } } validateCapability(capability) { const validCapabilities = ['full', 'partial', 'facilitates', 'governance', 'validates']; if (!validCapabilities.includes(capability.toLowerCase())) { throw new Error(`Invalid capability '${capability}'. Valid options: ${validCapabilities.join(', ')}`); } } formatErrorMessage(error, toolName) { if (error instanceof Error) { // Provide helpful guidance for common errors if (error.message.includes('Safeguard') && error.message.includes('not found')) { return `${error.message}. Use list_available_safeguards to see all available options.`; } if (error.message.includes('Invalid capability')) { return `${error.message}. Capability roles determine what function the vendor tool plays in safeguard implementation.`; } if (error.message.includes('characters')) { return `${error.message}. Ensure your input text is substantive enough for analysis.`; } return error.message; } return `Unknown error in tool ${toolName}`; } async run() { const transport = new StdioServerTransport(); await this.server.connect(transport); console.error('🤖 Framework MCP Server v1.3.7 running via stdio'); console.error('📊 Clean capability assessment for CIS Controls v8.1'); } } // Start server if this file is run directly if (import.meta.url === `file://${process.argv[1]}`) { const server = new FrameworkMcpServer(); server.run().catch(console.error); } //# sourceMappingURL=mcp-server.js.map