The Filesystem MCP Server provides a secure interface for AI agents to interact with the local filesystem through the Model Context Protocol (MCP). It supports both STDIO and HTTP transport options, allowing AI agents to read, write, manage files and directories, and perform targeted file updates with robust security measures.
To get started with the Filesystem MCP Server:
Clone the repository:
git clone https://github.com/cyanheads/filesystem-mcp-server.git
cd filesystem-mcp-server
Install dependencies:
npm install
Build the project:
npm run build
The server can be configured using environment variables (you can use a .env
file):
MCP_LOG_LEVEL
(Optional): Set logging level (debug
, info
, warn
, error
). Default: debug
LOGS_DIR
(Optional): Directory for log files. Default: ./logs
NODE_ENV
(Optional): Runtime environment. Default: development
MCP_TRANSPORT_TYPE
(Optional): Choose stdio
or http
. Default: stdio
MCP_HTTP_PORT
(Optional): HTTP server port. Default: 3010
MCP_HTTP_HOST
(Optional): HTTP server host. Default: 127.0.0.1
MCP_ALLOWED_ORIGINS
(Optional): Comma-separated CORS originsMCP_AUTH_SECRET_KEY
(Required for HTTP): JWT authentication secret key (32+ characters)FS_BASE_DIRECTORY
(Optional but recommended): Root directory for all filesystem operations, restricting access to only this directory and its subdirectoriesStart the server from your terminal:
node dist/index.js
# Or from project root:
npm start
Configure your MCP client with:
node
/path/to/filesystem-mcp-server/dist/index.js
)Example configuration:
{
"mcpServers": {
"filesystem_stdio": {
"command": "node",
"args": ["/path/to/filesystem-mcp-server/dist/index.js"],
"env": {
"MCP_LOG_LEVEL": "debug"
},
"disabled": false,
"autoApprove": []
}
}
}
Configure your client with the server URL (e.g., http://localhost:3010
) and authentication method (JWT Bearer token if using MCP_AUTH_SECRET_KEY
).
The server provides these filesystem interaction tools:
set_filesystem_default
: Sets a default path for the session, making relative paths work from this locationread_file
: Reads the content of a file as UTF-8 textwrite_file
: Creates or overwrites a file with specified contentupdate_file
: Performs targeted search-and-replace operations within filesdelete_file
: Permanently removes a specific filelist_files
: Lists files and directories, optionally recursivelycreate_directory
: Creates a new directory (with parent directories if needed)delete_directory
: Removes a directory (with recursive option)move_path
: Moves or renames files or directoriescopy_path
: Copies files or directories (recursively by default)Each tool accepts both absolute paths and relative paths (resolved against the default path if set).
The server includes several security measures:
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "filesystem" '{"command":"node","args":["/path/to/filesystem-mcp-server/dist/index.js"],"env":{"MCP_LOG_LEVEL":"debug"},"disabled":false,"autoApprove":[]}'
See the official Claude Code MCP documentation for more details.
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 > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"filesystem": {
"command": "node",
"args": [
"/path/to/filesystem-mcp-server/dist/index.js"
],
"env": {
"MCP_LOG_LEVEL": "debug"
},
"disabled": false,
"autoApprove": []
}
}
}
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 explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"filesystem": {
"command": "node",
"args": [
"/path/to/filesystem-mcp-server/dist/index.js"
],
"env": {
"MCP_LOG_LEVEL": "debug"
},
"disabled": false,
"autoApprove": []
}
}
}
3. Restart Claude Desktop for the changes to take effect