filesystem-mcp-server
Licensed under Apache License 2.0, allowing for open-source use and modification with appropriate attribution.
Provides tools for interacting with the local filesystem, enabling reading, writing, updating, and managing files and directories. Supports operations like targeted file updates, listing directory contents, and path management.
Links to the GitHub repository for accessing source code, contributing to the project, and tracking stars/popularity.
Utilizes Mermaid for flowchart visualization of the server's architecture, showing the relationships between different components.
Uses Shields.io badges to display project metadata including TypeScript version, MCP version, license, and project status.
Built with TypeScript for type safety and reliability, providing a production-ready foundation for filesystem operations with comprehensive type definitions.
Incorporates Zod for robust input validation, ensuring that all filesystem operations receive properly formatted parameters.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@filesystem-mcp-server read the contents of config.json in the current directory"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Filesystem MCP Server
Empower your AI agents with robust, platform-agnostic file system capabilities, now with STDIO & Streamable HTTP transport options.
This Model Context Protocol (MCP) server provides a secure and reliable interface for AI agents to interact with the local filesystem. It enables reading, writing, updating, and managing files and directories, backed by a production-ready TypeScript foundation featuring comprehensive logging, error handling, security measures, and now supporting both STDIO and HTTP transports.
Table of Contents
Related MCP server: MCP Filesystem Server
Overview
The Model Context Protocol (MCP) is a standard framework allowing AI models to securely interact with external tools and data sources (resources). This server implements the MCP standard to expose essential filesystem operations as tools, enabling AI agents to:
Read and analyze file contents.
Create, modify, or overwrite files.
Manage directories and file paths.
Perform targeted updates within files.
Built with TypeScript, the server emphasizes type safety, modularity, and robust error handling, making it suitable for reliable integration into AI workflows. It now supports both STDIO for direct process communication and HTTP for network-based interactions.
Architecture
The server employs a layered architecture for clarity and maintainability:
flowchart TB
subgraph TransportLayer["Transport Layer"]
direction LR
STDIO["STDIO Transport"]
HTTP["HTTP Transport (Express, JWT Auth)"]
end
subgraph APILayer["API Layer"]
direction LR
MCP["MCP Protocol Interface"]
Val["Input Validation (Zod)"]
PathSan["Path Sanitization"]
MCP --> Val --> PathSan
end
subgraph CoreServices["Core Services"]
direction LR
Config["Configuration (Zod-validated Env Vars)"]
Logger["Logging (Winston, Context-aware)"]
ErrorH["Error Handling (McpError, ErrorHandler)"]
ServerLogic["MCP Server Logic"]
State["Session State (Default Path)"]
Config --> ServerLogic
Logger --> ServerLogic & ErrorH
ErrorH --> ServerLogic
State --> ServerLogic
end
subgraph ToolImpl["Tool Implementation"]
direction LR
FSTools["Filesystem Tools"]
Utils["Core Utilities (Internal, Security, Metrics, Parsing)"]
FSTools --> ServerLogic
Utils -- Used by --> FSTools
Utils -- Used by --> CoreServices
Utils -- Used by --> APILayer
end
TransportLayer --> MCP
PathSan --> FSTools
classDef layer fill:#2d3748,stroke:#4299e1,stroke-width:3px,rx:5,color:#fff
classDef component fill:#1a202c,stroke:#a0aec0,stroke-width:2px,rx:3,color:#fff
class TransportLayer,APILayer,CoreServices,ToolImpl layer
class STDIO,HTTP,MCP,Val,PathSan,Config,Logger,ErrorH,ServerLogic,State,FSTools,Utils componentTransport Layer: Handles communication via STDIO or HTTP (with Express.js and JWT authentication).
API Layer: Manages MCP communication, validates inputs using Zod, and sanitizes paths.
Core Services: Oversees configuration (Zod-validated environment variables), context-aware logging, standardized error reporting, session state (like the default working directory), and the main MCP server instance.
Tool Implementation: Contains the specific logic for each filesystem tool, leveraging a refactored set of shared utilities categorized into internal, security, metrics, and parsing modules.
Features
Comprehensive File Operations: Tools for reading, writing, listing, deleting, moving, and copying files and directories.
Targeted Updates:
update_filetool allows precise search-and-replace operations within files, supporting plain text and regex.Session-Aware Path Management:
set_filesystem_defaulttool establishes a default working directory for resolving relative paths during a session.Dual Transport Support:
STDIO: For direct, efficient communication when run as a child process.
HTTP: For network-based interaction, featuring RESTful endpoints, Server-Sent Events (SSE) for streaming, and JWT-based authentication.
Security First:
Built-in path sanitization prevents directory traversal attacks.
JWT authentication for HTTP transport.
Input validation with Zod.
Robust Foundation: Includes production-grade utilities, now reorganized for better modularity:
Internal Utilities: Context-aware logging (Winston), standardized error handling (
McpError,ErrorHandler), request context management.Security Utilities: Input sanitization, rate limiting, UUID and prefixed ID generation.
Metrics Utilities: Token counting.
Parsing Utilities: Natural language date parsing, partial JSON parsing.
Enhanced Configuration: Zod-validated environment variables for type-safe and reliable setup.
Type Safety: Fully implemented in TypeScript for improved reliability and maintainability.
Installation
Steps
Clone the repository:
git clone https://github.com/cyanheads/filesystem-mcp-server.git cd filesystem-mcp-serverInstall dependencies:
npm installBuild the project:
npm run buildThis compiles the TypeScript code to JavaScript in the
dist/directory and makes the main script executable. The executable will be located atdist/index.js.
Configuration
Configure the server using environment variables (a .env file is supported):
Core Server Settings:
MCP_LOG_LEVEL(Optional): Minimum logging level (e.g.,debug,info,warn,error). Defaults todebug.LOGS_DIR(Optional): Directory for log files. Defaults to./logsin the project root.NODE_ENV(Optional): Runtime environment (e.g.,development,production). Defaults todevelopment.
Transport Settings:
MCP_TRANSPORT_TYPE(Optional): Communication transport (stdioorhttp). Defaults tostdio.If
httpis selected:MCP_HTTP_PORT(Optional): Port for the HTTP server. Defaults to3010.MCP_HTTP_HOST(Optional): Host for the HTTP server. Defaults to127.0.0.1.MCP_ALLOWED_ORIGINS(Optional): Comma-separated list of allowed CORS origins (e.g.,http://localhost:3000,https://example.com).MCP_AUTH_SECRET_KEY(Required for HTTP Auth): A secure secret key (at least 32 characters long) for JWT authentication. CRITICAL for production.
Filesystem Security:
FS_BASE_DIRECTORY(Optional): Defines the root directory for all filesystem operations. This can be an absolute path or a path relative to the project root (e.g.,./data_sandbox). If set, the server's tools will be restricted to accessing files and directories only within this specified (and resolved absolute) path and its subdirectories. This is a crucial security feature to prevent unintended access to other parts of the filesystem. If not set (which is not recommended for production environments), a warning will be logged, and operations will not be restricted.
LLM & API Integration (Optional):
OPENROUTER_APP_URL: Your application's URL for OpenRouter.OPENROUTER_APP_NAME: Your application's name for OpenRouter. Defaults toMCP_SERVER_NAME.OPENROUTER_API_KEY: API key for OpenRouter services.LLM_DEFAULT_MODEL: Default LLM model to use (e.g.,google/gemini-2.5-flash-preview-05-20).LLM_DEFAULT_TEMPERATURE,LLM_DEFAULT_TOP_P,LLM_DEFAULT_MAX_TOKENS,LLM_DEFAULT_TOP_K,LLM_DEFAULT_MIN_P: Default parameters for LLM calls.GEMINI_API_KEY: API key for Google Gemini services.
OAuth Proxy Integration (Optional, for advanced scenarios):
OAUTH_PROXY_AUTHORIZATION_URL,OAUTH_PROXY_TOKEN_URL,OAUTH_PROXY_REVOCATION_URL,OAUTH_PROXY_ISSUER_URL,OAUTH_PROXY_SERVICE_DOCUMENTATION_URL,OAUTH_PROXY_DEFAULT_CLIENT_REDIRECT_URIS: Configuration for an OAuth proxy.
Refer to src/config/index.ts and the .clinerules file for the complete list and Zod schema definitions.
Usage with MCP Clients
To allow an MCP client (like an AI assistant) to use this server:
Run the Server: Start the server from your terminal:
node dist/index.js # Or if you are in the project root: # npm startConfigure the Client: Add the server to your MCP client's configuration. The exact method depends on the client.
For STDIO Transport (Default): Typically involves specifying:
Command:
nodeArguments: The absolute path to the built server executable (e.g.,
/path/to/filesystem-mcp-server/dist/index.js).Environment Variables (Optional): Set any required environment variables from the Configuration section.
Example MCP Settings for STDIO (Conceptual):
{ "mcpServers": { "filesystem_stdio": { "command": "node", "args": ["/path/to/filesystem-mcp-server/dist/index.js"], "env": { "MCP_LOG_LEVEL": "debug" // Other relevant env vars }, "disabled": false, "autoApprove": [] } } }For HTTP Transport: The client will need to know the server's URL (e.g.,
http://localhost:3010) and how to authenticate (e.g., providing a JWT Bearer token ifMCP_AUTH_SECRET_KEYis set). Refer to your MCP client's documentation for HTTP server configuration.
Once configured and running, the client will detect the server and its available tools.
Available Tools
The server exposes the following tools for filesystem interaction:
Tool | Description |
| Sets a default absolute path for the current session. Relative paths used in subsequent tool calls will be resolved against this default. Resets on server restart. |
| Reads the entire content of a specified file as UTF-8 text. Accepts relative (resolved against default) or absolute paths. |
| Writes content to a specified file. Creates the file (and necessary parent directories) if it doesn't exist, or overwrites it if it does. Accepts relative or absolute paths. |
| Performs targeted search-and-replace operations within an existing file using an array of |
| Lists files and directories within a specified path. Options include recursive listing ( |
| Permanently removes a specific file. Accepts relative or absolute paths. |
| Permanently removes a directory. Use |
| Creates a new directory at the specified path. By default ( |
| Moves or renames a file or directory from a source path to a destination path. Accepts relative or absolute paths for both. |
| Copies a file or directory from a source path to a destination path. For directories, it copies recursively by default ( |
Refer to the tool registration files (src/mcp-server/tools/*/registration.ts) for detailed input/output schemas (Zod/JSON Schema).
Project Structure
The codebase is organized for clarity and maintainability:
filesystem-mcp-server/
├── dist/ # Compiled JavaScript output (after npm run build)
├── logs/ # Log files (created at runtime)
├── node_modules/ # Project dependencies
├── src/ # TypeScript source code
│ ├── config/ # Configuration loading (index.ts)
│ ├── mcp-server/ # Core MCP server logic
│ │ ├── server.ts # Server initialization, tool registration, transport handling
│ │ ├── state.ts # Session state management (e.g., default path)
│ │ ├── tools/ # Individual tool implementations (one subdir per tool)
│ │ │ ├── readFile/
│ │ │ │ ├── index.ts
│ │ │ │ ├── readFileLogic.ts
│ │ │ │ └── registration.ts
│ │ │ └── ... # Other tools (writeFile, updateFile, etc.)
│ │ └── transports/ # Communication transport implementations
│ │ ├── authentication/ # Auth middleware for HTTP
│ │ │ └── authMiddleware.ts
│ │ ├── httpTransport.ts
│ │ └── stdioTransport.ts
│ ├── types-global/ # Shared TypeScript types and interfaces
│ │ ├── errors.ts # Custom error classes and codes (McpError, BaseErrorCode)
│ │ ├── mcp.ts # MCP related types
│ │ └── tool.ts # Tool definition types
│ ├── utils/ # Reusable utility modules, categorized
│ │ ├── internal/ # Core internal utilities (errorHandler, logger, requestContext)
│ │ ├── metrics/ # Metrics-related utilities (tokenCounter)
│ │ ├── parsing/ # Parsing utilities (dateParser, jsonParser)
│ │ ├── security/ # Security-related utilities (idGenerator, rateLimiter, sanitization)
│ │ └── index.ts # Barrel export for all utilities
│ └── index.ts # Main application entry point
├── .clinerules # Cheatsheet for LLM assistants
├── .dockerignore
├── Dockerfile
├── LICENSE
├── mcp.json # MCP server manifest (generated by SDK or manually)
├── package.json
├── package-lock.json
├── README.md # This file
├── repomix.config.json
├── smithery.yaml # Smithery configuration (if used)
└── tsconfig.json # TypeScript compiler optionsFor a live, detailed view of the current structure, run: npm run tree (This script might need to be updated if src/scripts/tree.ts was part of the changes).
Developer Note: This repository includes a .clinerules file. This cheat sheet provides your LLM coding assistant with essential context about codebase patterns, file locations, and usage examples. Keep it updated as the server evolves!
License
This project is licensed under the Apache License 2.0. See the LICENSE file for details.
Available Tools
10 toolscopy_pathB
Copies a file or directory to a new location. Accepts relative or absolute paths. Defaults to recursive copy for directories.
Inputs: destination_path (required), source_path (required), recursive.
create_directoryB
Creates a directory. Optionally creates parent directories. Accepts relative or absolute paths.
Inputs: path (required), create_parents.
delete_directoryB
Removes a directory. Optionally removes recursively. Accepts relative or absolute paths.
Inputs: path (required), recursive.
delete_fileA
Removes a specific file. Accepts relative or absolute paths.
Inputs: path (required).
list_filesA
Lists files and directories within the specified directory. Optionally lists recursively and returns a tree-like structure. Includes an optional maxEntries parameter (default 50) to limit the number of items returned.
Inputs: path (required), includeNested, maxEntries.
move_pathB
Moves or renames a file or directory. Accepts relative or absolute paths for source and destination.
Inputs: destination_path (required), source_path (required).
read_fileA
Reads the entire content of a specified file as UTF-8 text. Accepts relative or absolute paths. Relative paths are resolved against the session default set by set_filesystem_default.
Inputs: path (required).
set_filesystem_defaultA
Sets a default absolute path for the current session. Relative paths used in other filesystem tools (like readFile) will be resolved against this default. The default is cleared on server restart.
Inputs: path (required).
update_fileA
Performs targeted search-and-replace operations within an existing file using an array of {search, replace} blocks. Preferred for smaller, localized changes. For large-scale updates or overwrites, consider using write_file. Accepts relative or absolute paths. File must exist. Supports optional useRegex (boolean, default false) and replaceAll (boolean, default false).
Inputs: blocks (required), path (required), replaceAll, useRegex.
write_fileA
Writes content to a specified file. Creates the file (and necessary directories) if it doesn't exist, or overwrites it if it does. Accepts relative or absolute paths (resolved like readFile).
Inputs: content (required), path (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 10 tools
Each tool has a clearly distinct purpose with no ambiguity: copy_path, move_path, delete_file, and delete_directory handle different file operations; list_files, read_file, write_file, and update_file serve distinct read/write functions; create_directory and set_filesystem_default are unique utilities. The descriptions reinforce these distinctions, making misselection unlikely.
The tool names follow a consistent snake_case pattern with clear verb_noun structures (e.g., copy_path, delete_file). However, there is a minor deviation with set_filesystem_default, which uses a longer, descriptive name that breaks the simple verb_noun pattern, though it remains readable and consistent in style.
With 10 tools, the count is well-scoped for a filesystem server, covering essential operations like create, read, update, delete, list, copy, move, and session management. Each tool earns its place without redundancy, fitting the typical range of 3-15 tools for such a domain.
The tool set provides complete CRUD/lifecycle coverage for filesystem operations: create_directory, read_file, write_file, update_file, delete_file, and delete_directory handle core file management; list_files, copy_path, and move_path support navigation and organization; set_filesystem_default adds session context. There are no obvious gaps, enabling agents to perform comprehensive filesystem tasks without dead ends.
Maintenance
Related MCP Connectors
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
The Mercado Pago MCP Server implements the Model Context Protocol to provide AI agents and LLMs with access to Mercado Pago's APIs and tools within compatible development environments. It acts as an intermediary that translates Mercado Pago resources into executable functions (tools) that AI applications can invoke to perform actions and automate flows. The server simplifies integration, enables using documentation to implement or improve code, and optimizes operations through natural language interactions without manual implementations.
The Remote MCP server acts as a standardized bridge between LLM applications (like Claude, ChatGPT, and Cursor) and external services, enabling AI agents to access external tools and resources. Its primary capability is providing a centralized search tool to discover other MCP servers and their respective tools. Unlike local implementations, it runs remotely with OAuth authentication and permission controls for security.
A Model Context Protocol server for Wix AI tools
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol (MCP) server that allows AI models to safely access and interact with local file systems, enabling reading file contents, listing directories, and retrieving file metadata.10 npm10MIT
- AlicenseAqualityFmaintenanceA Model Context Protocol server that provides secure and intelligent interaction with files and filesystems, offering smart context management and token-efficient operations for working with large files and complex directory structures.2167MIT
- FlicenseNot gradedqualityDmaintenanceA Model Context Protocol server that extends AI capabilities by providing file system access and management functionalities to Claude or other AI assistants.277 npm5-
- AlicenseAqualityDmaintenanceA secure Model Context Protocol server that provides controlled filesystem access within predefined directories, enabling AI models to perform file and directory operations with strict path validation.1681 npm7MIT