Skip to content
Projects

About

Taiwan legal MCP server and CLI for Dr.Legal: search 22.85 million court judgments, current statutes, agency rulings, and labor decisions, with full-text access, links between court instances, and citation verification. Connects to AI tools such as Claude, ChatGPT, Gemini CLI, and Codex. Free to use; an account is required.

AI & Machine Learning

How these counts are measured

Measured star growth

in 24h
0
in 7 days
+30
in 15 days
+37
in 1 month
Collecting history

Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.

README.en.md

Original

Taiwan Legal RAG: Taiwan Legal MCP Server & CLI (twlegalrag)

Author: Aaron Huang (黃思齊), attorney-at-law, founder of Dr.Legal / 法律偵探 (profile).

🌐 Language / 語言 / 言語

繁體中文 ・ English ・ 日本語

GitHub stars PyPI Glama MCP server score

If TLR is useful, a ⭐ Star at the top right helps others find it.


Free, no API key; sign in to a Dr.Legal account when connecting. A Taiwan legal MCP server: add one URL (https://tlr.dr-legal.com.tw/mcp) to Claude, ChatGPT, Gemini CLI, Microsoft 365 Copilot, Codex or Cursor and your AI assistant can semantically search 22M+ Taiwan court judgments, administrative interpretations and Constitutional Court decisions, each with a citation check. A source-available CLI (twlegalrag) talks to the same backend.

Search by issuing court

Since 2026-11-22, you can name Taiwan’s Supreme Court (最高法院) or Supreme Administrative Court (最高行政法院) directly in a judgment search. For example, 最高法院民事判決 租賃押金返還 searches Supreme Court civil judgments about the return of a rental deposit. You can also ask for decisions by other courts that cite the Supreme Court. This works with existing MCP connections and the CLI. Changelog

Quick connect: Taiwan law MCP server

MCP endpoint (Streamable HTTP, OAuth):

https://tlr.dr-legal.com.tw/mcp
Client How to connect
Claude (web / desktop) Connect from the Claude connector directory, or add a custom connector and paste the endpoint
Claude Code claude mcp add --transport http --scope user tlr https://tlr.dr-legal.com.tw/mcp
Codex CLI codex mcp add tlr --url https://tlr.dr-legal.com.tw/mcp, then codex mcp login tlr
ChatGPT, Gemini, Cursor, Microsoft 365 Copilot Add a custom MCP connector and paste the endpoint; steps under "Other ways to connect" below

The first connection opens the Dr.Legal sign-in page (Google or email, free registration). No API key to request. Six tools: judgment search, judgment full text with appeal history, a citation-whitelisted bundle, current statute article lookup, administrative-interpretation lookup by serial number, and semantic search over administrative interpretations. Illustrated steps: dr-legal.com.tw/en/mcp.

Taiwan Legal RAG CLI retrieves Taiwan court judgments from Legal Detective's public TLR endpoint and packages them for use with your own AI tools. It does not generate legal advice, does not call any LLM, and does not guarantee semantic faithfulness of third-party model outputs. Its built-in citation check only verifies whether cited judgments belong to the retrieved bundle.

Data coverage (as of 2026-11-21, counted directly from the production database)

Corpus Size Access
Court judgments (all Taiwan court levels) 22,846,886 semantic + lexical search + exact docket lookup; daily incremental sync from Judicial Yuan open data, including post-publication corrections and takedowns
Appeal-chain relations 3,303,924 attached as case_history per judgment, with 主文 "廢棄/撤銷/駁回" flags and the disposition
Administrative rules / interpretations (行政規則・函釋) 107,921 exact serial lookup + semantic search (hosted MCP); 107 issuing agencies, per-agency detail below
Judicial Yuan Grand Justices interpretations (大法官解釋) 813 same as above
Constitutional Court judgments (憲判字) 59 same as above
Tax interpretations (財政部) 9,093 same as above
Interpretation validity ledger 85,024 repealed / ceased / superseded status, checked before citing
Labour arbitration decisions (勞動部裁決委員會) 467 surfaced alongside labour queries, explicitly labelled as non-court decisions
Constitutional-tier instruments (憲法位階) 7 228 articles: the Constitution, its additional articles, the implementation procedure and the martial-law orders. Searchable on dr-legal.com.tw
Acts (法律) 1,022 / 44,503 articles Named 法/律/條例/通則 per Central Regulation Standard Act §2. Same as above
Regulations (命令) 7,259 / 128,773 articles Named 規程/規則/細則/辦法/綱要/標準/準則 per §3. Same as above
Repealed instruments 3,526 320 acts, 3,204 regulations, plus constitutional-tier norms such as the Temporary Provisions; flagged as repealed for historical research

Judgments sync daily (Judicial Yuan open data lags publication by a few days; for very recent decisions consult the official site). Numbers above are taken directly from the production database on the stated date, not estimates.

Judgment detail (by court level / case category)

法院層級 筆數
地方法院 17,215,419
地方法院簡易庭 3,347,941
高等法院及分院 1,366,345
最高法院 407,441
高等行政法院 203,693
最高行政法院 124,677
地方行政訴訟庭 97,375
高雄少年及家事法院 26,072
智慧財產及商業法院 24,234
其他專業法庭・委員會 33,689
合計 22,846,886
案件類別 筆數
民事 14,654,445
刑事 7,569,416
行政 597,107
其他 25,918

Administrative rules by issuing agency (107 agencies, as of 2026-11-21)

Agency names are kept in their official Chinese form as recorded on each interpretation, including historical names of reorganized agencies.

Agency Count
財政部 10,707
內政部國土管理署 8,769
金管會 8,418
經濟部智慧財產局 7,208
勞動部 7,194
法務部 7,114
內政部 6,746
經濟部 6,694
行政院環境保護署 4,467
行政院公共工程委員會 4,104
銓敘部 4,016
考試院 3,416
農業部 3,091
教育部 2,914
文化部 1,521
前司法行政部 1,432
法務部行政執行署 1,417
內政部戶政司 1,391
環境部 1,123
主計總處 721
公務人員保障暨培訓委員會 693
國科會 576
文化部文化資產局 561
農業部水保署 543
司法行政部 444
考選部 429
人事行政總處 325
行政院消費者保護處 269
核能安全委員會 229
原住民族委員會 227
行政院 227
海洋委員會 224
公平交易委員會 205
僑務委員會 184
法務部矯正署 171
外交部 136
中央選舉委員會 112
農業部林業及自然保育署 103
客家委員會 97
國家發展委員會 86
個人資料保護委員會籌備處 79
故宮博物院 59
司法院 56
大陸委員會 52
臺灣高等法院檢察署 41
法務部政風司 37
法務部廉政署 32
經濟部能源署 28
法務部調查局 20
Other 58 agencies (each under 20) 120
合計 98,828

Why it is different

This is not a generic keyword judgment search tool. It connects to the TLR retrieval service that Legal Detective has been building for a long time:

  • 22,846,886 Taiwan court decisions (as of 2026-11-21), structurally processed and vectorized.
  • Semantic fuzzy search: natural-language queries find judgments that are "conceptually similar but worded differently"; lexical exact-match modes are available for technical vocabulary.
  • Exact docket lookup: a complete docket number switches to exact lookup automatically; a miss is reported honestly ("not found does not mean the judgment does not exist"), never padded with similar cases.
  • Appeal chain case_history: each judgment carries its recorded upper/lower instances with 主文 "廢棄/撤銷/駁回" flags and the disposition (in whole or in part), so you can see before citing whether a judgment has been overturned.
  • Paired interpretation tools: exact serial lookup (with validity status) and semantic search over administrative interpretations; interpretations and judgments are strictly separated. See docs/mcp-anchor.md.
  • Exact statute lookup: retrieve the current text of a Taiwan statute article by law name plus article number, with the law's last-amendment date, any abolition note and the official dataset version date the corpus corresponds to, so an article citation can be verified before it goes into legal writing instead of being recalled from model memory. Common abbreviations resolve to official law names. The statute corpus is checked against the official dataset daily. Current consolidated version only; for pre-amendment text consult the official amendment history.
  • Citation safeguards are first-class: allowed_citations read-whitelist, unread_candidates markers, per-bundle verification instructions, plus the CLI-side citation check, all aimed at legal AI's worst hallucination mode: real docket number, fabricated holding.
  • This CLI ships no judgment database and exposes no model weights, vector indexes, or retrieval-pipeline internals; it is a client for the public TLR retrieval endpoint.

Compared with "official-website wrapper" tools

Another common approach is to proxy the Judicial Yuan / law database websites' built-in search in real time. The two serve different purposes and can complement each other:

Official-site wrapper Taiwan Legal RAG
Search official site keyword search semantic retrieval over a self-built 22M-judgment corpus; finds conceptually similar cases even with different wording
Citation protection usually none read-whitelist + verification instructions + citation check
Docket lookup as provided by the site exact lookup; on a miss it explicitly says not to speculate
Appeal chain trace case by case yourself case_history attached, with vacated flags
Availability subject to site WAF / redesigns; often needs a local browser to pass challenges hosted endpoint, zero local setup
Freshness official site is real-time for very recently published decisions, check the official site

The wrapper's strength is real-time official-source access; this tool's strength is semantic retrieval quality and citation discipline.

Unlike keyword-only legal search tools, Taiwan Legal RAG CLI connects to a production semantic retrieval backend built on 22M+ Taiwan court judgments, enabling fuzzy concept-level search while keeping model weights, infrastructure, and private indexes server-side.

(Wording note: what is published here is the CLI, not the model or the vector store; the backend retrieval service, model weights, and private indexes stay server-side and are not published with this tool.)

What it does / does not do

Does: retrieve judgments with natural language → get a structured listing, judgment reasoning excerpts, and citation links → package them into a bundle for your own AI; and run a bundle-level citation check on any AI-generated answer.

Does not: this tool calls no LLM, generates no legal opinion, and endorses no model output. Answers are produced by the AI you choose (ChatGPT / Claude / Gemini / a local model).

What the built-in citation check can verify

check is a bundle-level, best-effort string check. It only verifies:

  • whether the case numbers cited in the answer are inside the bundle (catching "cited a number not in the bundle" = suspected fabrication);
  • citations of judgments outside the bundle, or nonexistent ones;
  • quote existence (bundle level): whether a verbatim sentence the answer attributes to "the court said…" appears anywhere in the bundle text.

What it cannot verify (important)

  • whether a quote comes from the specific judgment the answer attributes it to (existence check only looks at "does this sentence appear anywhere in the bundle", not bound to a particular judgment);
  • whether the court's holding was read correctly;
  • whether a party's argument (plaintiff/defendant/appellant) was mistaken for the court's holding;
  • whether obiter dicta was treated as the judgment's core authority;
  • paraphrase-style holding hallucinations.

All of these require reading the full judgment text, which is why bundles include judgment excerpts and verification instructions that require the downstream model to verify on its own. pass only means "the cited numbers match the bundle's identity list"; it does not mean "the legal reasoning is correct" or "the quote really comes from that judgment." Also, check only compares against bundle content, not the entire Legal Detective database: if you later open full judgment texts yourself and rewrite the answer, check still only sees the excerpts originally packed.

Install

pip install twlegalrag

Depends only on httpx / typer / rich. No LLM packages or LLM keys needed: this tool does not call LLMs. Set a TLR connection key before first use (see "Configuration" below); without one, commands print where to get it.

Usage

# 1) Pure retrieval: list matching judgments
twlegalrag search "勞資 加班費" -n 5 --read

# Restrict by judgment date and court, newest first (dates inside the query text do not filter)
twlegalrag search "商標權 侵害" --from 2026-10-01 --to 2026-10-31 --court 智慧財產及商業法院 --newest

# Restrict to one case category (刑事 criminal, 民事 civil, 行政 administrative)
twlegalrag search "小額付費 詐欺得利" --case-type 刑事

# 2) Pack: produce a bundle you can hand to any AI  ★ main flow
twlegalrag pack "車禍對方全責,我可以求償什麼?" -o bundle.json
#   → paste bundle.json to ChatGPT / Claude / Gemini and require it to cite
#     only judgments inside the bundle

# 3) Citation check: bundle-level check on any AI-generated answer
twlegalrag check bundle.json answer.txt

# 4) statute and interpretation lookup (no LLM)
twlegalrag law 民法 184
twlegalrag ref "台財稅第881945861號"
twlegalrag ref-search "扣繳義務人未依限申報之處罰" -n 5

# Service health
twlegalrag health

A pack bundle contains query, each judgment's citation_id (J1, J2, ...), citation_text, citation_url, doc_id, the Layer-1 listing, fulltext_excerpt (an excerpt of the judgment's reasoning, length-capped), case_history (database-recorded appeal chain, v1.1), allowed_citations, and a verification_instructions block that explicitly requires the downstream model to cite only in-bundle judgments and to mark unsupported propositions as unverified. An AI USE NOTICE is also printed to stderr.

