mishramohit437/file-system-mcp-server
If you are the rightful owner of file-system-mcp-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.
A Model Context Protocol (MCP) server that provides secure filesystem operations for AI assistants.
read_file
Read the contents of a file.
write_file
Write content to a file, overwriting if it exists.
move_file
Move or rename a file or directory.
create_directory
Create a new directory recursively.
list_directory
List contents of a directory.
get_file_info
Get file or directory metadata.
list_allowed_directories
List all directories the server is allowed to access.
Filesystem MCP Server
A Model Context Protocol (MCP) server that provides secure filesystem operations for AI assistants.
Features
- Read files: Read the contents of text files
- Write files: Create or overwrite files with new content
- List directories: Browse directory contents
- Create directories: Make new directories (with recursive creation)
- Delete files: Remove files from the filesystem
- Rename/move files: Rename files or move them to different locations
- File statistics: Get detailed file/directory metadata
- Path security: Restricts access to explicitly allowed paths only
Installation
- Clone or create the project:
mkdir filesystem-mcp-server
cd filesystem-mcp-server
- Install dependencies:
npm install
- Build the project:
npm run build
Usage
Running the Server
The server requires you to specify allowed paths as command line arguments:
node dist/index.js /path/to/allowed/directory1 /path/to/allowed/directory2
Example:
node dist/index.js /home/user/documents /home/user/projects /tmp
Configuration
To use this server with an MCP client, add it to your client's configuration:
{
"mcpServers": {
"filesystem": {
"command": "node",
"args": [
"/Users/mohitmishra/Desktop/mcp-for-file-system/dist/index.js",
"/home/user/documents",
"/home/user/projects"
]
}
}
}
Available Tools
-
read_file
- Read the contents of a file
- Parameters:
path
(string),head
(number, optional),tail
(number, optional)
-
write_file
- Write content to a file (overwrites if exists)
- Parameters:
path
(string),content
(string)
-
move_file
- Move or rename a file or directory
- Parameters:
source
(string),destination
(string)
-
create_directory
- Create a new directory (recursive)
- Parameters:
path
(string)
-
list_directory
- List contents of a directory
- Parameters:
path
(string)
-
get_file_info
- Get file or directory metadata
- Parameters:
path
(string)
-
list_allowed_directories
- List all directories the server is allowed to access
- No parameters
Security
This server implements path-based security:
- Only paths specified as command line arguments are accessible
- All file operations are restricted to these allowed paths
- Path traversal attempts are blocked
- Paths are resolved to absolute paths to prevent bypassing restrictions
Development
Running in Development Mode
npm run dev /path/to/test/directory
Building
npm run build
Testing
npm test
Error Handling
The server provides detailed error messages for common issues:
- Access Denied: When trying to access files outside allowed paths
- File Not Found: When specified files don't exist
- Permission Errors: When the process lacks necessary file permissions
- Invalid Parameters: When required parameters are missing or invalid
Example Usage
Once configured with an MCP client, you can use natural language to interact with the filesystem:
- "Read the contents of my config.json file"
- "Create a new directory called 'backups' in my documents folder"
- "List all files in the current project directory"
- "Write a TODO list to a new file called tasks.txt"
- "Rename config.json to config-backup.json"
- "Move report.pdf from downloads to documents folder"
Requirements
- Node.js 18.0.0 or higher
- TypeScript 5.0.0 or higher
- @modelcontextprotocol/sdk
License
MIT License - see LICENSE file for details.