io.github.aa0101181514/tw-legal-rag MCP Server
io.github.aa0101181514/tw-legal-rag
Semantic search over 22M Taiwan court judgments with citation verification and appeal-chain tracking.
What is the io.github.aa0101181514/tw-legal-rag MCP server?
Taiwan Legal RAG is an MCP server providing semantic retrieval over 22 million Taiwan court judgments and administrative interpretations, powered by Legal Detective's TLR infrastructure. It enables natural-language concept-level search (not just keyword matching), exact docket lookup, appeal-chain visibility, and bundle-level citation verification to prevent hallucinated case citations. The server does not generate legal advice, call LLMs, or guarantee model output faithfulness—it packages judgment data for your own AI tools to cite responsibly.
Taiwan Legal RAG connects AI tools to a production semantic-search backend over Taiwan's court decisions. Unlike keyword-only legal search, it finds conceptually similar cases even with different wording, shows whether judgments were vacated on appeal, and enforces citation discipline by packaging only read judgments into citation-safe bundles. Use it to ground legal research in real case law, verify holdings before citing them, and catch fabricated case numbers in AI-generated answers.
How to install io.github.aa0101181514/tw-legal-rag
Copy-paste configuration for popular MCP clients.
Tools & capabilities
Tools this server exposes to the agent.
search_bundle— Semantic search over Taiwan court judgments; returns a structured bundle with citation IDs, excerpts, appeal history, and an allowed-citations whitelist for safe downstream citation.search_judgments— Semantic search listing matching judgments with Layer-1 metadata (docket, court, date, parties, outcome).get_judgment_fulltext— Retrieve the full reasoning text excerpt for a specific judgment by its document ID.get_legal_reference— Exact lookup of Taiwan administrative interpretations (函釋) by serial number; returns full text and lifecycle status (active/repealed/superseded/no-longer-applied).search_legal_references— Natural-language semantic search over administrative interpretations with optional agency/source-kind filters; returns candidates with similarity scores and lifecycle status.
Use cases
- Search for Taiwan court judgments on a legal topic (e.g., 'labor dispute overtime pay') and retrieve semantically similar cases even if worded differently.
- Look up a specific Taiwan court docket number and get its full text, appeal chain, and whether it was vacated by a higher court.
- Pack judgment search results into a citation-safe bundle to hand to Claude or ChatGPT, with verification rules that require the AI to cite only judgments it actually read.
- Verify an administrative interpretation (函釋) by its serial number and check whether it is still active, repealed, or superseded before citing it.
- Run a citation check on an AI-generated legal answer to catch fabricated case numbers and verify that quoted text actually appears in the retrieved judgments.
io.github.aa0101181514/tw-legal-rag MCP server FAQ
Taiwan Legal RAG is an MCP server that provides semantic (concept-level) search over 22 million Taiwan court judgments and administrative interpretations. It retrieves cases by natural-language topic, shows appeal chains with vacated-judgment flags, and enforces citation discipline by packaging only read judgments into bundles for safe AI citation.
No. Taiwan Legal RAG retrieves and packages judgment data only; it does not call LLMs, generate opinions, or endorse any model output. Legal advice comes from your own AI tool (Claude, ChatGPT, etc.), and you remain responsible for reading full judgment texts and verifying holdings.
Yes. The public TLR endpoint at https://tlr.dr-lawbot.com requires no API key or account registration. Optional API keys may be issued by the service operator for higher quotas, but basic access is free.
Add it as a Remote MCP connector: in Claude Settings → Connectors → Add custom connector, enter https://tlr.dr-lawbot.com/mcp. OAuth completes automatically. In ChatGPT, add a custom MCP server with the same URL. No API key application needed.
The bundle-level check verifies that case numbers cited in an answer appear in the retrieved bundle, and that quoted text exists somewhere in the bundle excerpts. It cannot verify whether a quote comes from the specific judgment cited, whether the holding was read correctly, or whether obiter dicta was mistaken for core authority—those require reading the full judgment yourself.
Only your search query text is sent to the TLR endpoint to fetch judgments. Your full conversation with your AI, uploaded documents, and AI-generated answers never pass through TLR—they stay between you and your AI provider. TLR may log queries and result counts for retrieval analysis but does not use them to train models.
README (reference)
Source of truth, from the repository.
Taiwan Legal RAG (twlegalrag)
<div align="center">
🌐 Language / 語言 / 言語
</div>Source-available CLI for semantic Taiwan legal judgment retrieval, powered by Legal Detective's 22M-judgment retrieval infrastructure.
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.
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:
- About 22 million Taiwan court decisions, structurally processed and vectorized.
- Thousands of hours of retrieval pipeline optimization.
- Semantic fuzzy search — not limited to docket numbers, court names, or keywords; you can use natural language to find judgments that are "conceptually similar but worded differently."
- Exact docket lookup (v1.1) — when the query is a complete Taiwan docket number (e.g. 最高法院112年度台上字第9號), the tool automatically switches to exact lookup and returns that case's own documents (civil/criminal cases sharing the same number are listed side by side with labels). When nothing is found it says so explicitly: "not found does not mean the judgment does not exist; do not speculate about the case" — it never pads the result with semantically similar cases.
- Appeal chain
case_history(v1.1) — when reading a judgment's full text, the database-recorded upper/lower instances are attached (including a flag for 主文含「廢棄」, i.e. the holding was vacated on appeal). You can see whether a judgment has been vacated by a higher court before citing it. Absence of an upper-court record only means the database has no record; it does not mean the judgment is final. - Exact administrative-interpretation lookup
get_legal_reference(2026-08, hosted MCP) — look up an administrative interpretation (函釋) by its issuing serial number (e.g. 台財稅第881945861號) and get its full text plus a lifecycle status (verified-active / unverified / repealed / no-longer-applied / superseded). Verify existence and validity before citing an interpretation; a miss explicitly states that not found does not mean the interpretation does not exist. Interpretations and judgments are strictly separated: never mixed in one ranking, and never to be cited as court reasoning. Seedocs/mcp-anchor.md. - Semantic interpretation search
search_legal_references(2026-08, hosted MCP) — natural-language topic search over the same interpretation corpus (optional agency / source-kind filters). Returns candidates with the same lifecycle status field, a similarity score, and an excerpt — and deliberately performs no relevance judgment: the calling model must read each candidate, judge relevance itself, and verify text + validity viaget_legal_referencebefore citing. The pair closes the loop against serial-number guessing: search finds real serials, exact lookup verifies them. - Citation protection is a first-class citizen, not an afterthought — each
bundle carries an
allowed_citationswhitelist (only judgments whose reasoning text was actually read in),unread_candidatesmarkers (judgments whose reasoning was not read must not be cited as authority), verification instructions written into every bundle (including opinion-layer self-check), plus a bundle-level citation check on the CLI side. The whole design targets the most painful hallucination pattern in legal AI: real case number, fabricated holding. Ordinary retrieval tools stop at handing data to the model; here, citation discipline is part of the data format itself. - This CLI does not embed the judgment corpus and does not expose backend model weights or vector indexes; 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 keys needed —
this tool does not call LLMs.
Usage
# 1) Pure retrieval — list matching judgments
twlegalrag search "勞資 加班費" -n 5 --read
# 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
# 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 (optional)
By default the CLI talks to the public endpoint https://tlr.dr-lawbot.com,
no key required. If the service operator issues you an API key, put it in an
environment variable or ~/.twlegalrag/config.toml (git-ignored — never
commit it):
export TWLEGALRAG_TLR_BASE_URL=https://tlr.dr-lawbot.com # default
export TWLEGALRAG_TLR_API_KEY=... # optional
[tlr]
# base_url = "https://tlr.dr-lawbot.com"
# 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.
- No account registration: the public REST endpoint works without a key, the service has no user account system, and queries are not tied to any account identity.
- 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-lawbot.com) 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.
Other ways to connect (same TLR backend)
This CLI is one way to use the TLR retrieval service. The same backend
tlr.dr-lawbot.com also supports plugging judgment search directly into your
AI tools via Remote MCP. Both use the same MCP endpoint
https://tlr.dr-lawbot.com/mcp; OAuth completes automatically on connection
(dynamic registration, no API key application or setup needed):
- Claude (Remote MCP): Settings → Connectors → Add custom connector, URL
https://tlr.dr-lawbot.com/mcp. - ChatGPT (MCP connector): add a custom MCP server in Connectors, URL
https://tlr.dr-lawbot.com/mcp. - 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'spacksubcommand whenever a question involves Taiwan case law, citing onlycitation_ids that exist in the returned bundle. Setup notes and Windows caveats are in the skill'sSKILL.md. The Remote MCP surface currently has five tools:search_bundle,search_judgments,get_judgment_fulltext, plusget_legal_referenceandsearch_legal_referencesadded in 2026-08 (exact lookup and semantic search over administrative interpretations, seedocs/mcp-anchor.md); the last two are not wired into this CLI yet.
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 Server Registry ownership marker — verifies this PyPI package owns the io.github.aa0101181514/* namespace. Do not remove. -->
mcp-name: io.github.aa0101181514/tw-legal-rag
Related MCP servers
NoBrainner Spaced Repetition Flashcards, Study Stats & Multi-Language AI Deck Generation
View repository →
io.github.aabxtract/koda
Verification and memory layer for coding-agent workflows.
Control Unreal Engine 5 from Claude, Cursor, or any MCP client—288 commands for Blueprints, materials, Niagara, and more.
Kanban do Intelliboard por MCP: handoff entre agentes e validação imposta antes de concluir.
View repository →
AkTools MCP Server
Query stock, crypto prices, financial indicators, and market news via akshare through MCP.

Notify MCP Server
Send notifications to WeChat, Telegram, Bark, Lark, Feishu, DingTalk, and Home Assistant.


