sentry_create_alert_rule
Create custom alert rules for Sentry projects to monitor errors and performance issues, enabling automated notifications and actions based on defined conditions.
Instructions
Create an alert rule for a project
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectSlug | Yes | Project slug/identifier | |
| name | Yes | Alert rule name | |
| conditions | No | Alert conditions | |
| actions | No | Alert actions | |
| frequency | No | Check frequency in minutes |
Implementation Reference
- src/index.ts:1103-1137 (handler)MCP tool handler for 'sentry_create_alert_rule'. Extracts arguments, constructs alert rule with defaults, calls SentryAPIClient.createAlertRule, and returns confirmation.case "sentry_create_alert_rule": { if (!apiClient) { throw new Error("Sentry API client not initialized. Provide auth token."); } const { projectSlug, name, conditions = [], actions = [], frequency } = args as any; // Default alert rule if not provided const rule = { name, conditions: conditions.length > 0 ? conditions : [ { id: 'sentry.rules.conditions.first_seen_event.FirstSeenEventCondition', } ], actions: actions.length > 0 ? actions : [ { id: 'sentry.rules.actions.notify_event.NotifyEventAction', } ], actionMatch: 'all', frequency: frequency || 30, }; const createdRule = await apiClient.createAlertRule(projectSlug, rule); return { content: [ { type: "text", text: `Alert rule created: ${createdRule.name} for project ${projectSlug}`, }, ], }; }
- src/index.ts:484-514 (schema)Input schema and registration for the 'sentry_create_alert_rule' tool in the MCP server's tool list.{ name: "sentry_create_alert_rule", description: "Create an alert rule for a project", inputSchema: { type: "object", properties: { projectSlug: { type: "string", description: "Project slug/identifier", }, name: { type: "string", description: "Alert rule name", }, conditions: { type: "array", description: "Alert conditions", }, actions: { type: "array", description: "Alert actions", }, frequency: { type: "number", description: "Check frequency in minutes", default: 30, }, }, required: ["projectSlug", "name"], }, },
- src/sentry-api-client.ts:126-131 (helper)SentryAPIClient helper method that sends POST request to Sentry API endpoint to create the alert rule.async createAlertRule(projectSlug: string, rule: any) { return this.request(`/projects/${this.org}/${projectSlug}/rules/`, { method: 'POST', body: JSON.stringify(rule), }); }