Logo di filesystem-mcp-server

filesystem-mcp-server

Community
cyanheads

A Model Context Protocol (MCP) server for platform-agnostic file capabilities, including advanced search/replace and directory tree traversal

Autorecyanheads
Repositoryfilesystem-mcp-server
LinguaTypeScript
Fork
30
Stelle
51
Strumenti disponibili
9
Tipo di trasportostdio
Categorie
LicenzaApache-2.0
Link
  • Collega gli strumenti ai flussi di lavoro IA

    filesystem-mcp-server mette a disposizione funzionalità MCP utilizzabili da client e agenti IA compatibili.

  • 9 strumenti disponibili

    Esplora le azioni richiamabili qui sotto, con nomi e descrizioni quando forniti dal server.

  • Configurazione pronta da copiare

    Usa gli esempi di installazione per configurare questo server nel tuo client MCP preferito.

  • Indicatori di interesse open source

    51 stelle e 30 fork nel repository collegato.

Filesystem MCP Server

TypeScript Model Context Protocol Version License Status GitHub

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

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:

  • Transport 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_file tool allows precise search-and-replace operations within files, supporting plain text and regex.
  • Session-Aware Path Management: set_filesystem_default tool 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

  1. Clone the repository:
    bash
    git clone https://github.com/cyanheads/filesystem-mcp-server.git
    cd filesystem-mcp-server
  2. Install dependencies:
    bash
    npm install
  3. Build the project:
    bash
    npm run build
    This compiles the TypeScript code to JavaScript in the dist/ directory and makes the main script executable. The executable will be located at dist/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 to debug.
  • LOGS_DIR (Optional): Directory for log files. Defaults to ./logs in the project root.
  • NODE_ENV (Optional): Runtime environment (e.g., development, production). Defaults to development.

Transport Settings:

  • MCP_TRANSPORT_TYPE (Optional): Communication transport (stdio or http). Defaults to stdio.
    • If http is selected:
      • MCP_HTTP_PORT (Optional): Port for the HTTP server. Defaults to 3010.
      • MCP_HTTP_HOST (Optional): Host for the HTTP server. Defaults to 127.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 to MCP_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:

  1. Run the Server: Start the server from your terminal:

    bash
    node dist/index.js
    # Or if you are in the project root:
    # npm start
  2. Configure 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: node
    • Arguments: 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):

    json
    {
      "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 if MCP_AUTH_SECRET_KEY is 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:

ToolDescription
set_filesystem_defaultSets 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.
read_fileReads the entire content of a specified file as UTF-8 text. Accepts relative (resolved against default) or absolute paths.
write_fileWrites 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.
update_filePerforms targeted search-and-replace operations within an existing file using an array of {search, replace} blocks. Ideal for localized changes. Supports plain text or regex search (useRegex: true) and replacing all occurrences (replaceAll: true). Accepts relative or absolute paths. File must exist.
list_filesLists files and directories within a specified path. Options include recursive listing (includeNested: true) and limiting the number of entries (maxEntries). Returns a formatted tree structure. Accepts relative or absolute paths.
delete_filePermanently removes a specific file. Accepts relative or absolute paths.
delete_directoryPermanently removes a directory. Use recursive: true to remove non-empty directories and their contents (use with caution!). Accepts relative or absolute paths.
create_directoryCreates a new directory at the specified path. By default (create_parents: true), it also creates any necessary parent directories. Accepts relative or absolute paths.
move_pathMoves or renames a file or directory from a source path to a destination path. Accepts relative or absolute paths for both.
copy_pathCopies a file or directory from a source path to a destination path. For directories, it copies recursively by default (recursive: true). Accepts relative or absolute paths.

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 options

For 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.


Installazione

TypingMind
Prerequisiti:

Node.js 18+

{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": [
        "-y",
        "@cyanheads/filesystem-mcp-server"
      ]
    }
  }
}

Strumenti disponibili

  • read_file

    Read and analyze file contents

  • write_file

    Create, modify, or overwrite files

  • update_file

    Perform targeted search-and-replace operations within files with plain text and regex support

  • list_directory

    List files and directories

  • delete_file

    Delete files

  • delete_directory

    Delete directories

  • move_file

    Move files

  • copy_file

    Copy files

  • set_filesystem_default

    Set default working directory for resolving relative paths during session

Usa MCP filesystem-mcp-server con più modelli IA

TypingMind collega gli strumenti MCP a livello di area di lavoro: una volta connesso filesystem-mcp-server, puoi usarlo con diversi modelli IA in TypingMind, senza configurarlo separatamente per ogni modello. Questa integrazione MCP viene eseguita localmente sul tuo dispositivo tramite il connettore MCP di TypingMind.

Guida alla configurazione del connettore locale

Usa questo metodo quando il server MCP deve accedere a file locali, app o risorse private sul tuo computer.

1

Apri le impostazioni MCP