Since v1.1, verification_instructions additionally includes an OPINION-LAYER SELF-CHECK: after answering, the downstream model must go back and verify that (a) every holding attributed to a judgment actually appears in that judgment's excerpt (not another judgment's, not inferred); (b) outcome directions (win/lose/vacated/dismissed/remanded) are not reversed; (c) judgments shown as vacated in case_history are not cited as currently valid holdings. This complements check's bundle-level number check: a real case number does not make the attributed holding real, and opinion-layer verification can only be done by the model that read the text; these rules write that obligation into every bundle.

allowed_citations is the whitelist of citable judgments and only contains judgments whose reasoning text was actually read in. The CLI's pack reads every judgment it returns, so the two always match. For the hosted Remote MCP search_bundle (/v1/pack), when read_top < max_results, only the top read_top judgments are read in full; the rest remain listed in judgments for browsing but are moved to unread_candidates (not authority; must not be cited as court reasoning). See docs/mcp-anchor.md.

Configuration

By default the CLI talks to the public endpoint https://tlr.dr-legal.com.tw. Since 2026-10-30 REST calls need a credential: sign in to a Dr.Legal account (free), create a connection key on the connection keys page, and put it in an environment variable or ~/.twlegalrag/config.toml (git-ignored; never commit it):

export TWLEGALRAG_TLR_BASE_URL=https://tlr.dr-legal.com.tw   # default
export TWLEGALRAG_TLR_API_KEY=...   # required since 2026-10-30: a self-serve connection key, an institutional key from [email protected], or an OAuth access token you obtained yourself

