get_treaty_text
Get the full text of a Korean treaty in Korean or English by providing its serial number from a treaty search.
Instructions
[조약] 조약 본문 조회. 한글/영문 선택 가능.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | 조약일련번호 (search_treaties 결과에서 획득) | |
| chrClsCd | Yes | 언어 (010202=한글, 010203=영문, 기본:한글) | 010202 |
| apiKey | No | 법제처 Open API 인증키(OC). 사용자가 제공한 경우 전달 |
Implementation Reference
- src/tools/treaties.ts:80-85 (schema)Zod schema for get_treaty_text: validates 'id' (treaty serial number), 'chrClsCd' (language code, default Korean), and optional 'apiKey'.
export const getTreatyTextSchema = z.object({ id: z.string().describe("조약일련번호 (search_treaties 결과에서 획득)"), chrClsCd: z.enum(["010202", "010203"]).default("010202") .describe("언어 (010202=한글, 010203=영문, 기본:한글)"), apiKey: z.string().optional().describe("법제처 Open API 인증키(OC). 사용자가 제공한 경우 전달"), }) - src/tools/treaties.ts:89-156 (handler)Main handler function for get_treaty_text. Fetches treaty text via LawApiClient, parses JSON response, extracts treaty info and body text, returns formatted output.
export async function getTreatyText( apiClient: LawApiClient, args: GetTreatyTextInput ): Promise<{ content: Array<{ type: string, text: string }>, isError?: boolean }> { try { const extraParams: Record<string, string> = { ID: String(args.id), chrClsCd: String(args.chrClsCd || "010202"), } const responseText = await apiClient.fetchApi({ endpoint: "lawService.do", target: "trty", type: "JSON", extraParams, apiKey: args.apiKey, }) let data: any try { data = JSON.parse(responseText) } catch { throw new Error("Failed to parse JSON response from API") } // API는 BothTrtyService 또는 TrtyService로 응답 const trty = data.BothTrtyService || data.TrtyService if (!trty) { throw new Error("Treaty not found or invalid response format") } // 조약내용이 중첩 객체일 수 있음 const bodyObj = trty.조약내용 || {} const bodyText = typeof bodyObj === "string" ? bodyObj : bodyObj.조약내용 || "" const basic = { 조약명: trty.조약명, 조약번호: trty.조약번호, 체결일자: trty.체결일자, 발효일자: trty.발효일자, 조약구분: trty.조약구분명, 체결상대국: trty.체결상대국, } let output = `=== ${basic.조약명 || "조약"} ===\n\n` output += `기본 정보:\n` output += ` 조약번호: ${basic.조약번호 || "N/A"}\n` output += ` 체결일: ${basic.체결일자 || "N/A"}\n` output += ` 발효일: ${basic.발효일자 || "N/A"}\n` output += ` 구분: ${basic.조약구분 || "N/A"}\n` output += ` 체결상대국: ${basic.체결상대국 || "N/A"}\n\n` if (bodyText) { output += `조약 본문:\n${bodyText}\n` } return { content: [{ type: "text", text: truncateResponse(output) }] } } catch (error) { const msg = error instanceof Error ? error.message : String(error) return { content: [{ type: "text", text: `Error: ${msg}` }], isError: true } } } - src/tool-registry.ts:498-503 (registration)Registration of the 'get_treaty_text' tool in the tool registry with name, description, schema, and handler.
{ name: "get_treaty_text", description: "[조약] 조약 본문 조회. 한글/영문 선택 가능.", schema: getTreatyTextSchema, handler: getTreatyText }, - src/tool-registry.ts:45-45 (registration)Import of getTreatyText and getTreatyTextSchema from the treaties module.
import { searchTreaties, searchTreatiesSchema, getTreatyText, getTreatyTextSchema } from "./tools/treaties.js"