Skip to main content
Glama
index.js5.35 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 { program } from 'commander'; import { AudioInspector } from './lib/inspector.js'; import { promises as fs } from 'fs'; import path from 'path'; // CLI setup for standalone usage program .name('mcp-audio-inspector') .description('Comprehensive audio file analysis and metadata extraction') .version('1.0.0'); program .option('--standalone <file>', 'Analyze a single audio file (standalone mode)') .option('--batch <directory>', 'Analyze all audio files in a directory') .option('--format <format>', 'Output format (json, yaml, csv)', 'json') .option('--output <file>', 'Output file (default: stdout)'); // Parse CLI arguments program.parse(); const options = program.opts(); // Standalone mode for testing if (options.standalone || options.batch) { const inspector = new AudioInspector(); try { if (options.standalone) { const result = await inspector.analyzeFile(options.standalone); const output = JSON.stringify(result, null, 2); if (options.output) { await fs.writeFile(options.output, output); console.log(`Analysis saved to ${options.output}`); } else { console.log(output); } } else if (options.batch) { const results = await inspector.analyzeBatch(options.batch); const output = JSON.stringify(results, null, 2); if (options.output) { await fs.writeFile(options.output, output); console.log(`Batch analysis saved to ${options.output}`); } else { console.log(output); } } } catch (error) { console.error('Error:', error.message); process.exit(1); } process.exit(0); } // MCP Server mode const server = new Server( { name: 'mcp-audio-inspector', version: '1.0.0', }, { capabilities: { tools: {}, }, } ); // Initialize audio inspector const inspector = new AudioInspector(); // List available tools server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ { name: 'analyze_audio_file', description: 'Analyze a single audio file and extract comprehensive metadata', inputSchema: { type: 'object', properties: { filePath: { type: 'string', description: 'Path to the audio file to analyze' }, includeGameAnalysis: { type: 'boolean', description: 'Include game-specific audio analysis', default: true } }, required: ['filePath'] } }, { name: 'analyze_audio_batch', description: 'Analyze all audio files in a directory', inputSchema: { type: 'object', properties: { directoryPath: { type: 'string', description: 'Path to directory containing audio files' }, recursive: { type: 'boolean', description: 'Search subdirectories recursively', default: false }, includeGameAnalysis: { type: 'boolean', description: 'Include game-specific audio analysis', default: true } }, required: ['directoryPath'] } }, { name: 'get_supported_formats', description: 'Get list of supported audio formats', inputSchema: { type: 'object', properties: {} } } ] }; }); // Handle tool calls server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; try { switch (name) { case 'analyze_audio_file': const fileResult = await inspector.analyzeFile( args.filePath, args.includeGameAnalysis ?? true ); return { content: [ { type: 'text', text: JSON.stringify(fileResult, null, 2) } ] }; case 'analyze_audio_batch': const batchResult = await inspector.analyzeBatch( args.directoryPath, args.recursive ?? false, args.includeGameAnalysis ?? true ); return { content: [ { type: 'text', text: JSON.stringify(batchResult, null, 2) } ] }; case 'get_supported_formats': const formats = inspector.getSupportedFormats(); return { content: [ { type: 'text', text: JSON.stringify(formats, null, 2) } ] }; default: throw new Error(`Unknown tool: ${name}`); } } catch (error) { throw new Error(`Tool execution failed: ${error.message}`); } }); // Start server async function main() { const transport = new StdioServerTransport(); await server.connect(transport); } main().catch((error) => { console.error('Server error:', error); process.exit(1); });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/DeveloperZo/mcp-audio-inspector'

If you have feedback or need assistance with the MCP directory API, please join our Discord server