@quorum-us/opsgenie-mcp
Version:
MCP server for Opsgenie alert management with comprehensive filtering, custom queries, and AI-friendly interface
100 lines (99 loc) • 4.19 kB
JavaScript
import { z } from "zod";
import { createOpsgenieClient } from "./opsgenie-client.js";
import { LIMITS } from "./constants.js";
/**
* Register the listAlerts tool with comprehensive filtering options
*/
export function registerListAlertsTool(server) {
server.tool("listAlerts_Opsgenie", "List Opsgenie alerts with comprehensive filtering options. You can either use individual filters (status, priority, etc.) OR provide a custom Opsgenie query for full control. If 'query' parameter is provided, it takes precedence over all other filters and is used as-is.", {
// Pagination
limit: z.number()
.min(LIMITS.MIN_LIMIT)
.max(LIMITS.MAX_LIMIT)
.optional()
.describe("Maximum number of alerts to return (1-100)"),
offset: z.number()
.min(LIMITS.MIN_OFFSET)
.optional()
.describe("Number of alerts to skip for pagination"),
// Status and Priority filters
status: z.enum(['open', 'acknowledged', 'closed', 'all'])
.optional()
.describe("Filter by alert status (open, acknowledged, closed, all)"),
priority: z.enum(['P1', 'P2', 'P3', 'P4', 'P5'])
.optional()
.describe("Filter by alert priority (P1-P5)"),
// Content filters
message: z.string()
.optional()
.describe("Filter alerts by message content"),
source: z.string()
.optional()
.describe("Filter alerts by source"),
owner: z.string()
.optional()
.describe("Filter alerts by owner"),
// Array filters
tags: z.array(z.string())
.optional()
.describe("Filter by tags (all tags must match)"),
teams: z.array(z.string())
.optional()
.describe("Filter by team names"),
// Advanced search (takes precedence over all other filters)
query: z.string()
.optional()
.describe("Custom Opsgenie search query with full control. If provided, this takes precedence over ALL other filter parameters. Examples: 'status: open AND priority: P1', 'message: database* AND teams: backend', 'tag: production AND source: monitoring AND (priority: P1 OR priority: P2)'"),
// Saved search
searchIdentifier: z.string()
.optional()
.describe("Identifier of saved search query"),
searchIdentifierType: z.enum(['id', 'name'])
.optional()
.describe("Type of search identifier (id or name)"),
// Sorting
sort: z.enum([
'createdAt', 'updatedAt', 'tinyId', 'alias', 'message', 'status',
'acknowledged', 'isSeen', 'snoozed', 'snoozedUntil', 'count',
'lastOccurredAt', 'source', 'owner', 'integration.name',
'integration.type', 'report.acknowledgedBy', 'report.closedBy'
])
.optional()
.describe("Field to sort alerts by"),
order: z.enum(['asc', 'desc'])
.optional()
.describe("Sort order (ascending or descending)"),
}, async ({ limit, offset, status, priority, message, source, owner, tags, teams, query, searchIdentifier, searchIdentifierType, sort, order }) => {
const client = createOpsgenieClient();
const filter = {
query,
status: status,
priority: priority,
message,
source,
owner,
tags,
teams,
searchIdentifier,
searchIdentifierType: searchIdentifierType,
offset,
limit,
sort: sort,
order: order,
};
return await client.listAlerts(filter);
});
}
/**
* Register the getAlert tool
*/
export function registerGetAlertTool(server) {
server.tool("getAlert_Opsgenie", "Get details of a specific Opsgenie alert", {
identifier: z.string()
.min(1)
.describe("Alert identifier (ID or alias)")
}, async ({ identifier }) => {
const client = createOpsgenieClient();
return await client.getAlert(identifier);
});
}