API & MCP

Everything a person can do on Number-Theory Lab, a program or AI agent can do with the same inputs and get the identical result.

HTTP API

  • POST https://numbertheorylab.usefulweb.site/api/v1/calculate – run Number-Theory Lab
  • GET https://numbertheorylab.usefulweb.site/api/v1/tool – inputs, output schema, examples
  • OpenAPI 3.1: /openapi.json · /openapi.yaml
  • Errors: application/problem+json; 422 includes per-field errors.

Number-Theory Lab

Big-integer number theory with the working shown: Miller–Rabin primality (deterministic up to 3.3·10^24, otherwise with a stated number of rounds), factorisation by trial division and Pollard rho, gcd/lcm with the extended Euclidean table, modular inverse and exponentiation, the Chinese remainder theorem, Euler φ and divisors, prime counting up to 10 million, Collatz sequences and continued fractions.

Inputs of Number-Theory Lab
FieldTypeDefaultDescription
operationselect (analyze, gcd, modpow, modinv, crt, primecount, collatz, cf)"analyze"Operation
atext"561"n or a. Integer: decimal, 0x hex, 0b binary, or a power such as 2^127-1.
btext—b (second number / exponent / denominator)
mtext—Modulus m
congruencestextarea—Congruences (one per line: remainder modulus). For the CRT: each line "a m" means x ≡ a (mod m). Moduli need not be coprime.
roundsinteger40Miller–Rabin rounds above 3.3·10^24. Error probability at most 4^−rounds for numbers beyond the deterministic range.

Example request

561, the smallest Carmichael number

curl -X POST https://numbertheorylab.usefulweb.site/api/v1/calculate -H 'content-type: application/json' -d '{"operation":"analyze","a":"561"}'

Every result contains

inputs (normalised, defaults applied), summary, result (validated against the published schema), units, assumptions, sources, warnings, computedAt and links.

MCP (Model Context Protocol)

  • Streamable HTTP endpoint: https://numbertheorylab.usefulweb.site/mcp – protocol revisions 2026-07-28 (stateless) and 2025-11-25 / 2025-06-18 / 2025-03-26 (initialize handshake).
  • Tools: number_theory_lab
  • Local stdio connector: node src/mcp-stdio.ts --tool=number-theory-lab
{
  "mcpServers": {
    "number-theory-lab": { "type": "http", "url": "https://numbertheorylab.usefulweb.site/mcp" }
  }
}