Translate source code with Gemma, then review and fix it with Claude or Codex — usable as a library, a CLI, or an MCP server.
The pipeline has three stages:
- Translate —
google-genaiwith Gemma (defaultgemma-4-26b-a4b-it, any model overridable). - Validate — per-language compiler/AST + linter plugins (run whatever toolchains are installed).
- Review/fix — your choice of
claude(Claude Agent SDK,claude-opus-4-8, effortmax) orcodex(thecodexCLI, latest model, reasoning efforthigh), looping until the validators pass.
pip install -e . # installs the `code-translator` and `code-translator-mcp` scriptspip install -e . is what registers the code-translator and code-translator-mcp
console scripts. Until you install, you can run the tool directly without installing:
python code-translator.py ... # same as the `code-translator` script
python -m code_translator ... # equivalent
python -m code_translator.mcp_server # same as `code-translator-mcp`Credentials:
- Gemma/translation needs
GEMINI_API_KEYin the environment or a.envfile (searched in./.env,./src/.env, and the repo root). - Claude review uses the logged-in
claudeCLI (claude login); no API key in the repo. - Codex review uses the logged-in
codexCLI (codex login).
Run code-translator doctor to see which reviewers and language toolchains are available.
# Translate only (Gemma)
code-translator translate src/balloon.c zig -o balloon.zig
# Full pipeline: translate -> validate -> review/fix -> deliver
code-translator run src/balloon.c zig --reviewer claude -o balloon.zig
code-translator run src/balloon.c c --reviewer codex -o balloon_out.c
# Review/fix an existing translation
code-translator review balloon.zig -l zig --reviewer claude -s src/balloon.c
# Environment report
code-translator doctor--reviewer is required for review/run — you choose the provider, every time.
The MCP server exposes the same pipeline as tools any MCP-capable agent can call. It speaks
stdio and is named code-translator.
code-translator-mcp # stdio server; or: python -m code_translator.mcp_serverLong-running tools.
review_codeandtranslate_and_review_codedrive Claude/Codex at max effort, looping up tomax_iterationstimes, so a single call can run for several minutes. The server streams every stage as an MCP progress + log notification, which resets the client's per-call timeout and shows live progress — so the default ~120s ceiling no longer trips them. For very large jobs you can still raise the client's tool timeout (in Claude Code,MCP_TOOL_TIMEOUT), or lowermax_iterations.
Claude Code (one-liner):
claude mcp add code-translator -- code-translator-mcp
# not installed? point it at the module via your venv python:
claude mcp add code-translator -- /path/to/.venv/bin/python -m code_translator.mcp_serverClaude Desktop / generic MCP client (mcpServers config). Use the installed script…
{
"mcpServers": {
"code-translator": {
"command": "code-translator-mcp",
"env": { "GEMINI_API_KEY": "your-key" }
}
}
}…or, without installing, run the module directly (set cwd to the repo so .env is found):
{
"mcpServers": {
"code-translator": {
"command": "python",
"args": ["-m", "code_translator.mcp_server"],
"cwd": "C:/Users/Rudy/Desktop/Projects/code-translator",
"env": { "GEMINI_API_KEY": "your-key" }
}
}
}The Claude/Codex reviewers authenticate through their own logged-in CLIs (
claude login,codex login) on the host running the server — no keys go in the MCP config. OnlyGEMINI_API_KEY(for translation) is needed there, and only if it isn't already in a.env.
| Tool | Required args | Optional args | Returns |
|---|---|---|---|
translate_code |
source_code, target_language |
source_language, source_path, model (default gemma-4-26b-a4b-it) |
{ code, model, target_language, log } |
review_code |
code, target_language, reviewer |
source_code, model, max_iterations (3) |
{ code, reviewer, model, iterations, fixed, validation_ok, remaining[], log } |
translate_and_review_code |
source_code, target_language, reviewer |
source_language, source_path, translate_model, review_model, max_iterations (3) |
{ code, translation_model, reviewer, review_model, iterations, fixed, validation_ok, remaining[], log } |
list_supported_languages |
— | — | { languages: [ { language, validators: [ { validator, tool, available } ] } ] } |
list_reviewers |
— | — | { reviewers: [ { name, default_model, available } ] } |
revieweris required for any review and must be"claude"or"codex"— the agent chooses, there is no default. Calllist_reviewersfirst to see which are available.target_languageaccepts canonical names or common aliases:python/py,c,cpp/c++,zig,go/golang,rust/rs,javascript/js,typescript/ts,java.- Each
remaining[]item is{ message, severity, line, column, tool }— these are compiler/AST errors the reviewer could not resolve withinmax_iterations.
- (Optional) Call
list_reviewers/list_supported_languagesto confirm what's available. - For a one-shot translation with review, call
translate_and_review_codewithsource_code,target_language, andreviewer. For an existing translation you want checked/fixed, callreview_codeand pass the original assource_codefor context. - Inspect
validation_ok:true→ the deliveredcodepasses every installed validator (or only validators whose toolchain is missing were skipped). Use it.false→ readremaining[]. Retry with a highermax_iterations, switchreviewer, or surface the diagnostics to the user.
fixedsays whether the reviewer changed anything;iterationsis how many passes ran;logis a human-readable stage list you can stream to the user as progress.
Example call:
{
"name": "translate_and_review_code",
"arguments": {
"source_code": "int add(int a, int b) { return a + b; }",
"target_language": "zig",
"reviewer": "claude"
}
}from code_translator import translate, review, translate_and_review
result = translate_and_review(open("src/balloon.c").read(), "zig", reviewer="claude",
source_path="src/balloon.c")
print(result.code)Validators are defined for python, c, c++, zig, go, rust, javascript, typescript, and java.
Each uses that language's real tooling (e.g. clang -fsyntax-only, zig ast-check,
rustc --emit=metadata, node --check, Python's built-in compiler). A missing toolchain
is skipped with a warning, never a hard failure — install the compiler to turn that
language's checks on with no code change.