normalize_width
Convert half-width characters to full-width or vice versa in Japanese text. Choose from six modes for ASCII, digits, and kana conversion.
Instructions
Convert between half-width (半角) and full-width (全角) characters.
Args: text: Input string. mode: Conversion direction. One of: - 'to_full' : half-width → full-width for all categories (kana, ascii, digits) - 'to_half' : full-width → half-width for all categories - 'to_full_ascii_only' : convert only ASCII letters and digits to full-width, leave kana untouched - 'to_half_ascii_only' : convert only full-width ASCII to half-width - 'to_full_kana_only' : convert only half-width katakana to full-width - 'to_half_kana_only' : convert only full-width katakana to half-width
Returns: dict with keys: - input: str - output: str - mode: str
Examples: normalize_width("ABC123", "to_half") → "ABC123" normalize_width("ABC123", "to_full") → "ABC123" normalize_width("カタカナ", "to_full") → "カタカナ"
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | ||
| mode | No | to_full |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/japan_utils_mcp/server.py:439-485 (handler)The `normalize_width` function is the MCP tool handler. It is decorated with @mcp.tool() (line 439) and receives a `text` string and `mode` parameter (defaulting to 'to_full'). It uses jaconv.h2z/z2h for conversion between half-width and full-width characters, supporting six modes (to_full, to_half, to_full_ascii_only, to_half_ascii_only, to_full_kana_only, to_half_kana_only). Returns a dict with input, output, and mode keys.
@mcp.tool() def normalize_width(text: str, mode: str = "to_full") -> dict[str, Any]: """Convert between half-width (半角) and full-width (全角) characters. Args: text: Input string. mode: Conversion direction. One of: - 'to_full' : half-width → full-width for all categories (kana, ascii, digits) - 'to_half' : full-width → half-width for all categories - 'to_full_ascii_only' : convert only ASCII letters and digits to full-width, leave kana untouched - 'to_half_ascii_only' : convert only full-width ASCII to half-width - 'to_full_kana_only' : convert only half-width katakana to full-width - 'to_half_kana_only' : convert only full-width katakana to half-width Returns: dict with keys: - input: str - output: str - mode: str Examples: normalize_width("ABC123", "to_half") → "ABC123" normalize_width("ABC123", "to_full") → "ABC123" normalize_width("カタカナ", "to_full") → "カタカナ" """ m = mode.strip().lower() if m == "to_full": out = jaconv.h2z(text, kana=True, digit=True, ascii=True) elif m == "to_half": out = jaconv.z2h(text, kana=True, digit=True, ascii=True) elif m == "to_full_ascii_only": out = jaconv.h2z(text, kana=False, digit=True, ascii=True) elif m == "to_half_ascii_only": out = jaconv.z2h(text, kana=False, digit=True, ascii=True) elif m == "to_full_kana_only": out = jaconv.h2z(text, kana=True, digit=False, ascii=False) elif m == "to_half_kana_only": out = jaconv.z2h(text, kana=True, digit=False, ascii=False) else: raise ValueError( f"Unknown mode: {mode!r}. " "Use 'to_full', 'to_half', or one of the *_only variants." ) return {"input": text, "output": out, "mode": m} - src/japan_utils_mcp/server.py:439-439 (registration)The tool is registered as an MCP tool via the @mcp.tool() decorator on line 439. The FastMCP instance is created on line 28.
@mcp.tool() - src/japan_utils_mcp/server.py:1-2 (helper)The `jaconv` library (imported on line 21) is the external helper that provides the character width conversion functions h2z (half-to-full) and z2h (full-to-half).
"""japan-utils-mcp — MCP server exposing Japan-specific utilities to AI agents.