modelcontextprotocol / modelcontextprotocol/servers

Proposal: Environment Variable Configuration for Filesystem MCP Server

Open
#1,879 0 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement server-filesystem
Dominant language
TypeScript
Stars
90.5k
Forks
11.7k
Avg merge
2d 2h
Merged PRs (30d)
5

Description

Proposal: Environment Variable Configuration for Filesystem MCP Server

Overview

Currently, the Filesystem MCP Server only supports configuring allowed and denied directories through command-line arguments. This approach can become unwieldy and hard to manage when complex configurations are needed. I propose adding support for environment variable-based configuration to improve usability.

Proposed Changes

Allow configuration of allowed and denied directories through the following environment variables:

  • ALLOWED_DIRS: Semicolon-separated list of allowed directories
  • ALLOWED_READONLY_DIRS: Semicolon-separated list of read-only allowed directories
  • DENIED_DIRS: Semicolon-separated list of denied directories
  • RECURSIVE: When set to "true", all subdirectories of allowed directories are also allowed

Existing command-line argument functionality would be maintained for backward compatibility.

Benefits

  1. Improved Readability: Complex directory configurations can be expressed more cleanly
  2. Easier Management: Multiple directories can be configured in a single line with semicolon separators
  3. Reusability: Environment variables can be easily reused in scripts or Docker configurations
  4. Backward Compatibility: Existing command-line argument approach continues to work

Implementation Example

Here's an example of changes to the index.ts file:

// Load settings from environment variables
function parseDirectories(envVarValue: string | undefined): string[] {
  if (!envVarValue) return [];
  return envVarValue
    .split(';')
    .map((dir) => dir.trim())
    .filter(Boolean);
}

// Get settings from environment variables
const envAllowedDirs = parseDirectories(process.env.ALLOWED_DIRS);
const envAllowedReadOnlyDirs = parseDirectories(process.env.ALLOWED_READONLY_DIRS);
const envDeniedDirs = parseDirectories(process.env.DENIED_DIRS);
const envRecursive = process.env.RECURSIVE === 'true';

// Parse command-line arguments
const args = process.argv.slice(2);
if (args.length === 0 && envAllowedDirs.length === 0 && envAllowedReadOnlyDirs.length === 0) {
  console.error(
    'Usage: mcp-server-filesystem [options] <allowed_directory> [additional_directories...]'
  );
  // ... existing help text ...
  console.error('');
  console.error('Configuration via environment variables:');
  console.error('  ALLOWED_DIRS: Semicolon-separated list of allowed directories');
  console.error(
    '  ALLOWED_READONLY_DIRS: Semicolon-separated list of read-only allowed directories'
  );
  console.error('  DENIED_DIRS: Semicolon-separated list of denied directories');
  console.error(
    '  RECURSIVE: When set to "true", all subdirectories of allowed directories are also allowed'
  );
  console.error('  Example:');
  console.error(
    '    ALLOWED_DIRS="/home/user;/home/user/projects" DENIED_DIRS="/home/user/.ssh;/home/user/.config" RECURSIVE="true" mcp-server-filesystem'
  );
  process.exit(1);
}

Usage Example

Example in mcp.json file:

{
  "mcpServers": {
    "filesystem": {
      "command": "node",
      "args": ["/path/to/filesystem/dist/index.js"],
      "env": {
        "ALLOWED_DIRS": "/home/user",
        "ALLOWED_READONLY_DIRS": "/home/user/Documents;/home/user/Library/Mobile Documents/com~apple~CloudDocs",
        "DENIED_DIRS": "/home/user/.ssh;/home/user/.config;/home/user/.local;/home/user/.cache;/home/user/.npm;/home/user/.yarn;/home/user/.pnpm;/home/user/.cargo;/Volumes/BackUp",
        "RECURSIVE": "true"
      }
    }
  }
}

I believe this enhancement will significantly improve the usability of the MCP Filesystem Server.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in index.ts and inspect the existing command-line argument parsing and usage output. Add support for ALLOWED_DIRS, ALLOWED_READONLY_DIRS, DENIED_DIRS, and RECURSIVE while preserving the current CLI behavior. Done means the environment variables configure directories as described, including semicolon-separated values and recursive mode.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
devtools
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.