The MCP Edit File Lines Server provides powerful functionality for making precise, line-based edits to text files through a clean API interface. It allows for string or regex pattern matching with a safety-focused two-step editing process where changes can be previewed before being applied.
To install and use the MCP Edit File Lines Server with Claude Desktop:
MacOS:
~/Library/Application Support/Claude/claude_desktop_config.json
Windows:
%APPDATA%/Claude/claude_desktop_config.json
{
"mcpServers": {
"edit-file-lines": {
"command": "node",
"args": [
"/path/to/edit-file-lines/build/index.js",
"/path/to/allowed/directory"
],
"env": {
"MCP_EDIT_STATE_TTL": "300000"
}
}
}
}
Replace /path/to/edit-file-lines/build/index.js
with the actual path to the built server, and /path/to/allowed/directory
with the directory containing files you want to edit.
If you need to start the server manually:
node build/index.js /path/to/allowed/directory [additional-directories...]
All file operations will be restricted to these allowed directories for security.
edit_file_lines
This is the primary tool for making line-based edits to files. It supports both string and regex pattern matching.
Make edits with a dry run first (recommended):
{
"p": "src/components/App.tsx",
"e": [{
"startLine": 2,
"endLine": 2,
"content": "primary",
"strMatch": "blue"
}],
"dryRun": true
}
This will provide a diff view and a state ID for later approval.
p
: Path to the file (relative to allowed directories)e
: Array of edit operations
startLine
: First line to editendLine
: Last line to editcontent
: New content to insertstrMatch
: String to match (optional)regexMatch
: Regex pattern to match (optional)dryRun
: Set to true
to preview changes without applying themapprove_edit
Apply changes from a previous dry run:
{
"stateId": "fcbf740a"
}
This two-step process ensures you can review changes before applying them.
get_file_lines
Inspect specific lines in a file before editing:
{
"path": "src/components/App.tsx",
"lineNumbers": [1, 2, 3],
"context": 1
}
search_file
Find specific patterns before editing:
{
"path": "src/components/App.tsx",
"pattern": "const",
"contextLines": 2
}
type
: "text" (default) or "regex"caseSensitive
: Boolean (default: false)wholeWord
: Boolean (default: false)contextLines
: Number of lines to show around matches (default: 2)maxMatches
: Maximum number of matches to return (default: 100)multiline
: Enable multiline regex mode (default: false){
"path": "src/config.ts",
"pattern": "API_URL",
"wholeWord": true
}
{
"p": "src/config.ts",
"e": [{
"startLine": 23,
"endLine": 23,
"content": "export const API_URL = 'https://new-api.example.com';",
"strMatch": "export const API_URL = 'https://api.example.com';"
}],
"dryRun": true
}
{
"stateId": "abc123def"
}
To make several related changes at once:
{
"p": "src/components/App.tsx",
"e": [
{
"startLine": 2,
"endLine": 2,
"content": "primary",
"strMatch": "blue"
},
{
"startLine": 9,
"endLine": 9,
"content": "description = \"New caption\"",
"strMatch": "subtitle = \"Default subtitle\""
}
],
"dryRun": true
}
The server provides powerful editing capabilities while maintaining security through allowed directory restrictions and the two-step edit approval process.
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "edit-file-lines" '{"command":"node","args":["/path/to/edit-file-lines/build/index.js","<allowed-directory>"],"env":{"MCP_EDIT_STATE_TTL":"300000"}}'
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": {
"edit-file-lines": {
"command": "node",
"args": [
"/path/to/edit-file-lines/build/index.js",
"<allowed-directory>"
],
"env": {
"MCP_EDIT_STATE_TTL": "300000"
}
}
}
}
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": {
"edit-file-lines": {
"command": "node",
"args": [
"/path/to/edit-file-lines/build/index.js",
"<allowed-directory>"
],
"env": {
"MCP_EDIT_STATE_TTL": "300000"
}
}
}
}
3. Restart Claude Desktop for the changes to take effect