validate_siret
Validates French SIRET numbers using the Luhn algorithm, extracting SIREN and establishment identifiers, and handling the La Poste special case automatically.
Instructions
Validates a French SIRET (14-digit company establishment number) using the official Luhn algorithm. The first 9 digits are the SIREN (company identifier) and the last 5 identify the specific establishment. Returns { valid: boolean, siren: string, establishment: string, siret: string }. Handles the La Poste special case automatically.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| siret | Yes | 14-digit French SIRET, with or without spaces/dashes. Example: '732 829 320 00074' |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| valid | Yes | ||
| siren | No | ||
| establishment | No | ||
| siret | No | ||
| reason | No |
Implementation Reference
- index.js:198-218 (handler)The validate_siret tool handler function that validates a French SIRET (14-digit company establishment number) using the Luhn algorithm. It strips spaces/dashes, checks for exactly 14 digits, handles the La Poste special case (starts with 356000000), applies the Luhn algorithm with alternating doubling, and returns {valid, siren, establishment, siret}.
// ── 8. Validate French SIRET ── server.registerTool("validate_siret", { description: "Validates a French SIRET (14-digit company establishment number) using the official Luhn algorithm. The first 9 digits are the SIREN (company identifier) and the last 5 identify the specific establishment. Returns { valid: boolean, siren: string, establishment: string, siret: string }. Handles the La Poste special case automatically.", inputSchema: { siret: z.string().describe("14-digit French SIRET, with or without spaces/dashes. Example: '732 829 320 00074'") }, outputSchema: { valid: z.boolean(), siren: z.string().optional(), establishment: z.string().optional(), siret: z.string().optional(), reason: z.string().optional() }, annotations: { title: "Validate French SIRET", readOnlyHint: true, idempotentHint: true, openWorldHint: false } }, async ({ siret }) => { const clean = siret.replace(/[\s\-]/g, ""); if (!/^\d{14}$/.test(clean)) return { content: [{ type: "text", text: JSON.stringify({ valid: false, reason: "SIRET must have exactly 14 digits" }) }] }; if (clean.startsWith("356000000")) { const valid = clean.split("").reduce((acc, d) => acc + parseInt(d), 0) % 5 === 0; return { content: [{ type: "text", text: JSON.stringify({ valid, siren: clean.substring(0, 9), establishment: clean.substring(9), siret: clean }) }] }; } let sum = 0; for (let i = 0; i < 14; i++) { let digit = parseInt(clean[i]); if (i % 2 === 0) { digit *= 2; if (digit > 9) digit -= 9; } sum += digit; } return { content: [{ type: "text", text: JSON.stringify({ valid: sum % 10 === 0, siren: clean.substring(0, 9), establishment: clean.substring(9), siret: clean }) }] }; }); - index.js:199-203 (registration)Registration of the validate_siret tool via server.registerTool(), including its description, inputSchema, outputSchema, and annotations (title: 'Validate French SIRET', readOnlyHint, idempotentHint).
server.registerTool("validate_siret", { description: "Validates a French SIRET (14-digit company establishment number) using the official Luhn algorithm. The first 9 digits are the SIREN (company identifier) and the last 5 identify the specific establishment. Returns { valid: boolean, siren: string, establishment: string, siret: string }. Handles the La Poste special case automatically.", inputSchema: { siret: z.string().describe("14-digit French SIRET, with or without spaces/dashes. Example: '732 829 320 00074'") }, outputSchema: { valid: z.boolean(), siren: z.string().optional(), establishment: z.string().optional(), siret: z.string().optional(), reason: z.string().optional() }, annotations: { title: "Validate French SIRET", readOnlyHint: true, idempotentHint: true, openWorldHint: false } - index.js:200-202 (schema)Input schema (z.string() for 'siret') and output schema (valid boolean, siren string optional, establishment string optional, siret string optional, reason string optional) for the validate_siret tool.
description: "Validates a French SIRET (14-digit company establishment number) using the official Luhn algorithm. The first 9 digits are the SIREN (company identifier) and the last 5 identify the specific establishment. Returns { valid: boolean, siren: string, establishment: string, siret: string }. Handles the La Poste special case automatically.", inputSchema: { siret: z.string().describe("14-digit French SIRET, with or without spaces/dashes. Example: '732 829 320 00074'") }, outputSchema: { valid: z.boolean(), siren: z.string().optional(), establishment: z.string().optional(), siret: z.string().optional(), reason: z.string().optional() },