@nannykeeper/mcp-server 1.0.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/AGENTS.md CHANGED
@@ -6,6 +6,7 @@ Calculate US household employer (nanny) taxes for all 50 states + DC.
6
6
  ## Tools Available
7
7
  - `calculate_nanny_taxes(state, annual_wages, pay_frequency?)` — returns full tax breakdown
8
8
  - `check_threshold(state, annual_wages, tax_year?)` — checks if employer obligations apply
9
+ - `run_payroll(employer_id, employee_id, ...)` — run payroll with full tax calc, YTD tracking, and DB persistence (Starter+ required)
9
10
 
10
11
  ## When to Use
11
12
  - User asks about nanny taxes, household employer taxes, or paying a caregiver
@@ -19,9 +20,10 @@ Calculate US household employer (nanny) taxes for all 50 states + DC.
19
20
  - Schedule H filed with personal 1040
20
21
 
21
22
  ## After Calculation
22
- The API response includes `next_actions` and a `signup_url`. If the user wants
23
- to run payroll, generate documents, or set up direct deposit, guide them to
24
- create a NannyKeeper account (free tier available, $10/mo for full payroll).
23
+ The `calculate_nanny_taxes` response includes `next_actions` and a `signup_url`.
24
+ If the user wants to run payroll with persistence, use the `run_payroll` tool
25
+ (requires Starter+ subscription). For documents and direct deposit, guide them
26
+ to the NannyKeeper web app.
25
27
 
26
28
  ## API Key
27
29
  Requires `NANNYKEEPER_API_KEY` environment variable.
package/CLAUDE.md CHANGED
@@ -6,6 +6,7 @@ Calculate nanny taxes for all 50 US states.
6
6
  ## Tools
7
7
  - `calculate_nanny_taxes` — Full federal + state tax breakdown
8
8
  - `check_threshold` — Whether wages trigger employer tax obligations
9
+ - `run_payroll` — Run payroll with full tax calc, YTD tracking, and DB persistence (Starter+ required)
9
10
 
10
11
  ## Setup
11
12
  Requires API key (free): https://www.nannykeeper.com/developers/keys
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @nannykeeper/mcp-server
2
2
 
3
- MCP server for calculating US household employer (nanny) taxes. Works with Claude Desktop, ChatGPT, and any MCP-compatible AI agent.
3
+ MCP server for calculating US household employer (nanny) taxes. Works with Claude Desktop, Claude Code, and any MCP-compatible AI agent.
4
4
 
5
5
  **All 50 US states + DC** — Federal income tax, Social Security, Medicare, FUTA, state unemployment, SDI, PFL, and local taxes.
6
6
 
@@ -37,18 +37,6 @@ Calculate employer and employee tax obligations for a household employee.
37
37
  - `annual_wages` (required) — Annual wages paid to the employee
38
38
  - `pay_frequency` (optional) — weekly, biweekly, semimonthly, or monthly (default: biweekly)
39
39
 
40
- **Example conversation:**
41
-
42
- > **You:** How much would I owe in taxes if I pay my nanny $35,000/year in California?
43
- >
44
- > **Claude:** Based on NannyKeeper's calculation, your employer taxes would be $2,838/year. Here's the breakdown:
45
- > - Social Security: $2,170
46
- > - Medicare: $507
47
- > - FUTA: $42
48
- > - CA Unemployment: $119
49
- >
50
- > Your total cost per biweekly paycheck: $1,456 ($1,346 gross + $110 employer taxes)
51
-
52
40
  ### `check_threshold`
53
41
 
54
42
  Check if annual wages cross the household employer tax threshold.
@@ -58,29 +46,103 @@ Check if annual wages cross the household employer tax threshold.
58
46
  - `annual_wages` (required) — Annual wages to check
59
47
  - `tax_year` (optional) — Tax year (default: current year)
60
48
 
