validate_polish_nip
Validates a Polish NIP tax identification number using the official checksum algorithm. Accepts dashes/spaces and returns validity status.
Instructions
Validate a Polish NIP (tax identification number).
Applies the official 10-digit checksum algorithm. Accepts NIP with or without dashes/spaces.
Returns {'valid': bool, 'nip': str, 'normalized': str}.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| nip | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/mcp_ksef_pl/server.py:183-201 (handler)The tool handler for 'validate_polish_nip'. It is decorated with @mcp.tool, accepts a NIP string, normalizes it (removes dashes/spaces), delegates to validate_nip(), and returns a dict with valid, nip, normalized, and message fields.
@mcp.tool async def validate_polish_nip(nip: str) -> dict[str, Any]: """Validate a Polish NIP (tax identification number). Applies the official 10-digit checksum algorithm. Accepts NIP with or without dashes/spaces. Returns {'valid': bool, 'nip': str, 'normalized': str}. """ import re normalized = re.sub(r"[\s\-]", "", nip) valid = validate_nip(nip) return { "valid": valid, "nip": nip, "normalized": normalized, "message": "NIP is valid." if valid else "NIP failed checksum validation.", } - The core checksum validation function. Strips non-digit characters, verifies 10 digits, computes weighted sum modulo 11, and checks the checksum digit.
def validate_nip(nip: str) -> bool: """Return True when *nip* passes the Polish NIP checksum algorithm.""" digits = re.sub(r"[\s\-]", "", nip) if not digits.isdigit() or len(digits) != 10: return False total = sum(int(d) * w for d, w in zip(digits, _NIP_WEIGHTS)) remainder = total % 11 return remainder != 10 and remainder == int(digits[9]) - src/mcp_ksef_pl/server.py:183-184 (registration)Registration of the tool via the @mcp.tool decorator on the async function.
@mcp.tool async def validate_polish_nip(nip: str) -> dict[str, Any]: - src/mcp_ksef_pl/server.py:183-184 (schema)Input schema is implicitly defined by the function signature (nip: str). Output is dict[str, Any].
@mcp.tool async def validate_polish_nip(nip: str) -> dict[str, Any]: - src/mcp_ksef_pl/server.py:22-22 (registration)The import of validate_nip from party_validator module.
from .party_validator import PolishPartyValidator, validate_nip, validate_regon