Skip to content

Security fixes, new MCP tools, and quality improvements#1

Open
tomehb wants to merge 6 commits intoDatanoiseTV:mainfrom
tomehb:main
Open

Security fixes, new MCP tools, and quality improvements#1
tomehb wants to merge 6 commits intoDatanoiseTV:mainfrom
tomehb:main

Conversation

@tomehb
Copy link

@tomehb tomehb commented Dec 29, 2025

Summary

This PR includes critical security fixes, new features, and quality improvements for the translator-ai MCP server.

Security Fixes (Critical)

Command Injection Vulnerability - The MCP server used exec() with string interpolation, allowing arbitrary command execution:

// BEFORE (vulnerable)
const cmd = `translator-ai ${inputFile} -l ${targetLanguage}`;
await execAsync(cmd);  // Injection possible!

// AFTER (secure)
await execFileAsync('translator-ai', [inputFile, '-l', targetLanguage]);

Changes:

  • Replace exec() with execFile() - no shell interpretation
  • Add input validation for file paths and language codes
  • Use argument arrays instead of string interpolation

New Features

3 New MCP Tools

Tool Description
detect_language Detect source language of a JSON file
validate_translation Verify translated file has all keys from source
translate_string Translate a single text string

Context Parameter

  • All translation tools now accept a context parameter for cultural adaptation
  • Example: "Use formal Spanish, Latin American dialect"

Provider/Model Info

  • MCP responses now show which AI provider and model was used
  • Example: Provider: gemini | Model: gemini-3-flash-preview

Bug Fixes

  • Fix uninitialized variable in ollama.ts extraction strategies
  • Remove outdated @ts-ignore in gemini.ts (type now exists in SDK v0.24.1)
  • Fix path validation rejecting valid {lang} placeholder in output paths

Configuration & Tests

  • Rename jest.config.js → jest.config.cjs for ESM compatibility
  • Add moduleNameMapper to resolve .js imports in tests
  • Update npm start to use compiled dist (fixes integration tests)
  • All 139 tests passing

Documentation

  • Add npm link instructions for MCP server development setup
  • Document all 5 MCP tools with examples
  • Add fork notice with funding link for original developer

Attribution

This PR was developed with AI assistance (Claude Code). All changes have been human-reviewed and tested

tomehb and others added 6 commits December 28, 2025 20:51
- Migrate from CommonJS to ESM (Node16 module system)
- Add --context CLI flag for custom translation instructions
- Add context parameter to MCP tools for cultural adaptation
- Update default Gemini model to gemini-3-flash-preview
- Add GEMINI_MODEL and OPENAI_MODEL environment variable support
- Rewrite README with MCP-first focus and cultural adaptation examples
- Support multi-language translation in single MCP call

Examples of context usage:
- "Use Latin American Spanish, informal tone"
- "Adapt idioms for Japanese culture"
- "Target audience: medical professionals"

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add detect_language tool for source language detection
- Add validate_translation tool for translation completeness verification
- Add translate_string tool for single string translations
- Add fork notice and prominent funding link for original developer
- Document all 5 MCP tools in README

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The MCP server requires the translator-ai CLI to be globally available.
Added clear instructions explaining npm link is required after building.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
All MCP tools now display which AI provider and model was used:
- translate_json: Shows provider/model on success and error
- translate_multiple: Shows provider/model in output
- detect_language: Shows provider/model with detected language
- translate_string: Shows provider/model with translation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Security (CRITICAL):
- Replace exec() with execFile() to prevent command injection attacks
- Add input validation for file paths (path traversal prevention)
- Add language code validation (format verification)
- Add context validation (length limits)
- Use argument arrays instead of string interpolation in shell commands

Bug Fixes:
- Fix uninitialized variable in ollama.ts extraction strategies
- Remove outdated @ts-ignore in gemini.ts (responseMimeType now in types)

Configuration:
- Rename jest.config.js to jest.config.cjs for ESM compatibility

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Path Validation:
- Remove overly aggressive shell metacharacter blocking that rejected {lang} placeholder
- Since we use execFile (not exec), shell metacharacters are safe

Jest Configuration:
- Add moduleNameMapper to resolve .js imports to .ts files
- Configure ts-jest with CommonJS mode for test compatibility
- Fix npm start to use compiled dist instead of ts-node

Test Fixes:
- Update geminiModel tests to expect gemini-3-flash-preview (new default)
- Update multiFile integration tests to match current output format

All 139 tests now pass.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant