A TypeScript SDK and hosted HTTP API for generating, validating, and submitting HMRC-compliant fraud prevention headers.
This monorepo contains:
-
@hmrc-sync/engine— Core header generation and validation logicWhen to use @hmrc-sync/engine:
- Server-side header generation - When you need to generate HMRC fraud prevention headers on your server before making API calls to HMRC
- Header validation - When you want to validate headers before sending them to HMRC APIs
- Via Server connection methods - When using
WEB_APP_VIA_SERVER,DESKTOP_APP_VIA_SERVER, orMOBILE_APP_VIA_SERVER(client sends data to your server, your server appends server info and generates headers)
Why use it:
- Type safety - Uses TypeScript discriminated unions to ensure only valid fields are included for each connection method at compile time
- Supports all 6 HMRC connection methods -
DESKTOP_APP_DIRECT,DESKTOP_APP_VIA_SERVER,WEB_APP_VIA_SERVER,MOBILE_APP_DIRECT,MOBILE_APP_VIA_SERVER,BATCH_PROCESS_DIRECT - Structured error handling -
validateHeaders()never throws, returns structured validation results with British English error messages - VPN/proxy handling - Accurately reports network topology including VPNs and proxies without attempting to detect or circumvent them
Typical flow:
- Client collects data via @hmrc-sync/collector
- Client POSTs data to your server
- Your server uses @hmrc-sync/engine to merge with server IP/port and generate headers
- Attach headers to HMRC API request
-
@hmrc-sync/collector— Client-side data collection utilitiesWhen to use @hmrc-sync/collector:
- Browser environments - Use
collectBrowserData()when building web applications (forWEB_APP_VIA_SERVERorMOBILE_APP_VIA_SERVERconnection methods) - Desktop/Node.js environments - Use
collectDesktopData()when building desktop applications (forDESKTOP_APP_DIRECTorDESKTOP_APP_VIA_SERVERconnection methods) - Mobile environments - Use
collectMobileData()when building mobile apps (forMOBILE_APP_DIRECTorMOBILE_APP_VIA_SERVERconnection methods)
Why use it:
- Collects required client data - Gathers device info, screen data, timezone, local IPs, MAC addresses, and other data needed for HMRC fraud prevention headers
- Environment-specific - Each function collects data appropriate for its environment (browser vs desktop vs mobile)
- Silent failure handling - All failures return
""or[]per HMRC's "silent rule" - never throws errors - Type safety - Returns complete
CollectedClientDataobjects with all fields present
Typical flow:
- Client calls appropriate collection function based on environment
- Client sends collected data to your server (for VIA_SERVER methods)
- Server uses @hmrc-sync/engine to merge with server info and generate headers
- Attach headers to HMRC API request
Data collected:
- Screen dimensions, scaling factor, colour depth
- Timezone
- User agent (browser only)
- Local IPs and MAC addresses (desktop only)
- Device ID
- OS info (desktop only)
- Window size
- Browser environments - Use
-
@hmrc-sync/agent-skill— High-level orchestration and MCP tool handlersWhen to use @hmrc-sync/agent-skill:
- High-level orchestration - When you want a simple
prepareHmrcRequest()function that handles the entire workflow (collect → generate → validate → plan submission) in one call - AI/agent integrations - When building AI agents or chat interfaces that need MCP (Model Context Protocol) tool handlers for HMRC header workflows
- Guardrails and validation - When you need built-in policy checks (e.g., blocking browser-originated direct HMRC submissions, enforcing required fields for VIA_SERVER methods)
- Human-readable guidance - When you want
explainModeto provide clear remediation steps when validation fails - Starter templates - When you want pre-built intent templates for common integration patterns (web via server, desktop direct, validate before submit)
Two usage modes:
- SDK (embed in your codebase) - Install and use directly in your Node.js/TypeScript project for full control
- HTTP API (hosted service) - Call the hosted API over HTTPS with auth, rate limiting, and audit logging
MCP stdio server:
- Use when integrating with MCP-native clients like Cursor, Windsurf, or Claude Desktop
- Run via
pnpm --filter @hmrc-sync/agent-skill mcp:stdioornpx hmrc-agent-skill-mcp
Tool catalog:
hmrc.collect_client_data(environment)hmrc.generate_headers(...)hmrc.validate_headers(...)hmrc.build_submission(...)
Why use it instead of lower-level packages:
- Simpler API - one function call instead of coordinating collector + engine
- Built-in guardrails and policy enforcement
- MCP-ready for AI agent integration
- Explain mode for debugging and user guidance
- High-level orchestration - When you want a simple
-
examples/express-mcp-server— Reference HTTP API implementation with auth, rate limiting, and audit logging
For installation and usage examples, see packages/@hmrc-sync/agent-skill/README.md.
| Package | Description |
|---|---|
@hmrc-sync/engine |
Server-side header generation and validation |
@hmrc-sync/collector |
Client-side data collection |
@hmrc-sync/agent-skill |
High-level orchestration and MCP tools |
# Install dependencies
pnpm install
# Build all packages
pnpm -r build
# Run tests
pnpm -r test
# Run the HTTP API example
pnpm --filter express-mcp-server devMIT