Skip to main content
Glama

cls_search_log

Search and analyze logs in Tencent Cloud Log Service using CQL queries and SQL pipelines to filter, aggregate, and extract insights from log data.

Instructions

检索分析 CLS 日志。支持 CQL 检索和 SQL 管道分析。

CQL 语法速查

CQL (CLS Query Language) 是 CLS 自研的检索分析语法,语句结构为:[检索条件] | [SQL 语句]。 检索条件用于过滤日志,SQL 用于统计分析。不需要分析时可省略 | 及 SQL 部分。

检索语法

  • 键值检索: status:404level:ERROR(字段值包含该词)

  • 全文检索: errortimeout(全文中包含该词)

  • 短语检索: "connection timeout"'user_name:"bob"'(精确短语,支持通配符如 "/var/log/acc*.log"

  • 逻辑操作符: ANDORNOT(不区分大小写,AND 优先级高于 OR)

  • 分组: level:(ERROR OR WARNING) AND pid:1234

  • 数值比较: status:>400status:>=400status:=200latency:<100

  • 模糊匹配: host:www.test*.com* 匹配零到多个字符,不支持前缀模糊如 *test

  • 字段存在性: key:*(字段存在)、key:""(字段存在但值为空)

  • 转义: body:user_name\:bob(特殊字符用 \ 转义)

SQL 分析(检索条件 | SQL,无需 FROM 和分号)

  • 字符串用单引号 '',字段名冲突用双引号 ""

  • * | SELECT COUNT(*) AS total

  • * | SELECT status, COUNT(*) AS cnt GROUP BY status ORDER BY cnt DESC

  • 默认返回 100 行,LIMIT 最大 100 万行

CLS 扩展函数

  • histogram(时间分桶): histogram(__TIMESTAMP__, interval 1 hour) — 直接传 LONG 型,自动 UTC+8

  • time_series(时序补全): time_series(__TIMESTAMP__, '5m', '%Y-%m-%d %H:%i:%s', '0') — 必须 GROUP BY + ORDER BY,不支持 DESC,分钟用 %i

  • compare(同环比): compare(count(*), 86400) — 返回数组下标从 1 开始,86400=日/604800=周

  • IP 地理: ip_to_province/city/country/provider(ip)

  • 百分位: APPROX_PERCENTILE(field, 0.99)

关键注意

  • CQL 是 CLS 推荐语法(SyntaxRule=1),相比 Lucene 更简便,特殊字符限制更少

  • CQL 中多个分词默认为 AND 关系(Lucene 默认为 OR)

  • __TIMESTAMP__ 是 bigint 毫秒时间戳,from_unixtime 要除 1000

  • 脏数据用 try_cast 代替 cast

  • 时区:histogram/time_series 传 LONG 型自动 UTC+8,其他日期函数默认 UTC+0,需手动加 8 小时

参数说明

  • topic_id: 日志主题 ID(必填)

  • query: CQL 检索语句(必填),如 level:ERROR* | SELECT COUNT(*) as cnt

  • start_time: 起始时间,Unix 时间戳(毫秒)

  • end_time: 结束时间,Unix 时间戳(毫秒)

  • limit: 返回条数,默认 100,最大 1000(仅对原始日志有效,SQL 分析不受此限制)

  • context: 翻页游标,首次查询无需传入,从上次返回结果获取

  • sort: 排序方式,asc(升序)或 desc(降序,默认)

注意事项

  • start_time/end_time 为毫秒时间戳,请先调用 cls_convert_time 工具转换,不要手动计算

  • 💡 编写 SQL 分析语句前,建议先调用 cls_describe_index 获取索引配置,确认字段名称和类型

  • CQL 执行报错时,可调用 cls_describe_search_syntax 获取 CLS 完整扩展语法参考文档

  • region: 地域(可选),如 ap-guangzhou、na-ashburn,不传则使用默认地域

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
topic_idYes
queryYes
start_timeYes
end_timeYes
limitNo
contextNo
sortNodesc
regionNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes
Behavior4/5

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

With no annotations provided, the description carries full burden and does an excellent job disclosing behavioral traits: it explains the CQL/SQL syntax, default return limits (100 rows, max 1M for SQL), pagination via context parameter, timezone handling (UTC+8 vs UTC+0), error handling recommendations, and regional defaults. The only minor gap is lack of explicit rate limit or authentication requirements.

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

Conciseness3/5

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

The description is comprehensive but overly long (500+ words) with extensive syntax documentation that might be better in separate reference tools. While well-structured with clear sections, it includes implementation details like CQL syntax examples and SQL function references that exceed what's needed for tool selection. Some content could be moved to cls_describe_search_syntax.

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

Completeness5/5

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

Given the tool's complexity (8 parameters, no annotations, rich functionality) and presence of an output schema, the description is remarkably complete. It covers purpose, usage guidelines, parameter semantics, behavioral traits, error handling, and sibling tool relationships. The output schema existence means return values don't need explanation, and the description addresses all other aspects thoroughly.

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

Parameters5/5

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

With 0% schema description coverage, the description fully compensates by providing detailed parameter explanations in the '参数说明' section. It clarifies required vs optional parameters, default values (limit=100, sort=desc), format requirements (millisecond timestamps), and practical usage guidance (call cls_convert_time for timestamps). This adds substantial value beyond the bare schema.

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 description clearly states the tool's purpose as '检索分析 CLS 日志' (search and analyze CLS logs) with specific mention of supporting both CQL retrieval and SQL pipeline analysis. It distinguishes itself from siblings like cls_describe_index and cls_describe_search_syntax by being the primary execution tool for log queries rather than metadata or syntax reference tools.

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?

The description provides explicit guidance on when to use this tool versus alternatives, including calling cls_convert_time for timestamp conversion, cls_describe_index for field verification before SQL analysis, and cls_describe_search_syntax for syntax reference when errors occur. It also distinguishes from siblings like cls_get_log_count and cls_get_log_histogram by being the comprehensive query tool.

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/Tinker-LGD2026/cls-mcp-server'

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