validate_polish_regon
Verify the correctness of a Polish business registry number (REGON) of 9 or 14 digits. Returns validation status, the number, and its length.
Instructions
Validate a Polish REGON (business registry number — 9 or 14 digits).
Returns {'valid': bool, 'regon': str, 'length': int}.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| regon | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/mcp_ksef_pl/server.py:204-220 (handler)The @mcp.tool handler that exposes validate_polish_regon as an MCP tool. It normalizes the REGON string and delegates to the validate_regon helper.
@mcp.tool async def validate_polish_regon(regon: str) -> dict[str, Any]: """Validate a Polish REGON (business registry number — 9 or 14 digits). Returns {'valid': bool, 'regon': str, 'length': int}. """ import re normalized = re.sub(r"\s", "", regon) valid = validate_regon(regon) return { "valid": valid, "regon": regon, "normalized": normalized, "length": len(normalized), "message": "REGON is valid." if valid else "REGON failed checksum validation.", } - The validate_regon helper function that implements the actual 9- and 14-digit Polish REGON checksum algorithm.
def validate_regon(regon: str) -> bool: """Return True when *regon* passes the 9- or 14-digit Polish REGON checksum.""" digits = re.sub(r"\s", "", regon) if not digits.isdigit(): return False if len(digits) == 9: total = sum(int(d) * w for d, w in zip(digits, _REGON9_WEIGHTS)) return total % 11 % 10 == int(digits[8]) if len(digits) == 14: total = sum(int(d) * w for d, w in zip(digits, _REGON14_WEIGHTS)) return total % 11 % 10 == int(digits[13]) return False - src/mcp_ksef_pl/server.py:204-204 (registration)The @mcp.tool decorator on line 204 registers the function as an MCP tool named 'validate_polish_regon'.
@mcp.tool - src/mcp_ksef_pl/server.py:214-219 (schema)Return type schema showing the dict keys returned: valid, regon, normalized, length, message.
return { "valid": valid, "regon": regon, "normalized": normalized, "length": len(normalized), "message": "REGON is valid." if valid else "REGON failed checksum validation.",