AbhishekCbanaj/MCP-Filesystem-Server
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 Model Context Protocol server implementation designed for filesystem operations with a web-based frontend interface.
create_file
Create a new file with specified content
read_file
Read the contents of an existing file
edit_file
Edit an existing file by replacing its content
delete_file
Delete a file
list_files
List all files in a directory
create_directory
Create a new directory
MCP Filesystem Server
A Model Context Protocol (MCP) server implementation for filesystem operations with a web-based frontend interface.
Features
- MCP Server: Complete filesystem operations (create, read, edit, delete files and directories)
- MCP Client: JavaScript client to communicate with the server
- Web Frontend: Interactive interface for file management with drag-and-drop support
- Command Processing: Natural language commands for file operations
Project Structure
mcp-filesystem-server/
āāā src/
ā āāā server.js # MCP server implementation
ā āāā client.js # MCP client implementation
ā āāā frontend.html # Web interface
āāā package.json # Dependencies and scripts
āāā README.md # This file
āāā workspace/ # Default working directory (created automatically)
Prerequisites
- Node.js (v16 or higher)
- npm or yarn
Installation
-
Clone or create the project directory:
mkdir mcp-filesystem-server cd mcp-filesystem-server
-
Initialize the project:
npm init -y
-
Install dependencies:
npm install @modelcontextprotocol/sdk npm install --save-dev nodemon
-
Create the project structure:
mkdir src mkdir workspace
-
Copy the provided files:
- Copy
server.js
tosrc/server.js
- Copy
client.js
tosrc/client.js
- Copy
frontend.html
tosrc/frontend.html
- Update
package.json
with the provided configuration
- Copy
Usage
Running the MCP Server
# Start the server
npm start
# Or for development with auto-reload
npm run dev
Using the Web Interface
- Open
src/frontend.html
in a web browser - The interface will automatically simulate connection to the MCP server
- Upload a folder using drag-and-drop or the file picker
- Use the command prompt to perform operations
Available Commands
create file filename.txt with content Hello World!
read file filename.txt
edit file filename.txt with content Updated content
delete file filename.txt
list files
MCP Client Usage (Programmatic)
import { FilesystemMCPClient } from './src/client.js';
const client = new FilesystemMCPClient();
await client.connect();
// Create a file
await client.createFile('./workspace/test.txt', 'Hello World!');
// Read a file
const result = await client.readFile('./workspace/test.txt');
console.log(result);
// Process natural language commands
const response = await client.processPrompt('create file hello.txt with content Hello MCP!');
MCP Server Tools
The server implements the following MCP tools:
- create_file: Create a new file with specified content
- read_file: Read the contents of an existing file
- edit_file: Edit an existing file by replacing its content
- delete_file: Delete a file
- list_files: List all files in a directory
- create_directory: Create a new directory
API Reference
Server Endpoints
All tools follow the MCP protocol specification:
{
"method": "tools/call",
"params": {
"name": "create_file",
"arguments": {
"filepath": "path/to/file.txt",
"content": "File content here"
}
}
}
Error Handling
The server includes comprehensive error handling for:
- File not found errors
- Permission errors
- Invalid file paths
- Network connectivity issues
Development
Adding New Tools
To add a new tool to the MCP server:
- Add the tool definition in
ListToolsRequestSchema
handler - Implement the tool logic in
CallToolRequestSchema
handler - Add corresponding client method in
FilesystemMCPClient
Extending the Frontend
The frontend is built with vanilla HTML/CSS/JavaScript and can be extended with:
- Additional command types
- File preview capabilities
- Syntax highlighting
- Real-time collaboration features
Security Considerations
- The server operates within the specified working directory only
- File paths are validated to prevent directory traversal attacks
- No network file access is permitted
- All operations are logged for audit purposes
Troubleshooting
Common Issues
- Connection Failed: Ensure the MCP server is running before starting the client
- File Permission Errors: Check that the workspace directory has proper read/write permissions
- Port Conflicts: The server uses stdio transport, so no port conflicts should occur
Debug Mode
Enable debug logging by setting the environment variable:
DEBUG=mcp:* npm start
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
License
MIT License - see LICENSE file for details
Assignment Submission Notes
This project demonstrates:
- Complete MCP Server Implementation: All required filesystem operations
- MCP Client Integration: Proper SDK usage and connection handling
- Frontend Interface: Interactive web application with file upload and command processing
- Error Handling: Comprehensive error management throughout the stack
- Documentation: Complete setup and usage instructions
Demo Commands for Testing
create file demo.txt with content This is a demo file
read file demo.txt
edit file demo.txt with content This file has been updated
list files
delete file demo.txt
The implementation showcases understanding of the MCP protocol, client-server architecture, and modern web development practices.