Skip to main content
Glama
legal-search-mcp

legal-search-mcp

by LimEulYoung
README.md
# Legal Search MCP

English | [한국어](README.ko.md)

Korean case law, statutes and sentencing data as [MCP](https://modelcontextprotocol.io)
tools. Connect an AI client to find judgments, look up statutes as of a date,
check what a judgment held in its own words and gather the statutory penalties,
guideline ranges and actual sentences for a case's charges.

Five read-only tools:

| Tool | What it does |
|---|---|
| `precedent_search` | Find judgments by facts, charge, court, year or case number |
| `precedent_dive` | Read one judgment body and answer a question about it |
| `statute_search` | Find statutes, administrative rules and tax treaties by name or keywords; a statute named with article numbers returns those articles |
| `statute_read` | Read a found statute's articles, current or as of a date, or list its article titles |
| `sentencing_analysis` | Statutory penalties, guideline ranges and factors, and first-instance sentences for one charge or several |

This repository publishes the MCP tools used by
[로풀 (Lawful)](https://lawful.crow-tit.com), a free Korean legal-AI service.
The tools in `src/lawful_mcp/harness_local` are the code the hosted service
runs, copied unchanged; this repository adds a server you can run yourself and
a sample corpus. The web application and hosted Agent API are maintained
separately. The
research prototype and benchmark archive live in
[`legal_mcp`](https://github.com/LimEulYoung/legal_mcp) — see [Paper](#paper).

## Quick start — hosted

The hosted service provides the full corpus, including statute amendment
history, with no rate limits. Three ways to connect:

**Claude / ChatGPT on the web — no code.** Add a custom connector with this
URL, sign in with OAuth when asked, and the five tools appear. No API key
needed:

```
https://mcp.crow-tit.com/mcp
```

Step-by-step with the exact menu clicks: [crow-tit.com/docs#mcp](https://crow-tit.com/docs#mcp)

**Claude Code** — one command, with a free key from
[console.crow-tit.com](https://console.crow-tit.com):

```bash
claude mcp add --transport http lawful https://mcp.crow-tit.com/mcp \
  --header "Authorization: Bearer ct_..."
```

**Clients with HTTP MCP configuration** — use the same key. Configuration
formats vary; for clients that accept an `mcpServers` HTTP entry:

```json
{
  "mcpServers": {
    "lawful": {
      "url": "https://mcp.crow-tit.com/mcp",
      "headers": { "Authorization": "Bearer ct_..." }
    }
  }
}
```

## Quick start — self-host

Requires **Python 3.11+**. Install in a virtual environment; the bundled
sample works without API keys:

```bash
git clone https://github.com/LimEulYoung/lawful-mcp
cd lawful-mcp
python3 -m venv .venv
.venv/bin/python -m pip install -e .
```

For a local stdio client, replace the path below with the absolute path to
your clone. The client starts the server:

```json
{
  "mcpServers": {
    "lawful-mcp": {
      "command": "/absolute/path/to/lawful-mcp/.venv/bin/lawful-mcp"
    }
  }
}
```

For HTTP at `http://127.0.0.1:8100/mcp`, run:

```bash
.venv/bin/lawful-mcp --transport http --port 8100
```

The self-hosted server has no authentication or usage metering. Access control
for a shared HTTP endpoint belongs to your deployment.

### Configuration and data flow

Settings are listed in [`.env.example`](.env.example). The server reads process
environment variables; it does **not** load `.env` automatically. Export values
in the launching shell or set them in your MCP client's `env` configuration.

With the defaults, four tools run locally against the corpus.
`precedent_dive` additionally sends the selected public judgment text, case
metadata and the supplied question to your configured model endpoint. Keep
that question limited to issues in the public judgment.

```bash
export DIVE_API_KEY=...
export DIVE_BASE_URL=https://api.openai.com/v1   # any OpenAI-compatible endpoint
export DIVE_MODEL=...
```

All three values are required to register `precedent_dive`. Without them,
the other four tools still work. Restart the server after changing settings.

`precedent_search` also takes an optional `issue`: the legal question the
search is meant to answer. With `JEV_API_KEY` (an OpenRouter key) set, it sends
each candidate's result block — public case metadata, holding and preview —
and that question to OpenRouter's Jev endpoint, and returns the cases that
decided the question first. Without the key, or when a request fails or takes
longer than 1.5 seconds, results keep their keyword order.

### Check the installation

The tests use the bundled sample and constructed test data; no network or
model keys are needed:

```bash
.venv/bin/python -m pip install -e ".[dev]"
.venv/bin/python -m pytest tests/ -q
```

## The corpus

The tools read one SQLite file. The bundled sample is about 49 MiB:

| | Sample (`data/fixture.db`) | Hosted |
|---|---|---|
| Judgments | 600 | 220,000+ |
| Statutes | 27 core laws, current text and addenda | All, with amendment history |
| Administrative rules | 20 | All |
| Tax treaties | 3 partners and the multilateral conventions, 7 documents | All |
| Sentencing guidelines | Complete | Complete |
| Charge taxonomy | Complete | Complete |

The sample supports local trials and testing. Use the hosted service for the
full corpus, or set `CORPUS_DB` to a compatible database you maintain.

The sample holds each law as in force on the day it was built: amendments
taking effect later and earlier wordings are left out, so lookups as of
another date need the hosted corpus.

Statute lookups distinguish repeal from loss of effect, such as expiry, when
the corpus supplies that information. The sample's lapse register is empty;
those rules are covered by constructed test data.

A tax treaty comes with every document of the same partner and the
multilateral conventions, in order of entry into force. The official source
has no consolidated text and records no termination, so the lookup does not
say which wording is current.

Default search combines trigram and [Kiwi](https://github.com/bab2min/kiwipiepy)
morpheme indexes using reciprocal rank fusion. The morpheme index makes
two-character charge names such as `사기`, `절도` and `폭행` searchable.

Judgments are non-copyrightable under Article 7 of the Korean Copyright Act.
Court and case-number provenance is preserved in the data.

### Building your own

[`scripts/build_sample_db.py`](scripts/build_sample_db.py) extracts a sample
from an existing compatible corpus and rebuilds its search indexes. It also
documents the schema: every table is created from the source's definition, and
the build stops if one the tools read is missing. It does not download the
hosted corpus:

```bash
.venv/bin/python scripts/build_sample_db.py --source /path/to/corpus.db \
    --dest my_sample.db --cases 5000 --statutes all
```

## Paper

The retrieval and tool-use design was evaluated on the Korean Bar Examination:

> **Agentic RAG for Legal Question Answering in Civil Law: Evidence From the Korean Bar Examination**
> Eul Young Lim and Jihun Park
> *IEEE Access*, vol. 14, pp. 124441–124458, 2026.
> [doi:10.1109/ACCESS.2026.3722717](https://doi.org/10.1109/ACCESS.2026.3722717) — open access

Benchmark code, questions and per-model results are archived in
[`legal_mcp`](https://github.com/LimEulYoung/legal_mcp). If you use this tool
in research, please cite the paper ([`CITATION.cff`](CITATION.cff)).

## Also available

- **Lawful Agent API** — one question in, a grounded answer out.
  [crow-tit.com](https://crow-tit.com)
- **로풀 (Lawful)** — the free consumer service, 법률AI: chat, search, labour
  calculators, legal document drafting.
  [lawful.crow-tit.com](https://lawful.crow-tit.com)

## Notes

This is a search tool over public legal sources, not legal advice. What it
returns is source material and statistics; deciding what they mean for a
particular matter is a lawyer's job.

Development happens in a private repository and lands here in batches, so
issues are welcome but pull requests may be merged by hand rather than
through the button.

Report vulnerabilities privately using [SECURITY.md](SECURITY.md).
Code is [MIT licensed](LICENSE).

TDQS

A4.4/5.0

Scored across 4 tools

Disambiguation5/5

Each tool targets a distinct resource: precedents, statutes, empirical sentencing data, and guideline-based range calculation. The sentencing pair is explicitly differentiated, with compute_sentencing_range producing guideline ranges and sentence_statistics providing real case distributions.

Naming Consistency3/5

All names are lowercase snake_case and readable, but they mix conventions: precedent_search and statute_lookup are object+verb, sentence_statistics is a noun phrase, and compute_sentencing_range is verb+object. The pattern is not predictable enough for an agent to infer a new tool's name.

Tool Count5/5

Four tools is well-scoped for a legal research and sentencing assistant. Each tool is broad and complex enough to justify its place, with no redundant tools.

Completeness2/5

The set covers statutes and sentencing well, but precedent_search explicitly instructs callers to continue with precedent_dive, which is not exposed in the tool list. This creates a dead end for full-text precedent access and is a significant gap for the stated legal-research purpose.

Maintenance

ActivityActive
ResponsivenessNo recent community issues