madankumar2473/File_Manipulationby_MCPServer
If you are the rightful owner of File_Manipulationby_MCPServer 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 Model Context Protocol (MCP) server is a backend solution designed to facilitate secure and efficient file management operations through a structured protocol.
MCP Filesystem Web App
A full-stack web application that provides a modern interface for managing files using the Model Context Protocol (MCP). This application allows users to perform file operations through a React frontend, natural language commands, and a secure MCP backend.
๐ Features
- Modern Web Interface: React-based frontend with drag-and-drop file upload
- Natural Language Commands: Execute file operations using plain English
- Secure File Operations: Create, read, edit, delete, and list files
- Real-time Logging: Live operation logs and status monitoring
- File Explorer: Interactive file tree with visual file management
- RESTful API: HTTP bridge for frontend-backend communication
- TypeScript: Full type safety across the entire stack
๐ Prerequisites
Before you begin, ensure you have the following installed:
- Node.js (v18 or higher)
- npm (v8 or higher)
- Git (for cloning the repository)
๐๏ธ Project Structure
mcp-filesystem/
โโโ client/ # MCP Client SDK
โ โโโ src/
โ โ โโโ client.ts # Type-safe MCP client
โ โ โโโ utils/
โ โ โโโ PromptParser.ts
โ โโโ package.json
โโโ frontend/ # React Frontend
โ โโโ src/
โ โ โโโ components/ # React components
โ โ โโโ utils/ # Utility functions
โ โ โโโ clientHttp.ts # HTTP client for API calls
โ โ โโโ main.tsx # Main React app
โ โโโ index.html
โ โโโ package.json
โโโ server/ # MCP Backend Server
โ โโโ src/
โ โ โโโ server.ts # MCP server implementation
โ โ โโโ httpBridge.ts # HTTP bridge for frontend
โ โ โโโ main.tsx # Server entry point
โ โโโ package.json
โโโ workspace/ # File storage directory
๐ ๏ธ Installation & Setup
Step 1: Clone the Repository
git clone <repository-url>
cd mcp-filesystem
Step 2: Install Dependencies
Install dependencies for all three components:
# Install client dependencies
cd client
npm install
# Install frontend dependencies
cd ../frontend
npm install
# Install server dependencies
cd ../server
npm install
Step 3: Create Workspace Directory
# From the project root
mkdir workspace
๐ Running the Application
Step 1: Start the Backend Server
cd server
npm run http
This starts the HTTP bridge server on http://localhost:3001
with the following endpoints:
GET /health
- Health checkPOST /api/files
- Create filePUT /api/files
- Edit fileDELETE /api/files
- Delete fileGET /api/files
- Read fileGET /api/files/list
- List files
Step 2: Start the Frontend
cd frontend
npm run dev
This starts the React development server on http://localhost:5173
.
Step 3: Access the Application
Open your browser and navigate to http://localhost:5173
to access the MCP Filesystem Web App.
๐ Usage Guide
File Upload
- Drag and Drop: Drag files or folders directly onto the upload area
- Click to Select: Click the upload area to open a file picker
- Multiple Files: Select multiple files at once
- Real-time Feedback: See upload progress and status
Natural Language Commands
Use the command input box to perform file operations using natural language:
Create Files
create test.txt
create config.json with content '{"key": "value"}'
make a new file called readme.md
new file called data.csv
Edit Files
edit test.txt
edit config.json with content '{"updated": "content"}'
modify readme.md
update data.csv
Delete Files
delete old.txt
remove temp.json
erase backup.log
Read Files
read config.json
show test.txt
display readme.md
List Files
list files
show all files
what files are in the directory
File Explorer
- Navigate: Click on folders to navigate into them
- Go Back: Use the ".." button to go back to parent directory
- File Actions: Use action buttons on files:
- ๐๏ธ Read file content
- โ๏ธ Edit file content
- ๐๏ธ Delete file
- ๐ Open directory (for folders)
- Refresh: Click the refresh button to update the file list
Status Monitoring
The right panel shows:
- Connection Status: Real-time connection to MCP server
- Operation Logs: Detailed logs of all file operations
- Error Messages: Clear error reporting
- Success Confirmations: Operation success notifications
๐ง Development
Project Architecture
Frontend (React + TypeScript)
- Components: Modular React components for each UI section
- State Management: React hooks for local state
- HTTP Client: Custom client for API communication
- Styling: CSS modules with responsive design
Backend (Node.js + TypeScript)
- MCP Server: Implements Model Context Protocol
- HTTP Bridge: Express server for frontend communication
- File Operations: Secure file system operations
- Validation: Path and file extension validation
Client SDK (TypeScript)
- Type-safe API: Full TypeScript support
- Error Handling: Comprehensive error management
- Retry Logic: Automatic retry for failed operations
Key Components
FileUploader Component
- Handles drag-and-drop file uploads
- Supports multiple file selection
- Provides visual feedback during upload
PromptBox Component
- Natural language command input
- Real-time command parsing
- Command execution feedback
FileTree Component
- Interactive file explorer
- File operation buttons
- Directory navigation
StatusBar Component
- Connection status monitoring
- Operation log display
- Error reporting
API Endpoints
File Operations
// Create file
POST /api/files
{
"path": "filename.txt",
"content": "file content",
"description": "optional description"
}
// Edit file
PUT /api/files
{
"path": "filename.txt",
"content": "new content",
"description": "optional description"
}
// Delete file
DELETE /api/files
{
"path": "filename.txt",
"description": "optional description"
}
// Read file
GET /api/files?path=filename.txt
// List files
GET /api/files/list?path=.
๐ Security Features
Path Validation
- Prevents path traversal attacks (
../
) - Restricts operations to workspace directory
- Validates file extensions
File Extension Whitelist
Allowed file extensions:
- Text files:
.txt
,.md
,.json
,.log
- Code files:
.js
,.ts
,.jsx
,.tsx
,.html
,.css
- Data files:
.csv
,.xml
,.yaml
,.yml
- Scripts:
.sh
,.bat
,.ps1
- Configuration:
.ini
,.cfg
,.conf
Error Handling
- Comprehensive error catching
- User-friendly error messages
- Detailed logging for debugging
๐งช Testing
Manual Testing
- File Upload: Test drag-and-drop and file picker
- Natural Language: Test various command patterns
- File Operations: Test create, read, edit, delete
- Navigation: Test directory navigation
- Error Handling: Test invalid commands and operations
API Testing
# Test health endpoint
curl http://localhost:3001/health
# Test file creation
curl -X POST http://localhost:3001/api/files \
-H "Content-Type: application/json" \
-d '{"path":"test.txt","content":"Hello World"}'
# Test file listing
curl http://localhost:3001/api/files/list
๐ Troubleshooting
Common Issues
Frontend Not Loading
- Check if frontend server is running on port 5173
- Verify all dependencies are installed
- Check browser console for errors
Backend Connection Failed
- Ensure backend server is running on port 3001
- Check if workspace directory exists
- Verify server logs for errors
File Operations Not Working
- Check file permissions in workspace directory
- Verify file extension is allowed
- Check server logs for validation errors
Natural Language Commands Not Working
- Check browser console for parsing errors
- Verify command syntax matches supported patterns
- Check network tab for API call failures
Debug Mode
Enable debug logging by checking the browser console for detailed information about:
- Command parsing
- API calls
- File operations
- Error details
๐ Configuration
Environment Variables
Create a .env
file in the server directory:
# Server Configuration
PORT=3001
WORKSPACE_PATH=../workspace
# Security
ALLOWED_EXTENSIONS=txt,md,json,js,ts,html,css
MAX_FILE_SIZE=10485760
Customization
Adding File Extensions
Edit server/src/server.ts
:
private allowedExtensions: Set<string> = new Set([
'txt', 'md', 'json', 'js', 'ts', 'jsx', 'tsx',
// Add your extensions here
]);
Changing Ports
Edit the respective package.json
files or use environment variables.
๐ค Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- Model Context Protocol (MCP) for the underlying protocol
- React team for the frontend framework
- Node.js community for the backend runtime
- TypeScript team for type safety
๐ Support
For issues and questions:
- Check the troubleshooting section
- Review the logs and console output
- Create an issue in the repository
- Contact the development team
Happy File Management! ๐