Skip to main content
Glama
ahmetshbz1

Filesystem MCP Server

by ahmetshbz1
backup.test.ts1.48 kB
import { describe, it, expect, vi, beforeEach } from 'vitest'; import fs from 'fs/promises'; import path from 'path'; import { handlers } from '../src/handlers/utility.js'; import { setAllowedDirectories } from '../src/lib.js'; // Mock fs vi.mock('fs/promises'); vi.mock('../src/logger.js', () => ({ logger: { info: vi.fn() }, })); const mockFs = fs as any; describe('file_backup', () => { const mockFs = fs as any; beforeEach(() => { setAllowedDirectories(['/tmp']); vi.clearAllMocks(); mockFs.realpath.mockImplementation((p: string) => Promise.resolve(p)); }); it('should create backup with default path', async () => { mockFs.copyFile.mockResolvedValue(undefined); const result = await handlers.utility({ operation: 'backup-create', path: '/tmp/file.txt' }); // Note: utility handler uses timestamp in backup path if not specified, so exact match is hard // But we can check if copyFile was called expect(mockFs.copyFile).toHaveBeenCalled(); expect(result.content[0].text).toContain('Backup created:'); }); it('should create backup with custom path', async () => { mockFs.copyFile.mockResolvedValue(undefined); const result = await handlers.utility({ operation: 'backup-create', path: '/tmp/file.txt', backupPath: '/tmp/backup.txt' }); expect(mockFs.copyFile).toHaveBeenCalledWith('/tmp/file.txt', '/tmp/backup.txt'); expect(result.content[0].text).toBe('Backup created: /tmp/backup.txt'); }); });

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/ahmetshbz1/filesystem-mcp'

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