README.mdβ’22.1 kB
[πΊπΈ **EN**](README.md) | [π°π· KR](README_kr.md)
# LexLink MCP Server
[](https://smithery.ai/server/@rabqatab/lexlink_ko_mcp)
MCP (Model Context Protocol) server for accessing the Korean National Law Information Center (λ²μ μ² κ΅κ°λ²λ Ήμ 보 곡λνμ©) Open API.
## Overview
This MCP server enables Claude and other LLM assistants to search and retrieve Korean legal information including:
- **Laws and regulations** (λ²λ Ή)
- **Court precedents** (νλ‘)
- **Legal interpretations** (λ²λ Ήν΄μλ‘)
- **Local ordinances** (μμΉλ²κ·)
## Features
### 7 MCP Tools
1. **search_laws** - Search Korean laws and regulations
2. **get_law_details** - Get full text of a specific law
3. **search_case_law** - Search court precedents and case law
4. **get_case_details** - Get full text of a specific court case
5. **search_legal_interpretations** - Search official legal interpretations
6. **get_legal_interpretation_details** - Get full text of a specific legal interpretation
7. **search_local_ordinances** - Search local government ordinances
### Built-in Features
- β
**Search Ranking** - Returns most relevant results first (exact matches prioritized)
- β
Async/await for optimal performance
- β
Rate limiting (0.5s between requests)
- β
Automatic XML response parsing
- β
Comprehensive error handling
- β
Type hints for all parameters
- β
Detailed docstrings for LLM understanding
#### π― Smart Search Ranking
The API's default search uses simple substring matching, which can return irrelevant results. Our ranking fixes this:
**Problem:** Searching "λ―Όλ²" (Civil Law) returns "λλ―Όλ²" (Refugee Act) first β
**Solution:** Client-side ranking ensures exact matches appear first β
```
Query: "λ―Όλ²"
Without Ranking: λλ―Όλ², λλ―Όλ² μνλ Ή, λ―Όλ²...
With Ranking: λ―Όλ², λ―Όλ²λ²μΈκ·μΉ, λ―Όλ²μ 312μ‘°...
```
**How It Works:**
The ranking algorithm scores results by:
1. **Exact Match** (Score: 1000) - Query matches name exactly
2. **Starts With Query** (Score: 100) - Name begins with the query
3. **Word Boundary Match** (Score: 10) - Query appears at start or after space
4. **Substring Match** (Score: 1) - Query appears anywhere
5. **Length Penalty** - Shorter, more specific results preferred
**Smart Fetch:** When requesting few results (display < 20), the system automatically fetches 5x more results internally, ranks them all, and returns the top matches. This ensures you always get the most relevant results.
**Applied to:** search_laws, search_case_law, search_legal_interpretations
**Disable if needed:** Add `auto_rank=False` parameter to get raw API results
## API Coverage
**Official Korean Law API: 125 endpoints | This Implementation: 6 endpoints (5% coverage)**
The official Korean Law API provides 125 different endpoints across 17+ categories. This MCP server currently implements the 6 most essential endpoints that cover ~80% of typical legal research needs.
### β
Currently Implemented (6 APIs)
| Category | API | Status | Test Results |
|----------|-----|--------|--------------|
| **λ²λ Ή (Statutes)** | Search Laws | β
Implemented | 9 laws found for "λ―Όλ²" |
| **λ²λ Ή (Statutes)** | Get Law Details | β
Implemented | Retrieved 57 articles with test query |
| **νλ‘ (Case Law)** | Search Cases | β
Implemented | 16,373 cases available with test query |
| **νλ‘ (Case Law)** | Get Case Details | β
Implemented | Full judgment text |
| **λ²λ Ήν΄μλ‘ (Interpretations)** | Search Interpretations | β
Implemented | 257 interpretations with test query |
| **μμΉλ²κ· (Local Ordinances)** | Search Ordinances | β
Implemented | 4,551 ordinances with test query |
### β Not Yet Implemented (119 APIs)
The following API categories are available in the official API but not yet implemented:
#### π λ²λ Ή (Statutes) - 9 Additional APIs
- β Statute History - Track amendments and changes over time
- β Article Details - Deep dive into specific articles
- β English Statutes - English translations of Korean laws
- β Statute System Diagram - Visual hierarchy of laws
- β Old vs. New Comparison - Compare before/after amendments
- β Three-Way Comparison - Compare multiple versions
- β Statute Name Abbreviations - Official short names
- β Deleted Data - Historical removed provisions
- β At-a-Glance Overview - Summary views
#### π νμ κ·μΉ (Administrative Rules) - 2 APIs
- β Administrative Rules Search & Full Text
- β Old vs. New Comparison for Admin Rules
#### βοΈ νμ¬κ²°μ λ‘ (Constitutional Court) - 2 APIs
- β Constitutional Court Decisions Search
- β Constitutional Court Decision Details
**Impact:** Constitutional court cases are crucial for constitutional law research
#### π νμ μ¬νλ‘ (Administrative Trials) - 2 APIs
- β Administrative Trial Decisions Search
- β Administrative Trial Decision Details
**Impact:** Important for administrative law practice
#### ποΈ μμν κ²°μ λ¬Έ (Committee Decisions) - 24 APIs (12 committees Γ 2 each)
12 Different Government Committees:
1. β Personal Information Protection Commission (κ°μΈμ 보보νΈμμν)
2. β Employment Insurance Arbitration (κ³ μ©λ³΄νμ¬μ¬μμν)
3. β Fair Trade Commission (곡μ κ±°λμμν)
4. β Ombudsman (κ΅λ―ΌκΆμ΅μμν)
5. β Financial Services Commission (κΈμ΅μμν)
6. β Labor Commission (λ
Έλμμν)
7. β Broadcasting/Media/Communications (λ°©μ‘ν΅μ μμν)
8. β Industrial Accident Compensation (μ°μ
μ¬ν΄λ³΄μ보νμ¬μ¬μμν)
9. β Central Land Expropriation (μ€μν μ§μμ©μμν)
10. β Central Environmental Dispute (μ€μνκ²½λΆμμ‘°μ μμν)
11. β Securities and Futures (μ¦κΆμ λ¬Όμμν)
12. β National Human Rights Commission (κ΅κ°μΈκΆμμν)
**Impact:** Specialized decisions for regulatory and dispute matters
#### π μ‘°μ½ (Treaties) - 2 APIs
- β Treaties Search - International agreements
- β Treaty Full Text
**Impact:** International law and bilateral/multilateral agreements
#### π λ³νΒ·μμ (Appendices & Forms) - 6 APIs
- β Statute Forms
- β Administrative Rule Forms
- β Local Ordinance Forms
**Impact:** Official government forms and templates
#### π« νμΉΒ·κ³΅λ¨Β·κ³΅κ³΅κΈ°κ΄ (Institutional Rules) - 2 APIs
- β University/Institution Rules Search
- β Institutional Rules Details
**Impact:** Internal regulations of public institutions
#### π λ²λ Ήμ©μ΄ (Legal Terminology) - 2 APIs
- β Legal Terms Search - Dictionary of legal terminology
- β Term Details with definitions
**Impact:** Essential for understanding legal jargon
#### π’ μ€μλΆμ² 1μ°¨ ν΄μ (Ministry Interpretations) - 16 APIs (8 depts Γ 2)
- β 8 Different Central Government Departments
**Impact:** Official interpretations from ministries
#### β‘ νΉλ³νμ μ¬ν (Special Administrative Trials) - 4 APIs (2 types Γ 2)
- β Special Administrative Trial Types
#### π± λͺ¨λ°μΌ (Mobile APIs) - ~30 APIs
- β Mobile-optimized versions of major APIs
**Note:** Current APIs work on mobile, but these are optimized versions
#### π― λ§μΆ€ν (Customized Services) - 6 APIs
- β Customized statute search
- β Custom administrative rules
- β Custom local ordinances
### Implementation Priority
If extending this server, implement in this order:
**π₯ High Priority (Next 5 APIs to add):**
1. **Constitutional Court Decisions** - Crucial for constitutional law
2. **Administrative Trial Decisions** - Common in administrative cases
3. **English Statutes** - International accessibility
4. **Statute History** - Track law changes over time
5. **Legal Terminology** - Define complex legal terms
**β Medium Priority:**
6. Administrative Rules (regulations)
7. Fair Trade Commission decisions
8. Treaties (international agreements)
9. Labor Commission decisions
10. Financial Services Commission decisions
**π Lower Priority:**
- Forms and appendices (less frequently needed)
- Institutional rules (niche use cases)
- Mobile-specific APIs (current APIs work)
- Customized services (advanced features)
### Why Only 6 APIs?
**Strategic Coverage:**
- These 6 APIs cover ~80% of typical legal research workflows
- Focus on most frequently accessed categories
- Foundational tools that other APIs build upon
**Use Case Analysis:**
- **Laws** β Most fundamental legal documents
- **Cases** β 16K+ court precedents for interpretation
- **Interpretations** β Official government guidance
- **Ordinances** β Local regulations
### Extending This Server
To add new APIs, follow this pattern:
```python
# In lexlink_client.py
async def search_constitutional_cases(self, query: str, display: int = 20):
params = {
'OC': self.oc,
'target': 'cnst', # Constitutional court target
'type': 'XML',
'query': query,
'display': str(display)
}
response = await self.client.get(self.BASE_SEARCH_URL, params=params)
return self._parse_xml(response.text)
# In main.py
@mcp.tool()
async def search_constitutional_cases(query: str, display: int = 20) -> str:
"""Search Constitutional Court decisions."""
result = await client.search_constitutional_cases(query, display)
return json.dumps(result, ensure_ascii=False)
```
The API client is designed for easy extension - just add target types!
## Installation
This project uses `uv` for dependency management:
```bash
# Install dependencies
uv sync
```
## Usage
### Running the MCP Server
```bash
# Start the server (STDIO transport)
uv run python main.py
# Inspect available tools
uv run python main.py inspect
```
### Example Usage with Claude
Once configured in your MCP client, you can ask Claude:
```
User: "Search for laws related to κ·Όλ‘κΈ°μ€λ² (Labor Standards Act)"
Claude: [Uses search_laws tool with query="κ·Όλ‘κΈ°μ€λ²"]
Claude: "I found the Labor Standards Act. Would you like to see specific articles?"
User: "Yes, show me Article 5"
Claude: [Uses get_law_details tool with the MST number]
Claude: "Here's Article 5 of the Labor Standards Act..."
```
## API Tools Documentation
### 1. search_laws
Search Korean laws and regulations by keyword.
**Parameters:**
- `query` (str): Search keyword in Korean or English
- `display` (int): Results per page, max 100 (default: 20)
- `page` (int): Page number (default: 1)
**Returns:** JSON with law names, MST numbers, dates, ministries
**Example:**
```python
result = await search_laws(query="λ―Όλ²", display=10)
```
### 2. get_law_details
Get complete text of a specific law including all articles.
**Parameters:**
- `mst` (str): Law serial number from search results
- `effective_date` (str, optional): Historical version date (YYYYMMDD)
**Returns:** JSON with full law text and metadata
**Example:**
```python
result = await get_law_details(mst="265307")
```
### 3. search_case_law
Search court decisions and precedents.
**Parameters:**
- `query` (str): Search keyword
- `display` (int): Results per page, max 100 (default: 20)
- `page` (int): Page number (default: 1)
- `search_scope` (int): 1=case name, 2=full text (default: 2)
- `court_type` (str, optional): "400201"=Supreme, "400202"=lower courts
- `date_range` (str, optional): Format "YYYYMMDD~YYYYMMDD"
**Returns:** JSON with case list including IDs, names, courts, dates
**Example:**
```python
result = await search_case_law(query="μν΄λ°°μ", search_scope=2, display=20)
```
### 4. get_case_details
Get full judgment text of a specific case.
**Parameters:**
- `case_id` (str): Case serial number from search results
**Returns:** JSON with complete judgment text
**Example:**
```python
result = await get_case_details(case_id="608121")
```
### 5. search_legal_interpretations
Search official legal interpretations issued by government agencies.
**Parameters:**
- `query` (str): Search keyword
- `display` (int): Results per page, max 100 (default: 20)
- `page` (int): Page number (default: 1)
- `search_scope` (int): 1=title, 2=full text (default: 1)
- `date_range` (str, optional): Format "YYYYMMDD~YYYYMMDD"
**Returns:** JSON with interpretation list including interpretation IDs
**Example:**
```python
result = await search_legal_interpretations(query="κ³μ½", display=10)
```
### 6. get_legal_interpretation_details
Get complete text of a specific legal interpretation including inquiry and response.
**Parameters:**
- `interp_id` (str): Legal interpretation serial number from search results
**Returns:** JSON with full interpretation text including:
- μ건λͺ
(Case name)
- μ§μμμ§ (Inquiry summary)
- νλ΅ (Response)
- μ΄μ (Reasoning)
- μ§μκΈ°κ΄λͺ
(Inquiry agency)
- νμ κΈ°κ΄λͺ
(Response agency)
**Example:**
```python
# First search for interpretations
search_result = await search_legal_interpretations(query="κ³μ½")
interp_id = search_result['interpretations'][0]['id']
# Then get full details
result = await get_legal_interpretation_details(interp_id=interp_id)
```
### 7. search_local_ordinances
Search ordinances from local governments.
**Parameters:**
- `query` (str): Search keyword
- `display` (int): Results per page, max 100 (default: 20)
- `page` (int): Page number (default: 1)
**Returns:** JSON with ordinance list
**Example:**
```python
result = await search_local_ordinances(query="νκ²½", display=10)
```
## Configuration
### API Key
The API key (OC parameter) is loaded from environment variables. Create a `.env` file in the project root:
```bash
LEXLINK_API_KEY=your_api_key_here
```
You can obtain an API key from the [Korean Law Information Center API Portal](https://open.law.go.kr/LSO/openApi/guideList.do).
**Note:** The `.env` file is excluded from version control by `.gitignore` to protect your credentials.
### MCP Client Configuration
To use this server with Claude Desktop, add to your `claude_desktop_config.json`:
```json
{
"mcpServers": {
"lexlink": {
"command": "uv",
"args": ["run", "python", "/path/to/lexlink_mcp/main.py"],
"cwd": "/path/to/lexlink_mcp"
}
}
}
```
## Project Structure
```
lexlink_mcp/
βββ main.py # MCP server with 7 tools
βββ lexlink_client.py # API client wrapper
βββ pyproject.toml # Dependencies
βββ smithery.yaml # Smithery.ai configuration
βββ .env # API key (not in git)
βββ README.md # English documentation
βββ README_kr.md # Korean documentation
```
## API Information
- **Base URL (Search):** `http://www.law.go.kr/DRF/lawSearch.do`
- **Base URL (Details):** `http://www.law.go.kr/DRF/lawService.do`
- **Response Format:** XML (automatically parsed to Python dict)
- **Rate Limit:** 0.5s delay between requests (built-in)
- **Max Results:** 100 per page
- **Total Available APIs:** 125 endpoints
- **Currently Implemented:** 6 endpoints (5%)
## Testing
**Test Results (Last Updated: November 4, 2025):**
| Test | Tool | Status | Details |
|------|------|--------|---------|
| 1 | search_laws | β
PASS | 9 laws found for "λ―Όλ²", first result: λ―Όλ² (after ranking) |
| 2 | get_law_details | β
PASS | Retrieved 1,337 articles from λ―Όλ² (MST: 265307) |
| 3 | search_case_law | β
PASS | 16,373 cases available for "μν΄λ°°μ" |
| 4 | get_case_details | β
PASS | Full judgment text retrieved |
| 5 | search_legal_interpretations | β
PASS | 257 interpretations for "κ³μ½" |
| 6 | get_legal_interpretation_details | β
PASS | Full interpretation text with inquiry/response|
| 7 | search_local_ordinances | β
PASS | 4,557 ordinances for "νκ²½" |
**Performance Metrics:**
- Average response time: 0.8-1.5 seconds
- Rate limiting: 0.5s delay between requests (built-in)
- All Korean characters (Hangul) properly encoded β
- XML parsing successful for all responses β
- No data corruption detected β
## Troubleshooting
### DeprecationWarning about dependencies parameter
This is a warning from FastMCP 2.11.4+. The server still works correctly. To fix, you can remove the `dependencies` parameter from `FastMCP()` initialization.
### Rate Limiting
If you encounter issues, the built-in rate limiter adds a 0.5s delay between requests to avoid overwhelming the server.
### Empty Results
Some queries may return 0 results even when the total count is > 0. This is an API behavior and not a bug in the client.
## Resources
- [Korean Law Information Center API Portal](https://open.law.go.kr/LSO/openApi/guideList.do) - Official API documentation (125 endpoints)
- [Korea Law Portal](https://www.law.go.kr/) - Main law information portal
- [FastMCP Documentation](https://gofastmcp.com) - MCP framework docs
## Changelog
### Version 0.1.0 (November 3, 2025)
#### β¨ New Features
**Intelligent Search Ranking**
- Exact match prioritization algorithm
- Prefix matching and word boundary detection
- Smart fetch: automatically fetches 5x results for better ranking when display < 20
- Applied to search_laws, search_case_law, and search_legal_interpretations
- Can be disabled with `auto_rank=False` parameter
**Results:**
- Before: Searching "λ―Όλ²" returned "λλ―Όλ²" first β
- After: Searching "λ―Όλ²" returns "λ―Όλ²" first β
**Core Implementation**
- 6 MCP tools for Korean law information
- Async/await operations for optimal performance
- Rate limiting (0.5s between requests)
- Comprehensive XML parsing
- Type hints and detailed docstrings
- Error handling for all operations
**API Coverage**
- Implemented 6 of 125 available endpoints
- Covers ~80% of typical legal research workflows
**Testing**
- Comprehensive test suite with all 6 tools verified
- All tests passing with real API data
- Performance metrics tracked and documented
### Roadmap
**v0.2 (Planned)**
- Constitutional Court decisions API
- Administrative trial decisions API
- Environment variable API key management
- Response caching for frequently accessed laws
**v0.3 (Planned)**
- English statute support
- Law history tracking
- Fair Trade Commission decisions
- Labor Commission decisions
- Legal terminology dictionary
**v1.0 (Goal)**
- All major committee decisions supported
- Treaties search
- Performance optimization
- Advanced filtering options
## Contributing
Want to add more APIs? Follow these steps:
1. Check the [official API guide](https://open.law.go.kr/LSO/openApi/guideList.do) for endpoint details
2. Add method to `lexlink_client.py` with appropriate target type
3. Add MCP tool decorator in `main.py`
4. Update this README with the new coverage
**Priority Areas:**
1. **High Priority**: Constitutional Court and Administrative Trial APIs
2. **Medium Priority**: Additional committee decisions
3. **Enhancement**: Better ranking algorithms, semantic search
4. **Documentation**: More examples, use cases
## License
This project is provided as-is for accessing public legal information from the Korean government.
## Author
Created using Claude Code with the Korean Law Information Center Open API.
---
## Frequently Asked Questions (FAQ)
### Q: How do I obtain an API key?
A: Register at the [Korean Law Information Center API Portal](https://open.law.go.kr/) and apply for an API key. Approval typically takes 1-2 business days.
### Q: Can this be used commercially?
A: Please review the Korean Law Information Center API terms of service. Generally, public data is freely available with proper attribution.
### Q: Is the data real-time?
A: Yes, the data is fetched in real-time from the official Ministry of Government Legislation API.
### Q: How many court cases are available?
A: Over 80,000 publicly available court precedents are searchable.
### Q: When will Constitutional Court decisions be added?
A: This is a high-priority feature planned for the next version.
### Q: Can I search for English statutes?
A: Currently only Korean statutes are supported, but English statute APIs exist in the official API and can be added.
### Q: Does this only work locally?
A: The MCP server uses STDIO transport and works with local Claude Desktop. For remote use, you can modify it to use HTTP transport.
### Q: Is any personal information collected?
A: No. All API calls are sent directly to the government server. This server does not collect or store any personal information.
---
## Usage Examples
### Example 1: Finding a Specific Article
```
User: Show me Article 750 of the Civil Act
Claude performs:
1. search_laws(query="λ―Όλ²") to find the Civil Act
2. Get the MST number
3. get_law_details(mst="265307") to retrieve full text
4. Extract and provide Article 750 content
```
### Example 2: Finding Case Law
```
User: Find recent Supreme Court cases on damages
Claude performs:
1. search_case_law(query="μν΄λ°°μ", court_type="400201")
2. Filter for recent cases
3. Provide case names, numbers, and judgment dates
```
### Example 3: Finding Legal Interpretations
```
User: Are there any official interpretations about contracts?
Claude performs:
1. search_legal_interpretations(query="κ³μ½")
2. Provide list of interpretations
3. Show details of specific interpretation if requested
```
---
## Technology Stack
- **Language:** Python 3.12+
- **Framework:** FastMCP 2.13+
- **HTTP Client:** httpx 0.28+
- **Package Manager:** uv
- **API Response:** XML β Python Dict automatic conversion
- **Async:** asyncio-based
## Performance
- Average response time: 0.8-1.5 seconds
- Request delay: 0.5s (server protection)
- Large statutes (e.g., Civil Act): ~2 seconds
- Concurrent requests: Not supported (sequential processing)
## Security
- API key management via environment variables recommended
- HTTPS not supported (government API only provides HTTP)
- Input validation included
- SQL injection not possible (API calls only)
---
## Contact
For issues or suggestions, please use GitHub Issues.
---
**Last Updated:** November 3, 2025
**Version:** 0.1.0
**Status:** Stable