Skip to main content
Glama
simple-filesystem-test.jsโ€ข6.45 kB
import { spawn } from 'child_process'; import { writeFile, mkdir, rmdir } from 'fs/promises'; import { join } from 'path'; import { existsSync } from 'fs'; /** * Simple filesystem test to verify basic functionality */ class SimpleFilesystemTest { constructor() { this.server = null; this.testDir = join(process.cwd(), 'simple-test-workspace'); } async setupTestEnvironment() { console.log('๐Ÿ› ๏ธ Setting up test environment...'); if (!existsSync(this.testDir)) { await mkdir(this.testDir, { recursive: true }); } // Create a simple test file await writeFile(join(this.testDir, 'test.js'), ` function hello(name) { return "Hello, " + name + "!"; } console.log(hello("World")); `); console.log('โœ… Test environment ready'); } async startServer() { console.log('๐Ÿš€ Starting MCP server...'); this.server = spawn('bun', ['server.js'], { stdio: ['pipe', 'pipe', 'pipe'], cwd: process.cwd(), }); // Wait for server to be ready await new Promise((resolve, reject) => { const timeout = setTimeout(() => { reject(new Error('Server startup timeout')); }, 15000); this.server.stderr.on('data', (data) => { const output = data.toString(); console.log('Server output:', output); if (output.includes('server started successfully')) { clearTimeout(timeout); resolve(); } }); this.server.on('error', (error) => { clearTimeout(timeout); reject(error); }); }); console.log('โœ… Server started successfully'); } async stopServer() { if (this.server) { this.server.kill(); console.log('๐Ÿ›‘ Server stopped'); } } async testListTools() { console.log('\n๐Ÿงช Testing: List available tools'); const request = { jsonrpc: '2.0', id: 1, method: 'tools/list', }; const response = await this.sendRequest(request); console.log('Available tools:', response.result.tools.map(t => t.name)); // Check if filesystem tools are available const toolNames = response.result.tools.map(t => t.name); const expectedTools = [ 'create_file', 'read_file', 'update_file', 'delete_file', 'list_directory', 'search_files', 'search_in_files', 'analyze_project', 'find_similar_files', 'extract_snippet', 'request_editing_help', ]; const missingTools = expectedTools.filter(tool => !toolNames.includes(tool)); if (missingTools.length > 0) { console.log('โŒ Missing tools:', missingTools); } else { console.log('โœ… All filesystem tools are available'); } } async testBasicFileOperations() { console.log('\n๐Ÿงช Testing: Basic file operations'); // Change to test directory process.chdir(this.testDir); // Test create_file console.log('๐Ÿ“ Testing create_file...'); const createResponse = await this.sendRequest({ jsonrpc: '2.0', id: 2, method: 'tools/call', params: { name: 'create_file', arguments: { filePath: 'new-file.txt', content: 'Hello, World!\nThis is a test file.', }, }, }); console.log('Create file response:', createResponse.result.content[0].text); // Test read_file console.log('๐Ÿ“– Testing read_file...'); const readResponse = await this.sendRequest({ jsonrpc: '2.0', id: 3, method: 'tools/call', params: { name: 'read_file', arguments: { filePath: 'new-file.txt', }, }, }); console.log('Read file response:', readResponse.result.content[0].text); // Test list_directory console.log('๐Ÿ“ Testing list_directory...'); const listResponse = await this.sendRequest({ jsonrpc: '2.0', id: 4, method: 'tools/call', params: { name: 'list_directory', arguments: { directoryPath: '.', }, }, }); console.log('List directory response:', listResponse.result.content[0].text); // Test search_files console.log('๐Ÿ” Testing search_files...'); const searchResponse = await this.sendRequest({ jsonrpc: '2.0', id: 5, method: 'tools/call', params: { name: 'search_files', arguments: { pattern: '*.js', directoryPath: '.', }, }, }); console.log('Search files response:', searchResponse.result.content[0].text); } async sendRequest(request) { return new Promise((resolve, reject) => { const timeout = setTimeout(() => { reject(new Error('Request timeout')); }, 10000); const responseHandler = (data) => { clearTimeout(timeout); try { const response = JSON.parse(data.toString()); resolve(response); } catch (error) { console.log('Raw response:', data.toString()); reject(new Error('Invalid JSON response: ' + error.message)); } }; this.server.stdout.once('data', responseHandler); this.server.stdin.write(JSON.stringify(request) + '\n'); }); } async cleanupTestEnvironment() { console.log('๐Ÿงน Cleaning up test environment...'); // Return to original directory process.chdir(join(this.testDir, '..')); try { if (existsSync(this.testDir)) { await rmdir(this.testDir, { recursive: true }); } console.log('โœ… Cleanup complete'); } catch (error) { console.warn('Warning: Failed to cleanup test environment:', error.message); } } async run() { try { await this.setupTestEnvironment(); await this.startServer(); await this.testListTools(); await this.testBasicFileOperations(); console.log('\n๐ŸŽ‰ All tests completed successfully!'); } catch (error) { console.error('โŒ Test failed:', error.message); console.error('Stack trace:', error.stack); } finally { await this.stopServer(); await this.cleanupTestEnvironment(); } } } // Run the test async function main() { console.log('๐Ÿงช Starting Simple Filesystem Tools Test'); console.log('=' .repeat(50)); const test = new SimpleFilesystemTest(); await test.run(); } main().catch(console.error);

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/moikas-code/moidvk'

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