Skip to main content
Glama
josemvelez78

mcp-europe-business

validate_nif

Read-onlyIdempotent

Validates Portuguese NIF (tax identification number) using modulo-11 checksum to confirm format and check digit, ensuring fiscal compliance for invoices, supplier onboarding, and user registration.

Instructions

Validates a Portuguese NIF (Número de Identificação Fiscal) — the 9-digit tax identification number issued by the Portuguese Tax Authority (AT) to individuals and companies. Applies the official modulo-11 checksum algorithm to verify the check digit. Returns { valid: true, nif: string } for valid NIFs, or { valid: false, reason: string } for invalid format or failed checksum. First-digit rules are enforced: 1–3 for individuals, 5 for corporations, 6 for public entities, 7–8 for other entities, 9 for occasional taxpayers. Use when processing Portuguese invoices (faturas), onboarding suppliers, validating user registrations, or any fiscal compliance workflow. Does not query the AT database — offline format and checksum validation only.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nifYes9-digit Portuguese NIF, with or without spaces. Example: '123456789'

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
validYesWhether the NIF is valid
nifNoNormalized NIF without spaces
reasonNoReason for invalidity if valid is false

Implementation Reference

  • index.js:19-36 (registration)
    Registration of the validate_nif tool with description, input/output schemas, and annotations
    server.registerTool("validate_nif", {
      description: "Validates a Portuguese NIF (Número de Identificação Fiscal) — the 9-digit tax identification number issued by the Portuguese Tax Authority (AT) to individuals and companies. Applies the official modulo-11 checksum algorithm to verify the check digit. Returns { valid: true, nif: string } for valid NIFs, or { valid: false, reason: string } for invalid format or failed checksum. First-digit rules are enforced: 1–3 for individuals, 5 for corporations, 6 for public entities, 7–8 for other entities, 9 for occasional taxpayers. Use when processing Portuguese invoices (faturas), onboarding suppliers, validating user registrations, or any fiscal compliance workflow. Does not query the AT database — offline format and checksum validation only.",
      inputSchema: { nif: z.string().describe("9-digit Portuguese NIF, with or without spaces. Example: '123456789'") },
      outputSchema: { valid: z.boolean().describe("Whether the NIF is valid"), nif: z.string().optional().describe("Normalized NIF without spaces"), reason: z.string().optional().describe("Reason for invalidity if valid is false") },
      annotations: { title: "Validate Portuguese NIF", readOnlyHint: true, idempotentHint: true, openWorldHint: false }
    }, async ({ nif }) => {
      const clean = nif.replace(/\s/g, "");
      if (!/^\d{9}$/.test(clean)) { const r = { valid: false, reason: "NIF must have exactly 9 digits" }; return { content: [{ type: "text", text: JSON.stringify(r) }], structuredContent: r }; }
      const validFirst = [1,2,3,5,6,7,8,9];
      if (!validFirst.includes(parseInt(clean[0]))) { const r = { valid: false, reason: "Invalid first digit" }; return { content: [{ type: "text", text: JSON.stringify(r) }], structuredContent: r }; }
      let sum = 0;
      for (let i = 0; i < 8; i++) sum += parseInt(clean[i]) * (9 - i);
      const remainder = sum % 11;
      const checkDigit = remainder < 2 ? 0 : 11 - remainder;
      const valid = checkDigit === parseInt(clean[8]);
      const r = { valid, nif: clean };
      return { content: [{ type: "text", text: JSON.stringify(r) }], structuredContent: r };
    });
  • index.js:24-36 (handler)
    Handler function that validates a Portuguese NIF: strips spaces, checks 9-digit format, validates first digit, applies modulo-11 checksum algorithm, and returns result
    }, async ({ nif }) => {
      const clean = nif.replace(/\s/g, "");
      if (!/^\d{9}$/.test(clean)) { const r = { valid: false, reason: "NIF must have exactly 9 digits" }; return { content: [{ type: "text", text: JSON.stringify(r) }], structuredContent: r }; }
      const validFirst = [1,2,3,5,6,7,8,9];
      if (!validFirst.includes(parseInt(clean[0]))) { const r = { valid: false, reason: "Invalid first digit" }; return { content: [{ type: "text", text: JSON.stringify(r) }], structuredContent: r }; }
      let sum = 0;
      for (let i = 0; i < 8; i++) sum += parseInt(clean[i]) * (9 - i);
      const remainder = sum % 11;
      const checkDigit = remainder < 2 ? 0 : 11 - remainder;
      const valid = checkDigit === parseInt(clean[8]);
      const r = { valid, nif: clean };
      return { content: [{ type: "text", text: JSON.stringify(r) }], structuredContent: r };
    });
  • Input and output schema definitions for validate_nif using Zod validation
    inputSchema: { nif: z.string().describe("9-digit Portuguese NIF, with or without spaces. Example: '123456789'") },
    outputSchema: { valid: z.boolean().describe("Whether the NIF is valid"), nif: z.string().optional().describe("Normalized NIF without spaces"), reason: z.string().optional().describe("Reason for invalidity if valid is false") },
Behavior4/5

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

Beyond annotations (readOnlyHint, idempotentHint), adds that validation is offline, enforces first-digit rules, and returns specific failure reasons, but does not detail all possible failure scenarios.

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

Conciseness4/5

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

Well-structured with front-loaded purpose, algorithm, return format, use cases, and limitation; efficient but could be slightly shorter.

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?

Combined with schema and annotations, provides complete guidance for usage, return format, and limitations, requiring no additional context.

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 covers the one parameter with format and example; description adds checksum algorithm and first-digit rules, enriching meaning beyond schema.

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?

Specifies validation of Portuguese NIF with modulo-11 checksum, clearly distinguishing from sibling tools like validate_nif_es.

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

Usage Guidelines4/5

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

Lists concrete use cases (invoices, onboarding, compliance) and explicitly states it does not query the AT database, clarifying scope, though no explicit alternatives are mentioned.

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