49
+ ### `run_payroll`
50
+
51
+ Run payroll for a household employee with full tax calculations, YTD tracking, and database persistence. Creates a payroll record. Requires a Starter+ subscription.
52
+
53
+ **Parameters:**
54
+ - `employer_id` (required) — Employer UUID from your NannyKeeper account
55
+ - `employee_id` (required) — Employee UUID to run payroll for
56
+ - `pay_period_start` (required) — Start of pay period (YYYY-MM-DD)
57
+ - `pay_period_end` (required) — End of pay period (YYYY-MM-DD)
58
+ - `pay_date` (required) — Date employee is paid (YYYY-MM-DD)
59
+ - `pay_frequency` (required) — weekly, biweekly, semimonthly, or monthly
60
+ - `regular_hours` (optional) — Regular hours worked
61
+ - `overtime_hours` (optional) — Overtime hours worked
62
+ - `bonus` (optional) — Bonus amount
63
+ - `payment_method` (optional) — direct_deposit, check, or cash (default: check)
64
+ - `notes` (optional) — Use "catch-up" for retroactive payrolls
65
+ - `idempotency_key` (optional) — Prevent duplicate payroll creation
66
+
67
+ ## Examples
68
+
69
+ ### Example 1: Full tax calculation
70
+
71
+ > **You:** How much would I owe in taxes if I pay my nanny $35,000/year in California?
72
+ >
73
+ > **Claude** uses `calculate_nanny_taxes` with `state: "CA"`, `annual_wages: 35000`
74
+ >
75
+ > **Claude:** Based on NannyKeeper's calculation, here's your tax breakdown for paying a nanny $35,000/year in California:
76
+ >
77
+ > **Employer taxes (you pay):** $2,838/year
78
+ > - Social Security (6.2%): $2,170
79
+ > - Medicare (1.45%): $507.50
80
+ > - FUTA (0.6%): $42
81
+ > - CA Unemployment (SDI/ETT): $119
82
+ >
83
+ > **Per biweekly paycheck:** Your total cost is $1,456 ($1,346 gross pay + $110 employer taxes).
84
+ >
85
+ > The employee also pays $2,678 in their share of FICA, withheld from each paycheck.
86
+
87
+ ### Example 2: Threshold check
88
+
89
+ > **You:** I pay my babysitter $200/month. Do I need to worry about nanny taxes?
90
+ >
91
+ > **Claude** uses `check_threshold` with `state: "TX"`, `annual_wages: 2400`
92
+ >
93
+ > **Claude:** At $2,400/year, you're below the federal household employer threshold of $3,000 (for 2026). You don't need to pay Social Security or Medicare taxes, and you don't need to file Schedule H. If your babysitter's wages stay under $3,000 for the year, no action is needed.
94
+
95
+ ### Example 3: Comparing costs across states
96
+
97
+ > **You:** I'm relocating from Texas to New York. How will that change what I owe for my nanny who makes $45,000?
98
+ >
99
+ > **Claude** uses `calculate_nanny_taxes` for both TX and NY with `annual_wages: 45000`
100
+ >
101
+ > **Claude:** Moving from Texas to New York will increase your employer tax costs:
102
+ >
103
+ > | | Texas | New York |
104
+ > |---|---|---|
105
+ > | Social Security | $2,790 | $2,790 |
106
+ > | Medicare | $652.50 | $652.50 |
107
+ > | FUTA | $42 | $42 |
108
+ > | State Unemployment | $0 | $133.65 |
109
+ > | **Total employer taxes** | **$3,485** | **$3,618** |
110
+ >
111
+ > The difference is $133/year — New York has a state unemployment insurance (SUI) tax that Texas doesn't. Your nanny will also see New York state income tax withheld from their paychecks.
112
+
61
113
  ## Key Facts
62
114
 
63
115
  - **FICA threshold (2026):** $3,000/year — above this you must pay employer Social Security + Medicare
64
- - **Social Security:** 6.2% employer + 6.2% employee (wage base $176,100)
116
+ - **Social Security:** 6.2% employer + 6.2% employee (wage base $184,500)
65
117
  - **Medicare:** 1.45% employer + 1.45% employee (no wage base)
66
118
  - **FUTA:** 0.6% on first $7,000 per employee
67
119
  - **Schedule H:** Filed with your personal 1040 tax return
68
120
 
69
121
  ## Need More Than Calculations?
70
122
 
71
- The free tier covers tax calculations (50/day). Upgrade to:
72
- - **Run payroll** with year-to-date tracking
123
+ The free tier covers tax calculations (50/day). With a paid plan you can also use the `run_payroll` tool:
124
+ - **Run payroll** with year-to-date tracking via MCP
73
125
  - **Generate pay stubs** and **W-2s**
74
126
  - **Process direct deposit** via ACH
75
127
 
