mcp-fileencoding
Click on "Install 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., "@mcp-fileencodingread the file src/main.cpp with encoding detection"
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.
MCP FileEncoding
MCP server that solves the issue of garbled text when AI coding assistants read/write non-UTF-8 files (such as GBK/GB18030) on Windows.
It automatically detects the encoding during read operations and converts it to UTF-8 for the AI, and automatically converts it back to the original encoding during write operations, making it completely transparent to the AI.
Background
In Windows Chinese environments, many projects (C/C++, Lisp, etc.) save source files using GBK encoding. AI coding assistants default to reading these files with UTF-8, causing Chinese comments and strings to become garbled. This MCP handles encoding conversion automatically during file I/O, allowing the AI to correctly process non-UTF-8 files.
Related MCP server: filesystem-mcp
Supported Encodings
UTF-8 / UTF-8 BOM
GBK / GB2312
GB18030
Other encodings supported by Python
codecs
Installation
git clone https://github.com/jidzhang/mcp-fileencoding.git
cd mcp-fileencoding
pip install -r requirements.txtConfiguration
Claude Code
claude mcp add fileencoding -- python /path/to/mcp-fileencoding/src/server.pyClaude Desktop / Cursor / Other MCP Clients
Add to your MCP configuration file (the file path varies by client; refer to the corresponding client documentation):
{
"mcpServers": {
"fileencoding": {
"command": "python",
"args": ["/path/to/mcp-fileencoding/src/server.py"]
}
}
}Usage
Once configured, the AI will automatically gain access to the following 5 tools.
Tool List
Tool | Description |
| Read file, auto-detect encoding, return UTF-8 content |
| Write file, auto-convert back to original encoding |
| Partially replace file content (string replacement) |
| Query the recorded encoding of a file |
| List all recorded encodings |
Method 1: PreToolUse Hook (Recommended)
Using the Claude Code Hook mechanism, the AI automatically checks the file type and prompts the use of MCP whenever it calls Read/Write/Edit tools. This is more reliable than system prompts and will not fail during multi-turn conversations.
Create .claude/settings.json in the project root directory:
{
"hooks": {
"PreToolUse": [
{
"matcher": "Read|Write|Edit",
"hooks": [
{
"type": "prompt",
"prompt": "检查 $ARGUMENTS 中的文件路径,如果文件扩展名是 .cpp、.h 或 .lsp,则:\n- 对于 Read 操作:使用 mcp__fileencoding__read_file_with_encoding 代替 Read 工具\n- 对于 Write/Edit 操作:使用 mcp__fileencoding__write_file_with_encoding 代替 Write/Edit 工具\n\n返回 JSON: {\"hookSpecificOutput\": {\"hookEventName\": \"PreToolUse\", \"additionalContext\": \"提示信息\"}}"
}
]
}
]
}
}Modify the matched file extensions (.cpp, .h, .lsp, etc.) as needed.
Method 2: System Prompt
Add the prompt in Claude Code via the --system-prompt parameter or the project's CLAUDE.md file:
claude --system-prompt "在读取和修改 .cpp/.h/.lsp/.txt 等文本文件时,使用 fileencoding MCP。.py/.js/.html 等文件不需要使用。其他文件一般不需要使用,只有遇到读取文本乱码后才尝试使用。"Note: System prompts may be ignored by the AI in long conversations; the PreToolUse Hook is a more reliable choice.
Workflow
Taking editing a GBK-encoded .cpp file as an example:
AI calls
read_file_with_encodingto read the file → automatically detects it as GBK → returns UTF-8 content to the AIAfter the AI understands the content, it calls
edit_file_with_encodingto modify it → automatically writes it back to the file using GBKThe file encoding remains unchanged, ensuring compatibility with other tools
Notes
Encoding records are stored in memory and cleared when the MCP server restarts
If the encoding record is lost when writing a file, you need to manually specify the
encodingparameterDetection is based on file content; short text may not be accurate enough. It is recommended that the file content contains at least several dozen Chinese characters
Development
Install Development Dependencies
pip install -r requirements.txt
pip install pytest pyrightRun Tests
python -m pytest tests/ -vType Checking
npx pyright src/The project uses pyright strict mode; all source code type checks must pass with zero errors.
Project Structure
src/
├── server.py # MCP 服务器入口,工具定义和请求处理
├── detector.py # 编码检测(charset-normalizer + GBK 回退)
├── converter.py # 编码转换(字节 ↔ UTF-8)
└── encoding_store.py # 内存编码记录存储
tests/
├── test_server.py # 服务器 handler 测试
├── test_detector.py # 编码检测测试
├── test_converter.py # 编码转换测试
└── test_encoding_store.py # 存储模块测试Dependencies
Python >= 3.10
mcp >= 1.0.0
charset-normalizer >= 3.0.0
License
MIT
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseAqualityAmaintenanceEncoding-aware, indentation-smart file tools for AI coding agents. 20+ tools including read/edit with automatic encoding detection, smart indentation conversion, SSH, SFTP, process management, and system utilities.1124MIT
- AlicenseAqualityFmaintenanceEnables AI assistants to read, write, and manage files on the local system with security features like path restrictions and optional read-only mode.92MIT
- AlicenseAqualityCmaintenanceEnables AI assistants to read and write local Excel and CSV files, supporting editing, styling, and image insertion.1570MIT
- FlicenseNot gradedqualityBmaintenanceEnables AI assistants to read, create, edit Word/Excel/PPT files and manage the filesystem on the user's computer via natural language.
Related MCP Connectors
Connect AI assistants to your GitHub-hosted Obsidian vault to seamlessly access, search, and analy…
OCR, transcription, file extraction, and image generation for AI agents via MCP.
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/jidzhang/mcp-fileencoding'
If you have feedback or need assistance with the MCP directory API, please join our Discord server