validate_codice_fiscale
Validate an Italian Codice Fiscale using the official odd/even position checksum algorithm to ensure compliance with Italian revenue agency standards.
Instructions
Validates an Italian Codice Fiscale (fiscal code) for individuals — a 16-character alphanumeric code issued by the Italian Revenue Agency (Agenzia delle Entrate). Applies the official odd/even position checksum algorithm. Returns { valid: boolean, codice_fiscale: string } or { valid: false, reason: string }. Use when processing Italian invoices, onboarding Italian individuals, or any Italian compliance workflow requiring a verified personal fiscal code.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| codice_fiscale | Yes | 16-character Italian Codice Fiscale. Example: 'RSSMRA85T10A562S' |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| valid | Yes | ||
| codice_fiscale | No | ||
| reason | No |
Implementation Reference
- index.js:279-284 (registration)Registration of the 'validate_codice_fiscale' tool via server.registerTool(), including description, input/output schemas, and annotations.
server.registerTool("validate_codice_fiscale", { description: "Validates an Italian Codice Fiscale (fiscal code) for individuals — a 16-character alphanumeric code issued by the Italian Revenue Agency (Agenzia delle Entrate). Applies the official odd/even position checksum algorithm. Returns { valid: boolean, codice_fiscale: string } or { valid: false, reason: string }. Use when processing Italian invoices, onboarding Italian individuals, or any Italian compliance workflow requiring a verified personal fiscal code.", inputSchema: { codice_fiscale: z.string().describe("16-character Italian Codice Fiscale. Example: 'RSSMRA85T10A562S'") }, outputSchema: { valid: z.boolean(), codice_fiscale: z.string().optional(), reason: z.string().optional() }, annotations: { title: "Validate Italian Codice Fiscale", readOnlyHint: true, idempotentHint: true, openWorldHint: false } }, async ({ codice_fiscale }) => { - index.js:284-299 (handler)Handler function for validate_codice_fiscale: validates a 16-character Italian Codice Fiscale by applying the official odd/even position checksum algorithm using character value lookup tables.
}, async ({ codice_fiscale }) => { const clean = codice_fiscale.replace(/\s/g, "").toUpperCase(); if (!/^[A-Z]{6}\d{2}[A-Z]\d{2}[A-Z]\d{3}[A-Z]$/.test(clean)) { return { content: [{ type: "text", text: JSON.stringify({ valid: false, reason: "Codice Fiscale must be 16 characters: 6 letters, 2 digits, 1 letter, 2 digits, 1 letter, 3 digits, 1 letter" }) }] }; } const oddValues = { 0:1,1:0,2:5,3:7,4:9,5:13,6:15,7:17,8:19,9:21,A:1,B:0,C:5,D:7,E:9,F:13,G:15,H:17,I:19,J:21,K:2,L:4,M:18,N:20,O:11,P:3,Q:6,R:8,S:12,T:14,U:16,V:10,W:22,X:25,Y:24,Z:23 }; const evenValues = { 0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,A:0,B:1,C:2,D:3,E:4,F:5,G:6,H:7,I:8,J:9,K:10,L:11,M:12,N:13,O:14,P:15,Q:16,R:17,S:18,T:19,U:20,V:21,W:22,X:23,Y:24,Z:25 }; let sum = 0; for (let i = 0; i < 15; i++) { const char = clean[i]; sum += (i % 2 === 0) ? oddValues[char] : evenValues[char]; } const expectedCheck = String.fromCharCode(65 + (sum % 26)); const valid = clean[15] === expectedCheck; return { content: [{ type: "text", text: JSON.stringify({ valid, codice_fiscale: clean }) }] }; }); - index.js:281-282 (schema)Input schema (zod) for validate_codice_fiscale: expects 'codice_fiscale' (string). Output schema includes 'valid' (boolean), 'codice_fiscale' (optional string), and 'reason' (optional string).
inputSchema: { codice_fiscale: z.string().describe("16-character Italian Codice Fiscale. Example: 'RSSMRA85T10A562S'") }, outputSchema: { valid: z.boolean(), codice_fiscale: z.string().optional(), reason: z.string().optional() }, - index.js:289-290 (helper)Lookup tables for odd-position (oddValues) and even-position (evenValues) character values used in the Italian Codice Fiscale checksum algorithm.
const oddValues = { 0:1,1:0,2:5,3:7,4:9,5:13,6:15,7:17,8:19,9:21,A:1,B:0,C:5,D:7,E:9,F:13,G:15,H:17,I:19,J:21,K:2,L:4,M:18,N:20,O:11,P:3,Q:6,R:8,S:12,T:14,U:16,V:10,W:22,X:25,Y:24,Z:23 }; const evenValues = { 0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,A:0,B:1,C:2,D:3,E:4,F:5,G:6,H:7,I:8,J:9,K:10,L:11,M:12,N:13,O:14,P:15,Q:16,R:17,S:18,T:19,U:20,V:21,W:22,X:23,Y:24,Z:25 };