Skip to main content
Glama

check_tax

Read-onlyIdempotent

Validate Japanese invoice registration numbers and compute source-withholding for transactions. Ensure compliance with the invoice system in one API call.

Instructions

Run a Japanese tax compliance check on a single transaction. No authentication required.

Performs three checks in one call:

  1. Validates the qualified-invoice registration number (T-number) against the NTA registry.

  2. Determines whether source-withholding (源泉徴収) applies based on the service description.

  3. If withholding applies, computes the withholding amount and net payable.

Intended for Japanese corporations that pay AI / API services and need to file withholding correctly under the qualified-invoice (インボイス制度) regime.

Returns: { invoice: { valid, name, ... }, withholding: { required, rate, amount, net } } Errors: invalid registrationNumber returns invoice.valid = false (not an exception).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
registrationNumberYesQualified-invoice registration number issued by the Japanese NTA (e.g. "T1234567890123").
serviceDescriptionYesPlain-text description of what was purchased. Used to classify whether source-withholding applies.
grossAmountJpyYesGross transaction amount in JPY, tax inclusive.

Implementation Reference

  • MCP tool handler for check_tax — calls apiPost("/api/tax/full-check") with registrationNumber, serviceDescription, and grossAmountJpy, returns the JSON result.
    // ─── check_tax ───────────────────────────────────────────────────────
    case "check_tax": {
      const result = await apiPost("/api/tax/full-check", {
        registrationNumber: args.registrationNumber,
        serviceDescription: args.serviceDescription,
        grossAmountJpy:     args.grossAmountJpy,
      });
      return json(result);
    }
  • MCP tool schema definition for check_tax — declares name, description, annotations, and inputSchema with required fields: registrationNumber (string, T+13 digits pattern), serviceDescription (string), grossAmountJpy (number > 0).
    // ─── check_tax(認証不要) ───────────────────────────────────────────
    {
      name: "check_tax",
      description: [
        "Run a Japanese tax compliance check on a single transaction. No authentication required.",
        "",
        "Performs three checks in one call:",
        "  1. Validates the qualified-invoice registration number (T-number) against the NTA registry.",
        "  2. Determines whether source-withholding (源泉徴収) applies based on the service description.",
        "  3. If withholding applies, computes the withholding amount and net payable.",
        "",
        "Intended for Japanese corporations that pay AI / API services and need to file",
        "withholding correctly under the qualified-invoice (インボイス制度) regime.",
        "",
        "Returns: { invoice: { valid, name, ... }, withholding: { required, rate, amount, net } }",
        "Errors: invalid registrationNumber returns invoice.valid = false (not an exception).",
      ].join("\n"),
      annotations: {
        title:           "Japanese tax compliance check",
        readOnlyHint:    true,
        destructiveHint: false,
        idempotentHint:  true,
        openWorldHint:   true,
      },
      inputSchema: {
        type: "object",
        required: ["registrationNumber", "serviceDescription", "grossAmountJpy"],
        additionalProperties: false,
        properties: {
          registrationNumber: {
            type:        "string",
            description: "Qualified-invoice registration number issued by the Japanese NTA (e.g. \"T1234567890123\").",
            pattern:     "^T?\\d{13}$",
          },
          serviceDescription: {
            type:        "string",
            description: "Plain-text description of what was purchased. Used to classify whether source-withholding applies.",
            minLength:   1,
          },
          grossAmountJpy: {
            type:        "number",
            description: "Gross transaction amount in JPY, tax inclusive.",
            exclusiveMinimum: 0,
          },
        },
      },
    },
  • API route POST /api/tax/full-check — validates input with Zod, calls checkInvoiceRegistration and checkWithholdingTax concurrently, hashes the evidence, returns invoice, withholding, evidenceHash, and checkedAt.
    // ─── POST /api/tax/full-check ─────────────────────────────────
    // インボイス照合 + 源泉判定を一括実行
    taxRouter.post(
      "/full-check",
      zValidator(
        "json",
        z.object({
          registrationNumber: z.string(),
          serviceDescription: z.string().min(1).max(500),
          grossAmountJpy:     z.number().int().positive(),
        }),
      ),
      async (c) => {
        const { registrationNumber, serviceDescription, grossAmountJpy } = c.req.valid("json");
    
        const [invoice, withholding] = await Promise.all([
          checkInvoiceRegistration(registrationNumber),
          Promise.resolve(checkWithholdingTax(serviceDescription, grossAmountJpy)),
        ]);
    
        const evidenceHash = hashEvidence({ invoice, withholding });
    
        return c.json({
          invoice,
          withholding,
          evidenceHash,
          checkedAt: new Date().toISOString(),
        });
      },
    );
  • Helper function checkInvoiceRegistration — validates T-number format, calls NTA web API to verify qualified invoice registration, returns isQualified boolean with registrant details or error.
    export async function checkInvoiceRegistration(
      registrationNumber: string,
    ): Promise<InvoiceCheckResult> {
      // T + 13桁の数字 (法人番号または個人番号)
      const normalized = registrationNumber.toUpperCase().trim();
      if (!/^T\d{13}$/.test(normalized)) {
        return {
          registrationNumber: normalized,
          isQualified: false,
          error: "無効な登録番号フォーマット (T + 13桁が必要)",
        };
      }
    
      try {
        const res = await fetch(
          `${NTA_API_BASE}/invoice/${encodeURIComponent(normalized)}?type=21`,
          {
            headers: {
              "Accept": "application/json",
              "Accept-Language": "ja",
            },
            signal: AbortSignal.timeout(10_000),
          },
        );
    
        if (!res.ok) {
          return {
            registrationNumber: normalized,
            isQualified: false,
            error: `国税庁API エラー: HTTP ${res.status}`,
          };
        }
    
        const data: NtaApiResponse = await res.json();
    
        if (data.code !== "000" || !data.registrantList?.length) {
          return { registrationNumber: normalized, isQualified: false };
        }
    
        const registrant = data.registrantList[0];
        // process "3" = 取消済み → 適格事業者ではない
        const isQualified = registrant.process !== "3" && !registrant.cancellationDate;
    
        return { registrationNumber: normalized, isQualified, registrant };
      } catch (err) {
        return {
          registrationNumber: normalized,
          isQualified: false,
          error: `国税庁API 通信エラー: ${(err as Error).message}`,
        };
      }
    }
  • Helper function checkWithholdingTax — classifies service description against non-withholding keywords (API/SaaS) and withholding categories (design, legal, medical, etc.) per Japanese Income Tax Law Article 204, computes withholding amount at 10.21% or 20.42% rate.
    export function checkWithholdingTax(
      serviceDescription: string,
      grossAmountJpy: number,
    ): WithholdingCheckResult {
      const text = serviceDescription.toLowerCase();
    
      // 対象外キーワードが先に見つかれば源泉不要 (高信頼)
      const nonWithholdingMatch = NON_WITHHOLDING_KEYWORDS.find(kw =>
        text.includes(kw.toLowerCase()),
      );
      if (nonWithholdingMatch) {
        return {
          required:    false,
          rate:        0,
          grossAmount: grossAmountJpy,
          taxAmount:   0,
          netAmount:   grossAmountJpy,
          confidence:  "high",
          reason:      `「${nonWithholdingMatch}」はAPI/SaaS利用料として源泉徴収対象外`,
        };
      }
    
      // 204条対象キーワード検索
      for (const { category, keywords } of WITHHOLDING_CATEGORIES) {
        const matched = keywords.find(kw => text.includes(kw.toLowerCase()));
        if (matched) {
          // 100万円超は20.42%、以下は10.21%
          const rate = grossAmountJpy > 1_000_000 ? 0.2042 : 0.1021;
          const taxAmount  = Math.floor(grossAmountJpy * rate);
          const netAmount  = grossAmountJpy - taxAmount;
          return {
            required:    true,
            category,
            rate,
            grossAmount: grossAmountJpy,
            taxAmount,
            netAmount,
            confidence:  "high",
            reason:      `「${matched}」は所得税法第204条第1項 (${category}) に該当`,
          };
        }
      }
    
      // 判定不能 → 人間レビューフラグ
      return {
        required:    false,
        rate:        0,
        grossAmount: grossAmountJpy,
        taxAmount:   0,
        netAmount:   grossAmountJpy,
        confidence:  "low",
        reason:      "自動判定不可 — 税理士確認を推奨",
      };
    }
Behavior5/5

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

Annotations already indicate readOnlyHint=true and idempotentHint=true. The description adds significant behavioral context: it performs three composite checks, has no authentication requirement, returns specific error handling (invalid returns false, not exception), and describes output structure. This goes well beyond annotations.

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 well-structured: first sentence for purpose and auth, numbered list for three checks, then intended audience, then return format and error behavior. Every sentence is informative and concise.

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?

Given the tool has 3 required parameters and no output schema, the description fully explains the return structure (invoice with valid, name; withholding with required, rate, amount, net) and error handling. It is complete for the tool's complexity.

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 description coverage is 100% with clear parameter descriptions. The description adds value by linking each parameter to the three checks (registrationNumber for check 1, serviceDescription for check 2, grossAmountJpy for check 3), enhancing understanding of how parameters are used.

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 it runs a Japanese tax compliance check on a single transaction, listing three specific checks. It distinguishes itself from sibling tools like call_service, check_balance, etc., which are unrelated.

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?

The description specifies 'No authentication required' and 'Intended for Japanese corporations that pay AI/API services', giving clear usage context. It could be improved by explicitly stating when not to use it, but the context is sufficient.

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/evidai/lemon-cake'

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