Skip to main content
Glama

LexLink Korean Law MCP Server

by rabqatab
README.mdβ€’22.1 kB
[πŸ‡ΊπŸ‡Έ **EN**](README.md) | [πŸ‡°πŸ‡· KR](README_kr.md) # LexLink MCP Server [![smithery badge](https://smithery.ai/badge/@rabqatab/lexlink_ko_mcp)](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

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/rabqatab/LexLink_ko_mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server