get_admin_rule
Get the full text of an administrative rule by its ID. Use after searching for rules.
Instructions
[행정규칙] 행정규칙 전문 조회.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | 행정규칙ID (search_admin_rule에서 획득) | |
| apiKey | No | 법제처 Open API 인증키(OC). 사용자가 제공한 경우 전달 |
Implementation Reference
- src/tools/admin-rule.ts:102-238 (handler)Main handler function for the get_admin_rule tool. Takes an API client and input (id, apiKey), fetches admin rule XML from the law API, parses it using DOMParser, and extracts the rule name, date, type, organization, article contents, addendums, and annexes for display.
export async function getAdminRule( apiClient: LawApiClient, input: GetAdminRuleInput ): Promise<{ content: Array<{ type: string, text: string }>, isError?: boolean }> { try { const xmlText = await apiClient.getAdminRule(input.id, input.apiKey) const parser = new DOMParser() const doc = parser.parseFromString(xmlText, "text/xml") // 행정규칙 정보 추출 const ruleName = doc.getElementsByTagName("행정규칙명")[0]?.textContent || "알 수 없음" const promDate = doc.getElementsByTagName("공포일자")[0]?.textContent || "" const orgName = doc.getElementsByTagName("소관부처")[0]?.textContent || "" const ruleType = doc.getElementsByTagName("행정규칙종류")[0]?.textContent || "" let resultText = `행정규칙명: ${ruleName}\n` if (promDate) resultText += `공포일: ${promDate}\n` if (ruleType) resultText += `종류: ${ruleType}\n` if (orgName) resultText += `소관부처: ${orgName}\n` resultText += `\n━━━━━━━━━━━━━━━━━━━━━━\n\n` // 조문 추출 - <조문내용> 태그 사용 const joContents = doc.getElementsByTagName("조문내용") if (joContents.length === 0) { // 첨부파일 확인 const attachments = doc.getElementsByTagName("첨부파일링크") if (attachments.length > 0) { resultText += "⚠️ 이 행정규칙은 조문 형식이 아닌 첨부파일로 제공됩니다.\n\n" resultText += "📎 첨부파일:\n" for (let i = 0; i < attachments.length; i++) { const link = attachments[i].textContent || "" if (link) { resultText += ` ${i + 1}. ${link}\n` } } return { content: [{ type: "text", text: truncateResponse(resultText) }] } } return { content: [{ type: "text", text: "행정규칙 전문을 조회할 수 없습니다.\n\n" + "⚠️ 법제처 API 제한: 일부 행정규칙은 전문 조회가 지원되지 않습니다.\n" + "💡 대안: search_admin_rule 결과의 '행정규칙상세링크'를 통해 웹에서 확인하세요." }], isError: true } } // 조문내용이 비어있는지 확인 let hasContent = false for (let i = 0; i < joContents.length; i++) { const content = joContents[i].textContent?.trim() || "" if (content.length > 0) { hasContent = true break } } if (!hasContent) { // 첨부파일 확인 const attachments = doc.getElementsByTagName("첨부파일링크") if (attachments.length > 0) { resultText += "⚠️ 이 행정규칙은 조문 형식이 아닌 첨부파일로 제공됩니다.\n\n" resultText += "📎 첨부파일:\n" for (let i = 0; i < attachments.length; i++) { const link = attachments[i].textContent || "" if (link) { resultText += ` ${i + 1}. ${link}\n` } } } else { resultText += "⚠️ 이 행정규칙은 조문 내용이 비어있습니다." } return { content: [{ type: "text", text: truncateResponse(resultText) }] } } // 조문 내용 출력 for (let i = 0; i < joContents.length; i++) { const joContent = joContents[i].textContent?.trim() || "" if (joContent.length > 0) { resultText += `${joContent}\n\n` } } // 부칙 추가 const addendums = doc.getElementsByTagName("부칙내용") if (addendums.length > 0) { resultText += `\n━━━━━━━━━━━━━━━━━━━━━━\n부칙\n━━━━━━━━━━━━━━━━━━━━━━\n\n` for (let i = 0; i < addendums.length; i++) { const content = addendums[i].textContent?.trim() || "" if (content.length > 0) { resultText += `${content}\n\n` } } } // 별표 추가 const annexes = doc.getElementsByTagName("별표내용") if (annexes.length > 0) { resultText += `\n━━━━━━━━━━━━━━━━━━━━━━\n별표\n━━━━━━━━━━━━━━━━━━━━━━\n\n` for (let i = 0; i < annexes.length; i++) { const title = doc.getElementsByTagName("별표제목")[i]?.textContent?.trim() || "" const content = annexes[i].textContent?.trim() || "" if (title) { resultText += `[${title}]\n` } if (content.length > 0) { resultText += `${content}\n\n` } } } return { content: [{ type: "text", text: truncateResponse(resultText) }] } } catch (error) { return formatToolError(error, "get_admin_rule") } } - src/tools/admin-rule.ts:95-98 (schema)Zod schema for get_admin_rule input validation. Requires 'id' (admin rule ID from search) and optional 'apiKey'.
export const GetAdminRuleSchema = z.object({ id: z.string().describe("행정규칙ID (search_admin_rule에서 획득)"), apiKey: z.string().optional().describe("법제처 Open API 인증키(OC). 사용자가 제공한 경우 전달") }) - src/tool-registry.ts:142-147 (registration)Registers the tool with name 'get_admin_rule' in the tool registry, linking it to GetAdminRuleSchema and getAdminRule handler.
{ name: "get_admin_rule", description: "[행정규칙] 행정규칙 전문 조회.", schema: GetAdminRuleSchema, handler: getAdminRule }, - src/lib/api-client.ts:224-237 (helper)API client helper that makes the actual HTTP call to the law API's lawService.do endpoint with target=admrul and the given ID to fetch admin rule XML data.
async getAdminRule(id: string, apiKey?: string): Promise<string> { const apiParams = new URLSearchParams({ target: "admrul", OC: this.getApiKey(apiKey), type: "XML", ID: id, }) const url = `${LAW_API_BASE}/lawService.do?${apiParams.toString()}` const text = await this.fetchText(url, "getAdminRule") this.checkHtmlError(text, "행정규칙을 찾을 수 없습니다. ID를 확인해주세요") return text } - src/lib/tool-chain-config.ts:71-75 (helper)Tool chain configuration linking search_admin_rule to get_admin_rule as the detail tool, with the detail parameter being 'id'.
search_admin_rule: { detailTool: "get_admin_rule", detailParam: "id", idRegex: /행정규칙ID:\s*(\S+)/, // 행정규칙은 [ID] 형식이 아님 },