Skip to main content
Glama
vivek081166

japan-utils-mcp

western_to_era

Convert a Gregorian year to the corresponding Japanese era year, returning era name in kanji and English, year of era, and formatted strings like '令和8年' and 'R8'.

Instructions

Convert a Western (Gregorian) year to its Japanese era year.

Note: this returns the era in effect for the majority of the given Gregorian year. For year transitions (e.g. 1989 split between 昭和64 and 平成1), it returns the newer era.

Args: year: Western year (e.g. 2026). Must be 1868 or later.

Returns: dict with keys: - era_kanji: str - era_english: str - year_of_era: int (1 for the first year of an era; written as 元年 in formal Japanese) - era_year_kanji: str (e.g. '令和8年') - era_year_short: str (e.g. 'R8')

Examples: western_to_era(2026) → {"era_kanji": "令和", "era_english": "Reiwa", "year_of_era": 8, "era_year_kanji": "令和8年", "era_year_short": "R8"}

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
yearYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The `western_to_era` function itself — the actual tool handler that converts a Western year to a Japanese era year. It iterates over `_ERAS` (ordered from newest to oldest), finds the matching era, and returns era_kanji, era_english, year_of_era, era_year_kanji, and era_year_short.
    def western_to_era(year: int) -> dict[str, Any]:
        """Convert a Western (Gregorian) year to its Japanese era year.
    
        Note: this returns the era in effect for the *majority* of the given
        Gregorian year. For year transitions (e.g. 1989 split between 昭和64
        and 平成1), it returns the newer era.
    
        Args:
            year: Western year (e.g. 2026). Must be 1868 or later.
    
        Returns:
            dict with keys:
                - era_kanji: str
                - era_english: str
                - year_of_era: int (1 for the first year of an era; written as 元年 in formal Japanese)
                - era_year_kanji: str (e.g. '令和8年')
                - era_year_short: str (e.g. 'R8')
    
        Examples:
            western_to_era(2026) → {"era_kanji": "令和", "era_english": "Reiwa",
                                     "year_of_era": 8, "era_year_kanji": "令和8年",
                                     "era_year_short": "R8"}
        """
        if year < 1868:
            raise ValueError("Years before 1868 (Meiji 1) are not supported.")
    
        for start_year, kanji, english, letter in _ERAS:
            if year >= start_year:
                year_of_era = year - start_year + 1
                if year_of_era == 1:
                    era_year_kanji = f"{kanji}元年"
                else:
                    era_year_kanji = f"{kanji}{year_of_era}年"
                return {
                    "era_kanji": kanji,
                    "era_english": english,
                    "year_of_era": year_of_era,
                    "era_year_kanji": era_year_kanji,
                    "era_year_short": f"{letter}{year_of_era}",
                }
  • The `@mcp.tool()` decorator that registers `western_to_era` as an MCP tool on the FastMCP server instance.
    @mcp.tool()
  • The `_ERAS` constant — the era data list used by `western_to_era`. Defines the 5 supported eras (Reiwa, Heisei, Showa, Taisho, Meiji) with their start years, kanji names, English names, and single-letter aliases.
    _ERAS: list[tuple[int, str, str, str]] = [
        (2019, "令和", "Reiwa", "R"),
        (1989, "平成", "Heisei", "H"),
        (1926, "昭和", "Showa", "S"),
        (1912, "大正", "Taisho", "T"),
        (1868, "明治", "Meiji", "M"),
    ]
  • Lookup dictionaries `_ERA_KANJI_TO_INFO` and `_ERA_LETTER_TO_INFO` built from `_ERAS`, used by `era_to_western` and referenced by the era data structure.
    _ERA_KANJI_TO_INFO: dict[str, tuple[int, str, str, str]] = {
        e[1]: e for e in _ERAS
    }
    _ERA_LETTER_TO_INFO: dict[str, tuple[int, str, str, str]] = {
        e[3]: e for e in _ERAS
    }
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It discloses the transition behavior and the year constraint, but does not mention error handling for invalid inputs (e.g., year < 1868). The return structure is well-documented.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with sections (Note, Args, Returns, Examples) and front-loaded with the purpose. It is slightly lengthy but each section adds value. Could be more concise, but not wasteful.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given that an output schema exists, the description still provides a detailed return structure and covers the main behavioral note. It lacks error handling details but is otherwise complete for a simple conversion tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It explains the 'year' parameter with an example and the constraint 'Must be 1868 or later', adding significant meaning beyond the bare schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states it converts a Western year to Japanese era year, with specific verb 'convert' and resource 'year'. It distinguishes itself from the sibling tool 'era_to_western' by its direction.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides necessary context: it returns the era for the majority of the year, handles year transitions by returning the newer era, and requires years 1868 or later. However, it does not explicitly mention when not to use this tool or direct alternatives, though the sibling list makes it obvious.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/vivek081166/japan-utils-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server