Skip to main content
Glama

Convert filter condition to matching rule

compile_expression_from_where
Read-only

Compile Expression

When to use: 매칭 규칙 조건을 사람이 읽고 쓰기 쉬운 SQL WHERE 절로 표현하고, 저장에 필요한 legacy AST(mapping_rule)와 화면 편집용 2단 구조(mapping_rule_fe)를 한 번에 얻고 싶을 때. 규칙 생성 도구가 둘 사이를 파생해 주지 않아 사람이 손으로 두 JSON 트리를 조립해야 했던 단계를 대체한다. 광고 매칭·상품 매칭·온톨로지 매칭이 모두 같은 두 필드를 쓰므로 도메인과 무관하게 쓸 수 있다.

When NOT to use: 이미 저장된 규칙의 조건을 조회하는 것이라면 규칙 목록 도구(list_ad_mappings·list_item_mappings 등)를 쓴다. 조건이 실제로 몇 건의 광고행을 잡는지는 count_ad_rule_matches.

Limitations: 🔴 읽기 전용 — 저장하지 않는다. 응답의 mapping_rule/mapping_rule_fe 를 규칙 생성·수정 도구(예: create_ad_mapping_rule)에 넣어야 실제로 저장된다. 🔴 컬럼 이름을 검증하지 않는다 — 도메인마다 허용 컬럼이 다르고 상품 매칭은 dim 테이블 기반이라 동적이기 때문이다. 오타(adset_nmae)도 그대로 AST 가 되고 저장 후 매칭 0건으로만 드러나므로, 저장 전에 count_ad_rule_matches 로 실제 매칭 건수를 확인할 것. OR-그룹 × AND-조건 2단 구조로 펴기 위해 DNF(논리합 정규형) 정규화를 타므로 A AND (B OR C) 는 (A AND B) OR (A AND C) 로 조건이 복제된다(정상). 대응 연산자가 없는 조건(컬럼끼리 비교·함수 호출·서브쿼리·값 가운데 %가 낀 LIKE·%x% 아닌 위치의 NOT LIKE)은 일부만 버리지 않고 요청 전체를 거절한다(400, rejected_conditions 에 조건별 사유). laplace 의 LIKE 는 SQL LIKE 가 아니라 contains 라 와일드카드 위치로 LIKE/START_WITH/END_WITH 가 갈리고, 와일드카드 없는 LIKE 는 EQ 로 컴파일되며 warnings 에 남는다.

Examples:

  • Q: 광고채널이 구글이고 광고그룹 이름에 '여름세일'이 들어가는 조건으로 규칙을 만들어줘 params: {'body': {'where': "ad_channel_name IN ('GOOGLE_ADS') AND adset_name LIKE '%여름세일%'"}}

Output shape: object: mapping_rule(legacy AST) + mapping_rule_fe(2단 구조) + conditions(도메인 중립 조건 목록) + warnings

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "where": "<where>"
    },
    "name": "compile_expression_from_where"
  }
}

Input Schema

NameRequiredDescriptionDefault
whereYesWHERE 절 본문. 선행 WHERE 키워드는 있어도 없어도 된다.
dialectNosqlglot 파싱 방언.trino
project-idNo

Output Schema

NameRequiredDescriptionDefault

No arguments

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A4.4/5.0
Behavior5/5

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

Annotations already declare readOnlyHint=true and destructiveHint=false, and the description adds substantial context beyond them: it explicitly says nothing is persisted and the output must be fed to a rule-creation tool, that column names are NOT validated (typos silently become AST), that DNF normalization duplicates conditions so `A AND (B OR C)` becomes `(A AND B) OR (A AND C)`, that unsupported conditions cause whole-request rejection with per-condition reasons in rejected_conditions, and that LIKE maps to contains/START_WITH/END_WITH/EQ with warnings.

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?

Structure is strong and front-loaded: when-to-use, when-not-to-use, limitations, example, output shape. The Limitations paragraph is dense and mixes several distinct warnings, but each sentence carries real operational information rather than filler, so it stays close to the right size for a tool with this many edge cases.

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

Completeness4/5

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

An output schema exists, yet the description still summarizes the return shape (mapping_rule + mapping_rule_fe + conditions + warnings), and it covers error behavior and the save-vs-compile boundary thoroughly. The remaining gap is the unaddressed `dialect` and `project-id` parameters plus the schema-inconsistent example, which keep it from being fully complete.

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

Parameters2/5

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

With 67% schema coverage, the description should carry the undocumented parameters, but it never mentions `dialect` (sqlglot parsing dialect, default trino) or `project-id`. Worse, the only parameter illustration is `params: {'body': {'where': ...}}`, which nests `where` under a `body` key that does not exist in the input schema and could lead an agent to emit an invalid call.

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

Purpose5/5

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

The 'When to use' block states a concrete verb and resource: take a matching-rule condition expressed as a SQL WHERE clause and return both the legacy AST (mapping_rule) and the two-tier FE structure (mapping_rule_fe) in one call. It also names the exact step it replaces (hand-assembling two JSON trees because rule-creation tools don't derive one from the other), which is enough for an agent to tell it apart from create_ad_mapping_rule or list_ad_mappings without opening any schema.

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

Usage Guidelines5/5

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

It gives an explicit when-to-use, an explicit when-NOT-to-use with the named alternative (list_ad_mappings / list_item_mappings for reading existing rule conditions), and a named follow-up validator (count_ad_rule_matches) for checking match counts. It even states the tool is domain-agnostic across ad/item/ontology matching, so the agent knows no domain switch is required.

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

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.

Resources