No institutional key but want to call REST from your own code? Sign in once with the OAuth authorization-code + PKCE flow (a browser opens on the Dr.Legal sign-in page), then the refresh token keeps the session alive while you keep using it. A standard-library-only example is in docs/tlr_oauth_cli.py: python3 docs/tlr_oauth_cli.py login, then python3 docs/tlr_oauth_cli.py law 民法 184. Tokens are stored in ~/.twlegalrag/tlr_oauth.json (mode 600). Send an identifying User-Agent; the default Python-urllib is blocked at the edge.

[tlr]
# base_url = "https://tlr.dr-legal.com.tw"
# api_key  = "..."

Privacy and data flow

First, what never passes through the TLR server:

  • Your full conversation with your AI (Claude / ChatGPT / local model), your uploaded documents, and the AI-generated answers all happen between you and your AI provider and never pass through TLR. TLR is a retrieval-only server; the only things it receives are the retrieval query strings your AI client decides to send and the subsequent judgment-document requests.
  • Account sign-in on connection: since 30 October 2026, MCP authorization requires signing in to a Dr.Legal account (Google or email; free registration). Queries are tied to that account for user identification and usage statistics. The REST endpoint requires an institutional key or an OAuth access token; anonymous requests receive 401.
  • The judgment data itself consists of Taiwan's publicly available court decisions; responses contain no non-public personal data.

