Skip to main content
Glama
josemvelez78

mcp-europe-business

validate_nif_es

Read-onlyIdempotent

Validates Spanish tax IDs (NIF, NIE, CIF) by automatically detecting the document type and returning a boolean validity flag, type, and normalized ID.

Instructions

Validates Spanish tax identification numbers — NIF (DNI, 8 digits + check letter, for Spanish citizens), NIE (Número de Identidad de Extranjero, starts with X/Y/Z, for foreign residents), and CIF (Código de Identificación Fiscal, letter + 7 digits + control, for companies). Automatically detects the document type. Returns { valid: boolean, type: 'NIF'|'NIE'|'CIF', id: string }.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesSpanish NIF, NIE or CIF. Examples: '12345678Z' (NIF), 'X1234567L' (NIE), 'B12345678' (CIF)

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
validYes
typeNo
idNo
reasonNo

Implementation Reference

  • The handler function for the 'validate_nif_es' tool. It validates Spanish tax identification numbers: NIF (DNI - 8 digits + check letter using TRWAGMYFPDXBNJZSQVHLCKE algorithm), NIE (starts with X/Y/Z mapped to 0/1/2 + 7 digits + check letter), and CIF (letter + 7 digits + control digit using the official weighted sum algorithm). Returns {valid, type: 'NIF'|'NIE'|'CIF', id} or {valid: false, reason}.
    server.registerTool("validate_nif_es", {
      description: "Validates Spanish tax identification numbers — NIF (DNI, 8 digits + check letter, for Spanish citizens), NIE (Número de Identidad de Extranjero, starts with X/Y/Z, for foreign residents), and CIF (Código de Identificación Fiscal, letter + 7 digits + control, for companies). Automatically detects the document type. Returns { valid: boolean, type: 'NIF'|'NIE'|'CIF', id: string }.",
      inputSchema: { id: z.string().describe("Spanish NIF, NIE or CIF. Examples: '12345678Z' (NIF), 'X1234567L' (NIE), 'B12345678' (CIF)") },
      outputSchema: { valid: z.boolean(), type: z.enum(["NIF","NIE","CIF"]).optional(), id: z.string().optional(), reason: z.string().optional() },
          annotations: { title: "Validate Spanish NIF / NIE / CIF", readOnlyHint: true, idempotentHint: true, openWorldHint: false }
    }, async ({ id }) => {
      const clean = id.replace(/\s/g, "").toUpperCase();
      const nifLetters = "TRWAGMYFPDXBNJZSQVHLCKE";
      if (/^\d{8}[A-Z]$/.test(clean)) {
        const valid = clean[8] === nifLetters[parseInt(clean.slice(0, 8)) % 23];
        return { content: [{ type: "text", text: JSON.stringify({ valid, type: "NIF", id: clean }) }] };
      }
      if (/^[XYZ]\d{7}[A-Z]$/.test(clean)) {
        const nieMap = { X: "0", Y: "1", Z: "2" };
        const valid = clean[8] === nifLetters[parseInt(nieMap[clean[0]] + clean.slice(1, 8)) % 23];
        return { content: [{ type: "text", text: JSON.stringify({ valid, type: "NIE", id: clean }) }] };
      }
      if (/^[ABCDEFGHJKLMNPQRSUVW]\d{7}[0-9A-J]$/.test(clean)) {
        const letters = "JABCDEFGHI";
        let sumOdd = 0, sumEven = 0;
        for (let i = 1; i <= 7; i++) {
          const digit = parseInt(clean[i]);
          if (i % 2 === 0) sumEven += digit;
          else { const d = digit * 2; sumOdd += d > 9 ? d - 9 : d; }
        }
        const controlDigit = (10 - ((sumOdd + sumEven) % 10)) % 10;
        const valid = clean[8] === controlDigit.toString() || clean[8] === letters[controlDigit];
        return { content: [{ type: "text", text: JSON.stringify({ valid, type: "CIF", id: clean }) }] };
      }
      return { content: [{ type: "text", text: JSON.stringify({ valid: false, reason: "Format not recognized. Expected NIF (8 digits + letter), NIE (X/Y/Z + 7 digits + letter) or CIF (letter + 7 digits + control)" }) }] };
    });
  • index.js:166-196 (registration)
    The registration of the 'validate_nif_es' tool via server.registerTool() on line 166, including its input schema (z.string() for 'id'), output schema (valid, type enum, id, reason), description, and annotations.
    server.registerTool("validate_nif_es", {
      description: "Validates Spanish tax identification numbers — NIF (DNI, 8 digits + check letter, for Spanish citizens), NIE (Número de Identidad de Extranjero, starts with X/Y/Z, for foreign residents), and CIF (Código de Identificación Fiscal, letter + 7 digits + control, for companies). Automatically detects the document type. Returns { valid: boolean, type: 'NIF'|'NIE'|'CIF', id: string }.",
      inputSchema: { id: z.string().describe("Spanish NIF, NIE or CIF. Examples: '12345678Z' (NIF), 'X1234567L' (NIE), 'B12345678' (CIF)") },
      outputSchema: { valid: z.boolean(), type: z.enum(["NIF","NIE","CIF"]).optional(), id: z.string().optional(), reason: z.string().optional() },
          annotations: { title: "Validate Spanish NIF / NIE / CIF", readOnlyHint: true, idempotentHint: true, openWorldHint: false }
    }, async ({ id }) => {
      const clean = id.replace(/\s/g, "").toUpperCase();
      const nifLetters = "TRWAGMYFPDXBNJZSQVHLCKE";
      if (/^\d{8}[A-Z]$/.test(clean)) {
        const valid = clean[8] === nifLetters[parseInt(clean.slice(0, 8)) % 23];
        return { content: [{ type: "text", text: JSON.stringify({ valid, type: "NIF", id: clean }) }] };
      }
      if (/^[XYZ]\d{7}[A-Z]$/.test(clean)) {
        const nieMap = { X: "0", Y: "1", Z: "2" };
        const valid = clean[8] === nifLetters[parseInt(nieMap[clean[0]] + clean.slice(1, 8)) % 23];
        return { content: [{ type: "text", text: JSON.stringify({ valid, type: "NIE", id: clean }) }] };
      }
      if (/^[ABCDEFGHJKLMNPQRSUVW]\d{7}[0-9A-J]$/.test(clean)) {
        const letters = "JABCDEFGHI";
        let sumOdd = 0, sumEven = 0;
        for (let i = 1; i <= 7; i++) {
          const digit = parseInt(clean[i]);
          if (i % 2 === 0) sumEven += digit;
          else { const d = digit * 2; sumOdd += d > 9 ? d - 9 : d; }
        }
        const controlDigit = (10 - ((sumOdd + sumEven) % 10)) % 10;
        const valid = clean[8] === controlDigit.toString() || clean[8] === letters[controlDigit];
        return { content: [{ type: "text", text: JSON.stringify({ valid, type: "CIF", id: clean }) }] };
      }
      return { content: [{ type: "text", text: JSON.stringify({ valid: false, reason: "Format not recognized. Expected NIF (8 digits + letter), NIE (X/Y/Z + 7 digits + letter) or CIF (letter + 7 digits + control)" }) }] };
    });
  • Input and output Zod schemas for the validate_nif_es tool. Input: {id: z.string()} - the Spanish NIF/NIE/CIF string. Output: {valid: z.boolean(), type: z.enum(['NIF','NIE','CIF']), id: z.string(), reason: z.string()}.
    inputSchema: { id: z.string().describe("Spanish NIF, NIE or CIF. Examples: '12345678Z' (NIF), 'X1234567L' (NIE), 'B12345678' (CIF)") },
    outputSchema: { valid: z.boolean(), type: z.enum(["NIF","NIE","CIF"]).optional(), id: z.string().optional(), reason: z.string().optional() },
Behavior4/5

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

The description adds value beyond annotations: it explains the automatic detection of document type and the return format (valid, type, id). Annotations already indicate read-only and idempotent behavior, but the description provides necessary behavioral details.

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

Conciseness5/5

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

The description is two sentences with no wasted words. It efficiently conveys the tool's purpose, types, and return format.

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

Completeness5/5

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

The tool has an output schema (mentioned in context) and the description covers the return structure. For a validation tool with one parameter, the description is complete and provides sufficient information for correct invocation.

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

Parameters4/5

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

Schema coverage is 100%, so the schema already documents the parameter. The description adds meaning by explaining the supported ID formats and examples, going beyond the base baseline of 3.

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 the tool validates Spanish tax identification numbers and specifies three types (NIF, NIE, CIF) with brief format details. It distinguishes itself from sibling tools like 'validate_nif' by covering all three Spanish ID types.

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

Usage Guidelines3/5

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

The description provides clear context for when to use (for Spanish tax IDs) but does not explicitly state when not to use or mention alternatives. It implies use for Spanish IDs, but lacks exclusion guidance.

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/josemvelez78/mcp-europe-business'

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