Aakash231217/MCP_Server_assignment
If you are the rightful owner of MCP_Server_assignment 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.
A comprehensive MCP (Model Context Protocol) server implementation for managing filesystem operations with a modern web interface.
create_file
Create a new file
edit_file
Edit existing file
delete_file
Delete file or directory
read_file
Read file contents
list_files
List directory contents
create_directory
Create directory
MCP Filesystem Operations
A complete MCP (Model Context Protocol) implementation for filesystem operations with a modern web interface.
Features
- MCP Server: Supports create, edit, delete, read files and directories
- MCP Client: Interactive command-line interface
- Web Frontend: Modern React/Next.js interface with drag-and-drop folder upload
- REST API: Bridge between frontend and MCP server
- Natural Language Processing: Parse user prompts into filesystem operations
Architecture
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Frontend ββββββΆβ REST API ββββββΆβ MCP Server β
β (Next.js) β β (Express) β β (Node.js) β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β β
β β βΌ
β β βββββββββββββββββββ
β β β File System β
β β β Operations β
ββββββββββββββββββββββββββΌββββββββββββββββ΄ββββββββββββββββββ
β
βΌ
βββββββββββββββββββ
β MCP Client β
β (CLI) β
βββββββββββββββββββ
Quick Start
1. Install Dependencies
# Install main dependencies
npm install
# Install frontend dependencies
cd frontend
npm install
cd ..
2. Start the MCP Server
npm start
3. Run the Web Interface
# Terminal 1: Start the API server
node api/server.js
# Terminal 2: Start the frontend
cd frontend
npm run dev
4. Try the CLI Client
npm run client
Usage Examples
Web Interface
- Upload Folder: Drag and drop a folder to upload all files
- Use Natural Language: Type commands like:
- "Create file 'hello.txt' with 'Hello World'"
- "Edit file 'package.json' with 'updated content'"
- "Delete 'old-file.txt'"
- "Read 'README.md'"
CLI Client
π > create_file hello.txt "Hello World"
β
File created successfully: hello.txt
π > read_file hello.txt
β
Hello World
π > edit_file hello.txt "Hello MCP World!" replace
β
File edited successfully: hello.txt
π > list_files .
β
[
{
"name": "hello.txt",
"type": "file",
"size": 17,
"modified": "2024-01-15T10:30:00.000Z"
}
]
π > delete_file hello.txt
β
Deleted successfully: hello.txt
REST API
# Execute MCP operations
curl -X POST http://localhost:3002/api/execute \
-H "Content-Type: application/json" \
-d '{"operation": "create_file", "args": {"path": "test.txt", "content": "Hello"}}'
# Use natural language prompts
curl -X POST http://localhost:3002/api/prompt \
-H "Content-Type: application/json" \
-d '{"prompt": "Create file '\''hello.txt'\'' with '\''Hello World'\''"}'
# List files
curl http://localhost:3002/api/files?path=.
# Read file
curl http://localhost:3002/api/file/hello.txt
MCP Tools Available
Tool | Description | Parameters |
---|---|---|
create_file | Create a new file | path , content |
edit_file | Edit existing file | path , content , mode (replace/append) |
delete_file | Delete file or directory | path |
read_file | Read file contents | path |
list_files | List directory contents | path (optional) |
create_directory | Create directory | path |
Security Features
- Path Validation: Prevents directory traversal attacks
- Working Directory Restriction: Operations limited to designated folder
- File Type Validation: Configurable file type restrictions
- Size Limits: Configurable file size limits
Development
Project Structure
mcp-filesystem/
βββ server/
β βββ index.js # MCP Server implementation
βββ client/
β βββ index.js # CLI client
βββ api/
β βββ server.js # REST API server
βββ frontend/
β βββ app/
β β βββ page.tsx # Main React component
β β βββ layout.tsx # Layout component
β β βββ globals.css # Global styles
β βββ package.json # Frontend dependencies
β βββ next.config.js # Next.js configuration
βββ package.json # Main package.json
βββ README.md # This file
Adding New Tools
- Add tool definition in
server/index.js
:
{
name: "my_new_tool",
description: "Description of the tool",
inputSchema: {
type: "object",
properties: {
param1: { type: "string", description: "Parameter description" }
},
required: ["param1"]
}
}
- Implement tool handler:
case "my_new_tool":
return await this.myNewTool(args.param1);
- Add method implementation:
async myNewTool(param1) {
// Implementation here
return {
content: [{ type: "text", text: "Result message" }]
};
}
Deployment
Docker
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000 3001 3002
CMD ["npm", "start"]
Environment Variables
# API Server
PORT=3002
MCP_SERVER_PATH=../server/index.js
# Frontend
NEXT_PUBLIC_API_URL=http://localhost:3002
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
License
MIT License - see LICENSE file for details
Troubleshooting
Common Issues
-
MCP Server Connection Failed
- Ensure Node.js version >= 18
- Check if server/index.js is executable
- Verify dependencies are installed
-
File Upload Not Working
- Check folder permissions
- Ensure API server is running on port 3002
- Verify CORS settings
-
Frontend Build Errors
- Run
npm install
in frontend directory - Check TypeScript version compatibility
- Verify all dependencies are installed
- Run
Debug Mode
Enable debug logging:
DEBUG=mcp:* npm start
Support
For issues and questions:
- Create an issue on GitHub
- Check the troubleshooting section
- Review the API documentation
Built with β€οΈ using MCP (Model Context Protocol)