text_file_read_and_refactor_mcp
A token-efficient MCP server for safe text-file search, reading, and refactoring, with automatic BOM and encoding detection — preserving original encoding on write. All operations are constrained to server-configured allowed directories.
File Information
List allowed directories
Get total character length or line count of a file
Expand a character slice to cover full lines, returning both character and line-number slices
Reading Content
Read a character slice (Python-style start/stop)
Read a range of lines
Find the first or last occurrence of exact text, whole-word, or identifier-style matches, with optional start/stop offsets
Find content between left and right boundary markers (returning only the inner content)
Find content including boundary markers
Locate the character slices of the boundary markers themselves
Modifying Content
Replace a character slice or line range with new text
Find-and-replace exact, whole-word, or identifier-style matches (with optional count limit)
Replace content between boundary markers (preserving the markers)
Replace content including boundary markers
Batch patch: apply an ordered list of boundary-span replacements in one call
Boundary Marker Types: text, word (whole-word), dev_word (identifier-style), regex, or absent (file start/end)
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., "@text_file_read_and_refactor_mcp find 'error' in logfile.txt"
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.
Text File Read And Refactor MCP
Token-efficient Python stdio MCP server exposing safe text-file search, reading, and refactoring tools. Tools automatically resolve the file BOM and codepage; edit tools save files with their original encoding and BOM.
Glama.AI
Github repository
Github repository is a curated public mirror of the project. Active development (including experimental code and private research notes) happens in a private repository; selected snapshots are published here periodically.
Installation
Install
uv: https://docs.astral.sh/uv/getting-started/installation/Configure your MCP client to run the server via
uvx:
{
"mcpServers": {
"text-file-read-and-refactor": {
"command": "uvx",
"args": [
"text-file-read-and-refactor-mcp"
]
}
}
}Related MCP server: MCP File Context Server
Tools
Slice concept: an analog of the slice(start: integer, stop: integer) - stores the start and end indices of a range.
Boundary concept: an analog of the Boundary(text: string, type: Enum[text, word, dev_word, regex])
Span concept: an analog of the Span(left_boundary: Boundary, right_boundary: Boundary). It allows for search/replace operations such as give me the text between "my_config_param:" and ";" or replace the text between "%my_regex_1%" and "%my_regex_2%" with "my_text".
Read-only tools:
text_file__list_allowed_directories- in pseudocode: "text_file__list_allowed_directories() -> List[directory_path]"text_file__file_content_length- in pseudocode: "text_file__file_content_length() -> integer_characters_num"text_file__read_slice- in pseudocode: "text_file__read_slice(characters_slice) -> text"text_file__file_lines_num- in pseudocode: "text_file__file_lines_num() -> integer_lines_num"text_file__read_content_by_line_range- in pseudocode: "text_file__read_content_by_line_range(lines_slice) -> text"text_file__find_text- in pseudocode: "text_file__find_text(text, type: Enum[text, word, dev_word, regex]) -> {found, result?: {slice, lines, text}}"text_file__find_all_text_occurrences- in pseudocode: "text_file__find_all_text_occurrences(text, type: Enum[text, word, dev_word, regex], result_index_start, result_index_stop) -> List[{found, result: {slice, lines, text}}]"text_file__expand_slice_to_lines- in pseudocode: "text_file__expand_slice_to_lines(characters_slice) -> lines_slice"text_file__find_span_boundaries- in pseudocode: "text_file__find_span_boundaries(left_boundary, right_boundary) -> Tuple[left_boundary_characters_slice, right_boundary_characters_slice]"text_file__find_span_between_boundaries- in pseudocode: "text_file__find_span_between_boundaries(left_boundary, right_boundary) -> text". Example:text_file__find_span_between_boundaries("my_config_param:", ";")will return string " my_value".text_file__find_span_with_boundaries- in pseudocode: "text_file__find_span_with_boundaries(left_boundary, right_boundary) -> text". Example:text_file__find_span_with_boundaries("my_config_param:", ";")will return string "my_config_param: my_value;".
Edit tools:
text_file__replace_content_by_line_range- in pseudocode: "text_file__replace_content_by_line_range(text, lines_slice)"text_file__replace_slice- in pseudocode: "text_file__replace_slice(text, characters_slice)"text_file__replace_text- in pseudocode: "text_file__replace_slice(old_text, new_text)"text_file__replace_span_between_boundaries- in pseudocode: "text_file__replace_span_between_boundaries(text, left_boundary, right_boundary)".text_file__replace_span_with_boundaries- in pseudocode: "text_file__replace_span_with_boundaries(text, left_boundary, right_boundary)".text_file__patch_spans_by_boundary_patterns- in pseudocode: "text_file__patch_spans_by_boundary_patterns(List[Tuple[text, left_boundary, right_boundary]])".
Cengal
Based on Cengal
Projects using Cengal
InterProcessPyObjects - High-performance package delivers blazing-fast inter-process communication through shared memory, enabling Python objects to be shared across processes with exceptional efficiency.
cengal_app_dir_path_finder - A Python module offering a unified API for easy retrieval of OS-specific application directories, enhancing data management across Windows, Linux, and macOS
cengal_cpu_info - Extended, cached CPU info with consistent output format.
cengal_memory_barriers - Fast cross-platform memory barriers for Python.
flet_async - wrapper which makes Flet async and brings booth Cengal.coroutines and asyncio to Flet (Flutter based UI)
justpy_containers - wrapper around JustPy in order to bring more security and more production-needed features to JustPy (VueJS based UI)
Bensbach - decompiler from Unreal Engine 3 bytecode to a Lisp-like script and compiler back to Unreal Engine 3 bytecode. Made for a game modding purposes
Realistic-Damage-Model-mod-for-Long-War - Mod for both the original XCOM:EW and the mod Long War. Was made with a Bensbach, which was made with Cengal
SmartCATaloguer.com - TagDB based catalog of images (tags), music albums (genre tags) and apps (categories)
License
Copyright © 2026 ButenkoMS. All rights reserved.
Licensed under the Apache License, Version 2.0.
Available Tools
16 toolstext_file__expand_slice_to_linesA
Opens the text file, automatically resolving the BOM and codepage. Expands a character slice to cover complete lines and returns both the expanded character slice and selected line-number slice. Provide slices as JSON objects matching Python slice(start, stop, step); omit fields for None, and never use step 0. Token-efficient: targets specific file content or returns compact structured results to reduce unnecessary context.
Inputs: place (required), source_file_path (required).
text_file__file_content_lengthA
Opens the text file, automatically resolving the BOM and codepage. Returns the number of characters in the decoded file content. Token-efficient: targets specific file content or returns compact structured results to reduce unnecessary context.
Inputs: source_file_path (required).
text_file__file_lines_numA
Opens the text file, automatically resolving the BOM and codepage. Returns the number of lines in the decoded file content. Token-efficient: targets specific file content or returns compact structured results to reduce unnecessary context.
Inputs: source_file_path (required).
text_file__find_span_between_boundariesB
Opens the text file, automatically resolving the BOM and codepage. Finds content between matching boundary markers described by the boundary_span object and returns the inner slice, or null if not found. Token-efficient: targets specific file content or returns compact structured results to reduce unnecessary context.
Inputs: boundary_span (required), source_file_path (required), stop, start, +2 more.
text_file__find_span_boundariesA
Opens the text file, automatically resolving the BOM and codepage. Finds matching left and right boundary markers described by the boundary_span object and returns their slices. Token-efficient: targets specific file content or returns compact structured results to reduce unnecessary context.
Inputs: boundary_span (required), source_file_path (required), stop, start, +2 more.
text_file__find_span_with_boundariesB
Opens the text file, automatically resolving the BOM and codepage. Finds content plus its surrounding matching boundary markers and returns the full slice, or null if not found. Token-efficient: targets specific file content or returns compact structured results to reduce unnecessary context.
Inputs: boundary_span (required), source_file_path (required), stop, start, +2 more.
text_file__find_textA
Opens the text file, automatically resolving the BOM and codepage. Finds the first or last exact text, whole-word, or identifier-style word match within optional start/stop character offsets and returns its slice, or null if not found. Token-efficient: targets specific file content or returns compact structured results to reduce unnecessary context.
Inputs: text (required), source_file_path (required), stop, type, +7 more.
text_file__list_allowed_directoriesA
Returns the filesystem directories this server is allowed to access. File paths used by other tools must be inside one of these directories. Token-efficient: targets specific file content or returns compact structured results to reduce unnecessary context.
Inputs: no named parameters.
text_file__patch_spans_by_boundary_patternsB
Opens the text file, automatically resolving the BOM and codepage. Applies one boundary-span replacement or an ordered list of boundary-span replacements, then writes the modified content back. Token-efficient: targets specific file content or returns compact structured results to reduce unnecessary context. The file is saved with its original encoding and BOM.
Inputs: source_file_path (required), text, count, patch, +1 more.
text_file__read_content_by_line_rangeA
Opens the text file, automatically resolving the BOM and codepage. Reads complete lines selected by a Python-style line-number slice. Provide slices as JSON objects matching Python slice(start, stop, step); omit fields for None, and never use step 0. Token-efficient: targets specific file content or returns compact structured results to reduce unnecessary context.
Inputs: line_range (required), source_file_path (required).
text_file__read_sliceA
Opens the text file, automatically resolving the BOM and codepage. Allows you to read any section of the file content (or the entire content) using Python-style slicing. Provide slices as JSON objects matching Python slice(start, stop, step); omit fields for None, and never use step 0. Token-efficient: targets specific file content or returns compact structured results to reduce unnecessary context.
Inputs: slice (required), source_file_path (required).
text_file__replace_content_by_line_rangeA
Opens the text file, automatically resolving the BOM and codepage. Replaces complete lines selected by a Python-style line-number slice, then writes the modified content back. Provide slices as JSON objects matching Python slice(start, stop, step); omit fields for None, and never use step 0. Token-efficient: targets specific file content or returns compact structured results to reduce unnecessary context. The file is saved with its original encoding and BOM.
Inputs: text (required), line_range (required), source_file_path (required).
text_file__replace_sliceA
Opens the text file, automatically resolving the BOM and codepage. Replaces the content selected by a Python-style character slice, then writes the modified content back. Provide slices as JSON objects matching Python slice(start, stop, step); omit fields for None, and never use step 0. Token-efficient: targets specific file content or returns compact structured results to reduce unnecessary context. The file is saved with its original encoding and BOM.
Inputs: text (required), place (required), source_file_path (required).
text_file__replace_span_between_boundariesA
Opens the text file, automatically resolving the BOM and codepage. Replaces only the content between matching boundary markers, preserves the boundary markers, then writes the modified content back. Token-efficient: targets specific file content or returns compact structured results to reduce unnecessary context. The file is saved with its original encoding and BOM.
Inputs: text (required), boundary_span (required), source_file_path (required), count.
text_file__replace_span_with_boundariesB
Opens the text file, automatically resolving the BOM and codepage. Replaces matching boundary markers together with the content between them, then writes the modified content back. Token-efficient: targets specific file content or returns compact structured results to reduce unnecessary context. The file is saved with its original encoding and BOM.
Inputs: text (required), boundary_span (required), source_file_path (required), count.
text_file__replace_textA
Opens the text file, automatically resolving the BOM and codepage. Replaces exact substring, whole-word, or identifier-style word matches within optional start/stop character offsets, then writes the modified content back. Token-efficient: targets specific file content or returns compact structured results to reduce unnecessary context. The file is saved with its original encoding and BOM.
Inputs: new_text (required), old_text (required), source_file_path (required), stop, +8 more.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 16 tools
Most tools have distinct purposes, but some pairs like find_span_between_boundaries and find_span_with_boundaries could be confused. Descriptions help disambiguate.
All tools follow a consistent `text_file__verb_phrase` pattern with snake_case, making the naming predictable and uniform.
With 16 tools, the set is well-scoped for reading and refactoring text files, covering various operations without being overwhelming.
Core operations like reading, finding, and replacing are covered. However, missing tools for creating or deleting files limit full lifecycle management.
Maintenance
Related MCP Connectors
Shared memory MCP server for Claude Code, Codex, Gemini CLI and Cursor. Cited, editable.
Nifty's MCP server — exposes tasks, projects, messages, and files as tools for AI agents.
Agent-native MCP server over the public saagarpatel.dev corpus. Read-only, stateless.
Lean 4 MCP server: compile, prove theorems, and formalize math with Mathlib.
Related MCP Servers
- AlicenseAqualityAmaintenanceA line-oriented text file editor. Optimized for LLM tools with efficient partial file access to minimize token usage.6202MIT
- AlicenseBqualityDmaintenanceA Model Context Protocol server that enables LLMs to read, search, and analyze code files with advanced caching and real-time file watching capabilities.66 npm40MIT
- AlicenseBqualityDmaintenanceAn open source implementation of the Claude built-in text editor tool versions: text\_editor\_20241022 (Claude 3.5 Sonnet) text\_editor\_20250124 (Claude 3.7 Sonnet)166 npm36MIT
- AlicenseAqualityDmaintenanceEnables comprehensive file operations including reading, writing, searching, and editing files with advanced features like regex-based replacements, line-specific modifications, and directory-wide search capabilities. Provides 8 robust tools for safe file manipulation with content verification and detailed error handling.818 npm2MIT