suggest_law_names
Input a partial law name to get a list of matching law candidates for accurate law identification.
Instructions
[자동완성] 법령명 일부 입력 시 후보 목록 제안. 정확한 법령명을 모를 때 사용.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| partial | Yes | 부분 입력된 법령명 (예: '관세', '환경') | |
| apiKey | No | 법제처 Open API 인증키(OC). 사용자가 제공한 경우 전달 |
Implementation Reference
- src/tools/autocomplete.ts:18-126 (handler)The main handler function for suggest_law_names. Takes partial law name input, calls searchLaw to find matches, parses results by type (law, decree, rule), and returns formatted suggestions grouped by category.
export async function suggestLawNames( apiClient: LawApiClient, input: SuggestLawNamesInput ): Promise<{ content: Array<{ type: string, text: string }>, isError?: boolean }> { try { if (input.partial.length < 2) { return { content: [{ type: "text", text: "검색어는 최소 2글자 이상이어야 합니다." }], isError: true } } // Search for laws matching the partial input const searchResult = await searchLaw(apiClient, { query: input.partial, display: 20, apiKey: input.apiKey }) if (searchResult.isError) { return searchResult } const text = searchResult.content[0].text // Parse search results to extract law names const lines = text.split('\n') const suggestions: Array<{ name: string; type: string }> = [] for (let i = 0; i < lines.length; i++) { const line = lines[i] // Match lines like "1. 관세법" const nameMatch = line.match(/^\d+\.\s+(.+)$/) if (nameMatch) { const name = nameMatch[1].trim() // Look ahead for the type line " - 구분: 법률" const typeLine = lines[i + 4] // 4 lines down: lawId, MST, promDate, lawType const typeMatch = typeLine?.match(/구분:\s+(.+)/) if (typeMatch) { const type = typeMatch[1].trim() suggestions.push({ name, type }) } } } if (suggestions.length === 0) { return { content: [{ type: "text", text: `'${input.partial}'로 시작하는 법령을 찾을 수 없습니다.` }] } } let output = `=== 법령명 자동완성: "${input.partial}" ===\n\n` // Group by type const laws = suggestions.filter(s => s.type === "법률") const decrees = suggestions.filter(s => s.type === "대통령령") const rules = suggestions.filter(s => s.type === "총리령" || s.type === "부령") if (laws.length > 0) { output += `📜 법률 (${laws.length}건)\n` for (const law of laws.slice(0, 10)) { output += ` • ${law.name}\n` } if (laws.length > 10) { output += ` ... 외 ${laws.length - 10}건\n` } output += `\n` } if (decrees.length > 0) { output += `📋 시행령 (${decrees.length}건)\n` for (const decree of decrees.slice(0, 5)) { output += ` • ${decree.name}\n` } if (decrees.length > 5) { output += ` ... 외 ${decrees.length - 5}건\n` } output += `\n` } if (rules.length > 0) { output += `📄 시행규칙 (${rules.length}건)\n` for (const rule of rules.slice(0, 5)) { output += ` • ${rule.name}\n` } if (rules.length > 5) { output += ` ... 외 ${rules.length - 5}건\n` } output += `\n` } output += `💡 자세한 정보는 search_law Tool을 사용하세요.` return { content: [{ type: "text", text: output }] } } catch (error) { return formatToolError(error, "suggest_law_names") } } - src/tools/autocomplete.ts:11-14 (schema)Zod schema defining the tool's input: partial (string, required) and apiKey (optional).
export const SuggestLawNamesSchema = z.object({ partial: z.string().describe("부분 입력된 법령명 (예: '관세', '환경')"), apiKey: z.string().optional().describe("법제처 Open API 인증키(OC). 사용자가 제공한 경우 전달") }) - src/tool-registry.ts:128-133 (registration)Tool registration entry in the tool registry. Maps name 'suggest_law_names' to its schema and handler function. Imported from src/tools/autocomplete.ts via line 27.
{ name: "suggest_law_names", description: "[자동완성] 법령명 일부 입력 시 후보 목록 제안. 정확한 법령명을 모를 때 사용.", schema: SuggestLawNamesSchema, handler: suggestLawNames }, - src/tool-registry.ts:27-27 (registration)Import statement bringing suggestLawNames handler and SuggestLawNamesSchema into the tool registry.
import { suggestLawNames, SuggestLawNamesSchema } from "./tools/autocomplete.js" - src/tools/autocomplete.ts:124-124 (helper)Error handling using formatToolError helper, which formats errors with error codes and suggestions.
return formatToolError(error, "suggest_law_names")