get_related_laws
Retrieve a list of Korean laws related to a specified law ID or name. Customize the number of results up to 100 with the display parameter.
Instructions
[지식베이스] 용어 관련 법령 목록.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| lawId | No | 법령ID | |
| lawName | No | 법령명 | |
| display | Yes | 결과 수 (기본:20) | |
| apiKey | No | 법제처 Open API 인증키(OC). 사용자가 제공한 경우 전달 |
Implementation Reference
- src/tools/knowledge-base.ts:359-422 (handler)The main handler function for get_related_laws tool. Calls the lawSearch.do API with target=lawRel, parses XML response via parseKBXML, and returns a formatted list of related laws with their type/ID/kind information.
export async function getRelatedLaws( apiClient: LawApiClient, args: GetRelatedLawsInput ): Promise<{ content: Array<{ type: string; text: string }>; isError?: boolean }> { try { if (!args.lawId && !args.lawName) { throw new Error("lawId 또는 lawName 중 하나는 필수입니다."); } const extraParams: Record<string, string> = { display: (args.display || 20).toString(), }; if (args.lawId) extraParams.ID = String(args.lawId); if (args.lawName) extraParams.query = String(args.lawName); let xmlText: string; try { xmlText = await apiClient.fetchApi({ endpoint: "lawSearch.do", target: "lawRel", extraParams, apiKey: args.apiKey, }); } catch { return { content: [{ type: "text", text: `관련법령 조회 실패.\n\n💡 대안:\n get_law_system_tree(lawName="${args.lawName || args.lawId}") - 법령체계도\n get_three_tier(lawId="${args.lawId}") - 3단비교`, }], isError: true, }; } const result = parseKBXML(xmlText, "LawRelSearch"); const totalCount = parseInt(result.totalCnt || "0"); const items = result.data || []; if (totalCount === 0 || items.length === 0) { return { content: [{ type: "text", text: `관련법령을 찾을 수 없습니다.\n\n💡 get_law_system_tree 또는 get_three_tier를 사용해보세요.`, }], isError: true, }; } let output = `🔗 관련법령 (${totalCount}건):\n\n`; for (const item of items) { output += `📜 ${item.법령명}\n`; if (item.관계유형) output += ` 관계: ${item.관계유형}\n`; if (item.법령ID) output += ` 법령ID: ${item.법령ID}\n`; if (item.법령종류) output += ` 종류: ${item.법령종류}\n`; output += `\n`; } output += `\n💡 법령 조회: get_law_text(lawId="법령ID")`; return { content: [{ type: "text", text: truncateResponse(output) }] }; } catch (error) { return formatToolError(error, "get_related_laws"); } } - src/tools/knowledge-base.ts:350-355 (schema)Zod schema for get_related_laws input: lawId (optional), lawName (optional), display (default 20), apiKey (optional).
export const getRelatedLawsSchema = z.object({ lawId: z.string().optional().describe("법령ID"), lawName: z.string().optional().describe("법령명"), display: z.number().min(1).max(100).default(20).describe("결과 수 (기본:20)"), apiKey: z.string().optional().describe("법제처 Open API 인증키(OC). 사용자가 제공한 경우 전달"), }); - src/tool-registry.ts:570-575 (registration)Registration of the get_related_laws tool in the tool registry with name, description, schema, and handler.
{ name: "get_related_laws", description: "[지식베이스] 용어 관련 법령 목록.", schema: getRelatedLawsSchema, handler: getRelatedLaws }, - src/tools/knowledge-base.ts:374-381 (helper)API call to lawSearch.do endpoint with target=lawRel, parsed by parseKBXML helper for related law search results.
let xmlText: string; try { xmlText = await apiClient.fetchApi({ endpoint: "lawSearch.do", target: "lawRel", extraParams, apiKey: args.apiKey, });