Skip to main content
Glama

chain_law_system

Automatically chain legal statute searches, compare articles, and retrieve annexes to analyze legal structures.

Instructions

[⛓체인] 법체계 파악. 법령검색→3단비교→조문→별표 자동 연쇄. 법 구조 질문 시.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes법령명 또는 키워드 (예: '관세법', '건축법 허가')
articlesNo조회할 조문 번호 (예: ['제38조', '제39조'])
apiKeyNo

Implementation Reference

  • The main handler function for chain_law_system. It searches for laws, performs a 3-tier comparison (law/enforcement decree/enforcement rules), optionally fetches articles, and expands to annexes based on keyword detection.
    export async function chainLawSystem(
      apiClient: LawApiClient,
      input: z.infer<typeof chainLawSystemSchema>
    ): Promise<ToolResponse> {
      try {
        const laws = await findLaws(apiClient, input.query, input.apiKey)
        if (laws.length === 0) return noResult(input.query)
    
        const p = laws[0]
        const parts = [
          `═══ 법체계 확인: ${p.lawName} ═══`,
          `법령ID: ${p.lawId} | MST: ${p.mst} | 구분: ${p.lawType}`,
        ]
    
        // 3단 비교
        const threeTier = await callTool(getThreeTier, apiClient, { mst: p.mst, apiKey: input.apiKey })
        if (!threeTier.isError) parts.push(sec("3단 비교 (법률·시행령·시행규칙)", threeTier.text))
    
        // 조문 조회
        if (input.articles?.length) {
          const batch = await callTool(getBatchArticles, apiClient, {
            mst: p.mst,
            articles: input.articles,
            apiKey: input.apiKey,
          })
          if (!batch.isError) parts.push(sec("핵심 조문", batch.text))
        }
    
        // 키워드 확장: 별표
        const exp = detectExpansions(input.query)
        if (exp.includes("annex_fee") || exp.includes("annex_table") || exp.includes("annex_form")) {
          const annexes = await callTool(getAnnexes, apiClient, { lawName: p.lawName, apiKey: input.apiKey })
          if (!annexes.isError) parts.push(sec("별표/서식", annexes.text))
        }
    
        return wrapResult(parts.join("\n"))
      } catch (error) {
        return wrapError(error)
      }
    }
  • Zod schema for chain_law_system input validation: query (string), optional articles (array of strings), and optional apiKey.
    export const chainLawSystemSchema = z.object({
      query: z.string().describe("법령명 또는 키워드 (예: '관세법', '건축법 허가')"),
      articles: z.array(z.string()).optional().describe("조회할 조문 번호 (예: ['제38조', '제39조'])"),
      apiKey: z.string().optional(),
    })
  • Registration of chain_law_system in the MCP tool registry with name, description, schema, and handler.
    // === 체인 도구 (다단계 자동 실행) ===
    {
      name: "chain_law_system",
      description: "[⛓체인] 법체계 파악. 법령검색→3단비교→조문→별표 자동 연쇄. 법 구조 질문 시.",
      schema: chainLawSystemSchema,
      handler: chainLawSystem
    },
  • Helper function findLaws used by chainLawSystem to search and rank laws by relevance.
    async function findLaws(
      apiClient: LawApiClient,
      query: string,
      apiKey?: string,
      max = 3
    ): Promise<LawInfo[]> {
      // 1차: 원본 쿼리로 검색
      let results: LawInfo[] = []
      try {
        const xmlText = await apiClient.searchLaw(query, apiKey)
        results = parseLawXml(xmlText, max)
      } catch { /* 2차 시도로 진행 */ }
    
      // 2차: 결과 없으면 부가 키워드 제거 후 재시도
      if (results.length === 0) {
        const stripped = stripNonLawKeywords(query)
        if (stripped && stripped !== query) {
          try {
            const xmlText = await apiClient.searchLaw(stripped, apiKey)
            results = parseLawXml(xmlText, max)
          } catch { /* 빈 결과 반환 */ }
        }
      }
    
      // 쿼리와 법령명 관련도 기반 정렬 (정확 매칭 > 부분 매칭 > 나머지)
      if (results.length > 1) {
        const queryWords = query.replace(NON_LAW_NAME_RE, " ")
          .trim().split(/\s+/).filter(w => w.length > 0)
        results.sort((a, b) => {
          const scoreA = scoreLawRelevance(a.lawName, query, queryWords)
          const scoreB = scoreLawRelevance(b.lawName, query, queryWords)
          return scoreB - scoreA
        })
      }
    
      return results
    }
  • Query router rule that routes patterns like '3단 비교', '법 체계' etc. to the chain_law_system tool.
    {
      name: "law_system",
      patterns: [
        /3단\s*비교|위임\s*조문|인용\s*조문|법\s*체계|시행령\s*비교/,
      ],
      tool: "chain_law_system",
      extract: (query) => ({ query: extractLawName(query) || query }),
      reason: "법체계/3단비교 키워드 → 법체계 체인",
      priority: 10,
    },
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It describes the automatic chaining process (법령검색→3단비교→조문→별표), which is a key behavioral trait. However, it does not disclose potential side effects (none expected, but not stated), authentication needs, or error handling, leaving some gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is brief (two lines) and front-loaded with the core purpose. It uses a compact structure with emojis and bullet points, making it scannable. However, it could be more concise in English and avoid the initial bracket emoji for broader accessibility.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has 3 parameters, 1 required, and no output schema, the description should clarify what the tool returns. It only vaguely says '법체계 파악' without specifying the output format or content. For a chaining tool, the lack of detail on the final output or the steps' results reduces completeness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 67% description coverage (2 of 3 parameters described). The description adds context about the chaining process but does not explain parameters beyond what the schema already provides. The 'apiKey' parameter lacks description both in schema and description, so no added value.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description explicitly states the tool's purpose: to grasp the legal system by chaining law search, three-tier comparison, articles, and appendix. This clearly identifies the verb-phrase and resource (법체계 파악) and differentiates it from sibling chain tools like chain_action_basis and chain_alio_benchmark, which focus on different aspects.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description notes '법 구조 질문 시' (for law structure questions), implying the tool is suitable for structural queries. However, it does not explicitly state when not to use it or mention alternative tools, leaving some ambiguity compared to sibling tools like get_law_system_tree or get_law_tree.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/workbookbulb863/korean-law-alio-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server