Skip to main content
Glama
N3uraX

Tafa MCP Server

by N3uraX
basic-tests.jsβ€’5.8 kB
#!/usr/bin/env node import fs from "fs-extra"; import path from "path"; import { fileURLToPath } from "url"; import os from "os"; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); class TafaTests { constructor() { this.testDir = path.join(os.tmpdir(), 'tafa-mcp-tests'); this.testResults = []; } async runTests() { console.log('πŸ§ͺ Running Tafa MCP Basic Tests...\n'); // Setup test environment await this.setupTestEnv(); // Run tests await this.testFileOperations(); await this.testDirectoryOperations(); await this.testSearchOperations(); await this.testSecurity(); // Cleanup await this.cleanupTestEnv(); // Report results this.reportResults(); } async setupTestEnv() { console.log('πŸ”§ Setting up test environment...'); await fs.ensureDir(this.testDir); // Create test files await fs.writeFile(path.join(this.testDir, 'test1.txt'), 'Hello World\nThis is a test file'); await fs.writeFile(path.join(this.testDir, 'test2.js'), 'console.log("Hello from JS");'); await fs.writeFile(path.join(this.testDir, 'README.md'), '# Test README\nThis is a test readme'); // Create test subdirectory await fs.ensureDir(path.join(this.testDir, 'subdir')); await fs.writeFile(path.join(this.testDir, 'subdir', 'nested.txt'), 'Nested file content'); console.log('βœ… Test environment ready\n'); } async testFileOperations() { console.log('πŸ“„ Testing File Operations...'); // Test file reading await this.runTest('File Reading', async () => { const content = await fs.readFile(path.join(this.testDir, 'test1.txt'), 'utf8'); return content.includes('Hello World'); }); // Test file writing await this.runTest('File Writing', async () => { const testFile = path.join(this.testDir, 'write-test.txt'); await fs.writeFile(testFile, 'Test content'); const content = await fs.readFile(testFile, 'utf8'); return content === 'Test content'; }); // Test file copying await this.runTest('File Copying', async () => { const source = path.join(this.testDir, 'test1.txt'); const dest = path.join(this.testDir, 'copy-test.txt'); await fs.copy(source, dest); return await fs.pathExists(dest); }); console.log(''); } async testDirectoryOperations() { console.log('πŸ“ Testing Directory Operations...'); // Test directory creation await this.runTest('Directory Creation', async () => { const testDir = path.join(this.testDir, 'new-dir'); await fs.ensureDir(testDir); return await fs.pathExists(testDir); }); // Test directory listing await this.runTest('Directory Listing', async () => { const entries = await fs.readdir(this.testDir); return entries.length > 0; }); console.log(''); } async testSearchOperations() { console.log('πŸ” Testing Search Operations...'); // Test file search by pattern await this.runTest('File Pattern Search', async () => { const files = await fs.readdir(this.testDir); const jsFiles = files.filter(file => file.endsWith('.js')); return jsFiles.length > 0; }); // Test content search await this.runTest('Content Search', async () => { const content = await fs.readFile(path.join(this.testDir, 'test1.txt'), 'utf8'); return content.includes('Hello'); }); console.log(''); } async testSecurity() { console.log('πŸ”’ Testing Security Features...'); // Test path validation await this.runTest('Path Validation', async () => { const testPath = path.join(this.testDir, 'test1.txt'); const resolved = path.resolve(testPath); return resolved.startsWith(this.testDir); }); // Test file permissions await this.runTest('File Permissions', async () => { const testFile = path.join(this.testDir, 'test1.txt'); try { await fs.access(testFile, fs.constants.R_OK); return true; } catch { return false; } }); console.log(''); } async runTest(name, testFn) { try { const result = await testFn(); if (result) { console.log(`βœ… ${name}`); this.testResults.push({ name, status: 'PASS' }); } else { console.log(`❌ ${name}`); this.testResults.push({ name, status: 'FAIL' }); } } catch (error) { console.log(`❌ ${name} - Error: ${error.message}`); this.testResults.push({ name, status: 'ERROR', error: error.message }); } } async cleanupTestEnv() { console.log('🧹 Cleaning up test environment...'); await fs.remove(this.testDir); console.log('βœ… Cleanup complete\n'); } reportResults() { console.log('πŸ“Š Test Results Summary:'); console.log('========================'); const passed = this.testResults.filter(r => r.status === 'PASS').length; const failed = this.testResults.filter(r => r.status === 'FAIL').length; const errors = this.testResults.filter(r => r.status === 'ERROR').length; console.log(`βœ… Passed: ${passed}`); console.log(`❌ Failed: ${failed}`); console.log(`πŸ”₯ Errors: ${errors}`); console.log(`πŸ“ˆ Total: ${this.testResults.length}`); if (failed > 0 || errors > 0) { console.log('\n❌ Some tests failed. Check the output above for details.'); process.exit(1); } else { console.log('\nπŸŽ‰ All tests passed!'); } } } // Run tests if this file is executed directly if (import.meta.url === `file://${process.argv[1]}`) { const tests = new TafaTests(); tests.runTests().catch(console.error); }

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/N3uraX/tafa-mcp'

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