
I18n Codelens Mcp
io.github.hepter由 GitHub 帳號 hepter 發布v2.0.0更新於 Oct 24, 2026
Inspect, audit and safely edit i18n locale JSON files from AI agents.
概覽
讓助理不必把整個語系檔載入上下文,就能檢查、稽核並安全編輯專案中的 i18n 語系 JSON 檔案。
- 可以做什麼
- 透過 stdio 提供十個工具處理翻譯檔案:專案資訊、讀取翻譯、搜尋鍵、列出某個原始碼檔用到的鍵、找出鍵在程式碼中的引用,以及稽核缺少、未使用、佔位符不一致或未翻譯的鍵。寫入類工具可依語系建立或更新鍵、刪除鍵、重新命名鍵或搬移命名空間,並正規化格式。結果都是精簡的單行 JSON,寫入時會保留檔案結構、縮排與換行字元。
- 適用情境
- 適合把翻譯存放在語系 JSON 檔的專案,希望助理不用貼上整個檔案就能讀取、稽核或更新翻譯。常見情境包括為所有語系新增一個鍵、補齊缺少的翻譯,或檢查哪些鍵沒有被使用、哪些在程式碼中被引用。
- 執行需求
- 需要 Node.js 20 或更新版本,以及支援 stdio 伺服器的 MCP 用戶端,透過 npx 執行。語系資源必須是 JSON 檔。專案根目錄取自 WORKSPACE_ROOT、CLAUDE_PROJECT_DIR 或目前工作目錄,I18N_GLOB 與 I18N_CODE_GLOB 決定掃描範圍。未宣告任何驗證機制。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 I18n Codelens Mcp,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
i18n-codelens-mcp
Model Context Protocol (MCP) server for i18n translation files. It lets AI agents (Claude Code, Cursor, Antigravity, GitHub Copilot, Codex, Gemini CLI and any other MCP client) inspect, audit and safely edit locale JSON files without ever loading a whole locale file into the model context.
- Compact by design. Ten tools, single-line JSON results, no echoed input,
limit/includeValueseverywhere. A typical read costs 50-200 tokens. - Safe by construction. No write path can reduce a locale file's key set; mixed flat/nested files are edited in place, never converted; upserts report conflicts instead of overwriting.
- Current MCP. Built on the TypeScript SDK v2: protocol revision 2026-07-28 and the 2025 revisions, server instructions, prompts (slash commands), cache hints and elicitation-based confirmation for destructive tools.
- Any layout.
locales/en.json,locales/en-US.json,messages.en.jsonand i18next-stylelocales/en/common.json(namespace files, keys ascommon:nav.home).
This package is also the MCP backend of the i18n CodeLens VS Code extension.
Requirements
- Node.js 20 or newer
- Locale resources as JSON files
- An MCP client that supports stdio servers
Install
Client setup
Every command below registers the same thing: a stdio server named i18n-codelens running npx -y i18n-codelens-mcp. Pick your client, run one line, done.
The server needs to know which project to work on. Most clients start it in the project directory, and Claude Code passes the project root explicitly, so nothing else is needed. When your client starts the server from somewhere else, add the project path with the client's env flag, for example -e WORKSPACE_ROOT=/absolute/path/to/project.
Windows PowerShell: PowerShell can swallow a bare
--before it reaches the CLI, which then reportsunknown option '-y'. If that happens, quote the separator as'--', or run the command fromcmd, Git Bash or WSL.
Claude Code
Claude Code sets CLAUDE_PROJECT_DIR for stdio servers, so the server always finds the right project. Its tool-search feature defers MCP tools; i18n_upsert_translations and i18n_get_translations are marked anthropic/alwaysLoad so the two everyday tools need no lookup. The prompts show up as /i18n-codelens:audit, /i18n-codelens:add-key and /i18n-codelens:translate-missing.
Manual configuration
Project scope is .mcp.json in the repository root:
Google Antigravity
agy mcp list, agy mcp disable i18n-codelens and agy mcp remove i18n-codelens manage it afterwards. Inside the IDE, /mcp opens the MCP manager.
Manual configuration
Global is ~/.gemini/config/mcp_config.json (Windows: %USERPROFILE%\.gemini\config\mcp_config.json), per project .agents/mcp_config.json. In the IDE: … → MCP Servers → Manage MCP Servers → View raw config.
Antigravity also accepts disabled: true and disabledTools: ["i18n_format_resources"] per server.
Gemini CLI
Use -s project to write the project's settings instead. Gemini takes the command and its arguments positionally, so no -- is needed.
OpenAI Codex CLI
Manual configuration
~/.codex/config.toml:
VS Code and Copilot Chat
That writes the user profile. MCP: Add Server in the Command Palette does the same through a guided flow and can target the workspace.
Manual configuration
.vscode/mcp.json in the repository, which you can commit:
OpenCode
Manual configuration
opencode.json in the project root, or ~/.config/opencode/opencode.json:
GitHub Copilot CLI
Copilot CLI adds servers from inside a session rather than from the shell. Start copilot, then:
Fill in the form: Server Name i18n-codelens, Server Type STDIO, Command npx -y i18n-codelens-mcp. /mcp, /mcp show i18n-codelens and /mcp delete i18n-codelens manage it afterwards.
Manual configuration
User level is ~/.copilot/mcp-config.json; for a repository commit .github/mcp.json, or drop an uncommitted .mcp.json at the project root.
Cursor, Windsurf, Claude Desktop, Kiro, Cline and Roo Code
These clients have no command to add a server, so the configuration file is the way in. The shape is the same everywhere; only the path differs.
Cursor and Windsurf
.cursor/mcp.json in the project or ~/.cursor/mcp.json; Windsurf uses ~/.codeium/windsurf/mcp_config.json.
cursor-agent mcp list and cursor-agent mcp enable i18n-codelens manage it from the terminal once it is configured.
Claude Desktop
Open Settings → Developer → Edit Config.
Kiro
Command palette: Kiro: Open workspace MCP config (JSON) for .kiro/settings/mcp.json, or the user config at ~/.kiro/settings/mcp.json.
Zed
~/.config/zed/settings.json, or .zed/settings.json for the team. Zed calls MCP servers context_servers.
Cline and Roo Code
Open the extension panel → MCP Servers → Configure MCP Servers. Cline writes cline_mcp_settings.json, Roo Code mcp_settings.json or .roo/mcp.json per project.
Sharing with a team
Commit a project-level configuration so every teammate and every agent picks up the same server without touching global settings.
Workspace root
Resolution order:
- Per-tool
workspaceDirargument (must be inside the configured root, see below) - CLI
--workspaceRoot <path>/--workspace-root <path> WORKSPACE_ROOTCLAUDE_PROJECT_DIR(set by Claude Code)- Current working directory
- Server package directory
The workspaceDir tool argument can only select a sub-directory of the configured root. A model cannot point the server at another directory on disk unless the server is started with I18N_ALLOW_ANY_WORKSPACE=1.
Configuration
Tools
All results are compact single-line JSON. Empty sections are omitted, paths are workspace-relative with forward slashes, and every list honours limit (default 50). Errors come back as isError text with the fix in the message (for example the list of available locales).
Confirmation for destructive tools
i18n_delete_keys, i18n_rename_key and i18n_format_resources preview by default. When the model omits dryRun and the client supports MCP elicitation (Claude Code does), the server shows the user a one-question dialog describing the change and applies it on accept. Pass dryRun:false to apply without a dialog, dryRun:true to only preview. i18n_upsert_translations needs no confirmation: it cannot remove keys and refuses to overwrite a differing value unless overwrite:true.
Prompts
The server publishes three prompts that clients expose as commands: audit (full audit and fix proposals), add-key <key> [text] (add one key with copy for every locale) and translate-missing [locale] (fill missing translations in batches).
Instructions
On connect the server sends usage instructions (under 2 KB) that clients such as Claude Code add to the system prompt: never edit locale files directly, call i18n_project_info once, upsert with every locale in one call, and so on. Project-specific rules (key naming, tone, placeholder style) still belong in your own CLAUDE.md / AGENTS.md.
Namespaced layouts
If locale files live in per-locale directories (locales/en/common.json, locales/tr/auth.json), the directory is the locale and the file is the namespace. Keys are addressed as namespace:key (common:nav.home); i18n_project_info reports keyFormat: "namespace:key" and the namespaces. Set I18N_NS_SEPARATOR if your i18n library uses another separator and I18N_DEFAULT_NS for keys written without one.
Files whose name is not a locale tag (config.json) are skipped with a warning, and when a glob matches the same locale twice (src/locales/en.json and public/locales/en.json) the first is used and i18n_project_info warns you to narrow I18N_GLOB.
Structure and key safety
A locale file is classified by how its leaves are stored: flat ("nav.home": "Home"), nested (objects) or mixed. Under I18N_STRUCTURE=auto a flat file is written flat, a nested file nested, and a mixed file is never converted: every key stays where it is and a new key is written in the file's dominant style. Writes preserve the file's indentation, line endings and trailing newline, so a single-key change is a single-line diff.
Two guards make key loss structurally impossible:
unflattenObjectthrows on a value/namespace collision (dashboard.announcementboth a string and a parent) instead of overwriting one side.- Every write compares the new document against the file on disk and refuses when a key would disappear. Deletes and renames declare their removals; anything else that goes missing aborts the write and names the keys.
The regression suite in src/__tests__/tools-write.test.ts and resource-manager.test.ts reproduces the incident that motivated this (a 3,000-key mixed file, a leaf that is also a namespace) and asserts zero loss and one-line diffs on every write path.
Migrating from 1.x
2.0 consolidates 18 tools into 10 and changes two defaults.
Other changes: Node 20+; @modelcontextprotocol/sdk replaced by @modelcontextprotocol/server 2.0 (protocol 2026-07-28 and 2025 revisions, both served); default ignore globs now skip common build output; workspaceDir is confined to the configured root; paths are posix; the code regex accepts ns:key and matches a call at the start of a file.
Suggested agent instruction block for projects that used the 1.x names:
MCP Registry
package.json carries mcpName: io.github.hepter/i18n-codelens-mcp and server.json describes the package. Publish with:
Programmatic API
Every tool is exported as a plain async function taking (args, ctx), alongside the building blocks: loadProject (cached, namespace-aware), getCodeIndex (cached code scan), createResourceManager (write states with the key-loss guard), writeFilePretty, flattenObject, unflattenObject, classifyResourceStructure.
Changelog
2.0.0
- SDK v2 / protocol 2026-07-28.
@modelcontextprotocol/serverwithserveStdio, zod 4, Node 20+. Both the 2026-07-28 and 2025 revisions are served on stdio.tools/listandprompts/listcarry cache hints. - Ten tools instead of eighteen, compact single-line results, no
structuredContent, no echoed arguments. Tool definitions shrank from 13.5 K to 9.5 K characters. Measured against 1.x on the same project, a two-locale code base of about 7,600 keys, a 50-hit key search dropped from 12.5 K to 2.3 K characters and a full audit from 6.7 K characters and 1.0 s to 2.0 K characters and 0.4 s. - Upsert semantics. Writes immediately, validates the whole batch before touching a file (an unknown locale rejects everything), reports conflicts instead of overwriting unless
overwrite:true, warns about locales without a value and about placeholder mismatches against the values other locales hold. - Confirmation dialogs. Delete, rename and format use MCP elicitation when the client supports it and fall back to a preview with a hint otherwise.
- Server instructions and prompts (
audit,add-key,translate-missing), server metadata (websiteUrl,description), version read frompackage.json. - Namespaced layouts (
{locale}/{namespace}.json, keys asns:key), locale detection from file or directory names, duplicate and non-locale file warnings. - Caches. Parsed locale files and code scans are reused while mtime/size are unchanged; the audit scans code once.
.gitignoreand common build directories are excluded before files are read. - Fixes. Code regex character range (
.-_accidentally spanned:…^) and start-of-file matches; posix paths on Windows;CLAUDE_PROJECT_DIRrespected;workspaceDirconfined to the root; writes preserve indentation and CRLF;getWorkspaceRootno longer logs on every call.
1.1.0
Fixed a data-loss defect: a single upsert could convert a mixed file and drop keys whose name was both a value and a namespace. Mixed files are no longer converted, unflattenObject/setNestedValue throw on collisions, and every write is guarded against key loss.
License
MIT © Mustafa Kuru
來源:README.md,提交 1848524
工具
0版本歷史
1- v2.0.0最新Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分