native - MCP Translation Server
A stdio-based MCP (Model Context Protocol) server that provides translation
between Chinese and English using the Youdao translation API.
Features
-
Dual Mode Operation
- Pure text mode: Pipe text directly for translation
- MCP protocol mode: Full JSON-RPC MCP support
-
Auto Language Detection
- Automatically detects source language (Chinese/English)
- Translates to the opposite language by default
-
Youdao Translation API
- Uses the free public Youdao API
- No API key required
Installation
go build -o native main.go
Usage
Pure Text Mode
Pipe plain text to get translation:
# English to Chinese
echo "hello world" | ./native
# Output: 你好世界
# Chinese to English
echo "你好世界" | ./native
# Output: hello world
MCP Protocol Mode
Use via any MCP-compatible client (e.g., Claude Desktop):
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "translate",
"arguments": {
"text": "hello world"
}
}
}
Response:
{
"original_text": "hello world",
"translated_text": "你好世界",
"source_lang": "en",
"target_lang": "zh-CN"
}
Arguments:
| Name |
Type |
Required |
Description |
| text |
string |
Yes |
Text to translate |
| source_lang |
string |
No |
Source language (en, zh-CN) |
| target_lang |
string |
No |
Target language (en, zh-CN) |
Project Structure
native/
├── main.go # Entry point with mode detection
├── go.mod
├── go.sum
├── LICENSE # MIT License
├── .gitignore
├── .markdownlint.json
├── README.md
└── pkgs/
├── domain/ # Business entities
│ ├── entity.go
│ └── repository.go
├── application/ # Use cases
│ └── service.go
└── infrastructure/ # External implementations
└── translator/
└── youdao.go
Architecture
The project follows Domain-Driven Design (DDD) principles:
- Domain Layer: Business entities and repository interfaces
- Application Layer: Use cases and orchestration
- Infrastructure Layer: External service implementations (Youdao API)
Logging
Logs are written to ~/logs/native-mcp.log to avoid polluting stdio.
License
MIT License - see LICENSE for details.