What does travel over the network, and you should understand:

  • Your search terms / questions are sent to the TLR retrieval endpoint (https://tlr.dr-legal.com.tw) to fetch judgments.
  • TLR may log your query text, timestamp, IP-derived metadata, and result counts for retrieval-quality analysis. Do not submit personal secrets or confidential facts. Queries are not used to train generative models.
  • This tool calls no LLM and uses no server-side tokens; if you feed a bundle to some AI yourself, that transmission and its cost happen between you and your chosen AI provider and have nothing to do with this tool.
  • If you have an endpoint API key, keep it in environment variables; do not commit config files.

How the citation check works

twlegalrag/faithful/ is a set of zero-dependency pure functions (standard library re + unicodedata only). Given the answer text and the bundle's judgment excerpts, it returns pass / needs_review / fail. It is deliberately conservative: when unsure it returns needs_review rather than fail to keep false alarms low. It calls no LLM and touches no database; it is deterministic string analysis.

⚠️ This directory is a snapshot of internal code; some functions in it (e.g. check_party_as_court / run_all_checks) are not used by the CLI. Their presence does not mean the CLI can do opinion-layer / semantic verification; the CLI uses only two bundle-level checks. Do not read the file list as a feature list. See twlegalrag/faithful/VENDORED.md.

2026-08-20 hosted-service update (MCP / REST)

  • Bundle responses carry a result_token, so any judgment in the bundle can be read in full directly.
  • Every result carries hit_excerpt (a preview of the matched passage); quote from the full reasoning text, not from this field.
  • get_judgment_fulltext supports excerpt_offset paging, so long judgments can be read to the end.
  • Lexical search modes (search_type: keyword / phrase) improved for precise technical vocabulary; conceptual questions should still use the default hybrid.

Live now on REST and Remote MCP. CLI v2.1.0 follows suit: pack pages through long judgments to the end (per-judgment bundle budget doubled) and carries hit_excerpt into bundles.

Other ways to connect (same TLR backend)

This CLI is one way to use the TLR retrieval service. The same backend tlr.dr-legal.com.tw also supports plugging judgment search directly into your AI tools via Remote MCP. Both use the same MCP endpoint https://tlr.dr-legal.com.tw/mcp; OAuth completes automatically on connection (dynamic registration, no API key; you sign in to a Dr.Legal account during authorization):

  • Claude (Remote MCP): Settings → Connectors → Add custom connector, URL https://tlr.dr-legal.com.tw/mcp.
  • ChatGPT (MCP connector): add a custom MCP server in Connectors, URL https://tlr.dr-legal.com.tw/mcp.
  • Gemini web app (Spark): open gemini.google.com/spark/apps → the custom apps tab → paste https://tlr.dr-legal.com.tw/mcp into "Custom apps for Spark" → Continue and finish the authorization (automatic dynamic registration, no key). Requires Gemini Spark on the account; once linked, type @ in the Spark input box and pick the app to call it by name (the regular chat window does not call custom apps). Verified working from a Taiwan account on 2026-09-01.
  • Gemini CLI (Remote MCP): add {"tlr": {"httpUrl": "https://tlr.dr-legal.com.tw/mcp"}} under mcpServers in ~/.gemini/settings.json, then run /mcp auth tlr inside the CLI to authorize. Step-by-step instructions are in the user guide.
  • Microsoft 365 Copilot / Copilot Studio (MCP): add an MCP tool to your agent in Copilot Studio or Agent Builder, set the server URL to https://tlr.dr-legal.com.tw/mcp, and choose OAuth 2.0 with dynamic discovery; no app pre-registration is needed. Step-by-step instructions are in the user guide.
  • Claude Code (skill, wraps this CLI rather than MCP): a ready-made skill lives in skills/tw-legal-rag/. Copy that folder into your project's .claude/skills/ and Claude will run this CLI's pack subcommand whenever a question involves Taiwan case law, citing only citation_ids that exist in the returned bundle. Setup notes and Windows caveats are in the skill's SKILL.md. The Remote MCP surface currently has six tools:
Tool What it does Added In this CLI
search_bundle Search plus reasoning-text reads in one call, returning a bundle with a citation whitelist (recommended entry point) 2026-06 ✅
search_judgments Judgment search (structured listing; a full docket number switches to exact lookup) 2026-05 ✅
get_judgment_fulltext Full reasoning text of a judgment (with the case_history appeal chain) 2026-05 ✅
get_legal_reference Exact administrative-interpretation lookup by serial, with validity status 2026-08 ✅ ref
search_legal_references Semantic search over administrative interpretations 2026-08 ✅ ref-search
get_law_article Exact current-statute lookup and article-number verification 2026-09 ✅ law

Per-tool input/output contracts are in docs/mcp-anchor.md.

This server is listed in the official MCP Server Registry as io.github.aa0101181514/tw-legal-rag.

Whether you go through the CLI, MCP, or the Claude Code skill, answers are generated by your own AI; this service only provides judgment content and verifiable citation links.

Architecture

your question
   │
[retrieve]  TLR /v1/search   ──►  Layer-1 listings + result_token
   │        TLR /v1/fulltext ──►  reasoning excerpt per judgment (capped)
   │
[pack]      pack ──► bundle.json (citation_id / allowed_citations / verification rules)
   │                 └─► hand to your own AI tool
   │
[check]     check ──► bundle-level citation check (in/out of bundle + in-bundle quote existence)

The judgment corpus, embeddings, and retrieval logic live server-side and are not in this repo. This CLI is the published client and citation-check tool.

Disclaimer

This tool is an analysis aid, not legal advice, and not a lawyer. Always read the full text of cited judgments yourself. Judgments obtained through the API are Taiwan's publicly available court decisions; you are responsible for your own use.

License

Elastic License 2.0 (ELv2) from v2.0.0. Free to use, copy, modify and redistribute, including commercial and internal-business use, with two limits: you may not offer the software itself to third parties as a hosted or managed service, and you may not remove license/notice protections. Versions up to v1.2.2 remain MIT.

The hosted API and the judgment corpus were never covered by the code license; see TERMS.md. Project names and logos are not licensed; see TRADEMARK.md. This project does not accept external pull requests (single-author licensing policy); see CONTRIBUTING.md.


mcp-name: io.github.aa0101181514/tw-legal-rag

Explore related projects

Loading…