search_admin_rule
Search Korean administrative rules including instructions, regulations, notices, and guidelines. Filter results by rule type using the knd parameter.
Instructions
[행정규칙] 훈령/예규/고시/지침 검색. knd 파라미터로 종류 필터 가능(1=훈령, 2=예규, 3=고시).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | 검색할 행정규칙명 | |
| knd | No | 행정규칙 종류 (1=훈령, 2=예규, 3=고시, 4=공고, 5=일반) | |
| display | Yes | 최대 결과 개수 | |
| apiKey | No | 법제처 Open API 인증키(OC). 사용자가 제공한 경우 전달 |
Implementation Reference
- src/tools/admin-rule.ts:21-92 (handler)Main handler function for the search_admin_rule tool. Accepts query, optional knd (type filter), display count, and apiKey. Calls the API client to search administrative rules, parses XML response, and formats results.
export async function searchAdminRule( apiClient: LawApiClient, input: SearchAdminRuleInput ): Promise<{ content: Array<{ type: string, text: string }>, isError?: boolean }> { try { const xmlText = await apiClient.searchAdminRule({ query: input.query, knd: input.knd, apiKey: input.apiKey }) const parser = new DOMParser() const doc = parser.parseFromString(xmlText, "text/xml") const rules = doc.getElementsByTagName("admrul") if (rules.length === 0) { let errorMsg = "검색 결과가 없습니다." errorMsg += `\n\n💡 개선 방법:` errorMsg += `\n 1. 단순 키워드 사용:` const words = input.query.split(/\s+/) if (words.length > 1) { errorMsg += `\n search_admin_rule(query="${words[0]}")` } errorMsg += `\n\n 2. 상위 법령명 검색:` errorMsg += `\n search_law(query="관련 법령명")` errorMsg += `\n\n 3. 광범위 검색:` errorMsg += `\n search_all(query="${words[0] || input.query}")` return { content: [{ type: "text", text: errorMsg }], isError: true } } let resultText = `행정규칙 검색 결과 (총 ${rules.length}건):\n\n` const display = Math.min(rules.length, input.display) for (let i = 0; i < display; i++) { const rule = rules[i] const ruleName = rule.getElementsByTagName("행정규칙명")[0]?.textContent || "알 수 없음" const ruleSeq = rule.getElementsByTagName("행정규칙일련번호")[0]?.textContent || "" const ruleId = rule.getElementsByTagName("행정규칙ID")[0]?.textContent || "" const promDate = rule.getElementsByTagName("발령일자")[0]?.textContent || "" const ruleType = rule.getElementsByTagName("행정규칙종류")[0]?.textContent || "" const orgName = rule.getElementsByTagName("소관부처명")[0]?.textContent || "" resultText += `${i + 1}. ${ruleName}\n` resultText += ` - 행정규칙일련번호: ${ruleSeq}\n` resultText += ` - 행정규칙ID: ${ruleId}\n` resultText += ` - 공포일: ${promDate}\n` resultText += ` - 구분: ${ruleType}\n` resultText += ` - 소관부처: ${orgName}\n\n` } resultText += `\n💡 상세 내용을 조회하려면 get_admin_rule Tool을 사용하세요.` return { content: [{ type: "text", text: truncateResponse(resultText) }] } } catch (error) { return formatToolError(error, "search_admin_rule") } } - src/tools/admin-rule.ts:12-17 (schema)Zod schema for search_admin_rule input validation: query (string, required), knd (optional string for rule type filter 1-5), display (optional number, default 20), apiKey (optional string).
export const SearchAdminRuleSchema = z.object({ query: z.string().describe("검색할 행정규칙명"), knd: z.string().optional().describe("행정규칙 종류 (1=훈령, 2=예규, 3=고시, 4=공고, 5=일반)"), display: z.number().optional().default(20).describe("최대 결과 개수"), apiKey: z.string().optional().describe("법제처 Open API 인증키(OC). 사용자가 제공한 경우 전달") }) - src/tool-registry.ts:136-141 (registration)Registers search_admin_rule in the MCP tool registry with name, description, schema (SearchAdminRuleSchema), and handler (searchAdminRule function).
{ name: "search_admin_rule", description: "[행정규칙] 훈령/예규/고시/지침 검색. knd 파라미터로 종류 필터 가능(1=훈령, 2=예규, 3=고시).", schema: SearchAdminRuleSchema, handler: searchAdminRule }, - src/lib/api-client.ts:200-219 (helper)API client method that builds the URL and calls lawSearch.do with target=admrul to search administrative rules from the National Law Information Center API.
/** * 행정규칙 검색 */ async searchAdminRule(params: { query: string knd?: string apiKey?: string }): Promise<string> { const apiParams = new URLSearchParams({ OC: this.getApiKey(params.apiKey), type: "XML", target: "admrul", query: params.query, }) if (params.knd) apiParams.append("knd", params.knd) const url = `${LAW_API_BASE}/lawSearch.do?${apiParams.toString()}` return await this.fetchText(url, "searchAdminRule") } - src/lib/tool-chain-config.ts:71-75 (helper)Tool chain configuration linking search_admin_rule to get_admin_rule as its detail tool, extracting ID via '행정규칙ID:' regex pattern.
search_admin_rule: { detailTool: "get_admin_rule", detailParam: "id", idRegex: /행정규칙ID:\s*(\S+)/, // 행정규칙은 [ID] 형식이 아님 },