Skip to main content
Glama
Codepage Bridge MCP

Codepage Bridge MCP

by skyispainted

Codepage Bridge MCP

中文说明 / README_CN

Encoding-transparent file tools for Claude Code and other MCP clients.

Codepage Bridge exposes Read, Grep, Edit, and Write over MCP while transparently converting project files between their on-disk legacy encoding and Unicode text for the LLM. The model sees normal Unicode text; files are written back in the encoding selected by the nearest .encoding-rules.

It is designed for legacy codebases that still use GBK/GB2312/GB18030, Big5, Shift-JIS, EUC-KR, Windows codepages, UTF-16, and other non-UTF-8 encodings.

This is now the single recommended installation path for end users.

Windows

# Remove an older install with the same name first, if one exists.
claude mcp remove codepage-bridge -s user

# Register the npm package once, at user scope. `cmd` is required on Windows.
claude mcp add --scope user codepage-bridge -- cmd /d /s /c "npx -y codepage-bridge-mcp"
claude mcp get codepage-bridge

macOS / Linux

# Remove an older install with the same name first, if one exists.
claude mcp remove codepage-bridge -s user

# Register the npm package once, at user scope.
claude mcp add --scope user codepage-bridge -- npx -y codepage-bridge-mcp
claude mcp get codepage-bridge

What this requires locally:

  • claude

  • node

What it does not require:

  • git clone

  • npm install

  • npm run build

  • downloading a GitHub Release package first

Avoid duplicate MCP registrations

Register codepage-bridge in only one scope. Claude Code treats the same server name with different commands as a configuration conflict—for example, an older user-scoped local build and this repository's project-scoped .mcp.json npm command.

Run claude mcp list to diagnose duplicates. Keep the endpoint you want, then remove the other registration:

# Keep the npm command from the user-scoped installation.
claude mcp remove codepage-bridge -s project

# Or keep a project-local configuration and remove a previous user installation.
claude mcp remove codepage-bridge -s user

After removing a registration, run claude mcp get codepage-bridge again. It must report one endpoint with status Connected.

Large text files

Read and Grep allow individual text files up to 32 MiB by default. To use a different limit, set CODEPAGE_BRIDGE_MAX_TEXT_FILE_MIB to a positive integer before starting Claude Code:

setx CODEPAGE_BRIDGE_MAX_TEXT_FILE_MIB 64

Restart Claude Code after changing the variable. Larger files require proportionally more Node.js memory while decoding, splitting lines, and matching regular expressions.


Related MCP server: vulcan-file-ops

Why

Claude Code built-in file tools assume UTF-8 for normal text reads. In legacy projects this can lead to:

  • unreadable C/C++ comments and string literals;

  • searches that silently miss text;

  • edits that corrupt the original codepage;

  • accidental UTF-8 rewrites of GBK or other legacy files.

Codepage Bridge keeps encoding conversion below the model boundary:

legacy bytes on disk -> decode by .encoding-rules -> Unicode for the LLM
Unicode from the LLM -> strict encode by .encoding-rules -> legacy bytes on disk

If new text cannot be represented in the target encoding, the write fails instead of silently replacing characters with ?.


Required Claude Code configuration

Installing the MCP is not sufficient by itself.

Claude Code may still choose its built-in:

  • Read

  • Grep

  • Edit

  • Write

  • NotebookEdit

Those tools bypass .encoding-rules.

Step 1 — merge settings.fragment.json

Merge this into your existing ~/.claude/settings.json:

{
  "permissions": {
    "allow": [
      "mcp__codepage-bridge__Read",
      "mcp__codepage-bridge__Grep",
      "mcp__codepage-bridge__Edit",
      "mcp__codepage-bridge__Write"
    ],
    "deny": [
      "Read",
      "Grep",
      "Edit",
      "Write",
      "NotebookEdit"
    ]
  }
}

Template file:

  • examples/claude-config/settings.fragment.json

Do not replace your whole settings file unless it is empty. Merge these arrays into your existing configuration.

Step 2 — add a CLAUDE.md policy

Add this to the project CLAUDE.md, or to ~/.claude/CLAUDE.md for a global policy:

## File encoding policy

Use Codepage Bridge for all project file content operations:

- Read with `mcp__codepage-bridge__Read`.
- Search with `mcp__codepage-bridge__Grep`.
- Edit with `mcp__codepage-bridge__Edit`.
- Create or completely rewrite with `mcp__codepage-bridge__Write`.

Do not use built-in Read, Grep, Edit, Write, NotebookEdit, shell commands,
PowerShell commands, or scripts as substitutes for project file content access.
Glob may only be used to discover paths.

Do not manually transcode files or normalize line endings. `.encoding-rules`
is the source of truth.