In TypingMind, vai su Impostazioni, Impostazioni avanzate, poi su Model Context Protocol e scegli Configura MCP.

  1. Apri TypingMind nel tuo browser.
  2. Fai clic sull'icona Impostazioni.
  3. Vai a Impostazioni avanzate.
  4. Apri la sezione Model Context Protocol.
  5. Fai clic su Configura MCP e scegli Questo dispositivo.
Schermata di configurazione del connettore MCP di TypingMind con Questo dispositivo selezionato
2

Esegui il comando del connettore

Scegli Questo dispositivo, copia il comando da TypingMind ed eseguilo nel terminale. Lascia il processo in esecuzione mentre usi MCP.

  1. Copia il comando di configurazione mostrato da TypingMind.
  2. Apri Terminale su macOS o Windows Terminal su Windows.
  3. Incolla ed esegui il comando.
  4. Conferma l'installazione del pacchetto se il terminale ti chiede di procedere.
  5. Tieni aperta la finestra del terminale con il processo in esecuzione mentre usi gli strumenti MCP.
3

Aggiungi filesystem-mcp-server come server

Quando lo stato del connettore è Pronto, fai clic su Modifica server e incolla la configurazione del server MCP.

  1. Attendi che lo stato del connettore sia Pronto.
  2. Fai clic su Modifica server.
  3. Incolla la configurazione del server MCP di filesystem-mcp-server.
  4. Salva l'elenco dei server.
  5. Aggiorna per verificare che il connettore sia ancora pronto.
Impostazioni MCP di TypingMind con un server attivo e il pulsante Modifica server
{
  "mcpServers": {
    "filesystem-mcp-server": {
      "command": "npx",
      "args": [
        "-y",
        "@cyanheads/filesystem-mcp-server"
      ]
    }
  }
}
4

Usa la connessione con diversi modelli

Salva l'elenco dei server, apri Plugin, abilita gli strumenti MCP di filesystem-mcp-server, poi seleziona un modello IA supportato in TypingMind e usa gli strumenti in chat o assegnali a un agente IA.

  1. Apri la pagina Plugin in TypingMind.
  2. Abilita gli strumenti MCP di filesystem-mcp-server.
  3. Avvia una chat e scegli il modello IA che vuoi usare.
  4. Usa gli strumenti MCP in chat o assegnali a un agente IA.
  5. Passa a un altro modello IA quando serve, senza riconnettere MCP.
Chat di TypingMind che usa gli strumenti MCP abilitati con un modello IA selezionato
Puoi usare filesystem-mcp-server per aiutarmi con questa attività?
filesystem-mcp-server
Certo. Ho letto.
Ecco cosa ho trovato con filesystem-mcp-server.

Domande frequenti

A cosa serve il server MCP filesystem-mcp-server?

filesystem-mcp-server è un server MCP che consente ai client IA compatibili di accedere a strumenti e informazioni di contesto esterni. In TypingMind puoi aggiungere questo server MCP una sola volta e rendere disponibili i suoi strumenti nella tua area di lavoro IA.

Posso usare filesystem-mcp-server MCP con più modelli IA in TypingMind?

Sì. TypingMind collega gli strumenti MCP a livello di area di lavoro, quindi puoi usare filesystem-mcp-server con diversi modelli IA come Claude, ChatGPT, Gemini o altri modelli che hai configurato in TypingMind, senza dover configurare il server MCP separatamente per ogni modello.

Perché usare il connettore MCP filesystem-mcp-server con TypingMind?

TypingMind è una delle migliori interfacce per chattare con gli LLM perché riunisce più modelli IA, prompt, plugin, agenti IA, chiavi API e strumenti MCP in un'unica area di lavoro. Collegando filesystem-mcp-server, puoi usare i suoi strumenti MCP con i tuoi modelli preferiti e mantenere organizzato il tuo flusso di lavoro in chat su TypingMind.

Come collego filesystem-mcp-server MCP a TypingMind?

filesystem-mcp-server funziona tramite il connettore MCP locale di TypingMind. È la soluzione ideale quando il server MCP deve accedere a file locali, app desktop, strumenti da riga di comando o risorse private sul tuo computer.

Quali strumenti offre filesystem-mcp-server MCP in TypingMind?

filesystem-mcp-server mette a disposizione 9 strumenti MCP che puoi attivare dalla pagina Plugin di TypingMind e usare in chat o assegnare agli agenti IA.

Devo condividere le mie chiavi API con TypingMind per usare filesystem-mcp-server MCP?

No. TypingMind privilegia il funzionamento in locale e ti permette di mantenere il controllo su fornitori di modelli, chiavi API, prompt e configurazione MCP. Se filesystem-mcp-server richiede l'autenticazione, aggiungi le intestazioni, le impostazioni OAuth o la configurazione locale necessarie per quel server MCP quando crei la connessione.

Server MCP correlati

Vedi tutti

Crea subito la tua area di lavoro IA

Iscriviti alla nostra newsletter per ricevere aggiornamenti sulle nuove funzionalità e sulle prossime iniziative a premi 👇