MCP server providing regex-based file operations for LLM programming assistants.
- 5 Production-Ready Tools for regex operations on files
- Unified Glob Pattern API - all tools support single files or wildcards
- Concurrent Processing for multi-file operations
- Cross-platform support (Windows, Linux, macOS)
- Binary file detection with configurable buffer size
- Structured JSON output for reliable programmatic parsing
- Error handling with individual file error reporting
- No bash dependencies - pure Node.js implementation
- regex_search - Search for pattern matches in files (supports glob patterns)
- regex_replace - Replace pattern matches in files (supports glob patterns)
- regex_extract - Extract only capture groups for parsing
- regex_match_lines - Filter lines matching/not matching pattern
- regex_split - Split file content by regex delimiter
All tools accept path_pattern which can be:
- Exact file path:
"src/app.js" - Single directory glob:
"src/*.js" - Recursive glob:
"src/**/*.ts"(** matches any number of directories)
git clone https://github.com/DanNsk/fs-regex-mcp.git
cd fs-regex-mcp
npm install
npm run buildnpm testStart the MCP server directly:
npm startOr run from built code:
node dist/index.jsCreate a distributable package:
# Build the project
npm run build
# Create tarball for distribution
npm packThis creates fs-regex-mcp-1.0.0.tgz that can be installed anywhere:
# Install globally
npm install -g fs-regex-mcp-1.0.0.tgz
# Or install locally in another project
npm install /path/to/fs-regex-mcp-1.0.0.tgzAfter global installation, the server can be run as:
fs-regex-mcpConfigure Claude Code by adding to your MCP settings file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
Linux: ~/.config/Claude/claude_desktop_config.json
- Build and install globally:
git clone https://github.com/DanNsk/fs-regex-mcp.git
cd fs-regex-mcp
npm install
npm run build
npm install -g .- Configure:
{
"mcpServers": {
"fs-regex": {
"command": "fs-regex-mcp"
}
}
}{
"mcpServers": {
"fs-regex": {
"command": "node",
"args": ["/absolute/path/to/fs-regex-mcp/dist/index.js"]
}
}
}Restart Claude Code to load the server
For web-based Claude Code or other MCP clients:
# Start the server
npm startThe server communicates via stdio, so it can be used with any MCP client that supports stdio transport.
Search for function definitions in a single file:
{
"path_pattern": "src/app.js",
"pattern": "/function\\s+(\\w+)/g",
"context_after": 1
}Search across multiple files with glob:
{
"path_pattern": "src/**/*.js",
"pattern": "/TODO:.*$/gim",
"exclude": ["**/node_modules/**", "**/dist/**"]
}Search for literal text with special characters:
{
"path_pattern": "src/**/*.js",
"pattern": "function(x)",
"literal": true
}Convert var to const in a single file:
{
"path_pattern": "src/app.js",
"pattern": "var\\s+(\\w+)",
"replacement": "const $1",
"flags": "g",
"dry_run": true
}Replace across all TypeScript files:
{
"path_pattern": "src/**/*.ts",
"pattern": "console\\.log",
"replacement": "logger.debug",
"flags": "g",
"exclude": ["**/*.test.ts"]
}Replace literal text (no regex, no capture group substitution):
{
"path_pattern": "src/**/*.js",
"pattern": "price = $100",
"replacement": "price = $200",
"literal": true
}Parse JSON-like key-value pairs:
{
"path_pattern": "config.txt",
"pattern": "\"(\\w+)\":\\s*\"([^\"]+)\"",
"flags": "g"
}Filter error lines from logs:
{
"path_pattern": "logs/*.log",
"pattern": "ERROR|FATAL",
"flags": "i"
}Match lines containing literal special characters:
{
"path_pattern": "config/*.txt",
"pattern": "[debug]",
"literal": true
}Split markdown by headers:
{
"path_pattern": "docs/*.md",
"pattern": "^##\\s+",
"flags": "m"
}Split by literal delimiter:
{
"path_pattern": "data/*.txt",
"pattern": "***",
"literal": true
}All tools support these parameters:
- path_pattern (required): File path or glob pattern
"file.txt"- single file"*.js"- all .js files in current directory"src/**/*.ts"- recursive search (** = any directories)
- pattern (required): Regex pattern as string or
/pattern/flagsformat - flags (optional): Regex flags -
g(global),i(case-insensitive),m(multiline),s(dotall) - literal (optional): Treat pattern as literal string, not regex (default:
false)- When
true, special regex characters are escaped automatically - Multi-line patterns supported (matches both Windows CRLF and Unix LF)
- For
regex_replace, replacement string is also treated literally (no capture group substitution)
- When
- exclude (optional): Glob patterns to exclude (e.g.,
["**/node_modules/**"]) - binary_check_buffer_size (optional):
- Default:
8192(8KB) - checks first 8KB for null bytes <= 0- treat all files as text (no binary detection)> 0- check first N bytes
- Default:
- context_before (optional): Number of lines before match to include
- context_after (optional): Number of lines after match to include
- max_matches / max_replacements (optional): Limit number of results
- dry_run (optional): For replace operations, preview without modifying files
Both formats are supported:
-
Plain pattern with separate flags:
{ "pattern": "test\\d+", "flags": "gi" } -
Delimited format (flags extracted from pattern):
{ "pattern": "/test\\d+/gi" }
Replacement strings support:
- Numbered groups:
$1,$2,\1,\2, etc. - Named groups:
${groupName},\g<groupName> - Literal dollar:
$$for$
Example:
{
"pattern": "(?<firstName>\\w+)\\s+(?<lastName>\\w+)",
"replacement": "${lastName}, ${firstName}"
}All tools return:
- Success: JSON array (even if empty)
- Error: Plain text error message
Example success output (regex_search):
[
{
"file": "/path/to/file.js",
"line": 42,
"column": 5,
"match": "function hello",
"groups": ["function hello", "hello"],
"context_before": ["// Comment"],
"context_after": [" return true;"]
}
]Example error output:
File not found: /path/to/missing.txt
- All operations process files concurrently for optimal performance
- Binary files are skipped early to avoid unnecessary processing
- Configurable limits (
max_matches,max_replacements) prevent excessive resource usage
fs-regex-mcp/
├── src/
│ ├── index.ts # MCP server entry point
│ ├── types.ts # TypeScript interfaces
│ ├── utils.ts # Core utilities
│ └── tools/ # Tool implementations
│ ├── regex-search.ts
│ ├── regex-replace.ts
│ ├── regex-extract.ts
│ ├── regex-match-lines.ts
│ └── regex-split.ts
├── dist/ # Compiled output
├── package.json
├── tsconfig.json
└── jest.config.js
npm run build # Compile TypeScript
npm run dev # Watch mode for development
npm test # Run tests
npm test:watch # Watch mode for tests
npm pack # Create distributable tarball- Node.js >= 18.0.0
- npm >= 8.0.0
Tested on:
- ✅ Windows 10/11
- ✅ macOS (Intel & Apple Silicon)
- ✅ Linux (Ubuntu, Debian, Fedora)
Handles:
- Different line endings (LF, CRLF)
- File paths with spaces
- Unicode content
- Large files (binary detection on first 8KB only)
Make sure you've installed globally:
npm install -g .Or use the full path in Claude Code config:
{
"command": "node",
"args": ["/full/path/to/dist/index.js"]
}By default, files with null bytes are skipped. To search binary files:
{
"binary_check_buffer_size": 0
}Use exclude patterns and max_matches:
{
"path_pattern": "**/*.js",
"exclude": ["**/node_modules/**", "**/dist/**", "**/*.min.js"],
"max_matches": 100
}MIT
Issues and pull requests are welcome!