Skip to main content
Glama
SuxyEE
by SuxyEE

get_log_histogram

Visualize log volume distribution over time to identify error spikes and unusual activity patterns in Alibaba Cloud SLS logs.

Instructions

Get the time-series distribution of log counts matching a query. Returns a visual histogram showing log volume over time. Useful for identifying when errors spiked or when unusual activity occurred.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectYesSLS project name
logstoreYesSLS logstore name
queryNoSLS query statement to filter logs. Default: "*" for all logs*
time_rangeNoRelative time range. Formats: 15m, 1h, 6h, 12h, 1d, 3d1h
fromNoStart time as Unix timestamp (seconds). Overrides time_range.
toNoEnd time as Unix timestamp (seconds).
regionNoAlibaba Cloud region ID, e.g. cn-hangzhou. Defaults to SLS_REGION env variable.

Implementation Reference

  • The 'handleGetLogHistogram' function executes the logic to fetch log histogram data and format it into a string output.
    export async function handleGetLogHistogram(input: GetLogHistogramInput): Promise<string> {
      let from: number;
      let to: number;
    
      if (input.from && input.to) {
        from = input.from;
        to = input.to;
      } else {
        const range = parseTimeRange(input.time_range);
        from = range.from;
        to = range.to;
      }
    
      const histograms = await getLogHistogram({
        project: input.project,
        logstore: input.logstore,
        query: input.query,
        from,
        to,
        region: input.region,
      });
    
      const fromStr = formatTimestamp(from);
      const toStr = formatTimestamp(to);
      const totalCount = histograms.reduce((sum, h) => sum + h.count, 0);
      const maxCount = Math.max(...histograms.map((h) => h.count), 1);
    
      const header = [
        `## Log Distribution`,
        `**Project**: ${input.project} / **Logstore**: ${input.logstore}`,
        `**Time**: ${fromStr} → ${toStr}`,
        `**Query**: \`${input.query}\``,
        `**Total Logs**: ${totalCount}`,
      ].join('\n');
    
      if (histograms.length === 0) {
        return `${header}\n\nNo data in this time range.`;
      }
    
      const rows = histograms
        .filter((h) => h.count > 0)
        .map((h) => {
          const timeStr = formatTimestamp(h.from);
          const bar = renderBar(h.count, maxCount);
          return `${timeStr}  ${bar}  ${h.count}`;
        })
        .join('\n');
    
      return `${header}\n\n\`\`\`\n${rows}\n\`\`\`\n\nUse this distribution to identify time windows with unusual activity, then query specific windows for detailed logs.`;
    }
  • The 'getLogHistogramSchema' defines the input validation for the 'get_log_histogram' tool using Zod.
    export const getLogHistogramSchema = z.object({
      project: z.string().describe('SLS project name'),
      logstore: z.string().describe('SLS logstore name'),
      query: z.string().default('*').describe('SLS query statement to filter logs. Default: "*" for all logs'),
      time_range: z
        .string()
        .default('1h')
        .describe('Relative time range. Formats: 15m, 1h, 6h, 12h, 1d, 3d'),
      from: z.number().optional().describe('Start time as Unix timestamp (seconds). Overrides time_range.'),
      to: z.number().optional().describe('End time as Unix timestamp (seconds).'),
      region: z
        .string()
        .optional()
        .describe('Alibaba Cloud region ID, e.g. cn-hangzhou. Defaults to SLS_REGION env variable.'),
    });
  • src/index.ts:44-48 (registration)
    Tool registration for 'get_log_histogram' in the MCP server's TOOL list.
      name: 'get_log_histogram',
      description:
        'Get the time-series distribution of log counts matching a query. Returns a visual histogram showing log volume over time. Useful for identifying when errors spiked or when unusual activity occurred.',
      inputSchema: zodToJsonSchema(getLogHistogramSchema) as Tool['inputSchema'],
    },
  • The handler registration inside the main server request handler to route 'get_log_histogram' calls to 'handleGetLogHistogram'.
    case 'get_log_histogram': {
      const input = getLogHistogramSchema.parse(args);
      text = await handleGetLogHistogram(input);
      break;
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 explains the return format ('Returns a visual histogram showing log volume over time') and practical use case, but doesn't cover aspects like rate limits, authentication needs, error handling, or whether this is a read-only operation (though 'Get' implies it).

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

Conciseness5/5

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

The description is efficiently structured in three sentences: the core function, the return format, and the use case. Every sentence adds value without redundancy, making it appropriately sized and front-loaded with essential information.

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

Completeness3/5

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

For a tool with 7 parameters, no annotations, and no output schema, the description provides adequate context on purpose and usage but lacks details on behavioral aspects like permissions, rate limits, or error responses. It's complete enough for basic understanding but has gaps given the complexity.

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?

Schema description coverage is 100%, so the schema already documents all 7 parameters thoroughly. The description doesn't add any parameter-specific information beyond what's in the schema, so it meets the baseline of 3 when the schema does the heavy lifting.

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 with specific verbs ('Get the time-series distribution of log counts matching a query') and resource ('log counts'), distinguishing it from siblings like get_context_logs or query_logs by focusing on histogram/visual distribution rather than raw log retrieval or SQL queries.

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

Usage Guidelines4/5

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

The description provides clear context for when to use this tool ('Useful for identifying when errors spiked or when unusual activity occurred'), but it doesn't explicitly state when not to use it or name alternatives among the sibling tools, which would be needed for a score of 5.

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/SuxyEE/aliyun-sls-mcp'

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