Skip to main content
Glama
SuxyEE
by SuxyEE

get_context_logs

Retrieve surrounding log lines before and after a specific log entry to understand the full execution flow around errors or events in Alibaba Cloud SLS logs.

Instructions

Retrieve log lines before and after a specific log entry using its pack_id and pack_meta. First query logs with query_logs to find a log entry, then use its tag:pack_id and tag:pack_meta fields to get surrounding context. Useful for understanding full execution flow around an error.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectYesSLS project name
logstoreYesSLS logstore name
pack_idYesThe pack_id of the target log entry. Found in the __tag__:__pack_id__ field of any log. Example: "7FDBA9CB41D1D6F93C49A936ADF9C8FC-1B54"
pack_metaYesThe pack_meta (unique context identifier) of the target log entry within the log group. Found in the __tag__:__pack_meta__ field. Example: "0|MTY1NTcwNTUzODY5MTY0MDk1Mg==|3|0"
back_linesNoNumber of log lines before the target log (default: 10, max: 100)
forward_linesNoNumber of log lines after the target log (default: 10, max: 100)
regionNoAlibaba Cloud region ID, e.g. cn-hangzhou. Defaults to SLS_REGION env variable.

Implementation Reference

  • The handler function 'handleGetContextLogs' orchestrates fetching context logs from SLS and formatting them into a human-readable string.
    export async function handleGetContextLogs(input: GetContextLogsInput): Promise<string> {
      const result = await getContextLogs({
        project: input.project,
        logstore: input.logstore,
        packId: input.pack_id,
        packMeta: input.pack_meta,
        backLines: input.back_lines,
        forwardLines: input.forward_lines,
        region: input.region,
      });
    
      const header = [
        `## Context Logs`,
        `**Project**: ${input.project} / **Logstore**: ${input.logstore}`,
        `**Pack ID**: ${input.pack_id}`,
        `**Context**: ${result.backCount} before + ${result.forwardCount} after`,
      ].join('\n');
    
      if (result.logs.length === 0) {
        return `${header}\n\nNo context logs found.`;
      }
    
      const targetIndex = result.backCount;
    
      const entries = result.logs.map((log, i) => {
        let label: string;
        if (i < targetIndex) label = `[↑ before ${targetIndex - i}]`;
        else if (i === targetIndex) label = `[★ TARGET]`;
        else label = `[↓ after ${i - targetIndex}]`;
        return formatLogEntry(log, label);
      });
    
      return `${header}\n\n${entries.join('\n\n---\n\n')}`;
    }
  • Input validation schema for the 'get_context_logs' tool.
    export const getContextLogsSchema = z.object({
      project: z.string().describe('SLS project name'),
      logstore: z.string().describe('SLS logstore name'),
      pack_id: z
        .string()
        .describe(
          'The pack_id of the target log entry. Found in the __tag__:__pack_id__ field of any log. Example: "7FDBA9CB41D1D6F93C49A936ADF9C8FC-1B54"'
        ),
      pack_meta: z
        .string()
        .describe(
          'The pack_meta (unique context identifier) of the target log entry within the log group. Found in the __tag__:__pack_meta__ field. Example: "0|MTY1NTcwNTUzODY5MTY0MDk1Mg==|3|0"'
        ),
      back_lines: z
        .number()
        .min(1)
        .max(100)
        .default(10)
        .describe('Number of log lines before the target log (default: 10, max: 100)'),
      forward_lines: z
        .number()
        .min(1)
        .max(100)
        .default(10)
        .describe('Number of log lines after the target log (default: 10, max: 100)'),
      region: z
        .string()
        .optional()
        .describe('Alibaba Cloud region ID, e.g. cn-hangzhou. Defaults to SLS_REGION env variable.'),
    });
  • src/index.ts:105-109 (registration)
    Tool execution handling within the main switch block of the server.
    case 'get_context_logs': {
      const input = getContextLogsSchema.parse(args);
      text = await handleGetContextLogs(input);
      break;
    }
Behavior3/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It explains the tool's purpose and workflow but lacks details on permissions, rate limits, error handling, or response format. The description doesn't contradict annotations, but it doesn't fully compensate for the absence of structured behavioral hints.

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 concise and well-structured in two sentences. The first sentence states the purpose, and the second provides usage guidelines and context. Every sentence adds value with no wasted words, and it's front-loaded with the core functionality.

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?

Given the tool's complexity (7 parameters, no annotations, no output schema), the description is adequate but incomplete. It explains the purpose and workflow but lacks details on output format, error cases, or behavioral constraints. Without annotations or output schema, more context would be helpful for safe invocation.

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 parameters thoroughly. The description adds minimal value beyond the schema by mentioning pack_id and pack_meta fields but doesn't provide additional syntax or format details. This meets the baseline for high schema coverage.

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: 'Retrieve log lines before and after a specific log entry using its pack_id and pack_meta.' It specifies the verb ('retrieve'), resource ('log lines'), and scope ('before and after a specific log entry'), and distinguishes it from sibling tools by mentioning query_logs as a prerequisite step.

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 usage guidance: 'First query logs with query_logs to find a log entry, then use its __tag__:__pack_id__ and __tag__:__pack_meta__ fields to get surrounding context.' It names the alternative tool (query_logs) and specifies when to use this tool (after finding a log entry) versus when not to (for initial log queries).

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