mcp-filesystem-server

Niketan77/mcp-filesystem-server

3.2

If you are the rightful owner of mcp-filesystem-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

The MCP Filesystem Server is a comprehensive implementation of the Model Context Protocol (MCP) for managing filesystem operations with AI-enhanced file editing capabilities.

Tools
  1. create_file

    Create a new file with specified content.

  2. edit_file

    Edit a file using manual input or AI-powered prompts.

  3. delete_file

    Delete a specified file from the system.

  4. read_file

    Read and retrieve the content of a specified file.

MCP Filesystem Server

A complete Model Context Protocol (MCP) server implementation for filesystem operations with AI-powered file editing capabilities.

Demo Video:

https://drive.google.com/file/d/18sCyVpAekMkDgUfsKi423VfPN6Rbuj9T/view?usp=drive_link

πŸ“‹ Description

This project was built to fulfill the following requirements:

Implemented:

  1. Implement a Model Context Protocol (MCP) server for filesystem operations
  2. Create file management tools supporting create, edit, and delete operations
  3. Develop an MCP client that communicates using proper MCP protocol
  4. Build a simple frontend application for user interaction
  5. Enable folder upload functionality for batch file management
  6. Implement a prompt box for AI-powered file editing using natural language

🎯 Project Overview

This implementation demonstrates a complete MCP ecosystem:

  • True MCP Protocol: JSON-RPC 2.0 compliant server with proper tool registration
  • AI Integration: Mixtral-8x7B-Instruct model for intelligent file editing
  • Modern Frontend: Clean, responsive web interface with professional UX
  • File Management: Complete CRUD operations for filesystem management
  • Download System: Individual file downloads and bulk ZIP export

πŸ—οΈ Technical Architecture

MCP Protocol Implementation

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚Web Frontend β”‚ ←→ β”‚ Flask Bridge β”‚ ←→ β”‚ MCP Client  β”‚ ←→ β”‚ MCP Server  β”‚ ←→ β”‚ AI Service  β”‚
β”‚             β”‚    β”‚              β”‚    β”‚             β”‚    β”‚             β”‚    β”‚             β”‚
β”‚File Upload  β”‚    β”‚ REST API     β”‚    β”‚JSON-RPC 2.0 β”‚    β”‚ File Ops    β”‚    β”‚ AI Editing  β”‚
β”‚User Actions β”‚    β”‚ CORS Enabled β”‚    β”‚ Protocol    β”‚    β”‚ Tool Reg.   β”‚    β”‚ Mixtral-8x7Bβ”‚
β”‚Notificationsβ”‚    β”‚ File Serving β”‚    β”‚ stdio comm  β”‚    β”‚ Validation  β”‚    β”‚ Together AI β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Component Breakdown

  1. MCP Server (server/mcp_server.py)

    • True JSON-RPC 2.0 protocol implementation
    • Tool registration and capability advertisement
    • File operation handlers with validation
    • AI integration for intelligent editing
  2. MCP Client (server/mcp_client.py)

    • Protocol-compliant communication layer
    • Request/response handling with proper error management
    • Subprocess communication via stdio
  3. Flask Bridge (server/mcp_bridge.py)

    • REST API endpoints for frontend communication
    • File upload/download handling
    • CORS configuration for cross-origin requests
    • Error handling and response formatting
  4. Frontend (frontend/)

    • Modern HTML5/CSS3/JavaScript interface
    • Responsive design with professional styling
    • Real-time file management and notifications

πŸ“ Project Structure

mcp-filesystem-server/
β”œβ”€β”€ run.py                    # Main entry point
β”œβ”€β”€ requirements.txt          # Dependencies
β”œβ”€β”€ .env.example             # Environment configuration
β”œβ”€β”€ server/
β”‚   β”œβ”€β”€ mcp_server.py        # Core MCP server (JSON-RPC 2.0)
β”‚   β”œβ”€β”€ mcp_client.py        # MCP protocol client
β”‚   β”œβ”€β”€ mcp_bridge.py        # Flask bridge for frontend
β”‚   └── tools/               # MCP tool implementations
β”œβ”€β”€ frontend/                # Web interface
β”‚   β”œβ”€β”€ index.html          # Main UI
β”‚   β”œβ”€β”€ scripts/app.js      # Frontend logic
β”‚   └── styles/main.css     # Styling
β”œβ”€β”€ uploaded_files/          # File storage directory
└── test_mcp.py             # MCP protocol tests

πŸš€ Quick Start Guide

Prerequisites

  • Python 3.7+ installed on your system
  • pip package manager
  • Together AI API key (optional, for AI editing features)

Installation Steps

  1. Clone the repository:

    git clone https://github.com/Niketan77/mcp-filesystem-server.git
    cd mcp-filesystem-server
    
  2. Create a virtual environment (recommended):

    # Windows
    python -m venv venv
    venv\Scripts\activate
    
    # macOS/Linux
    python3 -m venv venv
    source venv/bin/activate
    
  3. Install dependencies:

    pip install -r requirements.txt
    
  4. Set up environment variables:

    # Copy the example environment file
    cp .env.example .env
    
    # Edit .env and add your Together AI API key (optional)
    # TOGETHER_AI_API_KEY=your_api_key_here
    
  5. Run the server:

    python run.py
    
  6. Access the application:

    • Open your browser and navigate to: http://localhost:5000
    • The frontend interface will load automatically

