Labsco
bsmi021 logo

Filesystem MCP Server

โ˜… 6

from bsmi021

Provides file system operations, analysis, and manipulation capabilities through a standardized tool interface.

๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅโœ“ VerifiedFreeAdvanced setup

Filesystem MCP Server

A Model Context Protocol (MCP) server implementation providing file system operations, analysis, and manipulation capabilities through a standardized tool interface.

Architecture

The server is built on the MCP SDK and organized into distinct layers:

Copy & paste โ€” that's it
graph TD
    A[MCP Server Layer] --> B[Tool Registry]
    B --> C[Operations Layer]
    C --> D[File System Operations]
    C --> E[Analysis Operations]
    C --> F[Stream Operations]

Components

  • Server Layer: Handles MCP protocol communication and tool dispatch
  • Tool Registry: Manages tool registration and execution
  • Operations Layer: Implements core functionality
  • File System Interface: Provides safe file system access

Tool Reference

Directory Operations

list_directory

Lists directory contents with metadata.

Copy & paste โ€” that's it
interface ListDirectoryParams {
    path: string;       // Directory path
    recursive?: boolean; // List recursively (default: false)
}

interface ListDirectoryResult {
    entries: {
        name: string;
        path: string;
        isDirectory: boolean;
        size: number;
        created: string;
        modified: string;
        accessed: string;
        mode: string;
    }[];
}

create_directory

Creates a new directory.

Copy & paste โ€” that's it
interface CreateDirectoryParams {
    path: string;       // Directory path
    recursive?: boolean; // Create parent directories (default: true)
}

File Operations

read_file

Reads file content with encoding support.

Copy & paste โ€” that's it
interface ReadFileParams {
    path: string;     // File path
    encoding?: string; // File encoding (default: 'utf8')
}

write_file

Writes content to a file.

Copy & paste โ€” that's it
interface WriteFileParams {
    path: string;     // File path
    content: string;  // Content to write
    encoding?: string; // File encoding (default: 'utf8')
}

append_file

Appends content to a file.

Copy & paste โ€” that's it
interface AppendFileParams {
    path: string;     // File path
    content: string;  // Content to append
    encoding?: string; // File encoding (default: 'utf8')
}

Analysis Operations

analyze_text

Analyzes text file properties.

Copy & paste โ€” that's it
interface AnalyzeTextParams {
    path: string; // File path
}

interface AnalyzeTextResult {
    lineCount: number;
    wordCount: number;
    charCount: number;
    encoding: string;
    mimeType: string;
}

calculate_hash

Calculates file hash using specified algorithm.

Copy & paste โ€” that's it
interface CalculateHashParams {
    path: string;           // File path
    algorithm?: 'md5' | 'sha1' | 'sha256' | 'sha512'; // Hash algorithm
}

interface CalculateHashResult {
    hash: string;
    algorithm: string;
}

find_duplicates

Identifies duplicate files in a directory.

Copy & paste โ€” that's it
interface FindDuplicatesParams {
    path: string; // Directory path
}

interface FindDuplicatesResult {
    duplicates: {
        hash: string;
        size: number;
        files: string[];
    }[];
}

Compression Operations

create_zip

Creates a ZIP archive.

Copy & paste โ€” that's it
interface CreateZipParams {
    files: string[];  // Files to include
    output: string;   // Output ZIP path
}

extract_zip

Extracts a ZIP archive.

Copy & paste โ€” that's it
interface ExtractZipParams {
    path: string;    // ZIP file path
    output: string;  // Output directory
}

Error Handling

The server uses standard MCP error codes:

Copy & paste โ€” that's it
enum ErrorCode {
    ParseError = -32700,
    InvalidRequest = -32600,
    MethodNotFound = -32601,
    InvalidParams = -32602,
    InternalError = -32603
}

Error responses include:

  • Error code
  • Human-readable message
  • Additional context when available

Example error:

Copy & paste โ€” that's it
{
    "code": -32602,
    "message": "File not found: /path/to/file.txt"
}

Development

Project Structure

Copy & paste โ€” that's it
src/
โ”œโ”€โ”€ operations/     # Core operations implementation
โ”œโ”€โ”€ tools/         # MCP tool definitions and handlers
โ”œโ”€โ”€ __tests__/     # Test suites
โ”œโ”€โ”€ index.ts       # Entry point
โ”œโ”€โ”€ server.ts      # MCP server setup
โ”œโ”€โ”€ types.ts       # Type definitions
โ””โ”€โ”€ utils.ts       # Utility functions

Running Tests

Run the test suite:

Copy & paste โ€” that's it
npm test

Run with coverage:

Copy & paste โ€” that's it
npm run test:coverage

Development Mode

Run in watch mode:

Copy & paste โ€” that's it
npm run watch

Code Quality

Lint the codebase:

Copy & paste โ€” that's it
npm run lint

Type check:

Copy & paste โ€” that's it
npm run type-check

Dependencies

Core dependencies:

  • @modelcontextprotocol/sdk: MCP server implementation
  • file-type: File type detection
  • mime-types: MIME type lookup
  • crypto-js: File hashing
  • archiver: ZIP creation
  • extract-zip: ZIP extraction
  • iconv-lite: Text encoding
  • chardet: Encoding detection

Development dependencies:

  • typescript: Type system
  • jest: Testing
  • eslint: Linting
  • prettier: Formatting
  • ts-node: TypeScript execution
  • nodemon: Development server

Contributing

  1. Fork the repository
  2. Create your feature branch
  3. Write tests for new features
  4. Ensure all tests pass
  5. Submit a pull request

License

MIT