MCP_Server_assignment

Aakash231217/MCP_Server_assignment

3.2

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.

Tools
  1. create_file

    Create a new file

  2. edit_file

    Edit existing file

  3. delete_file

    Delete file or directory

  4. read_file

    Read file contents

  5. list_files

    List directory contents

  6. 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

  1. Upload Folder: Drag and drop a folder to upload all files
  2. 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

ToolDescriptionParameters
create_fileCreate a new filepath, content
edit_fileEdit existing filepath, content, mode (replace/append)
delete_fileDelete file or directorypath
read_fileRead file contentspath
list_filesList directory contentspath (optional)
create_directoryCreate directorypath

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

  1. 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"]
  }
}
  1. Implement tool handler:
case "my_new_tool":
  return await this.myNewTool(args.param1);
  1. 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

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

License

MIT License - see LICENSE file for details

Troubleshooting

Common Issues

  1. MCP Server Connection Failed

    • Ensure Node.js version >= 18
    • Check if server/index.js is executable
    • Verify dependencies are installed
  2. File Upload Not Working

    • Check folder permissions
    • Ensure API server is running on port 3002
    • Verify CORS settings
  3. Frontend Build Errors

    • Run npm install in frontend directory
    • Check TypeScript version compatibility
    • Verify all dependencies are installed

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)