Template file:

  • examples/minimal-project/CLAUDE.md

Step 3 — add .encoding-rules

.encoding-rules is optional. When it is absent, Codepage Bridge treats the target file's directory as the allowed root and reads/writes using strict UTF-8. Add a rules file whenever the project contains legacy-encoded files or needs a shared project root.

Example:

# Last matching rule wins
*.c gbk
*.cpp gbk
*.h gbk
legacy/**/*.txt windows-1251
assets/**/*.csv shift_jis
**/*.json utf8

# Cancel earlier matches and return to strict UTF-8
!SourceCode/generated/**

Template file:

  • examples/minimal-project/.encoding-rules

Rules:

  • Empty lines and lines beginning with # are ignored.

  • *, **, and ? use glob semantics.

  • Patterns without /, such as *.cpp, match basenames at every directory depth.

  • Patterns containing / are relative to the .encoding-rules directory.

  • The last matching rule wins.

  • !pattern cancels previous matches and selects strict UTF-8.

  • Files with no matching rule use strict UTF-8.

  • The nearest .encoding-rules is used; its directory is the allowed project root.


Verify the setup

1. Check the MCP is connected

claude mcp get codepage-bridge

Expected:

  • name: codepage-bridge

  • status: Connected

2. Start a fresh Claude Code session in a legacy project

3. Ask Claude to read or search a legacy-encoded file

Examples:

Read SourceCode/Main.cpp and show the first 10 lines.
Search SourceCode for the string 错误码.

4. Confirm the model uses Codepage Bridge tools

In a verbose / print-mode session, the tool call should be one of:

  • mcp__codepage-bridge__Read

  • mcp__codepage-bridge__Grep

  • mcp__codepage-bridge__Edit

  • mcp__codepage-bridge__Write

It should not call built-in Read, Grep, Edit, or Write.


Features

  • Encoding-aware Read, Grep, Edit, and Write tools.

  • Project-level .encoding-rules with gitignore-like glob behavior.

  • The nearest .encoding-rules defines both the project root and active rules.

  • Last matching rule wins; !pattern resets matching files to strict UTF-8.

  • Basename patterns such as *.cpp match at every directory depth.

  • Strict UTF-8 fallback for files not matched by a rule.

  • GBK/GB2312/GB18030, Big5, Shift-JIS, EUC-KR, Windows codepages, UTF-8, and UTF-16 support.

  • BOM and dominant line-ending preservation for edits.

  • Read-before-write protection and stale-write detection using byte hashes.

  • Atomic temporary-file writes and per-path write locks.

  • Symlink and project-root boundary checks.

  • Image, PDF, and Jupyter Notebook reading.

  • Grep output modes, context lines, glob/type filters, regex flags, and pagination.

  • Large-file partial edit authorization: the model only needs to read the target lines it wants to edit, not the entire file.

  • Token-frugal results: Edit and Write return a one-line confirmation, and Read returns only the line-numbered text once, so no tool echoes file contents the model already has.

  • Line endings are transparent: Read states the file's CRLF/LF/CR style up front, Edit and Write accept either convention and keep the file's own style, and every result names the style it preserved.


Development

npm install
npm run check
npm test
npm run build
npm start

License

MIT. See LICENSE.

Available Tools

4 tools
EditPerforms exact string replacements in files.A

Performs exact string replacements in files.

Usage:

  • You must use your Read tool at least once in the conversation before editing. This tool will error if you attempt an edit without reading the file.

  • When editing text from Read tool output, ensure you preserve the exact indentation (tabs/spaces) as it appears AFTER the line number prefix. The line number prefix format is: line number + tab. Everything after that is the actual file content to match. Never include any part of the line number prefix in the old_string or new_string.

  • ALWAYS prefer editing existing files in the codebase. NEVER write new files unless explicitly required.

  • Only use emojis if the user explicitly requests it. Avoid adding emojis to files unless asked.

  • The edit will FAIL if old_string is not unique in the file. Either provide a larger string with more surrounding context to make it unique or use replace_all to change every instance of old_string.

  • Use replace_all for replacing and renaming strings across the file. This parameter is useful if you want to rename a variable for instance.

  • Line endings are handled for you: old_string and new_string may use either LF or CRLF, and the file keeps its own style on disk. Never inspect or rewrite a file just to fix line endings.

  • The success message states the encoding and line endings that were preserved. That is authoritative; no follow-up read or shell check is needed.

Inputs: file_path (required), new_string (required), old_string (required), replace_all.

GrepA powerful search tool built on regular expressions.A

A powerful search tool for file contents.

Usage:

  • ALWAYS use Grep for search tasks. NEVER invoke grep or rg as a Bash command.

  • Supports full regular expressions, file glob filters, file type filters, context lines, match-only output, multiline matching, pagination, file lists, and per-file counts.

  • Use output_mode=files_with_matches when you only need file paths; this is the default.

  • Use output_mode=content to see matching lines. Line numbers are included by default.

  • Use output_mode=count to see match counts per file.

  • scan_mode=exact is the default: pagination never stops scanning, so counts are exact when scanComplete is true. scan_mode=fast is opt-in and only valid for files_with_matches; it stops each matching file at its first match and reports countsExact=false.

  • Results are limited to 250 entries by default; use head_limit and offset for pagination. Check structuredContent scanComplete, truncationReason, and outputTruncated whenever a search is resource-limited.

  • Every file is decoded according to its nearest project .encoding-rules, so legacy encoded content is searched as Unicode transparently.

Inputs: pattern (required), -A, -B, -C, +12 more.

ReadRead a file from the local filesystem.A

Reads a file from the local filesystem. You can access any file directly by using this tool. Assume this tool is able to read all files on the machine. If the User provides a path to a file assume that path is valid. It is okay to read a file that does not exist; an error will be returned.

Usage:

  • The file_path parameter must be an absolute path, not a relative path

  • By default, it reads up to 2000 lines starting from the beginning of the file. Files larger than 256KB will return an error; use offset and limit for larger files

  • When you already know which part of the file you need, only read that part. This can be important for larger files.

  • Results are returned using cat -n format, with line numbers starting at 1

  • This tool allows Claude Code to read images (eg PNG, JPG, etc). When reading an image file the contents are presented visually as Claude Code is a multimodal LLM.

  • This tool can read PDF files (.pdf). For large PDFs (more than 10 pages), you MUST provide the pages parameter to read specific page ranges (e.g., pages: "1-5"). Reading a large PDF without the pages parameter will fail. Maximum 20 pages per request.

  • This tool can read Jupyter notebooks (.ipynb files) and returns all cells with their outputs, combining code, text, and visualizations.

  • This tool can only read files, not directories. To read a directory, use an ls command via the Bash tool.

  • You will regularly be asked to read screenshots. If the user provides a path to a screenshot, ALWAYS use this tool to view the file at the path. This tool will work with all temporary file paths.

  • If you read a file that exists but has empty contents you will receive a system reminder warning in place of file contents.

  • The first result line reports the file path, the line range you received, the encoding, and the file's line-ending style (CRLF, LF, or CR). Trust it; do not probe with Bash, od, file, or a second Read to learn any of those.

  • Content is always returned with LF line endings. A trailing newline is not shown as an extra empty line, so a 3-line file reports 3 lines.

Inputs: file_path (required), limit, pages, offset.

WriteWrite a file to the local filesystem.A

Writes a file to the local filesystem.

Usage:

  • This tool will overwrite the existing file if there is one at the provided path.

  • If this is an existing file, you MUST use the Read tool first to read the file's contents. This tool will fail if you did not read the file first.

  • Prefer the Edit tool for modifying existing files — it only sends the diff. Only use this tool to create new files or for complete rewrites.

  • NEVER create documentation files (*.md) or README files unless explicitly requested by the User.

  • Only use emojis if the user explicitly requests it. Avoid writing emojis to files unless asked.

  • Line endings and encoding are handled for you: content may use LF or CRLF and the existing file's style is kept. Never inspect or rewrite a file just to fix line endings.

  • The success message states the encoding and line endings that were preserved. That is authoritative; no follow-up read or shell check is needed.

Inputs: content (required), file_path (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.6/5.0

    Scored across 4 tools

    Disambiguation5/5

    Each tool maps to a single, well-known action on a distinct target: Grep searches contents, Read retrieves, Edit performs targeted replacement, Write creates or fully overwrites. The descriptions explicitly steer between Edit and Write (prefer Edit for existing files) and between Grep and shell grep, leaving no realistic misselection path.

    Naming Consistency5/5

    All four names are single TitleCase verbs (Grep, Edit, Write, Read) using one uniform convention with no verbs/nouns mixed. The pattern is immediately predictable even though it is verb-only rather than verb_noun.

    Tool Count4/5

    Four tools is a lean but defensible core for a file-operations-oriented server, and each earns its place. It sits at the thin edge: there is no directory listing or glob tool, so agents must infer the filesystem layout from search results alone.

    Completeness3/5

    Read/Write/Edit/Grep cover the basic lifecycle of reading and modifying file contents, including the encoding-preservation angle the server advertises. However, there is no way to list or traverse directories, delete/move files, or explicitly convert a file's encoding, and Read cannot handle directories while no Bash tool is provided as a fallback — a notable gap that will cause dead ends.

    Maintenance

    ActivityNo data
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers