|
| 1 | +# che-cn2tw-mcp |
| 2 | + |
| 3 | +Swift native MCP Server for converting Chinese Mainland terms to Taiwanese Mandarin equivalents. |
| 4 | + |
| 5 | +Detects and replaces mainland Chinese vocabulary with Taiwan-standard phrasing, powered by dictionaries from g0v (MOE data) and Wikipedia. |
| 6 | + |
| 7 | +## Build |
| 8 | + |
| 9 | +Requires Swift 5.9+ and macOS 13+. |
| 10 | + |
| 11 | +```bash |
| 12 | +git clone https://github.com/kiki830621/che-cn2tw-mcp.git |
| 13 | +cd che-cn2tw-mcp |
| 14 | +swift build -c release |
| 15 | +``` |
| 16 | + |
| 17 | +Binary location: `.build/release/CheCn2TwMCP` |
| 18 | + |
| 19 | +## Installation |
| 20 | + |
| 21 | +### Option A: Claude Code CLI |
| 22 | + |
| 23 | +```bash |
| 24 | +claude mcp add che-cn2tw-mcp -s user -- /path/to/.build/release/CheCn2TwMCP |
| 25 | +``` |
| 26 | + |
| 27 | +Verify: |
| 28 | + |
| 29 | +```bash |
| 30 | +claude mcp get che-cn2tw-mcp |
| 31 | +# Should show: Status: ✓ Connected |
| 32 | +``` |
| 33 | + |
| 34 | +### Option B: Edit config directly |
| 35 | + |
| 36 | +Add to `~/.claude.json`: |
| 37 | + |
| 38 | +```json |
| 39 | +{ |
| 40 | + "mcpServers": { |
| 41 | + "che-cn2tw-mcp": { |
| 42 | + "type": "stdio", |
| 43 | + "command": "/path/to/.build/release/CheCn2TwMCP" |
| 44 | + } |
| 45 | + } |
| 46 | +} |
| 47 | +``` |
| 48 | + |
| 49 | +### Option C: Claude Desktop |
| 50 | + |
| 51 | +Add to `~/Library/Application Support/Claude/claude_desktop_config.json`: |
| 52 | + |
| 53 | +```json |
| 54 | +{ |
| 55 | + "mcpServers": { |
| 56 | + "che-cn2tw-mcp": { |
| 57 | + "command": "/path/to/.build/release/CheCn2TwMCP" |
| 58 | + } |
| 59 | + } |
| 60 | +} |
| 61 | +``` |
| 62 | + |
| 63 | +## First Run |
| 64 | + |
| 65 | +After connecting, run `update_dictionary` to download term data: |
| 66 | + |
| 67 | +``` |
| 68 | +update_dictionary # Download from all sources |
| 69 | +update_dictionary source=g0v # g0v only |
| 70 | +update_dictionary source=wikipedia # Wikipedia only |
| 71 | +``` |
| 72 | + |
| 73 | +Dictionary files are stored at `~/.che-cn2tw-mcp/`. |
| 74 | + |
| 75 | +## Tools (8) |
| 76 | + |
| 77 | +### Text Conversion |
| 78 | + |
| 79 | +| Tool | Description | |
| 80 | +|------|-------------| |
| 81 | +| `convert_text` | Detect and replace mainland terms in text, returns converted text + change list | |
| 82 | +| `lookup_term` | Look up a single term (supports both CN→TW and TW→CN) | |
| 83 | +| `search_terms` | Fuzzy search the dictionary | |
| 84 | + |
| 85 | +### Dictionary Management |
| 86 | + |
| 87 | +| Tool | Description | |
| 88 | +|------|-------------| |
| 89 | +| `update_dictionary` | Download/refresh dictionary from online sources (g0v, Wikipedia) | |
| 90 | +| `add_term` | Add a custom CN→TW mapping (saved to `~/.che-cn2tw-mcp/custom.json`) | |
| 91 | +| `remove_term` | Remove a custom mapping | |
| 92 | + |
| 93 | +### Info |
| 94 | + |
| 95 | +| Tool | Description | |
| 96 | +|------|-------------| |
| 97 | +| `list_categories` | List all term categories with counts | |
| 98 | +| `get_stats` | Show dictionary stats (entry count, sources, last update) | |
| 99 | + |
| 100 | +## Data Sources |
| 101 | + |
| 102 | +| Source | Format | Scale | |
| 103 | +|--------|--------|-------| |
| 104 | +| g0v/moedict-data-csld (`=同實異名.json`) | JSON | ~750 pairs | |
| 105 | +| g0v/moedict-data-csld (同實異名.csv) | CSV | ~1,000 pairs | |
| 106 | +| Wikipedia (兩岸四地用語差異, 海峽兩岸術語差異) | Wikitext | Community-maintained | |
| 107 | +| User custom (`~/.che-cn2tw-mcp/custom.json`) | JSON | Unlimited | |
| 108 | + |
| 109 | +## Usage Examples |
| 110 | + |
| 111 | +Once connected, ask Claude things like: |
| 112 | + |
| 113 | +- "幫我把這段文字轉成台灣用語:这个视频的质量很高" |
| 114 | +- "查一下「軟件」的台灣說法" |
| 115 | +- "搜尋跟「網路」有關的對照詞彙" |
| 116 | +- "新增自訂對照:信息 → 資訊" |
| 117 | +- "更新詞庫" |
| 118 | +- "顯示詞庫統計" |
| 119 | + |
| 120 | +## Architecture |
| 121 | + |
| 122 | +``` |
| 123 | +Sources/ |
| 124 | +├── CheCn2TwMCP/ |
| 125 | +│ └── main.swift # Entry point |
| 126 | +└── CheCn2TwMCPCore/ |
| 127 | + ├── Server.swift # MCP Server (8 tools + dispatch) |
| 128 | + ├── TermDictionary.swift # Dictionary load/save/search/convert |
| 129 | + └── DictionaryUpdater.swift # Online fetcher (g0v + Wikipedia) |
| 130 | +``` |
| 131 | + |
| 132 | +- **No third-party dependencies** beyond MCP Swift SDK |
| 133 | +- Uses `URLSession` for all HTTP requests |
| 134 | +- Longest-match-first algorithm prevents substring false positives |
| 135 | +- Custom terms override built-in dictionary entries |
| 136 | + |
| 137 | +## How It Works |
| 138 | + |
| 139 | +The `convert_text` tool uses a **longest-match-first** algorithm: |
| 140 | + |
| 141 | +1. Sort all CN terms by length (descending) |
| 142 | +2. Scan through input text, matching the longest term first |
| 143 | +3. Track replaced positions to avoid overlapping replacements |
| 144 | +4. Return converted text + a change list with positions |
| 145 | + |
| 146 | +``` |
| 147 | +Input: "這個視頻的質量很高" |
| 148 | +Output: "這個影片的品質很高" |
| 149 | +Changes: [ |
| 150 | + { "視頻" → "影片", position: 3 }, |
| 151 | + { "質量" → "品質", position: 6 } |
| 152 | +] |
| 153 | +``` |
| 154 | + |
| 155 | +## License |
| 156 | + |
| 157 | +MIT |
0 commit comments