compare_admin_rule_old_new
Search for administrative rules by keyword and compare old and new versions side-by-side using the rule ID.
Instructions
[행정규칙] 행정규칙 신구법 비교. query로 검색, id로 본문 대조표 조회.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | No | 행정규칙명 키워드 (검색용) | |
| id | No | 행정규칙ID (본문 조회용, search_admin_rule에서 획득) | |
| apiKey | No | 법제처 Open API 인증키(OC). 사용자가 제공한 경우 전달 |
Implementation Reference
- src/tools/admin-rule.ts:251-342 (handler)Main handler function for compare_admin_rule_old_new. Calls lawService.do (target=admrulOldAndNew) with id for detailed comparison, or lawSearch.do (target=admrulOldAndNew) with query for search. Parses XML to extract old/new articles (구조문/신조문) and returns formatted comparison text.
export async function compareAdminRuleOldNew( apiClient: LawApiClient, input: CompareAdminRuleOldNewInput ): Promise<{ content: Array<{ type: string, text: string }>, isError?: boolean }> { try { if (input.id) { // 본문 조회: lawService.do, target=admrulOldAndNew const xmlText = await apiClient.fetchApi({ endpoint: "lawService.do", target: "admrulOldAndNew", type: "XML", extraParams: { ID: String(input.id) }, apiKey: input.apiKey }) const parser = new DOMParser() const doc = parser.parseFromString(xmlText, "text/xml") const ruleName = doc.getElementsByTagName("행정규칙명")[0]?.textContent || "알 수 없음" let resultText = `행정규칙 신구법 대조: ${ruleName}\n` resultText += `━━━━━━━━━━━━━━━━━━━━━━\n\n` const oldArticles = doc.getElementsByTagName("구조문") const newArticles = doc.getElementsByTagName("신조문") const maxCount = Math.max(oldArticles.length, newArticles.length) if (maxCount === 0) { resultText += "신구법 대조 데이터가 없습니다." return { content: [{ type: "text", text: resultText }] } } const displayCount = Math.min(maxCount, 30) for (let i = 0; i < displayCount; i++) { const oldContent = oldArticles[i]?.textContent?.trim() || "" const newContent = newArticles[i]?.textContent?.trim() || "" resultText += `━━━━━━━━━━━━━━━━━━━━━━\n` resultText += `[개정 전] ${oldContent || "(신설)"}\n\n` resultText += `[개정 후] ${newContent || "(삭제)"}\n\n` } if (maxCount > displayCount) { resultText += `\n... 외 ${maxCount - displayCount}개 항목 (생략)\n` } return { content: [{ type: "text", text: truncateResponse(resultText) }] } } // 검색: lawSearch.do, target=admrulOldAndNew const xmlText = await apiClient.fetchApi({ endpoint: "lawSearch.do", target: "admrulOldAndNew", type: "XML", extraParams: { query: String(input.query) }, apiKey: input.apiKey }) const parser = new DOMParser() const doc = parser.parseFromString(xmlText, "text/xml") const rules = doc.getElementsByTagName("admrul") if (rules.length === 0) { return { content: [{ type: "text", text: "행정규칙 신구법 검색 결과가 없습니다." }], isError: true } } let resultText = `행정규칙 신구법 검색 결과 (총 ${rules.length}건):\n\n` const display = Math.min(rules.length, 20) for (let i = 0; i < display; i++) { const rule = rules[i] const name = rule.getElementsByTagName("행정규칙명")[0]?.textContent || "알 수 없음" const ruleId = rule.getElementsByTagName("행정규칙ID")[0]?.textContent || "" const promDate = rule.getElementsByTagName("발령일자")[0]?.textContent || "" const orgName = rule.getElementsByTagName("소관부처명")[0]?.textContent || "" resultText += `${i + 1}. ${name}\n` resultText += ` - 행정규칙ID: ${ruleId}\n` resultText += ` - 발령일: ${promDate}\n` resultText += ` - 소관부처: ${orgName}\n\n` } resultText += `\n💡 본문 조회: compare_admin_rule_old_new(id="행정규칙ID")` return { content: [{ type: "text", text: truncateResponse(resultText) }] } } catch (error) { return formatToolError(error, "compare_admin_rule_old_new") } } - src/tools/admin-rule.ts:240-247 (schema)Zod schema defining input validation for compare_admin_rule_old_new: optional query (search keyword), optional id (rule ID for detail), optional apiKey. Refines to require at least one of query or id.
// compare_admin_rule_old_new 스키마 export const CompareAdminRuleOldNewSchema = z.object({ query: z.string().optional().describe("행정규칙명 키워드 (검색용)"), id: z.string().optional().describe("행정규칙ID (본문 조회용, search_admin_rule에서 획득)"), apiKey: z.string().optional().describe("법제처 Open API 인증키(OC). 사용자가 제공한 경우 전달") }).refine(data => data.query || data.id, { message: "query(검색) 또는 id(본문조회) 중 하나는 필수입니다" }) - src/tool-registry.ts:148-153 (registration)Tool registration in the allTools array. Maps the name 'compare_admin_rule_old_new' to its schema (CompareAdminRuleOldNewSchema) and handler (compareAdminRuleOldNew) with a Korean description.
{ name: "compare_admin_rule_old_new", description: "[행정규칙] 행정규칙 신구법 비교. query로 검색, id로 본문 대조표 조회.", schema: CompareAdminRuleOldNewSchema, handler: compareAdminRuleOldNew }, - src/tools/admin-rule.ts:5-9 (helper)Imports used by the handler: zod for validation, DOMParser for XML parsing, LawApiClient type, truncateResponse for output limiting, and formatToolError for error handling.
import { z } from "zod" import { DOMParser } from "@xmldom/xmldom" import type { LawApiClient } from "../lib/api-client.js" import { truncateResponse } from "../lib/schemas.js" import { formatToolError } from "../lib/errors.js"