Skip to main content
Glama
ahmad2x4

Seq MCP Server

by ahmad2x4

get-events

Retrieve and analyze structured log events from Seq server using filters like time range, signal IDs, or custom expressions to investigate patterns and frequencies.

Instructions

Retrieve and analyze a list of event filtered by parameters. Use this tool when you need to:

  • Investigate events that are being logged in the SEQ server

  • Details of each event is a structured log and can provide usefull information

  • Events could be information, error, debug, or critical

  • Analyze error patterns and frequencies

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
signalNoComma-separated list of signal IDs
filterNoFilter expression for events
countNoNumber of events to return (max 20)
fromDateUtcNoStart date/time in UTC
toDateUtcNoEnd date/time in UTC
rangeNoTime range (e.g., 1m, 15m, 1h, 1d, 7d)

Implementation Reference

  • Handler function that fetches events from the Seq API endpoint '/api/events' using the provided parameters (signal, filter, count, dates, range), formats the request, and returns the JSON events or error.
    async ({ signal, filter, count, fromDateUtc, toDateUtc, range }) => {
      try {
        const params: Record<string, string> = {};
        
        // Handle date range parameters
        if (range) {
          // If range is provided, it takes precedence over fromDateUtc/toDateUtc
          params.range = range;
        } else if (fromDateUtc || toDateUtc) {
          // Only add date parameters if they're provided
          if (fromDateUtc) params.fromDateUtc = fromDateUtc;
          if (toDateUtc) params.toDateUtc = toDateUtc;
        } else {
          // Default to last hour if no time parameters provided
          params.range = '1h';
        }
    
        // Add other optional parameters
        if (signal) params.signal = signal;
        if (filter) params.filter = filter;
        if (count) params.count = count.toString();
    
        const events = await makeSeqRequest<Event[]>('/api/events', params);
        
        return {
          content: [{
            type: "text",
            text: JSON.stringify(events)
          }]
        };
      } catch (error) {
        const err = error as Error;
        return {
          content: [{
            type: "text",
            text: `Error fetching events: ${err.message}`
          }],
          isError: true
        };
      }
    }
  • Input schema definition using Zod for the get-events tool parameters.
    {
      signal: z.string().optional()
        .describe('Comma-separated list of signal IDs'),
      filter: z.string().optional()
        .describe('Filter expression for events'),
      count: z.number().min(1).max(MAX_EVENTS).optional()
        .default(MAX_EVENTS)
        .describe(`Number of events to return (max ${MAX_EVENTS})`),
      fromDateUtc: z.string().optional()
        .describe('Start date/time in UTC'),
      toDateUtc: z.string().optional()
        .describe('End date/time in UTC'),
      range: timeRangeSchema.optional()
        .describe('Time range (e.g., 1m, 15m, 1h, 1d, 7d)')
    },
  • Registration of the 'get-events' tool on the MCP server using server.tool() with description, input schema, and handler function.
    server.tool(
      "get-events",
      `Retrieve and analyze a list of event filtered by parameters. Use this tool when you need to:
      - Investigate events that are being logged in the SEQ server
      - Details of each event is a structured log and can provide usefull information
      - Events could be information, error, debug, or critical
      - Analyze error patterns and frequencies  
      `,
      {
        signal: z.string().optional()
          .describe('Comma-separated list of signal IDs'),
        filter: z.string().optional()
          .describe('Filter expression for events'),
        count: z.number().min(1).max(MAX_EVENTS).optional()
          .default(MAX_EVENTS)
          .describe(`Number of events to return (max ${MAX_EVENTS})`),
        fromDateUtc: z.string().optional()
          .describe('Start date/time in UTC'),
        toDateUtc: z.string().optional()
          .describe('End date/time in UTC'),
        range: timeRangeSchema.optional()
          .describe('Time range (e.g., 1m, 15m, 1h, 1d, 7d)')
      },
      async ({ signal, filter, count, fromDateUtc, toDateUtc, range }) => {
        try {
          const params: Record<string, string> = {};
          
          // Handle date range parameters
          if (range) {
            // If range is provided, it takes precedence over fromDateUtc/toDateUtc
            params.range = range;
          } else if (fromDateUtc || toDateUtc) {
            // Only add date parameters if they're provided
            if (fromDateUtc) params.fromDateUtc = fromDateUtc;
            if (toDateUtc) params.toDateUtc = toDateUtc;
          } else {
            // Default to last hour if no time parameters provided
            params.range = '1h';
          }
    
          // Add other optional parameters
          if (signal) params.signal = signal;
          if (filter) params.filter = filter;
          if (count) params.count = count.toString();
    
          const events = await makeSeqRequest<Event[]>('/api/events', params);
          
          return {
            content: [{
              type: "text",
              text: JSON.stringify(events)
            }]
          };
        } catch (error) {
          const err = error as Error;
          return {
            content: [{
              type: "text",
              text: `Error fetching events: ${err.message}`
            }],
            isError: true
          };
        }
      }
    );
  • Shared helper function makeSeqRequest used by get-events tool to make authenticated HTTP requests to the Seq API.
    async function makeSeqRequest<T>(endpoint: string, params: Record<string, string> = {}): Promise<T> {
      const url = new URL(`${SEQ_BASE_URL}${endpoint}`);
      
      // Add API key as query parameter
      url.searchParams.append('apiKey', SEQ_API_KEY);
      
      // Add additional query parameters
      Object.entries(params).forEach(([key, value]) => {
        if (value !== undefined && value !== null) {
          url.searchParams.append(key, value);
        }
      });
    
      const headers: Record<string, string> = {
        'Accept': 'application/json',
        'X-Seq-ApiKey': SEQ_API_KEY
      };
    
      const response = await fetch(url.toString(), { headers });
    
      if (!response.ok) {
        throw new Error(`SEQ API error: ${response.statusText} (${response.status})`);
      }
    
      return response.json();
    }
  • Zod enum schema for valid time ranges used in the get-events input schema.
    const timeRangeSchema = z.enum(['1m', '15m', '30m', '1h', '2h', '6h', '12h', '1d', '7d', '14d', '30d']);
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/ahmad2x4/mcp-server-seq'

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