mcp file operations server
A Model Context Protocol server that enables enhanced file system operations including reading, writing, copying, moving files with streaming capabilities, directory management, file watching, and change tracking.
A Model Context Protocol server that enables enhanced file system operations including reading, writing, copying, moving files with streaming capabilities, directory management, file watching, and change tracking.
A Model Context Protocol (MCP) server that provides enhanced file operation capabilities with streaming, patching, and change tracking support.
To install File Operations Server for Claude Desktop automatically via Smithery:
npx -y @smithery/cli install @bsmi021/mcp-file-operations-server --client claude
npm install
npm start
For development with auto-reloading:
npm run dev
copy_file
: Copy a file to a new locationread_file
: Read content from a filewrite_file
: Write content to a filemove_file
: Move/rename a filedelete_file
: Delete a fileappend_file
: Append content to a filemake_directory
: Create a directoryremove_directory
: Remove a directorycopy_directory
: Copy a directory recursively (with progress reporting)watch_directory
: Start watching a directory for changesunwatch_directory
: Stop watching a directoryget_changes
: Get the list of recorded changesclear_changes
: Clear all recorded changesfile:///recent-changes
: List of recent file system changesfile://{path}
: Access file contentsmetadata://{path}
: Access file metadatadirectory://{path}
: List directory contents// Copy a file
await fileOperations.copyFile({
source: 'source.txt',
destination: 'destination.txt',
overwrite: false
});
// Watch a directory
await fileOperations.watchDirectory({
path: './watched-dir',
recursive: true
});
// Access file contents through resource
const resource = await mcp.readResource('file:///path/to/file.txt');
console.log(resource.contents[0].text);
// Copy directory with progress tracking
const result = await fileOperations.copyDirectory({
source: './source-dir',
destination: './dest-dir',
overwrite: false
});
// Progress token in result can be used to track progress
console.log(result.progressToken);
The server implements rate limiting to prevent abuse:
Rate limit errors include a retry-after period in the error message.
All file paths are validated to prevent directory traversal attacks:
../
)Long-running operations like directory copying provide progress updates:
interface ProgressUpdate {
token: string | number;
message: string;
percentage: number;
}
Progress can be tracked through the progress token returned in the operation result.
npm run build
npm run lint
npm run format
npm test
The server can be configured through various settings:
The server provides detailed error information through the FileOperationError
class and MCP error codes:
InvalidRequest
: Invalid parameters or request formatMethodNotFound
: Unknown tool or resource requestedInvalidParams
: Invalid parameters (e.g., path validation failure)InternalError
: Server-side errorsEach error includes:
git checkout -b feature/amazing-feature
)git commit -m 'Add amazing feature'
)git push origin feature/amazing-feature
)This project is licensed under the MIT License - see the LICENSE file for details.
[
{
"description": "Copy a file to a new location",
"inputSchema": {
"properties": {
"destination": {
"description": "Destination file path",
"type": "string"
},
"overwrite": {
"default": false,
"description": "Whether to overwrite existing file",
"type": "boolean"
},
"source": {
"description": "Source file path",
"type": "string"
}
},
"required": [
"source",
"destination"
],
"type": "object"
},
"name": "copy_file"
},
{
"description": "Read the contents of a file",
"inputSchema": {
"properties": {
"encoding": {
"default": "utf8",
"description": "File encoding (default: utf8)",
"type": "string"
},
"path": {
"description": "Path to the file to read",
"type": "string"
}
},
"required": [
"path"
],
"type": "object"
},
"name": "read_file"
},
{
"description": "Write content to a file",
"inputSchema": {
"properties": {
"content": {
"description": "Content to write to the file",
"type": "string"
},
"encoding": {
"default": "utf8",
"description": "File encoding (default: utf8)",
"type": "string"
},
"path": {
"description": "Path to write the file to",
"type": "string"
}
},
"required": [
"path",
"content"
],
"type": "object"
},
"name": "write_file"
},
{
"description": "Create a new directory",
"inputSchema": {
"properties": {
"path": {
"description": "Path to create the directory at",
"type": "string"
},
"recursive": {
"default": true,
"description": "Create parent directories if they Do not exist",
"type": "boolean"
}
},
"required": [
"path"
],
"type": "object"
},
"name": "make_directory"
},
{
"description": "Remove a directory",
"inputSchema": {
"properties": {
"path": {
"description": "Path to the directory to remove",
"type": "string"
},
"recursive": {
"default": false,
"description": "Remove directory contents recursively",
"type": "boolean"
}
},
"required": [
"path"
],
"type": "object"
},
"name": "remove_directory"
},
{
"description": "List contents of a directory with detailed metadata",
"inputSchema": {
"properties": {
"path": {
"description": "Path of directory to list",
"type": "string"
},
"recursive": {
"default": false,
"description": "Whether to list contents recursively",
"type": "boolean"
}
},
"required": [
"path"
],
"type": "object"
},
"name": "list_directory"
},
{
"description": "Copy a directory and its contents to a new location",
"inputSchema": {
"properties": {
"destination": {
"description": "Destination directory path",
"type": "string"
},
"overwrite": {
"default": false,
"description": "Whether to overwrite existing files/directories",
"type": "boolean"
},
"source": {
"description": "Source directory path",
"type": "string"
}
},
"required": [
"source",
"destination"
],
"type": "object"
},
"name": "copy_directory"
},
{
"description": "Watch a directory for changes",
"inputSchema": {
"properties": {
"path": {
"description": "Path to the directory to watch",
"type": "string"
},
"recursive": {
"default": false,
"description": "Watch subdirectories recursively",
"type": "boolean"
}
},
"required": [
"path"
],
"type": "object"
},
"name": "watch_directory"
},
{
"description": "Stop watching a directory",
"inputSchema": {
"properties": {
"path": {
"description": "Path to the directory to stop watching",
"type": "string"
}
},
"required": [
"path"
],
"type": "object"
},
"name": "unwatch_directory"
},
{
"description": "Check if a path is currently being watched",
"inputSchema": {
"properties": {
"path": {
"description": "Path to check",
"type": "string"
}
},
"required": [
"path"
],
"type": "object"
},
"name": "is_watching"
},
{
"description": "Get list of tracked changes",
"inputSchema": {
"properties": {
"limit": {
"description": "Maximum number of changes to return",
"type": "number"
},
"type": {
"description": "Filter changes by type",
"type": "string"
}
},
"type": "object"
},
"name": "get_changes"
},
{
"description": "Clear all tracked changes",
"inputSchema": {
"properties": {},
"type": "object"
},
"name": "clear_changes"
}
]