create_automation_rule
Create automation rules for GitHub projects to trigger actions based on events like issue changes, PR updates, or scheduled tasks.
Instructions
Create a new automation rule for a GitHub project
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | ||
| description | No | ||
| projectId | Yes | ||
| enabled | Yes | ||
| triggers | Yes | ||
| actions | Yes |
Implementation Reference
- Core handler implementing the GitHub GraphQL mutation to create ProjectV2 automation rulesasync create(data: CreateAutomationRule): Promise<AutomationRule> { const mutation = ` mutation($input: CreateProjectV2RuleInput!) { createProjectV2Rule(input: $input) { projectRule { id databaseId createdAt updatedAt isActive name ruleTrigger { type whenStateEquals whenStateWas whenFieldValueEquals whenFieldId } ruleActions { type fieldId value projectItemId sourceFieldId targetFieldId labelName milestoneId } } } } `; try { const variables = this.prepareCreateRuleVariables(data); const response = await this.graphql<CreateProjectRuleResponse>(mutation, variables); return this.mapGitHubRuleToAutomationRule(response.createProjectV2Rule.projectRule, data.projectId); } catch (error) { this.logger.error(`Failed to create automation rule for project ${data.projectId}`, error); throw this.handleGraphQLError(error); } }
- Service layer handler that validates input, checks project existence, and delegates to repositoryasync createAutomationRule(data: { name: string; description?: string; projectId: string; enabled?: boolean; triggers: Array<{ type: string; resourceType?: string; conditions?: Array<{ field: string; operator: string; value: any; }>; }>; actions: Array<{ type: string; parameters: Record<string, any>; }>; }): Promise<{ id: string; name: string; description?: string; projectId: string; enabled: boolean; triggers: any[]; actions: any[]; }> { try { // Verify project exists const project = await this.projectRepo.findById(data.projectId); if (!project) { throw new ResourceNotFoundError(ResourceType.PROJECT, data.projectId); } const rule = await this.automationRepo.create({ name: data.name, description: data.description, projectId: data.projectId, enabled: data.enabled ?? true, triggers: data.triggers as any, actions: data.actions as any }); return { id: rule.id, name: rule.name, description: rule.description, projectId: rule.projectId, enabled: rule.enabled, triggers: rule.triggers, actions: rule.actions }; } catch (error) { throw this.mapErrorToMCPError(error); }
- MCP tool definition including name, description, input schema, and examplesexport const createAutomationRuleTool: ToolDefinition<CreateAutomationRuleArgs> = { name: "create_automation_rule", description: "Create a new automation rule for a GitHub project", schema: createAutomationRuleSchema as unknown as ToolSchema<CreateAutomationRuleArgs>, examples: [ { name: "Auto-label PRs", description: "Automatically add 'needs-review' label when PR is opened", args: { name: "Auto-label new PRs", projectId: "PVT_kwDOLhQ7gc4AOEbH", enabled: true, triggers: [{ type: "pr_opened" }], actions: [{ type: "add_label", parameters: { labelName: "needs-review" } }] } }, { name: "Auto-assign issues", description: "Automatically assign issues with 'bug' label to maintainer", args: { name: "Auto-assign bugs", projectId: "PVT_kwDOLhQ7gc4AOEbH", enabled: true, triggers: [{ type: "issue_labeled", conditions: [{ field: "label", operator: "equals", value: "bug" }] }], actions: [{ type: "assign_user", parameters: { username: "maintainer" } }] } } ] };
- src/infrastructure/tools/ToolRegistry.ts:279-285 (registration)Registers the create_automation_rule tool in the central ToolRegistry singletonthis.registerTool(createAutomationRuleTool); this.registerTool(updateAutomationRuleTool); this.registerTool(deleteAutomationRuleTool); this.registerTool(getAutomationRuleTool); this.registerTool(listAutomationRulesTool); this.registerTool(enableAutomationRuleTool); this.registerTool(disableAutomationRuleTool);
- src/domain/automation-types.ts:68-75 (schema)Domain type definition for CreateAutomationRule input structure used across services and repositoryexport interface CreateAutomationRule { name: string; description?: string; projectId: string; enabled?: boolean; triggers: Omit<AutomationTrigger, "id">[]; actions: Omit<AutomationAction, "id">[]; }