MCP-Server-implementation

Priyankaa078/MCP-Server-implementation

3.2

If you are the rightful owner of MCP-Server-implementation 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 File System Server is a Model Context Protocol server designed to facilitate file system operations through a web-based interface, integrating AI assistance for natural language processing.

Tools
  1. create_file

    Creates a new file with specified content.

  2. read_file

    Reads the contents of an existing file.

  3. update_file

    Updates an existing file with new content.

  4. delete_file

    Deletes a file from the filesystem.

  5. list_files

    Lists files and directories in a specified directory.

MCP File System Server

A Model Context Protocol (MCP) server that provides file system operations with a simple web-based frontend.

Features

  • File Operations: Create, read, update, delete files
  • Directory Operations: List directory contents
  • Web Interface: Simple frontend for file management
  • AI Assistant: Natural language processing for file operations
  • File Upload: Drag and drop file upload functionality

Installation

  1. Clone the repository
git clone <your-repo-url>
cd mcp-filesystem-server
  1. Install dependencies
npm install @modelcontextprotocol/sdk
  1. Make the server executable
chmod +x server.js

Usage

Running the MCP Server

node server.js

The server will run on stdio and can be integrated with MCP-compatible clients.

Using the Web Interface

  1. Open index.html in your web browser
  2. Select the operation you want to perform
  3. Fill in the required fields
  4. Click "Execute Operation"

Available Operations

  • Create File: Create a new file with specified content
  • Read File: Read the contents of an existing file
  • Update File: Modify the contents of an existing file
  • Delete File: Remove a file from the filesystem
  • List Files: List all files in a directory

API Reference

Tools

create_file

Creates a new file with specified content.

Parameters:

  • filepath (string): Path where the file should be created
  • content (string): Content to write to the file
read_file

Reads the contents of an existing file.

Parameters:

  • filepath (string): Path to the file to read
update_file

Updates/edits an existing file with new content.

Parameters:

  • filepath (string): Path to the file to update
  • content (string): New content for the file
delete_file

Deletes a file from the filesystem.

Parameters:

  • filepath (string): Path to the file to delete
list_files

Lists files and directories in a specified directory.

Parameters:

  • dirpath (string): Path to the directory to list

Web Interface Features

File Operations Panel

  • Operation Selection: Dropdown to choose between create, read, update, delete, and list operations
  • Dynamic Fields: Form fields change based on selected operation
  • Execute Button: Runs the selected operation with provided parameters

File Upload & AI Assistant Panel

  • Drag & Drop Upload: Drop files directly onto the upload area
  • File Browser: Click to browse and select files
  • AI Prompt Input: Natural language interface for file operations
  • Process with AI: Interprets natural language requests and suggests operations

Output Panel

  • Real-time Results: Shows operation results and error messages
  • Formatted Output: Displays file contents and operation status
  • Clear Function: Button to clear the output area

Configuration

The server is configured with the following capabilities:

{
  name: 'filesystem-mcp-server',
  version: '0.1.0',
  capabilities: {
    tools: {}
  }
}

Error Handling

The server implements comprehensive error handling:

  • File System Errors: Catches and reports file access issues
  • Path Validation: Ensures directory structure exists before file creation
  • MCP Error Codes: Uses standard MCP error codes for consistent error reporting
  • Graceful Shutdown: Handles SIGINT for clean server shutdown

Dependencies

  • @modelcontextprotocol/sdk: MCP SDK for server implementation
  • fs/promises: Node.js file system operations
  • path: Path manipulation utilities

Security Considerations

  • Path Traversal: Be cautious with file paths to prevent directory traversal attacks
  • File Permissions: Ensure the server has appropriate permissions for file operations
  • Input Validation: Validate file paths and content before processing
  • Access Control: Consider implementing access controls for sensitive directories

Development

Running in Development Mode

node server.js

Testing with the Web Interface

  1. Start the MCP server in one terminal
  2. Open index.html in a web browser
  3. Test various file operations through the interface

Extending Functionality

To add new file operations:

  1. Add the tool definition in setupToolHandlers()
  2. Implement the handler method
  3. Add the case in the switch statement
  4. Update the web interface if needed

Troubleshooting

Common Issues

Server won't start:

  • Check that Node.js is installed
  • Verify MCP SDK is installed: npm list @modelcontextprotocol/sdk

File operations fail:

  • Check file system permissions
  • Verify file paths are correct
  • Ensure target directories exist

Web interface not connecting:

  • The web interface uses a simulated MCP client for demo purposes
  • For real MCP integration, connect through an MCP-compatible client