lodyhon
<p align="center">
<img src="https://raw.githubusercontent.com/Nightsky-na/lodyhon/main/assets/banner.svg" alt="lodyhon — Thai tax deduction planner, inside your AI chat" width="840">
</p>
<p align="center">
<strong>Thai personal income tax deduction planner for tax year 2569 — interactive cap bars, live sliders, and bracket drop view inside your AI chat.</strong>
</p>
<p align="center">
<a href="https://www.npmjs.com/package/lodyhon-mcp"><img src="https://img.shields.io/npm/v/lodyhon-mcp?color=0b7278&label=npm" alt="npm version"></a>
<a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-0f2744" alt="MIT License"></a>
<img src="https://img.shields.io/badge/node-%3E%3D20-149196" alt="Node.js >= 20">
<a href="https://modelcontextprotocol.io"><img src="https://img.shields.io/badge/MCP-Apps-0b7278" alt="MCP Apps"></a>
<img src="https://img.shields.io/badge/TypeScript-5.9-3178c6" alt="TypeScript">
<img src="https://img.shields.io/badge/tests-22%20passing-0e7c5a" alt="22 tests passing">
<img src="https://img.shields.io/badge/tax%20year-2569%20(2026)-0f2744" alt="Tax Year 2569">
</p>
<p align="center">
<a href="#quick-start">Quick start</a> |
<a href="#tools">Tools</a> |
<a href="#how-it-works">How it works</a> |
<a href="https://github.com/Nightsky-na/lodyhon/blob/main/docs/tax-rules-2569.md">Docs</a> |
<a href="https://github.com/Nightsky-na/lodyhon/blob/main/CONTRIBUTING.md">Contributing</a>
</p>
---
## ภาษาไทย
**lodyhon (ลดหย่อน)** คือ MCP Server พร้อมหน้าจอวางแผนแบบอินเทอร์แอกทีฟ (MCP App) สำหรับ **ภาษีเงินได้บุคคลธรรมดาของมนุษย์เงินเดือน มาตรา 40(1) ปีภาษี 2569** ที่ทำงานอยู่ในหน้าแชท AI ของคุณโดยตรง
- **เห็นช่องว่างทุกสิทธิลดหย่อน** พร้อมแถบเพดานรวมกลุ่ม (ประกันชีวิต+สุขภาพ ฿100,000 และกลุ่มเกษียณ ฿500,000) และเพดานแยกของ ThaiESG / ThaiESGX (฿300,000)
- **จัดอันดับว่าซื้ออะไรคุ้มสุด** จากภาษีที่ประหยัดได้จริง เงินที่ยังอยู่กับเรา (กองทุน > ประกัน > ค่าใช้จ่าย/บริจาค) และระยะเวลาถือครอง
- **ลากสไลเดอร์จำลองตัวเลขสดๆ** บนหน้าจอในแชท ใช้เครื่องยนต์คำนวณเดียวกับฝั่งเซิร์ฟเวอร์ ตัวเลขตรงกันเสมอ พร้อมกราฟขั้นบันไดภาษีและระยะตกขั้น (`ลดอีก ฿X ตกขั้นภาษี`)
- **โยนสลิปเงินเดือน / 50 ทวิ / ภ.ง.ด. / ใบเสร็จ** เพื่อส่งให้ AI ช่วยกรอกได้ (ไฟล์อยู่เฉพาะในเครื่องจนกว่าคุณจะกดส่ง) แล้วกด **ส่งแผนนี้ให้ AI** เพื่อคุยต่อได้ทันที
---
## About
Planning year-end Thai personal income tax usually means bouncing between a static spreadsheet, a standalone web calculator, and an AI chat that guesses deduction caps from stale training data.
Existing tools cover parts of the problem — single-tool calculators (`mythaitaxes-mcp`), bracket-only lookups (`inventivaglobal/thai-tax-mcp-server`), VAT/WHT references (`thailand-data-mcp`), chat-only prompt skills (`satasuk03/thai-personal-finance-planner`), or standalone web apps (`Tax-Planner`, `howtotax`) — but none combines verified 2569 rules with an interactive planner directly inside the AI conversation.
**lodyhon** bridges that gap:
- The **AI explains** eligibility, trade-offs, and next steps using grounded 2569 rules with official `rd.go.th` source links.
- The **in-chat MCP App UI** renders cap bars, a bracket step chart, and sliders so you can explore scenarios without another round-trip.
- **One shared TypeScript engine** (`src/engine.ts`) powers both the MCP server and the UI, guaranteeing the numbers in chat and on screen never diverge.
---
## Features
- **In-chat interactive MCP App UI:** Cap bars, sliders, and numeric inputs rendered directly inside MCP Apps hosts (`ui://lodyhon/planner`), recomputed locally with zero server round-trips.
- **Honest gap view and ranking:** Ranks remaining purchasable deductions by actual tax saved (handling bracket crossings), then by whether the money stays yours (`fund` > `insurance` > `spend`), then by shorter lock-up.
- **Shared-cap and donation awareness:** Enforces combined ceilings (`life_health` ฿100,000, `retirement` ฿500,000), gross-income percentage caps, and the post-deduction 10% donation cap with 2× e-Donation priority.
- **Bracket drop visibility:** Pure CSS bracket step chart showing how net income fills the 0%–35% progressive bands and the exact baht needed to drop into the next lower bracket.
- **Document drop for faster entry:** Drag-and-drop payslips, 50 ทวิ, ภ.ง.ด., or deduction receipts (PDF, images, CSV, TXT); files stay local until you click send.
- **Year-end deadline awareness:** Tracks days left until 31 December 2026 and reminds you that AMC cut-offs for RMF and ThaiESG can fall earlier.
- **Thai-first, host-adaptive design:** Styled with Kanit typography and a navy/teal palette that adapts to light and dark host themes across 360–720 px widths.
- **Stateless and local:** Stdio-only MCP server with no database, no persisted user financial data, and no outbound network requests.
---
## Quick start
### Claude Code
```sh
claude mcp add lodyhon -- npx -y lodyhon-mcp
```
### Claude Desktop
Add `lodyhon` to your `claude_desktop_config.json`:
```json
{
"mcpServers": {
"lodyhon": {
"command": "npx",
"args": ["-y", "lodyhon-mcp"]
}
}
}
```
### Local build
```sh
npm install
npm run build
```
Then point your MCP client to `node /path/to/lodyhon/dist/src/main.js` (or run `npm start` over stdio).
### Example prompt
> เงินเดือนทั้งปี 1,200,000 โบนัส 200,000 จ่ายประกันสังคมเต็ม กองทุนสำรองเลี้ยงชีพ 60,000 ประกันชีวิต 40,000 ดอกเบี้ยบ้าน 50,000 — ช่วยวางแผนลดหย่อนปี 2569 หน่อย
The assistant calls `thai_tax_overview`, summarizes your tax position and top opportunities in Thai, and opens the interactive planner UI.
---
## Tools
| Tool | Description | Inputs | Output |
|---|---|---|---|
| `thai_tax_overview` | Computes 40(1) tax owed, effective/marginal rates, remaining room per deduction, bracket drop distance, and ranked suggestions; opens `ui://lodyhon/planner`. | `salary` *(annual, number ≥ 0, default `0` — call with `{}` to open a blank planner)*, `bonus` *(number ≥ 0, default `0`)*, `deductions` *(partial map of deduction ID → baht ≥ 0, default `{}`)*, `year` *(integer, default `2569`)* | Thai text summary + `structuredContent: { input, result }` + `_meta.ui.resourceUri` |
| `thai_tax_deduction_rules` | Returns every supported deduction for the tax year with fixed caps, percentage caps, shared groups, lock-up periods, notes, and official source URLs. | `year` *(integer, default `2569`)* | Readable Thai rule list + full `TaxRules` object in `structuredContent` |
Negative values and unknown deduction IDs are rejected by Zod with clear validation errors. Amounts above a legal cap are not rejected — they are clamped to the legal ceiling and flagged with `capped: true` as a warning in both the summary and UI.
---
## The planner UI
Rendered via MCP resource `ui://lodyhon/planner` (`dist/ui/app.html`):
<p align="center">
<img src="https://raw.githubusercontent.com/Nightsky-na/lodyhon/main/assets/screenshots/planner-wide.png" alt="lodyhon planner at 720px: tax owed, step bar, ranked suggestions, bracket step chart and deduction sliders" width="720">
</p>
<table>
<tr>
<td align="center" width="33%"><img src="https://raw.githubusercontent.com/Nightsky-na/lodyhon/main/assets/screenshots/step-income.png" alt="Step 1: monthly salary, bonus and document drop" width="260"><br><sub><b>① รายได้</b> · income + document drop</sub></td>
<td align="center" width="33%"><img src="https://raw.githubusercontent.com/Nightsky-na/lodyhon/main/assets/screenshots/step-family.png" alt="Step 2: spouse, children, parents, social security" width="260"><br><sub><b>② ครอบครัว</b> · family allowances</sub></td>
<td align="center" width="33%"><img src="https://raw.githubusercontent.com/Nightsky-na/lodyhon/main/assets/screenshots/planner-dark.png" alt="Step 3 in dark theme: what to buy first and the bracket chart" width="260"><br><sub><b>③ วางแผนซื้อเพิ่ม</b> · dark theme</sub></td>
</tr>
</table>
- **Step-by-step flow (`รายได้ → ครอบครัว → วางแผนซื้อเพิ่ม`):** One panel at a time keeps the in-chat frame short. Opens on step 3 when the AI already knows your salary, or on step 1 with an empty form so you can type numbers yourself instead of putting everything in one chat message.
- **Editable income & family:** Monthly salary and bonus (`≈ N เดือน`), spouse checkbox, parent / disabled-dependant counters, and one-tap social security from salary (5% of wage ≤ ฿17,500/month).
- **Hero summary:** Estimated tax owed, effective rate, marginal bracket, net taxable income, and days remaining until 31 December 2026.
- **Ranked suggestions (`ซื้ออะไรคุ้มสุด`):** Top 4 unfilled purchasable deductions showing maximum tax saved, asset vs. expense tags, remaining room, and lock-up period.
- **Bracket step chart:** Visualizes net income across progressive tax brackets and highlights how many more baht drop you into the next lower rate (`ลดอีก ฿X ตกขั้นภาษี`).
- **Live cap bars and sliders:** Grouped cards for shared caps (`กลุ่มเกษียณ`, `ประกันชีวิต + สุขภาพ`) and standalone cards (e.g., `ThaiESG / ThaiESGX`, `ดอกเบี้ยบ้าน`) with `empty`, `maxed`, and `capped` states.
- **Collapsible `ลดหย่อนอื่นๆ`:** Keeps less common deductions (parents' health insurance, political party, art purchases, solar rooftop, general and 2× donations) out of the way until needed; auto-expands if already populated.
- **Local file drop (`โยนไฟล์ให้ AI ช่วยกรอก`):** Accepts payslips, 50 ทวิ, ภ.ง.ด., and receipts (PDF, images, CSV, TXT). Text/CSV is read locally in the iframe; images and PDFs are forwarded only if the host advertises binary support, otherwise the AI prompts you to attach them directly in chat.
- **Send back to chat (`ส่งแผนนี้ให้ AI`):** Pushes your adjusted plan (and any staged files) into `updateModelContext` and triggers `sendMessage` so the AI can continue advising on your updated numbers.
---
## Supported deductions (2569)
Automatic 40(1) deductions applied before itemized deductions:
- **Standard expense deduction (ค่าใช้จ่าย 40(1)):** 50% of gross income, capped at **฿100,000**.
- **Personal allowance (ค่าลดหย่อนส่วนตัว):** **฿60,000**.
| ID | Deduction | Cap | Shared group | Notes |
|---|---|---|---|---|
| `spouse` | คู่สมรส (ไม่มีเงินได้) | ฿60,000 | — | Spouse with no income |
| `children` | บุตร | Actual | — | ฿30,000/child; 2nd+ child born 2561+ is ฿60,000/child |
| `parents` | บิดามารดา | ฿120,000 | — | ฿30,000/parent (age 60+, income ≤ ฿30,000) |
| `disabled_dependant` | อุปการะผู้พิการ | Actual | — | ฿60,000/person |
| `pregnancy` | ฝากครรภ์และคลอดบุตร | ฿60,000 | — | — |
| `social_security` | ประกันสังคม | ฿10,500 | — | Wage base cap ฿17,500 starting 2569 |
| `life_insurance` | ประกันชีวิต | ฿100,000 | `life_health` (฿100,000) | Policy term ≥ 10 years |
| `health_insurance` | ประกันสุขภาพ | ฿25,000 | `life_health` (฿100,000) | Combined with `life_insurance` ≤ ฿100,000 |
| `parents_health_insurance` | ประกันสุขภาพบิดามารดา | ฿15,000 | — | — |
| `thai_esg` | ThaiESG / ThaiESGX | 30% of income, max ฿300,000 | — | Outside retirement cap; 5-year lock-up; 2569 is the final year at ฿300,000 |
| `pension_insurance` | ประกันบำนาญ | 15% of income, max ฿200,000 | `retirement` (฿500,000) | Combined retirement cap ฿500,000 |
| `pvd` | กองทุนสำรองเลี้ยงชีพ / กบข. | 15% of income, max ฿500,000 | `retirement` (฿500,000) | Combined retirement cap ฿500,000 |
| `rmf` | RMF | 30% of income, max ฿500,000 | `retirement` (฿500,000) | Hold ≥ 5 years and redeem at age 55+ |
| `home_loan_interest` | ดอกเบี้ยบ้าน | ฿100,000 | — | — |
| `political_party` | บริจาคพรรคการเมือง | ฿10,000 | — | — |
| `art` | ซื้องานศิลปะ | ฿100,000 | — | — |
| `solar_rooftop` | โซลาร์รูฟท็อป | ฿200,000 | — | Installed from 3 Mar 2569 with e-Tax invoice |
| `donation_double` | บริจาคการศึกษา/โรงพยาบาลรัฐ (×2) | 10% of net after other deductions (×2) | Donation cap | Via e-Donation; allocated before general donation |
| `donation_general` | บริจาคทั่วไป | 10% of net after other deductions (×1) | Donation cap | Via e-Donation |
> **Not in 2569:** **SSF** (ended after tax year 2567) and **Easy E-Receipt** (not renewed for 2569) are intentionally excluded. Proposed flood-repair deductions are also excluded until enacted into law.
For full tax brackets, formulas, and official source links for every entry, see [`docs/tax-rules-2569.md`](https://github.com/Nightsky-na/lodyhon/blob/main/docs/tax-rules-2569.md).
---
## How it works
```mermaid
flowchart LR
Chat["AI Chat Host"] -->|thai_tax_overview| Server["MCP Server (stdio)"]
Server --> Engine["Shared Tax Engine (src/engine.ts)"]
Engine -->|TaxResult + Thai summary| Chat
Chat -->|loads resource| UI["Planner UI (ui://lodyhon/planner)"]
UI -->|sliders recompute locally| Engine
UI -->|updateModelContext + sendMessage| Chat
```
1. You describe your income and deductions in chat; the model invokes `thai_tax_overview`.
2. The server runs `compute(input, rules)` and returns `structuredContent`, a Thai summary, and the `ui://lodyhon/planner` resource URI.
3. The host renders the single-file planner iframe and passes the result to `ui/app.ts`.
4. Dragging sliders or editing numbers calls the exact same `compute()` locally inside the iframe.
5. Clicking **ส่งแผนนี้ให้ AI** sends the adjusted plan (and any dropped documents) back to the model so you can keep iterating.
See [`docs/architecture.md`](https://github.com/Nightsky-na/lodyhon/blob/main/docs/architecture.md) for engine details, shared-cap allocation, donation ordering, and UI-to-host messaging.
---
## Development
Requires **Node.js `>= 20`**.
```sh
npm install
npm run typecheck
npm test
npm run build
```
`npm run build` produces:
- `dist/ui/app.html` — single-file inlined planner UI (Vite + `vite-plugin-singlefile`)
- `dist/src/main.js` — compiled stdio MCP server entry point
---
## Project structure
```text
lodyhon/
├── assets/
│ ├── banner.svg # README hero banner (navy + teal)
│ └── logo.svg # Brand mark + wordmark
├── docs/
│ ├── architecture.md # Engine, server, UI, and data flow
│ ├── tax-rules-2569.md # Complete 2569 brackets, caps, and sources
│ └── superpowers/specs/ # Original design specification
├── src/
│ ├── rules/
│ │ ├── types.ts # TaxRules & DeductionRule interfaces
│ │ ├── 2569.ts # Tax year 2569 rules table with source URLs
│ │ └── index.ts # Year registry (DEFAULT_YEAR = 2569)
│ ├── engine.ts # Pure calculation engine (shared by server & UI)
│ ├── summary.ts # Thai plain-text summary formatter
│ ├── server.ts # MCP server (2 tools + ui://lodyhon/planner)
│ └── main.ts # Stdio entry point (bin: lodyhon-mcp)
├── ui/
│ ├── app.html # MCP App HTML shell
│ ├── app.ts # Interactive planner logic + file drop
│ ├── theme.css # Design tokens & responsive light/dark styles
│ └── DESIGN.md # UI design tokens & DOM contract
└── test/
├── engine.test.ts # Tax math, caps, brackets, ranking tests
├── summary.test.ts # Summary formatting tests
└── server.test.ts # In-memory MCP server integration tests
```
---
## Roadmap
v1 focuses on **salaried income 40(1)** for **tax year 2569** over **stdio**. Planned follow-ups from the design spec:
- Additional income types **40(2)–40(8)** and mid-year **ภ.ง.ด.94** comparison
- Deeper receipt and **50 ทวิ** parsing workflows
- SME tax filing calendar
- Multi-year tax rule sets (`2570+`)
- HTTP transport alongside stdio
---
## Contributing
Contributions are welcome — especially rule updates backed by official `rd.go.th` / Royal Gazette citations, engine edge-case tests, and UI refinements.
- Read [`CONTRIBUTING.md`](https://github.com/Nightsky-na/lodyhon/blob/main/CONTRIBUTING.md) for local setup, adding tax rules with sources, and commit conventions.
- Participation is governed by our [`CODE_OF_CONDUCT.md`](CODE_OF_CONDUCT.md).
- To report a security issue privately, see [`SECURITY.md`](SECURITY.md).
---
## Disclaimer
All figures produced by `lodyhon` are **estimates for planning purposes only** and do **not** constitute formal tax, legal, or investment advice. Tax laws, eligibility conditions, and AMC year-end order cut-off dates can change — always verify final filing requirements with the Revenue Department at [rd.go.th](https://www.rd.go.th).
---
## License
Released under the [MIT License](https://github.com/Nightsky-na/lodyhon/blob/main/LICENSE). Copyright © 2026 Kontawat Wisetpaitoon.
TDQS
Scored across 2 tools
thai_tax_overview is an interactive calculator/planner while thai_tax_deduction_rules is a static reference listing caps and conditions, so their purposes are mostly distinct. There is some overlap because the overview also returns remaining room per deduction, which an agent might see as duplicating the rules tool, but compute-vs-lookup separates them adequately.
Both names use a snake_case thai_tax_ prefix with descriptive noun-phrase suffixes, which is predictable and readable. Neither uses a verb_noun pattern, so there is no action-oriented convention, but the two names are internally consistent.
Two tools is on the thin side for a tax domain; much of the functionality is packed into one large interactive planner tool. It is acceptable because the reference/list tool is cleanly separated, but the surface feels minimal.
Within the narrow scope of salaried 40(1) income for tax year 2569, the surface covers calculation, planning, and deduction rules. However, there are notable gaps: only one tax year, no handling of non-salary income types (40(2)-40(8)), and no filing/withholding guidance.