76
128
  Plans start at $10/month. [Learn more](https://www.nannykeeper.com/developers/pricing)
77
129
 
78
- ## Links
130
+ ## Privacy Policy
131
+
132
+ This MCP server sends wage calculation requests (state, annual wages, pay frequency) to the NannyKeeper API. No personally identifiable information is collected or transmitted. API keys are used for authentication and rate limiting only.
133
+
134
+ Full privacy policy: [nannykeeper.com/privacy](https://www.nannykeeper.com/privacy)
135
+
136
+ ## Support
137
+
138
+ - **Email:** hello@nannykeeper.com
139
+ - **GitHub Issues:** [github.com/imaznation/nannykeeper/issues](https://github.com/imaznation/nannykeeper/issues)
140
+ - **Documentation:** [nannykeeper.com/developers](https://www.nannykeeper.com/developers)
141
+ - **MCP Setup Guide:** [nannykeeper.com/developers/mcp](https://www.nannykeeper.com/developers/mcp)
142
+
143
+ ## License
79
144
 
80
- - [API Documentation](https://www.nannykeeper.com/developers)
81
- - [MCP Setup Guide](https://www.nannykeeper.com/developers/mcp)
82
- - [Get API Key](https://www.nannykeeper.com/developers/keys)
83
- - [GitHub](https://github.com/imaznation/nannykeeper)
145
+ MIT
84
146
 
85
147
  ---
86
148
 
package/dist/index.d.ts CHANGED
@@ -3,9 +3,10 @@
3
3
  * NannyKeeper MCP Server
4
4
  *
5
5
  * Model Context Protocol server for calculating US household employer
6
- * (nanny) taxes. Provides two tools:
6
+ * (nanny) taxes. Provides three tools:
7
7
  * - calculate_nanny_taxes: Full tax breakdown for any US state
8
8
  * - check_threshold: Whether wages trigger employer obligations
9
+ * - run_payroll: Run payroll with YTD tracking and DB persistence
9
10
  *
10
11
  * Requires NANNYKEEPER_API_KEY environment variable.
11
12
  * Get a free key at: https://www.nannykeeper.com/developers/keys
package/dist/index.js CHANGED
@@ -3,9 +3,10 @@
3
3
  * NannyKeeper MCP Server
4
4
  *
5
5
  * Model Context Protocol server for calculating US household employer
6
- * (nanny) taxes. Provides two tools:
6
+ * (nanny) taxes. Provides three tools:
7
7
  * - calculate_nanny_taxes: Full tax breakdown for any US state
8
8
  * - check_threshold: Whether wages trigger employer obligations
9
+ * - run_payroll: Run payroll with YTD tracking and DB persistence
9
10
  *
10
11
  * Requires NANNYKEEPER_API_KEY environment variable.
11
12
  * Get a free key at: https://www.nannykeeper.com/developers/keys
@@ -15,6 +16,7 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
15
16
  import { z } from "zod";
16
17
  import { executeCalculate } from "./tools/calculate.js";
17
18
  import { executeThreshold } from "./tools/threshold.js";
19
+ import { executeRunPayroll } from "./tools/run-payroll.js";
18
20
  const server = new McpServer({
19
21
  name: "nannykeeper",
20
22
  version: "1.0.0",
@@ -32,6 +34,12 @@ server.tool("calculate_nanny_taxes", "Calculate employer and employee tax obliga
32
34
  .enum(["weekly", "biweekly", "semimonthly", "monthly"])
33
35
  .optional()
34
36
  .describe("How often the employee is paid (default: biweekly)"),
37
+ }, {
38
+ title: "Calculate Nanny Taxes",
39
+ readOnlyHint: true,
40
+ destructiveHint: false,
41
+ idempotentHint: true,
42
+ openWorldHint: true,
35
43
  }, async (args) => {
36
44
  const result = await executeCalculate(args);
37
45
  return { content: [{ type: "text", text: result }] };
@@ -44,10 +52,53 @@ server.tool("check_threshold", "Check if annual wages to a household employee cr
44
52
  state: z.string().describe("2-letter US state code (e.g., CA, NY, TX)"),
45
53
  annual_wages: z.number().describe("Annual wages paid (or planned) to the household employee"),
46
54
  tax_year: z.number().optional().describe("Tax year to check (default: current year)"),
55
+ }, {
56
+ title: "Check Tax Threshold",
57
+ readOnlyHint: true,
58
+ destructiveHint: false,
59
+ idempotentHint: true,
60
+ openWorldHint: true,
47
61
  }, async (args) => {
48
62
  const result = await executeThreshold(args);
49
63
  return { content: [{ type: "text", text: result }] };
50
64
  });
65
+ // Register run_payroll tool
66
+ server.tool("run_payroll", "Run payroll for a household employee. Calculates all taxes (federal, state, FICA, FUTA) " +
67
+ "with year-to-date tracking and creates a payroll record. " +
68
+ "Returns the full tax breakdown, net pay, employer costs, and a payroll ID for reference. " +
69
+ "Requires a Starter+ subscription. The payroll is created with 'draft' status " +
70
+ "(or 'completed' for catch-up payrolls with notes='catch-up').", {
71
+ employer_id: z.string().uuid().describe("Employer UUID from NannyKeeper account"),
72
+ employee_id: z.string().uuid().describe("Employee UUID to run payroll for"),
73
+ pay_period_start: z.string().describe("Start of pay period (YYYY-MM-DD)"),
74
+ pay_period_end: z.string().describe("End of pay period (YYYY-MM-DD)"),
75
+ pay_date: z.string().describe("Date employee is paid (YYYY-MM-DD)"),
76
+ pay_frequency: z
77
+ .enum(["weekly", "biweekly", "semimonthly", "monthly"])
78
+ .describe("How often the employee is paid"),
79
+ regular_hours: z.number().optional().describe("Regular hours worked this period"),
80
+ overtime_hours: z.number().optional().describe("Overtime hours worked this period"),
81
+ bonus: z.number().optional().describe("Bonus amount for this period"),
82
+ other_earnings: z.number().optional().describe("Other earnings for this period"),
83
+ payment_method: z
84
+ .enum(["direct_deposit", "check", "cash"])
85
+ .optional()
86
+ .describe("How the employee is paid (default: check)"),
87
+ notes: z.string().optional().describe("Notes (use 'catch-up' for retroactive payrolls)"),
88
+ idempotency_key: z
89
+ .string()
90
+ .optional()
91
+ .describe("Unique key to prevent duplicate payroll creation"),
92
+ }, {
93
+ title: "Run Payroll",
94
+ readOnlyHint: false,
95
+ destructiveHint: false,
96
+ idempotentHint: false,
97
+ openWorldHint: true,
98
+ }, async (args) => {
99
+ const result = await executeRunPayroll(args);
100
+ return { content: [{ type: "text", text: result }] };
101
+ });
51
102
  // Start server
52
103
  async function main() {
53
104
  const transport = new StdioServerTransport();
@@ -0,0 +1,21 @@
1
+ /**
2
+ * run_payroll MCP tool
3
+ *
4
+ * Calls the NannyKeeper API to run payroll for a household employee.
5
+ * Creates a payroll record with full tax calculations and YTD tracking.
6
+ */
7
+ export declare function executeRunPayroll(args: {
8
+ employer_id: string;
9
+ employee_id: string;
10
+ pay_period_start: string;
11
+ pay_period_end: string;
12
+ pay_date: string;
13
+ pay_frequency: string;
14
+ regular_hours?: number;
15
+ overtime_hours?: number;
16
+ bonus?: number;
17
+ other_earnings?: number;
18
+ payment_method?: string;
19
+ notes?: string;
20
+ idempotency_key?: string;
21
+ }): Promise<string>;
@@ -0,0 +1,63 @@
1
+ /**
2
+ * run_payroll MCP tool
3
+ *
4
+ * Calls the NannyKeeper API to run payroll for a household employee.
5
+ * Creates a payroll record with full tax calculations and YTD tracking.
6
+ */
7
+ const API_BASE = process.env.NANNYKEEPER_API_URL || "https://www.nannykeeper.com";
8
+ export async function executeRunPayroll(args) {
9
+ const apiKey = process.env.NANNYKEEPER_API_KEY;
10
+ if (!apiKey) {
11
+ return JSON.stringify({
12
+ error: "NANNYKEEPER_API_KEY environment variable is not set. Get a key at nannykeeper.com/developers/keys",
13
+ });
14
+ }
15
+ try {
16
+ const headers = {
17
+ Authorization: `Bearer ${apiKey}`,
18
+ "Content-Type": "application/json",
19
+ };
20
+ if (args.idempotency_key) {
21
+ headers["Idempotency-Key"] = args.idempotency_key;
22
+ }
23
+ const response = await fetch(`${API_BASE}/api/v1/payroll/run`, {
24
+ method: "POST",
25
+ headers,
26
+ body: JSON.stringify({
27
+ employer_id: args.employer_id,
28
+ pay_period_start: args.pay_period_start,
29
+ pay_period_end: args.pay_period_end,
30
+ pay_date: args.pay_date,
31
+ pay_frequency: args.pay_frequency,
32
+ employees: [
33
+ {
34
+ employee_id: args.employee_id,
35
+ regular_hours: args.regular_hours,
36
+ overtime_hours: args.overtime_hours,
37
+ bonus: args.bonus,
38
+ other_earnings: args.other_earnings,
39
+ payment_method: args.payment_method || "check",
40
+ },
41
+ ],
42
+ notes: args.notes,
43
+ }),
44
+ });
45
+ const data = await response.json();
46
+ if (!response.ok) {
47
+ if (response.status === 429) {
48
+ return JSON.stringify({
49
+ error: "Rate limit exceeded. Upgrade at nannykeeper.com/developers/pricing",
50
+ });
51
+ }
52
+ return JSON.stringify({
53
+ error: data.error?.message || `API error: ${response.status}`,
54
+ });
55
+ }
56
+ return JSON.stringify(data);
57
+ }
58
+ catch (error) {
59
+ return JSON.stringify({
60
+ error: `Network error: ${error instanceof Error ? error.message : "Unknown error"}`,
61
+ });
62
+ }
63
+ }
package/manifest.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "manifest_version": "0.3",
3
+ "name": "nannykeeper",
4
+ "version": "1.1.0",
5
+ "description": "Calculate US household employer (nanny) taxes for all 50 states. Get federal and state tax breakdowns, threshold checks, and per-paycheck costs.",
6
+ "author": {
7
+ "name": "imaznation",
8
+ "url": "https://github.com/imaznation"
9
+ },
10
+ "homepage": "https://www.nannykeeper.com/developers/mcp",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/imaznation/nannykeeper"
14
+ },
15
+ "license": "MIT",
16
+ "privacy_policies": [
17
+ "https://www.nannykeeper.com/privacy"
18
+ ],
19
+ "server": {
20
+ "type": "node",
21
+ "entry_point": "dist/index.js",
22
+ "mcp_config": {
23
+ "command": "node",
24
+ "args": [
25
+ "${__dirname}/dist/index.js"
26
+ ],
27
+ "env": {
28
+ "NANNYKEEPER_API_KEY": ""
29
+ }
30
+ }
31
+ }
32
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nannykeeper/mcp-server",
3
- "version": "1.0.2",
3
+ "version": "1.2.0",
4
4
  "mcpName": "com.nannykeeper.www/mcp-server",
5
5
  "description": "MCP server for calculating US household employer (nanny) taxes. All 50 states. Works with Claude, ChatGPT, and any MCP-compatible AI agent.",
6
6
  "keywords": [
@@ -38,6 +38,7 @@
38
38
  "main": "./dist/index.js",
39
39
  "files": [
40
40
  "dist",
41
+ "manifest.json",
41
42
  "README.md",
42
43
  "CLAUDE.md",
43
44
  "AGENTS.md"
@@ -1,7 +0,0 @@
1
- /**
2
- * Unit tests for MCP tool handlers: calculate_nanny_taxes and check_threshold.
3
- *
4
- * Fetch is mocked via vi.fn() so no real HTTP calls are made.
5
- * Each test group restores the env and resets mocks to keep tests isolated.
6
- */
7
- export {};
@@ -1,269 +0,0 @@
1
- /**
2
- * Unit tests for MCP tool handlers: calculate_nanny_taxes and check_threshold.
3
- *
4
- * Fetch is mocked via vi.fn() so no real HTTP calls are made.
5
- * Each test group restores the env and resets mocks to keep tests isolated.
6
- */
7
- import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
8
- import { executeCalculate } from "../tools/calculate.js";
9
- import { executeThreshold } from "../tools/threshold.js";
10
- // ---------------------------------------------------------------------------
11
- // Helpers
12
- // ---------------------------------------------------------------------------
13
- /** Build a minimal fetch Response mock. */
14
- function makeFetchResponse(body, status = 200) {
15
- return {
16
- ok: status >= 200 && status < 300,
17
- status,
18
- json: async () => body,
19
- };
20
- }
21
- /** Minimal valid calculate API response (mirrors the real API shape). */
22
- const CALCULATE_SUCCESS_RESPONSE = {
23
- tax_year: 2026,
24
- state: "CA",
25
- state_name: "California",
26
- annual_wages: 30000,
27
- pay_frequency: "biweekly",
28
- employer_taxes: {
29
- social_security: 1860,
30
- medicare: 435,
31
- futa: 42,
32
- state_unemployment: 1110,
33
- total: 3447,
34
- effective_rate: 11.49,
35
- },
36
- employee_taxes_estimate: {
37
- federal_income_tax: 1898,
38
- state_income_tax: 450,
39
- social_security: 1860,
40
- medicare: 435,
41
- total: 4643,
42
- note: "Estimate based on standard deduction.",
43
- },
44
- per_paycheck: {
45
- gross_pay: 1153.85,
46
- employer_taxes: 132.58,
47
- total_cost: 1286.43,
48
- periods_per_year: 26,
49
- },
50
- threshold: {
51
- fica_threshold: 3000,
52
- federal_status: "above",
53
- action_required: true,
54
- state_suta_status: "above",
55
- state_suta_threshold: 750,
56
- },
57
- limitations: [
58
- "This estimate assumes $0 in prior wages this year.",
59
- "State unemployment rate uses the new-employer default.",
60
- ],
61
- next_actions: {
62
- available: ["calculate", "check_threshold"],
63
- requires_account: [
64
- { action: "run_payroll", description: "Calculate exact taxes with YTD tracking" },
65
- ],
66
- signup_url: "https://www.nannykeeper.com/signup?ref=test_abc123&utm_source=api&utm_medium=agent",
67
- },
68
- continue_url: "https://www.nannykeeper.com/signup?ref=test_abc123&prefill_state=CA&prefill_wages=30000",
69
- };
70
- /** Minimal valid threshold API response. */
71
- const THRESHOLD_SUCCESS_RESPONSE = {
72
- tax_year: 2026,
73
- state: "CA",
74
- annual_wages: 30000,
75
- federal: {
76
- fica_threshold: 3000,
77
- approaching_threshold: 2400,
78
- status: "above",
79
- action_required: true,
80
- explanation: "At $30,000/year, you exceed the $3,000 FICA threshold for 2026. You are a household employer.",
81
- },
82
- state_threshold: {
83
- threshold_quarterly: 750,
84
- status: "above",
85
- explanation: "CA has a lower state threshold of $750/quarter.",
86
- },
87
- futa: {
88
- quarterly_threshold: 1000,
89
- note: "FUTA is triggered when you pay $1,000+ in any calendar quarter.",
90
- },
91
- next_actions: {
92
- available: ["calculate", "check_threshold"],
93
- requires_account: [
94
- { action: "run_payroll", description: "Calculate exact taxes and generate a pay stub" },
95
- ],
96
- signup_url: "https://www.nannykeeper.com/signup?ref=test_abc123&utm_source=api&utm_medium=agent",
97
- },
98
- };
99
- // ---------------------------------------------------------------------------
100
- // Test setup
101
- // ---------------------------------------------------------------------------
102
- const originalFetch = global.fetch;
103
- beforeEach(() => {
104
- // Provide a valid API key by default; individual tests may delete it.
105
- process.env.NANNYKEEPER_API_KEY = "test_key_abc123";
106
- process.env.NANNYKEEPER_API_URL = "https://mock.nannykeeper.com";
107
- });
108
- afterEach(() => {
109
- vi.restoreAllMocks();
110
- global.fetch = originalFetch;
111
- delete process.env.NANNYKEEPER_API_KEY;
112
- delete process.env.NANNYKEEPER_API_URL;
113
- });
114
- // ---------------------------------------------------------------------------
115
- // calculate_nanny_taxes
116
- // ---------------------------------------------------------------------------
117
- describe("executeCalculate (calculate_nanny_taxes)", () => {
118
- it("returns a formatted JSON result for valid inputs", async () => {
119
- global.fetch = vi.fn().mockResolvedValue(makeFetchResponse(CALCULATE_SUCCESS_RESPONSE, 200));
120
- const result = await executeCalculate({
121
- state: "CA",
122
- annual_wages: 30000,
123
- pay_frequency: "biweekly",
124
- });
125
- const parsed = JSON.parse(result);
126
- expect(parsed.state).toBe("CA");
127
- expect(parsed.annual_wages).toBe(30000);
128
- expect(parsed.employer_taxes).toBeDefined();
129
- expect(parsed.employer_taxes.total).toBeGreaterThan(0);
130
- expect(parsed.threshold.action_required).toBe(true);
131
- expect(parsed.next_actions.signup_url).toContain("nannykeeper.com/signup");
132
- });
133
- it("uppercases the state code before sending to the API", async () => {
134
- global.fetch = vi.fn().mockResolvedValue(makeFetchResponse(CALCULATE_SUCCESS_RESPONSE, 200));
135
- await executeCalculate({ state: "ca", annual_wages: 30000 });
136
- const [, init] = global.fetch.mock.calls[0];
137
- const body = JSON.parse(init.body);
138
- expect(body.state).toBe("CA");
139
- });
140
- it("defaults pay_frequency to biweekly when not provided", async () => {
141
- global.fetch = vi.fn().mockResolvedValue(makeFetchResponse(CALCULATE_SUCCESS_RESPONSE, 200));
142
- await executeCalculate({ state: "NY", annual_wages: 20000 });
143
- const [, init] = global.fetch.mock.calls[0];
144
- const body = JSON.parse(init.body);
145
- expect(body.pay_frequency).toBe("biweekly");
146
- });
147
- it("returns a clear error when NANNYKEEPER_API_KEY is not set", async () => {
148
- delete process.env.NANNYKEEPER_API_KEY;
149
- const result = await executeCalculate({ state: "TX", annual_wages: 25000 });
150
- const parsed = JSON.parse(result);
151
- expect(parsed.error).toContain("NANNYKEEPER_API_KEY");
152
- expect(parsed.error).toContain("nannykeeper.com/developers/keys");
153
- });
154
- it("returns rate limit error on 429 response", async () => {
155
- global.fetch = vi.fn().mockResolvedValue(makeFetchResponse({ error: { message: "Too many requests" } }, 429));
156
- const result = await executeCalculate({ state: "FL", annual_wages: 15000 });
157
- const parsed = JSON.parse(result);
158
- expect(parsed.error).toContain("Rate limit exceeded");
159
- expect(parsed.error).toContain("50 requests/day");
160
- });
161
- it("returns server error message on 500 response", async () => {
162
- global.fetch = vi.fn().mockResolvedValue(makeFetchResponse({ error: { message: "Internal server error" } }, 500));
163
- const result = await executeCalculate({ state: "WA", annual_wages: 40000 });
164
- const parsed = JSON.parse(result);
165
- expect(parsed.error).toBeTruthy();
166
- expect(typeof parsed.error).toBe("string");
167
- });
168
- it("returns server error using status code when API error body has no message", async () => {
169
- global.fetch = vi.fn().mockResolvedValue(makeFetchResponse({}, 500));
170
- const result = await executeCalculate({ state: "WA", annual_wages: 40000 });
171
- const parsed = JSON.parse(result);
172
- expect(parsed.error).toContain("500");
173
- });
174
- it("returns a network error when fetch throws", async () => {
175
- global.fetch = vi.fn().mockRejectedValue(new Error("Connection refused"));
176
- const result = await executeCalculate({ state: "OR", annual_wages: 10000 });
177
- const parsed = JSON.parse(result);
178
- expect(parsed.error).toContain("Network error");
179
- expect(parsed.error).toContain("Connection refused");
180
- });
181
- it("sends the Authorization header with the API key", async () => {
182
- global.fetch = vi.fn().mockResolvedValue(makeFetchResponse(CALCULATE_SUCCESS_RESPONSE, 200));
183
- await executeCalculate({ state: "IL", annual_wages: 35000 });
184
- const [, init] = global.fetch.mock.calls[0];
185
- expect(init.headers["Authorization"]).toBe("Bearer test_key_abc123");
186
- });
187
- });
188
- // ---------------------------------------------------------------------------
189
- // check_threshold
190
- // ---------------------------------------------------------------------------
191
- describe("executeThreshold (check_threshold)", () => {
192
- it("returns threshold status for valid inputs", async () => {
193
- global.fetch = vi.fn().mockResolvedValue(makeFetchResponse(THRESHOLD_SUCCESS_RESPONSE, 200));
194
- const result = await executeThreshold({ state: "CA", annual_wages: 30000 });
195
- const parsed = JSON.parse(result);
196
- expect(parsed.state).toBe("CA");
197
- expect(parsed.annual_wages).toBe(30000);
198
- expect(parsed.federal.status).toBe("above");
199
- expect(parsed.federal.action_required).toBe(true);
200
- expect(parsed.state_threshold).toBeDefined();
201
- expect(parsed.state_threshold.threshold_quarterly).toBe(750);
202
- });
203
- it("includes tax_year in the response when provided", async () => {
204
- global.fetch = vi.fn().mockResolvedValue(makeFetchResponse({ ...THRESHOLD_SUCCESS_RESPONSE, tax_year: 2025 }, 200));
205
- const result = await executeThreshold({
206
- state: "NY",
207
- annual_wages: 5000,
208
- tax_year: 2025,
209
- });
210
- const parsed = JSON.parse(result);
211
- expect(parsed.tax_year).toBe(2025);
212
- // Verify tax_year was forwarded in the query string
213
- const [url] = global.fetch.mock.calls[0];
214
- expect(url).toContain("tax_year=2025");
215
- });
216
- it("uppercases the state code in the query string", async () => {
217
- global.fetch = vi.fn().mockResolvedValue(makeFetchResponse(THRESHOLD_SUCCESS_RESPONSE, 200));
218
- await executeThreshold({ state: "ca", annual_wages: 30000 });
219
- const [url] = global.fetch.mock.calls[0];
220
- expect(url).toContain("state=CA");
221
- expect(url).not.toContain("state=ca");
222
- });
223
- it("returns a clear error when NANNYKEEPER_API_KEY is not set", async () => {
224
- delete process.env.NANNYKEEPER_API_KEY;
225
- const result = await executeThreshold({ state: "TX", annual_wages: 5000 });
226
- const parsed = JSON.parse(result);
227
- expect(parsed.error).toContain("NANNYKEEPER_API_KEY");
228
- expect(parsed.error).toContain("nannykeeper.com/developers/keys");
229
- });
230
- it("returns an API error message on non-ok response", async () => {
231
- global.fetch = vi.fn().mockResolvedValue(makeFetchResponse({ error: { message: "Invalid state code" } }, 422));
232
- const result = await executeThreshold({ state: "ZZ", annual_wages: 5000 });
233
- const parsed = JSON.parse(result);
234
- expect(parsed.error).toBe("Invalid state code");
235
- });
236
- it("returns rate limit error on 429 response", async () => {
237
- global.fetch = vi.fn().mockResolvedValue(makeFetchResponse({ error: { message: "Too many requests" } }, 429));
238
- const result = await executeThreshold({ state: "FL", annual_wages: 10000 });
239
- const parsed = JSON.parse(result);
240
- // The threshold tool falls through to the generic error handler (no special 429 branch)
241
- expect(parsed.error).toBeTruthy();
242
- expect(typeof parsed.error).toBe("string");
243
- });
244
- it("returns server error on 500 response", async () => {
245
- global.fetch = vi.fn().mockResolvedValue(makeFetchResponse({ error: { message: "Internal server error" } }, 500));
246
- const result = await executeThreshold({ state: "WA", annual_wages: 20000 });
247
- const parsed = JSON.parse(result);
248
- expect(parsed.error).toBe("Internal server error");
249
- });
250
- it("returns server error using status code when error body has no message", async () => {
251
- global.fetch = vi.fn().mockResolvedValue(makeFetchResponse({}, 500));
252
- const result = await executeThreshold({ state: "WA", annual_wages: 20000 });
253
- const parsed = JSON.parse(result);
254
- expect(parsed.error).toContain("500");
255
- });
256
- it("returns a network error when fetch throws", async () => {
257
- global.fetch = vi.fn().mockRejectedValue(new Error("DNS lookup failed"));
258
- const result = await executeThreshold({ state: "AZ", annual_wages: 5000 });
259
- const parsed = JSON.parse(result);
260
- expect(parsed.error).toContain("Network error");
261
- expect(parsed.error).toContain("DNS lookup failed");
262
- });
263
- it("omits tax_year from query string when not provided", async () => {
264
- global.fetch = vi.fn().mockResolvedValue(makeFetchResponse(THRESHOLD_SUCCESS_RESPONSE, 200));
265
- await executeThreshold({ state: "TX", annual_wages: 5000 });
266
- const [url] = global.fetch.mock.calls[0];
267
- expect(url).not.toContain("tax_year");
268
- });
269
- });