This MCP server implements the Model Context Protocol for filesystem operations, allowing you to perform various file system tasks through a standardized API. It provides secure access to files and directories by restricting operations to explicitly allowed locations.
You can run the Filesystem MCP Server using either Docker or NPX. Choose the method that works best for your environment.
docker run -i --rm \
--mount type=bind,src=/Users/username/Desktop,dst=/projects/Desktop \
--mount type=bind,src=/path/to/other/allowed/dir,dst=/projects/other/allowed/dir,ro \
--mount type=bind,src=/path/to/file.txt,dst=/projects/path/to/file.txt \
mcp/filesystem /projects
Note: All directories must be mounted to /projects
by default. The ro
flag makes a directory read-only.
Install and run directly using NPX:
npx -y @modelcontextprotocol/server-filesystem \
/Users/username/Desktop \
/path/to/other/allowed/dir
To use this server with Claude Desktop, add the MCP server configuration to your claude_desktop_config.json
file:
{
"mcpServers": {
"filesystem": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"--mount", "type=bind,src=/Users/username/Desktop,dst=/projects/Desktop",
"--mount", "type=bind,src=/path/to/other/allowed/dir,dst=/projects/other/allowed/dir,ro",
"--mount", "type=bind,src=/path/to/file.txt,dst=/projects/path/to/file.txt",
"mcp/filesystem",
"/projects"
]
}
}
}
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"/Users/username/Desktop",
"/path/to/other/allowed/dir"
]
}
}
}
The Filesystem MCP Server provides the following tools for file operations:
// Read a file's contents
const fileContent = await resource.file.system.read_file({
path: "/projects/Desktop/example.txt"
});
// Create or overwrite a file
await resource.file.system.write_file({
path: "/projects/Desktop/new-file.txt",
content: "This is the content of the file."
});
// Edit a file with pattern matching
const editResult = await resource.file.system.edit_file({
path: "/projects/Desktop/config.json",
edits: [
{
oldText: '"debug": false',
newText: '"debug": true'
}
],
dryRun: true // Preview changes first
});
// Apply the changes after review
if (editResult.changes) {
await resource.file.system.edit_file({
path: "/projects/Desktop/config.json",
edits: [
{
oldText: '"debug": false',
newText: '"debug": true'
}
],
dryRun: false
});
}
// Create a directory
await resource.file.system.create_directory({
path: "/projects/Desktop/new-folder"
});
// List directory contents
const contents = await resource.file.system.list_directory({
path: "/projects/Desktop"
});
// Search for files
const results = await resource.file.system.search_files({
path: "/projects/Desktop",
pattern: "*.json",
excludePatterns: ["node_modules", ".git"]
});
// Get file metadata
const fileInfo = await resource.file.system.get_file_info({
path: "/projects/Desktop/example.txt"
});
The server only allows operations within directories that are explicitly specified via the args
parameter in your configuration. For maximum security, only mount directories that you need the server to access.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.