kanji_to_romaji
Transliterates Japanese kanji and kana text into Hepburn romaji, returning the romaji, hiragana reading, and original input.
Instructions
Transliterate Japanese text (kanji + kana mix) to Hepburn romaji.
Args: text: Japanese text. May contain kanji, hiragana, katakana, ASCII. Non-Japanese characters pass through unchanged.
Returns: dict with keys: - romaji: str (space-separated Hepburn romaji) - hiragana: str (kanji converted to hiragana, kana preserved) - input: str (echo of the original input)
Examples: kanji_to_romaji("山田太郎") → {"romaji": "yamada tarou", "hiragana": "やまだたろう"} kanji_to_romaji("東京駅") → {"romaji": "toukyou eki", "hiragana": "とうきょうえき"}
Caveats: - Kanji with multiple readings (e.g. proper nouns) may be ambiguous. The transliteration uses the most common reading, which is sometimes wrong for personal names. Use as a starting point, not a guarantee.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/japan_utils_mcp/server.py:177-208 (handler)The tool handler function for 'kanji_to_romaji'. Uses pykakasi to convert Japanese text (kanji + kana) to Hepburn romaji and hiragana.
@mcp.tool() def kanji_to_romaji(text: str) -> dict[str, Any]: """Transliterate Japanese text (kanji + kana mix) to Hepburn romaji. Args: text: Japanese text. May contain kanji, hiragana, katakana, ASCII. Non-Japanese characters pass through unchanged. Returns: dict with keys: - romaji: str (space-separated Hepburn romaji) - hiragana: str (kanji converted to hiragana, kana preserved) - input: str (echo of the original input) Examples: kanji_to_romaji("山田太郎") → {"romaji": "yamada tarou", "hiragana": "やまだたろう"} kanji_to_romaji("東京駅") → {"romaji": "toukyou eki", "hiragana": "とうきょうえき"} Caveats: - Kanji with multiple readings (e.g. proper nouns) may be ambiguous. The transliteration uses the most common reading, which is sometimes wrong for personal names. Use as a starting point, not a guarantee. """ results = _kakasi.convert(text) romaji = " ".join(r["hepburn"] for r in results if r["hepburn"]).strip() hira = "".join(r["hira"] for r in results) return { "romaji": romaji, "hiragana": hira, "input": text, } - The pykakasi instance used as the engine for transliteration. Initialized at module level.
_kakasi = pykakasi.kakasi() - src/japan_utils_mcp/server.py:177-177 (registration)The tool is registered via the @mcp.tool() decorator on the kanji_to_romaji function. mcp is a FastMCP instance created on line 28.
@mcp.tool() - The function signature defines the schema: input is 'text: str', output is dict with keys 'romaji', 'hiragana', and 'input'. Docstring describes the expected behavior.
@mcp.tool() def kanji_to_romaji(text: str) -> dict[str, Any]: """Transliterate Japanese text (kanji + kana mix) to Hepburn romaji. Args: text: Japanese text. May contain kanji, hiragana, katakana, ASCII. Non-Japanese characters pass through unchanged. Returns: dict with keys: - romaji: str (space-separated Hepburn romaji) - hiragana: str (kanji converted to hiragana, kana preserved) - input: str (echo of the original input) Examples: kanji_to_romaji("山田太郎") → {"romaji": "yamada tarou", "hiragana": "やまだたろう"} kanji_to_romaji("東京駅") → {"romaji": "toukyou eki", "hiragana": "とうきょうえき"} Caveats: - Kanji with multiple readings (e.g. proper nouns) may be ambiguous. The transliteration uses the most common reading, which is sometimes wrong for personal names. Use as a starting point, not a guarantee. """ results = _kakasi.convert(text) romaji = " ".join(r["hepburn"] for r in results if r["hepburn"]).strip() hira = "".join(r["hira"] for r in results) return { "romaji": romaji, "hiragana": hira, "input": text, }