Getting Together AI API Key (Optional)

  1. Visit Together AI and sign up
  2. Navigate to your dashboard and generate an API key or (https://api.together.ai/settings/api-keys)
  3. create key and copy it
  4. Add the key to your .env file:
    TOGETHER_AI_API_KEY=your_actual_api_key_here
    

πŸ”§ MCP Tools Available

The server implements these MCP tools:

ToolDescriptionParameters
create_fileCreate a new filefilename, content
edit_fileEdit file (manual or AI)filename, content/prompt, use_ai
delete_fileDelete a filefilename
read_fileRead file contentfilename

πŸ§ͺ Testing & Verification

Automated Tests

Run the comprehensive MCP protocol test suite:

python test_mcp.py

This test verifies:

  • βœ… MCP server startup and initialization
  • βœ… Tool discovery and registration (5 tools)
  • βœ… File creation, reading, editing, and deletion
  • βœ… AI-powered editing functionality
  • βœ… JSON-RPC 2.0 protocol compliance
  • βœ… Error handling and edge cases

Manual Testing

  1. Upload Test: Upload various file types and folder structures
  2. Edit Test: Use AI prompts to modify files
  3. Download Test: Test individual and bulk downloads
  4. UI Test: Verify notifications, responsive design, and user flow

Expected Test Output

πŸ”¬ MCP Filesystem Server Test Suite
πŸ§ͺ Testing MCP Filesystem Server...
==================================================
1. Starting MCP server... βœ…
2. Testing tool discovery... βœ… Found 5 tools
3. Testing file creation... βœ…
4. Testing file reading... βœ…
5. Testing file listing... βœ…
6. Testing manual file editing... βœ…
7. Testing AI-powered editing... βœ…
8. Testing file deletion... βœ…
9. Verifying file deletion... βœ…
==================================================
πŸŽ‰ All MCP tests passed successfully!

οΏ½ How to Use

1. Upload Files

  • Folder Upload: Click "Click to select folder" to upload entire directory structures
  • Individual Files: Use "Click to select individual files" for specific files
  • Drag & Drop: Simply drag files or folders onto the upload areas

2. File Management

  • Browse Files: View all uploaded files in the file browser
  • File Count: See total number of files in the header
  • Delete Files: Remove individual files or delete all files at once

3. Edit Files with AI

  • Click "Edit" on any file to open the editor
  • Enter a natural language prompt describing your desired changes:
    • "Add comments to this code"
    • "Fix any syntax errors"
    • "Convert this to TypeScript"
    • "Optimize this function for performance"
  • Click "Apply AI Edit" and watch the AI modify your file
  • Review and save the changes

4. Manual File Editing

  • Open any file in the editor
  • Modify content directly in the text area
  • Click "Save" to apply changes

5. Download Files

  • Individual Files: Click the download icon (πŸ“₯) next to any file
  • Bulk Download: Use "πŸ“¦ Download All as ZIP" to get all files in a ZIP archive
  • Current File: Download the currently open file from the editor

🎨 Features Showcase

File Operations

  • Smart Upload: Handles both folders and individual files
  • File Type Support: Text files, code files, configuration files, and more
  • Size Validation: Configurable file size limits (default: 10MB)
  • Progress Feedback: Real-time upload and operation status

AI Integration

  • Natural Language Editing: Describe changes in plain English
  • Mixtral Model: Powered by Mixtral-8x7B-Instruct for high-quality results
  • Context Aware: AI understands file types and provides appropriate modifications

Supported File Types

The application supports text-based files including:

CategoryExtensions
Code Files.py, .js, .ts, .html, .css, .java, .cpp, .c, .h, .php, .rb, .go, .rs
Data Files.txt, .md, .csv, .json, .xml, .yaml, .yml, .toml
Config Files.ini, .cfg, .conf, .env, .gitignore, .dockerignore
Scripts.sh, .bat, .ps1, .fish, .zsh
Documentation.rst, .tex, .wiki
Logs.log, .out, .err

Configuration Limits

SettingDefaultDescription
File Size10MBMaximum individual file size
Upload LimitUnlimitedNo limit on number of files
AI Timeout30sMaximum time for AI operations
Session StorageLocalFiles stored in uploaded_files/

🀝 Contributing

We welcome contributions! Here's how to get started:

Development Setup

  1. Fork the repository
  2. Clone your fork: git clone https://github.com/Niketan77/mcp-filesystem-server.git
  3. Create a virtual environment: python -m venv venv
  4. Install dependencies: pip install -r requirements.txt
  5. Create a feature branch: git checkout -b feature-name

Making Changes

  1. Backend: Modify files in server/ directory
  2. Frontend: Update files in frontend/ directory
  3. Tests: Add tests for new features
  4. Documentation: Update README if needed

Pull Request Process

  1. Run tests: python test_mcp.py
  2. Commit changes: git commit -m "Add feature description"
  3. Push to fork: git push origin feature-name
  4. Create pull request with detailed description

Code Style

  • Follow PEP 8 for Python code
  • Use meaningful variable names
  • Add comments for complex logic
  • Maintain consistent indentation

⭐ If you find this project helpful, please consider giving it a star on GitHub!