Skip to main content
Glama
nailuoGG

Aliyun MCP Server

by nailuoGG

querySLSLogs

Extract and analyze logs from Aliyun Simple Log Service (SLS) by specifying project, logstore, query, and time range. Supports pagination, result ordering, and customizable limits for efficient log retrieval.

Instructions

Query Aliyun SLS (Simple Log Service) logs

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fromNoStart time in milliseconds (defaults to 1 hour ago)
limitNoMaximum number of logs to return (default: 100, max: 1000)
logstoreYesSLS logstore name
offsetNoOffset for pagination (default: 0)
projectYesSLS project name
queryYesSLS query statement
reverseNoWhether to return results in reverse order (default: false)
toNoEnd time in milliseconds (defaults to now)

Implementation Reference

  • Core implementation of the querySLSLogs tool logic using Aliyun SLS SDK.
    public static async queryLogs(params: SLSQueryParams): Promise<any> {
        console.error('[SLS] Querying logs with params:', JSON.stringify({
            project: params.project,
            logstore: params.logstore,
            query: params.query,
            from: params.from,
            to: params.to,
            limit: params.limit
        }));
    
        try {
            const slsClient = this.getSLSClient();
    
            // Prepare query parameters
            const now = Math.floor(Date.now() / 1000);
            const queryParams = {
                projectName: params.project,
                logStoreName: params.logstore,
                from: params.from ? Math.floor(params.from / 1000) : now - 3600, // Default to last hour
                to: params.to ? Math.floor(params.to / 1000) : now,
                query: params.query,
                line: params.limit || 100,
                offset: params.offset || 0,
                reverse: params.reverse || false
            };
    
            // Execute the query
            return new Promise((resolve, reject) => {
                slsClient.getLogs(queryParams, (error: any, data: any) => {
                    if (error) {
                        console.error('[SLS] Error querying logs:', error);
                        reject(error);
                        return;
                    }
    
                    console.error('[SLS] Successfully retrieved logs');
                    resolve(data);
                });
            });
        } catch (error: any) {
            console.error('[SLS] Error in queryLogs:', error);
            throw new McpError(
                ErrorCode.InternalError,
                `SLS query failed: ${error.message || 'Unknown error'}`
            );
        }
    }
  • TypeScript interface defining the input parameters for the SLS log query.
    export interface SLSQueryParams {
        project: string;
        logstore: string;
        query: string;
        from?: number;
        to?: number;
        limit?: number;
        offset?: number;
        reverse?: boolean;
    }
  • src/index.ts:70-111 (registration)
    Tool registration in MCP ListTools response, defining name, description, and input schema.
    {
      name: "querySLSLogs",
      description: "Query Aliyun SLS (Simple Log Service) logs",
      inputSchema: {
        type: "object",
        properties: {
          project: {
            type: "string",
            description: "SLS project name"
          },
          logstore: {
            type: "string",
            description: "SLS logstore name"
          },
          query: {
            type: "string",
            description: "SLS query statement"
          },
          from: {
            type: "number",
            description: "Start time in milliseconds (defaults to 1 hour ago)"
          },
          to: {
            type: "number",
            description: "End time in milliseconds (defaults to now)"
          },
          limit: {
            type: "number",
            description: "Maximum number of logs to return (default: 100, max: 1000)"
          },
          offset: {
            type: "number",
            description: "Offset for pagination (default: 0)"
          },
          reverse: {
            type: "boolean",
            description: "Whether to return results in reverse order (default: false)"
          }
        },
        required: ["project", "logstore", "query"]
      }
    }
  • MCP CallToolRequestSchema handler for querySLSLogs, validates input and delegates to SLSService.
    case "querySLSLogs": {
      try {
        // Cast arguments to SLSQueryParams with proper type checking
        const args = request.params.arguments || {};
        const params: SLSQueryParams = {
          project: String(args.project || ''),
          logstore: String(args.logstore || ''),
          query: String(args.query || ''),
          from: typeof args.from === 'number' ? args.from : undefined,
          to: typeof args.to === 'number' ? args.to : undefined,
          limit: typeof args.limit === 'number' ? args.limit : undefined,
          offset: typeof args.offset === 'number' ? args.offset : undefined,
          reverse: typeof args.reverse === 'boolean' ? args.reverse : undefined
        };
    
        if (!params.project || !params.logstore || !params.query) {
          throw new McpError(
            ErrorCode.InvalidParams,
            "Missing required parameters: project, logstore, and query are required"
          );
        }
    
        const result = await SLSService.queryLogs(params);
    
        return {
          content: [{
            type: "text",
            text: JSON.stringify(result, null, 2)
          }]
        };
      } catch (error: any) {
        console.error('[Tool] Error executing querySLSLogs:', error);
    
        if (error instanceof McpError) {
          throw error;
        }
    
        throw new McpError(
          ErrorCode.InternalError,
          `Error querying SLS logs: ${error.message || 'Unknown error'}`
        );
      }
    }
Behavior2/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 mentions querying logs but fails to describe key behaviors such as authentication requirements, rate limits, error handling, or the format of returned results, leaving significant gaps for an agent.

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 a single, direct sentence with no wasted words, making it highly concise and front-loaded. It efficiently communicates the core function without unnecessary elaboration.

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 complexity of an 8-parameter log querying tool with no annotations and no output schema, the description is insufficient. It lacks details on behavior, results format, and usage context, making it incomplete for effective agent operation.

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 100% description coverage, clearly documenting all 8 parameters with defaults and constraints. The description adds no additional parameter semantics beyond the schema, so it meets the baseline for adequate but not enhanced coverage.

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 clearly states the verb 'query' and the resource 'Aliyun SLS (Simple Log Service) logs', making the purpose specific and understandable. However, with no sibling tools mentioned, it lacks explicit differentiation from potential alternatives, though this is not a fault given the context.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives, prerequisites, or context for its application. It merely states what it does without indicating scenarios or constraints for usage.

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

Related 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/nailuoGG/aliyun-mcp-server'

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