From 03bb1b6806755bfaa9e0d581b5a5df89faa9a96b Mon Sep 17 00:00:00 2001 From: Shaikhul Islam Date: Fri, 6 Nov 2026 13:31:28 -0500 Subject: [PATCH 1/7] feat: add public agent automation write tools Expose create, partial update, and delete operations for repository automations using GitHub's published REST fields and status codes. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- docs/feature-flags.md | 36 +++ .../__toolsnaps__/create_automation.snap | 79 ++++++ .../__toolsnaps__/delete_automation.snap | 36 +++ .../__toolsnaps__/update_automation.snap | 74 +++++ pkg/github/agent_automations.go | 262 +++++++++++++++++- pkg/github/agent_automations_test.go | 104 ++++++- pkg/github/tools.go | 3 + 7 files changed, 585 insertions(+), 9 deletions(-) create mode 100644 pkg/github/__toolsnaps__/create_automation.snap create mode 100644 pkg/github/__toolsnaps__/delete_automation.snap create mode 100644 pkg/github/__toolsnaps__/update_automation.snap diff --git a/docs/feature-flags.md b/docs/feature-flags.md index 75dd92a88f..0740d1a9bd 100644 --- a/docs/feature-flags.md +++ b/docs/feature-flags.md @@ -530,6 +530,27 @@ as output formatting) won't appear here. ### `agent_automations` +- **create_automation** - Create a repository automation + - **OAuth Challenge Scopes**: `repo` + - `continuous_history`: Whether the automation keeps a continuous conversation history. (boolean, optional) + - `enabled`: Whether the automation is enabled. (boolean, optional) + - `model`: The model used by the automation. (string, optional) + - `name`: The name of the automation. (string, required) + - `owner`: Repository owner (string, required) + - `prompt`: The prompt used when the automation runs. (string, required) + - `reasoning_effort`: The reasoning effort used by the automation. (string, optional) + - `repo`: Repository name (string, required) + - `require_actor_write_permission`: Whether the triggering actor must have write permission. (boolean, optional) + - `tools`: The tools enabled for the automation. (string[], optional) + - `triggers`: Trigger configuration for the automation. (object, optional) + - `type`: The automation type. (string, optional) + +- **delete_automation** - Delete a repository automation + - **OAuth Challenge Scopes**: `repo` + - `automation_id`: The automation identifier. (string, required) + - `owner`: Repository owner (string, required) + - `repo`: Repository name (string, required) + - **get_automation** - Get a repository automation - **OAuth Challenge Scopes**: `repo` - `automation_id`: The automation identifier. (string, required) @@ -574,6 +595,21 @@ as output formatting) won't appear here. - `owner`: Repository owner (string, required) - `repo`: Repository name (string, required) +- **update_automation** - Update a repository automation + - **OAuth Challenge Scopes**: `repo` + - `automation_id`: The automation identifier. (string, required) + - `continuous_history`: Whether the automation keeps a continuous conversation history. (boolean, optional) + - `enabled`: Whether the automation is enabled. (boolean, optional) + - `model`: The model used by the automation. (string, optional) + - `name`: The name of the automation. (string, optional) + - `owner`: Repository owner (string, required) + - `prompt`: The prompt used when the automation runs. (string, optional) + - `reasoning_effort`: The reasoning effort used by the automation. (string, optional) + - `repo`: Repository name (string, required) + - `require_actor_write_permission`: Whether the triggering actor must have write permission. (boolean, optional) + - `tools`: The tools enabled for the automation. (string[], optional) + - `triggers`: Trigger configuration for the automation. (object, optional) + ### `duplicate_detection` - **find_duplicate** - Find duplicate issues diff --git a/pkg/github/__toolsnaps__/create_automation.snap b/pkg/github/__toolsnaps__/create_automation.snap new file mode 100644 index 0000000000..afa6419b4e --- /dev/null +++ b/pkg/github/__toolsnaps__/create_automation.snap @@ -0,0 +1,79 @@ +{ + "annotations": { + "idempotentHint": false, + "readOnlyHint": false, + "title": "Create a repository automation" + }, + "description": "Create a Copilot automation in a repository.", + "inputSchema": { + "properties": { + "continuous_history": { + "description": "Whether the automation keeps a continuous conversation history.", + "type": "boolean" + }, + "enabled": { + "description": "Whether the automation is enabled.", + "type": "boolean" + }, + "model": { + "description": "The model used by the automation.", + "type": "string" + }, + "name": { + "description": "The name of the automation.", + "type": "string" + }, + "owner": { + "description": "Repository owner", + "type": "string" + }, + "prompt": { + "description": "The prompt used when the automation runs.", + "type": "string" + }, + "reasoning_effort": { + "description": "The reasoning effort used by the automation.", + "type": "string" + }, + "repo": { + "description": "Repository name", + "type": "string" + }, + "require_actor_write_permission": { + "description": "Whether the triggering actor must have write permission.", + "type": "boolean" + }, + "tools": { + "description": "The tools enabled for the automation.", + "items": { + "type": "string" + }, + "type": "array" + }, + "triggers": { + "description": "Trigger configuration for the automation.", + "type": "object" + }, + "type": { + "description": "The automation type.", + "enum": [ + "personal", + "shared" + ], + "type": "string" + } + }, + "required": [ + "owner", + "repo", + "name", + "prompt" + ], + "type": "object" + }, + "name": "create_automation", + "outputSchema": { + "additionalProperties": true, + "type": "object" + } +} \ No newline at end of file diff --git a/pkg/github/__toolsnaps__/delete_automation.snap b/pkg/github/__toolsnaps__/delete_automation.snap new file mode 100644 index 0000000000..b1b9630157 --- /dev/null +++ b/pkg/github/__toolsnaps__/delete_automation.snap @@ -0,0 +1,36 @@ +{ + "annotations": { + "destructiveHint": true, + "idempotentHint": true, + "readOnlyHint": false, + "title": "Delete a repository automation" + }, + "description": "Delete a Copilot automation from a repository.", + "inputSchema": { + "properties": { + "automation_id": { + "description": "The automation identifier.", + "type": "string" + }, + "owner": { + "description": "Repository owner", + "type": "string" + }, + "repo": { + "description": "Repository name", + "type": "string" + } + }, + "required": [ + "owner", + "repo", + "automation_id" + ], + "type": "object" + }, + "name": "delete_automation", + "outputSchema": { + "additionalProperties": true, + "type": "object" + } +} \ No newline at end of file diff --git a/pkg/github/__toolsnaps__/update_automation.snap b/pkg/github/__toolsnaps__/update_automation.snap new file mode 100644 index 0000000000..89df4dbebb --- /dev/null +++ b/pkg/github/__toolsnaps__/update_automation.snap @@ -0,0 +1,74 @@ +{ + "annotations": { + "idempotentHint": false, + "readOnlyHint": false, + "title": "Update a repository automation" + }, + "description": "Update a Copilot automation in a repository. Only the provided fields are changed.", + "inputSchema": { + "properties": { + "automation_id": { + "description": "The automation identifier.", + "type": "string" + }, + "continuous_history": { + "description": "Whether the automation keeps a continuous conversation history.", + "type": "boolean" + }, + "enabled": { + "description": "Whether the automation is enabled.", + "type": "boolean" + }, + "model": { + "description": "The model used by the automation.", + "type": "string" + }, + "name": { + "description": "The name of the automation.", + "type": "string" + }, + "owner": { + "description": "Repository owner", + "type": "string" + }, + "prompt": { + "description": "The prompt used when the automation runs.", + "type": "string" + }, + "reasoning_effort": { + "description": "The reasoning effort used by the automation.", + "type": "string" + }, + "repo": { + "description": "Repository name", + "type": "string" + }, + "require_actor_write_permission": { + "description": "Whether the triggering actor must have write permission.", + "type": "boolean" + }, + "tools": { + "description": "The tools enabled for the automation.", + "items": { + "type": "string" + }, + "type": "array" + }, + "triggers": { + "description": "Trigger configuration for the automation.", + "type": "object" + } + }, + "required": [ + "owner", + "repo", + "automation_id" + ], + "type": "object" + }, + "name": "update_automation", + "outputSchema": { + "additionalProperties": true, + "type": "object" + } +} \ No newline at end of file diff --git a/pkg/github/agent_automations.go b/pkg/github/agent_automations.go index 0cb9a7bf71..035f06019e 100644 --- a/pkg/github/agent_automations.go +++ b/pkg/github/agent_automations.go @@ -56,11 +56,50 @@ type AutomationCatalogInput struct { Repo string `json:"repo"` } +type CreateAutomationInput struct { + Owner string `json:"owner"` + Repo string `json:"repo"` + Name string `json:"name"` + Prompt string `json:"prompt"` + Triggers map[string]any `json:"triggers,omitempty"` + Model *string `json:"model,omitempty"` + ReasoningEffort *string `json:"reasoning_effort,omitempty"` + Tools []string `json:"tools,omitempty"` + Enabled *bool `json:"enabled,omitempty"` + Type *string `json:"type,omitempty"` + RequireActorWritePermission *bool `json:"require_actor_write_permission,omitempty"` + ContinuousHistory *bool `json:"continuous_history,omitempty"` +} + +type UpdateAutomationInput struct { + Owner string `json:"owner"` + Repo string `json:"repo"` + AutomationID string `json:"automation_id"` + Name *string `json:"name,omitempty"` + Enabled *bool `json:"enabled,omitempty"` + RequireActorWritePermission *bool `json:"require_actor_write_permission,omitempty"` + ContinuousHistory *bool `json:"continuous_history,omitempty"` + Model *string `json:"model,omitempty"` + ReasoningEffort *string `json:"reasoning_effort,omitempty"` + Triggers map[string]any `json:"triggers,omitempty"` + Prompt *string `json:"prompt,omitempty"` + Tools []string `json:"tools,omitempty"` +} + +type DeleteAutomationInput struct { + Owner string `json:"owner"` + Repo string `json:"repo"` + AutomationID string `json:"automation_id"` +} + type agentAutomationRequest struct { - method string - path string - query url.Values - body any + method string + path string + query url.Values + body any + successStatus int + noBody bool + successMessage string } type agentAutomationRequestBuilder[Input any] func(Input) (agentAutomationRequest, error) @@ -70,8 +109,10 @@ func newAgentAutomationTool[Input any]( name, title, description string, inputSchema *jsonschema.Schema, outputSchema json.RawMessage, + annotations mcp.ToolAnnotations, build agentAutomationRequestBuilder[Input], ) inventory.ServerTool { + annotations.Title = t("TOOL_"+name+"_USER_TITLE", title) tool := NewTool[Input, json.RawMessage]( ToolsetMetadataCopilotAutomations, mcp.Tool{ @@ -80,8 +121,11 @@ func newAgentAutomationTool[Input any]( InputSchema: inputSchema, OutputSchema: outputSchema, Annotations: &mcp.ToolAnnotations{ - Title: t("TOOL_"+name+"_USER_TITLE", title), - ReadOnlyHint: true, + Title: annotations.Title, + ReadOnlyHint: annotations.ReadOnlyHint, + DestructiveHint: annotations.DestructiveHint, + IdempotentHint: annotations.IdempotentHint, + OpenWorldHint: annotations.OpenWorldHint, }, }, scopes.RequireAll(scopes.Repo), @@ -105,17 +149,33 @@ func newAgentAutomationTool[Input any]( } var response json.RawMessage - httpResponse, err := client.Do(httpRequest, &response) + var responseTarget any = &response + if request.noBody { + responseTarget = nil + } + httpResponse, err := client.Do(httpRequest, responseTarget) if httpResponse != nil { defer func() { _ = httpResponse.Body.Close() }() } if err != nil { return ghErrors.NewGitHubAPIErrorResponse(ctx, "failed to access GitHub agent automations", httpResponse, err), nil, nil } - if httpResponse.StatusCode != http.StatusOK { + successStatus := request.successStatus + if successStatus == 0 { + successStatus = http.StatusOK + } + if httpResponse.StatusCode != successStatus { return utils.NewToolResultError(fmt.Sprintf("GitHub agent automations returned unexpected status %d", httpResponse.StatusCode)), nil, nil } + if request.successMessage != "" { + response, err = json.Marshal(map[string]string{"message": request.successMessage}) + if err != nil { + return utils.NewToolResultErrorFromErr("failed to marshal success response", err), nil, err + } + } else if len(response) == 0 { + response = json.RawMessage(`{}`) + } sanitizedResponse, err := sanitizeAutomationNames(response) if err != nil { return utils.NewToolResultErrorFromErr("failed to sanitize GitHub agent automation response", err), nil, nil @@ -170,6 +230,33 @@ func automationIntegerProperty(description string, minimum float64, maximum ...f return property } +func automationBooleanProperty(description string) *jsonschema.Schema { + return &jsonschema.Schema{Type: "boolean", Description: description} +} + +func automationStringArrayProperty(description string) *jsonschema.Schema { + return &jsonschema.Schema{ + Type: "array", + Description: description, + Items: &jsonschema.Schema{Type: "string"}, + } +} + +func automationConfigurationProperties() map[string]*jsonschema.Schema { + return map[string]*jsonschema.Schema{ + "name": automationStringProperty("The name of the automation."), + "triggers": {Type: "object", Description: "Trigger configuration for the automation."}, + "prompt": automationStringProperty("The prompt used when the automation runs."), + "model": automationStringProperty("The model used by the automation."), + "reasoning_effort": automationStringProperty("The reasoning effort used by the automation."), + "tools": automationStringArrayProperty("The tools enabled for the automation."), + "enabled": automationBooleanProperty("Whether the automation is enabled."), + "type": {Type: "string", Description: "The automation type.", Enum: []any{"personal", "shared"}}, + "require_actor_write_permission": automationBooleanProperty("Whether the triggering actor must have write permission."), + "continuous_history": automationBooleanProperty("Whether the automation keeps a continuous conversation history."), + } +} + func requireAutomationRepository(owner, repo string) error { if owner == "" { return errors.New("missing required parameter: owner") @@ -265,6 +352,7 @@ func ListAutomations(t translations.TranslationHelperFunc) inventory.ServerTool }, }, "owner", "repo"), agentAutomationObjectOutputSchema(), + mcp.ToolAnnotations{ReadOnlyHint: true}, func(args ListAutomationsInput) (agentAutomationRequest, error) { if err := requireAutomationRepository(args.Owner, args.Repo); err != nil { return agentAutomationRequest{}, err @@ -303,6 +391,7 @@ func GetAutomation(t translations.TranslationHelperFunc) inventory.ServerTool { "automation_id": automationStringProperty("The automation identifier."), }, "owner", "repo", "automation_id"), agentAutomationObjectOutputSchema(), + mcp.ToolAnnotations{ReadOnlyHint: true}, func(args GetAutomationInput) (agentAutomationRequest, error) { if err := requireAutomationRepository(args.Owner, args.Repo); err != nil { return agentAutomationRequest{}, err @@ -332,6 +421,7 @@ func ListAutomationRevisions(t translations.TranslationHelperFunc) inventory.Ser "perPage": automationIntegerProperty("Results per page, from 1 to 100.", 1, 100), }, "owner", "repo", "automation_id"), agentAutomationObjectOutputSchema(), + mcp.ToolAnnotations{ReadOnlyHint: true}, func(args ListAutomationRevisionsInput) (agentAutomationRequest, error) { if err := requireAutomationRepository(args.Owner, args.Repo); err != nil { return agentAutomationRequest{}, err @@ -371,6 +461,7 @@ func GetAutomationRevision(t translations.TranslationHelperFunc) inventory.Serve "revision_id": automationStringProperty("The revision identifier."), }, "owner", "repo", "automation_id", "revision_id"), agentAutomationObjectOutputSchema(), + mcp.ToolAnnotations{ReadOnlyHint: true}, func(args GetAutomationRevisionInput) (agentAutomationRequest, error) { if err := requireAutomationRepository(args.Owner, args.Repo); err != nil { return agentAutomationRequest{}, err @@ -403,6 +494,7 @@ func ListAvailableAutomationTools(t translations.TranslationHelperFunc) inventor "repo": automationStringProperty(DescriptionRepositoryName), }, "owner", "repo"), agentAutomationObjectOutputSchema(), + mcp.ToolAnnotations{ReadOnlyHint: true}, func(args AutomationCatalogInput) (agentAutomationRequest, error) { if err := requireAutomationRepository(args.Owner, args.Repo); err != nil { return agentAutomationRequest{}, err @@ -426,6 +518,7 @@ func ListAvailableAutomationTriggers(t translations.TranslationHelperFunc) inven "repo": automationStringProperty(DescriptionRepositoryName), }, "owner", "repo"), agentAutomationArrayOutputSchema(), + mcp.ToolAnnotations{ReadOnlyHint: true}, func(args AutomationCatalogInput) (agentAutomationRequest, error) { if err := requireAutomationRepository(args.Owner, args.Repo); err != nil { return agentAutomationRequest{}, err @@ -449,6 +542,7 @@ func GetAutomationsConfigurationForRepository(t translations.TranslationHelperFu "repo": automationStringProperty(DescriptionRepositoryName), }, "owner", "repo"), agentAutomationConfigurationOutputSchema(), + mcp.ToolAnnotations{ReadOnlyHint: true}, func(args AutomationCatalogInput) (agentAutomationRequest, error) { if err := requireAutomationRepository(args.Owner, args.Repo); err != nil { return agentAutomationRequest{}, err @@ -460,3 +554,155 @@ func GetAutomationsConfigurationForRepository(t translations.TranslationHelperFu }, ) } + +func CreateAutomation(t translations.TranslationHelperFunc) inventory.ServerTool { + properties := automationConfigurationProperties() + properties["owner"] = automationStringProperty(DescriptionRepositoryOwner) + properties["repo"] = automationStringProperty(DescriptionRepositoryName) + return newAgentAutomationTool[CreateAutomationInput]( + t, + "create_automation", + "Create a repository automation", + "Create a Copilot automation in a repository.", + agentAutomationInputSchema(properties, "owner", "repo", "name", "prompt"), + agentAutomationObjectOutputSchema(), + mcp.ToolAnnotations{}, + func(args CreateAutomationInput) (agentAutomationRequest, error) { + if err := requireAutomationRepository(args.Owner, args.Repo); err != nil { + return agentAutomationRequest{}, err + } + body := map[string]any{"name": args.Name, "prompt": args.Prompt} + if args.Name == "" { + return agentAutomationRequest{}, errors.New("missing required parameter: name") + } + if args.Prompt == "" { + return agentAutomationRequest{}, errors.New("missing required parameter: prompt") + } + if args.Triggers != nil { + body["triggers"] = args.Triggers + } + if args.Model != nil { + body["model"] = *args.Model + } + if args.ReasoningEffort != nil { + body["reasoning_effort"] = *args.ReasoningEffort + } + if args.Tools != nil { + body["tools"] = args.Tools + } + if args.Enabled != nil { + body["enabled"] = *args.Enabled + } + if args.Type != nil { + if *args.Type != "personal" && *args.Type != "shared" { + return agentAutomationRequest{}, errors.New("type must be personal or shared") + } + body["type"] = *args.Type + } + if args.RequireActorWritePermission != nil { + body["require_actor_write_permission"] = *args.RequireActorWritePermission + } + if args.ContinuousHistory != nil { + body["continuous_history"] = *args.ContinuousHistory + } + return agentAutomationRequest{ + method: http.MethodPost, + path: automationPath(args.Owner, args.Repo, ""), + body: body, + successStatus: http.StatusCreated, + }, nil + }, + ) +} + +func UpdateAutomation(t translations.TranslationHelperFunc) inventory.ServerTool { + properties := automationConfigurationProperties() + properties["owner"] = automationStringProperty(DescriptionRepositoryOwner) + properties["repo"] = automationStringProperty(DescriptionRepositoryName) + properties["automation_id"] = automationStringProperty("The automation identifier.") + delete(properties, "type") + return newAgentAutomationTool[UpdateAutomationInput]( + t, + "update_automation", + "Update a repository automation", + "Update a Copilot automation in a repository. Only the provided fields are changed.", + agentAutomationInputSchema(properties, "owner", "repo", "automation_id"), + agentAutomationObjectOutputSchema(), + mcp.ToolAnnotations{}, + func(args UpdateAutomationInput) (agentAutomationRequest, error) { + if err := requireAutomationRepository(args.Owner, args.Repo); err != nil { + return agentAutomationRequest{}, err + } + if args.AutomationID == "" { + return agentAutomationRequest{}, errors.New("missing required parameter: automation_id") + } + body := make(map[string]any) + if args.Name != nil { + body["name"] = *args.Name + } + if args.Enabled != nil { + body["enabled"] = *args.Enabled + } + if args.RequireActorWritePermission != nil { + body["require_actor_write_permission"] = *args.RequireActorWritePermission + } + if args.ContinuousHistory != nil { + body["continuous_history"] = *args.ContinuousHistory + } + if args.Model != nil { + body["model"] = *args.Model + } + if args.ReasoningEffort != nil { + body["reasoning_effort"] = *args.ReasoningEffort + } + if args.Triggers != nil { + body["triggers"] = args.Triggers + } + if args.Prompt != nil { + body["prompt"] = *args.Prompt + } + if args.Tools != nil { + body["tools"] = args.Tools + } + if len(body) == 0 { + return agentAutomationRequest{}, errors.New("at least one automation field must be provided") + } + return agentAutomationRequest{ + method: http.MethodPatch, + path: automationPath(args.Owner, args.Repo, url.PathEscape(args.AutomationID)), + body: body, + }, nil + }, + ) +} + +func DeleteAutomation(t translations.TranslationHelperFunc) inventory.ServerTool { + return newAgentAutomationTool[DeleteAutomationInput]( + t, + "delete_automation", + "Delete a repository automation", + "Delete a Copilot automation from a repository.", + agentAutomationInputSchema(map[string]*jsonschema.Schema{ + "owner": automationStringProperty(DescriptionRepositoryOwner), + "repo": automationStringProperty(DescriptionRepositoryName), + "automation_id": automationStringProperty("The automation identifier."), + }, "owner", "repo", "automation_id"), + agentAutomationObjectOutputSchema(), + mcp.ToolAnnotations{DestructiveHint: new(true), IdempotentHint: true}, + func(args DeleteAutomationInput) (agentAutomationRequest, error) { + if err := requireAutomationRepository(args.Owner, args.Repo); err != nil { + return agentAutomationRequest{}, err + } + if args.AutomationID == "" { + return agentAutomationRequest{}, errors.New("missing required parameter: automation_id") + } + return agentAutomationRequest{ + method: http.MethodDelete, + path: automationPath(args.Owner, args.Repo, url.PathEscape(args.AutomationID)), + successStatus: http.StatusNoContent, + noBody: true, + successMessage: "Automation deleted.", + }, nil + }, + ) +} diff --git a/pkg/github/agent_automations_test.go b/pkg/github/agent_automations_test.go index abdd6a0f04..3ae4b43c3c 100644 --- a/pkg/github/agent_automations_test.go +++ b/pkg/github/agent_automations_test.go @@ -3,6 +3,7 @@ package github import ( "context" "encoding/json" + "io" "net/http" "testing" @@ -25,6 +26,9 @@ func agentAutomationToolsForTest() []inventory.ServerTool { ListAvailableAutomationTools(t), ListAvailableAutomationTriggers(t), GetAutomationsConfigurationForRepository(t), + CreateAutomation(t), + UpdateAutomation(t), + DeleteAutomation(t), } } @@ -53,6 +57,7 @@ func TestAgentAutomationFeatureFlagAvailability(t *testing.T) { enabledFeatures []string toolsets []string insidersMode bool + readOnly bool wantAvailable bool }{ {name: "default with all toolsets"}, @@ -62,6 +67,12 @@ func TestAgentAutomationFeatureFlagAvailability(t *testing.T) { enabledFeatures: []string{FeatureFlagAgentAutomations}, wantAvailable: true, }, + { + name: "explicit opt-in in read-only mode", + enabledFeatures: []string{FeatureFlagAgentAutomations}, + readOnly: true, + wantAvailable: true, + }, { name: "explicit opt-in with default toolsets", enabledFeatures: []string{FeatureFlagAgentAutomations}, @@ -87,6 +98,7 @@ func TestAgentAutomationFeatureFlagAvailability(t *testing.T) { inv, err := inventory.NewBuilder(). SetTools(AllTools(translations.NullTranslationHelper)). WithToolsets(toolsets). + WithReadOnly(tc.readOnly). WithFeatureChecker(featureCheckerFor(flags...)). Build() require.NoError(t, err) @@ -100,7 +112,16 @@ func TestAgentAutomationFeatureFlagAvailability(t *testing.T) { } } if tc.wantAvailable { - assert.ElementsMatch(t, automationNames, availableNames) + expectedNames := automationNames + if tc.readOnly { + expectedNames = nil + for _, tool := range automationTools { + if tool.IsReadOnly() { + expectedNames = append(expectedNames, tool.Tool.Name) + } + } + } + assert.ElementsMatch(t, expectedNames, availableNames) return } assert.Empty(t, availableNames) @@ -384,3 +405,84 @@ func TestGetAutomationsConfigurationForRepositoryDoesNotCacheResponses(t *testin } assert.Equal(t, len(responses), calls) } + +func TestAgentAutomationWriteTools(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + tool func(translations.TranslationHelperFunc) inventory.ServerTool + args map[string]any + method string + endpoint string + status int + body string + response string + }{ + { + name: "create automation", + tool: CreateAutomation, + args: map[string]any{ + "owner": "octo-org", "repo": "octo-repo", "name": "Issue triage", "prompt": "Triage new issues.", + "type": "shared", "enabled": false, "tools": []string{"github/issue_read"}, + "triggers": map[string]any{"issue_opened": map[string]any{"query": "is:open"}}, + }, + method: http.MethodPost, + endpoint: "/agents/repos/octo-org/octo-repo/automations", + status: http.StatusCreated, + body: `{"name":"Issue triage","prompt":"Triage new issues.","type":"shared","enabled":false,"tools":["github/issue_read"],"triggers":{"issue_opened":{"query":"is:open"}}}`, + response: `{"id":"automation-id","name":"Issue triage"}`, + }, + { + name: "update automation", + tool: UpdateAutomation, + args: map[string]any{ + "owner": "octo-org", "repo": "octo-repo", "automation_id": "automation-id", + "enabled": false, "prompt": "Review new issues.", "tools": []string{}, + }, + method: http.MethodPatch, + endpoint: "/agents/repos/octo-org/octo-repo/automations/automation-id", + status: http.StatusOK, + body: `{"enabled":false,"prompt":"Review new issues.","tools":[]}`, + response: `{"id":"automation-id","prompt":"Review new issues."}`, + }, + { + name: "delete automation", + tool: DeleteAutomation, + args: map[string]any{"owner": "octo-org", "repo": "octo-repo", "automation_id": "automation-id"}, + method: http.MethodDelete, + endpoint: "/agents/repos/octo-org/octo-repo/automations/automation-id", + status: http.StatusNoContent, + response: `{"message":"Automation deleted."}`, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + tool := tt.tool(translations.NullTranslationHelper) + httpClient := MockHTTPClientWithHandler(func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, tt.method, r.Method) + assert.Equal(t, tt.endpoint, r.URL.Path) + assert.Equal(t, agentAutomationAPIVersion, r.Header.Get("X-GitHub-Api-Version")) + if tt.body == "" { + assert.Empty(t, r.Body) + } else { + body, err := io.ReadAll(r.Body) + require.NoError(t, err) + assert.JSONEq(t, tt.body, string(body)) + } + w.WriteHeader(tt.status) + if tt.status != http.StatusNoContent { + _, _ = w.Write([]byte(tt.response)) + } + }) + deps := BaseDeps{Client: mustNewGHClient(t, httpClient)} + request := createMCPRequest(tt.args) + result, err := tool.Handler(nil)(ContextWithDeps(context.Background(), deps), &request) + require.NoError(t, err) + require.False(t, result.IsError) + assert.JSONEq(t, tt.response, getTextResult(t, result).Text) + }) + } +} diff --git a/pkg/github/tools.go b/pkg/github/tools.go index d2d0cc2fb1..60a5084e97 100644 --- a/pkg/github/tools.go +++ b/pkg/github/tools.go @@ -309,6 +309,9 @@ func AllTools(t translations.TranslationHelperFunc, opts ...ToolOption) []invent ListAvailableAutomationTools(t), ListAvailableAutomationTriggers(t), GetAutomationsConfigurationForRepository(t), + CreateAutomation(t), + UpdateAutomation(t), + DeleteAutomation(t), // Copilot issue intents (non-default, opt-in) AssignCopilotToIssueWithIntent(t), From 034de04f0cd9d3a4fdd3c24f90839b14864edd85 Mon Sep 17 00:00:00 2001 From: Shaikhul Islam Date: Fri, 6 Nov 2026 16:27:02 -0500 Subject: [PATCH 2/7] fix: require user confirmation before deleting automations Bind the confirmation to the exact API request and reject missing, declined, mismatched, expired, or changed confirmations before sending a delete request. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../__toolsnaps__/delete_automation.snap | 2 +- pkg/github/agent_automations.go | 155 +++++++++++++++++- pkg/github/agent_automations_test.go | 149 ++++++++++++++++- 3 files changed, 298 insertions(+), 8 deletions(-) diff --git a/pkg/github/__toolsnaps__/delete_automation.snap b/pkg/github/__toolsnaps__/delete_automation.snap index b1b9630157..13a78a67d5 100644 --- a/pkg/github/__toolsnaps__/delete_automation.snap +++ b/pkg/github/__toolsnaps__/delete_automation.snap @@ -5,7 +5,7 @@ "readOnlyHint": false, "title": "Delete a repository automation" }, - "description": "Delete a Copilot automation from a repository.", + "description": "Delete a Copilot automation from a repository after explicit user confirmation.", "inputSchema": { "properties": { "automation_id": { diff --git a/pkg/github/agent_automations.go b/pkg/github/agent_automations.go index 035f06019e..65e5d477f9 100644 --- a/pkg/github/agent_automations.go +++ b/pkg/github/agent_automations.go @@ -2,12 +2,16 @@ package github import ( "context" + "crypto/sha256" + "encoding/hex" "encoding/json" "errors" "fmt" "net/http" "net/url" "strconv" + "strings" + "time" ghErrors "github.com/github/github-mcp-server/v2/pkg/errors" "github.com/github/github-mcp-server/v2/pkg/inventory" @@ -21,6 +25,9 @@ import ( ) const agentAutomationAPIVersion = "2026-03-10" +const agentAutomationConfirmationIDPrefix = "agent_automation_confirmation_" +const agentAutomationConfirmationField = "confirmation" +const agentAutomationConfirmationTTL = 10 * time.Minute type ListAutomationsInput struct { Owner string `json:"owner"` @@ -100,6 +107,21 @@ type agentAutomationRequest struct { successStatus int noBody bool successMessage string + confirmation *agentAutomationConfirmation +} + +type agentAutomationConfirmation struct { + id string + value string + message string +} + +type agentAutomationConfirmationState struct { + ToolName string `json:"tool_name"` + RequestDigest string `json:"request_digest"` + ConfirmationID string `json:"confirmation_id"` + ConfirmationValue string `json:"confirmation_value"` + ExpiresAt int64 `json:"expires_at"` } type agentAutomationRequestBuilder[Input any] func(Input) (agentAutomationRequest, error) @@ -129,11 +151,17 @@ func newAgentAutomationTool[Input any]( }, }, scopes.RequireAll(scopes.Repo), - func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest, args Input) (*mcp.CallToolResult, json.RawMessage, error) { + func(ctx context.Context, deps ToolDependencies, req *mcp.CallToolRequest, args Input) (*mcp.CallToolResult, json.RawMessage, error) { request, err := build(args) if err != nil { return utils.NewToolResultError(err.Error()), nil, nil } + if request.confirmation != nil { + result, err := agentAutomationConfirmationResult(ctx, deps, req, name, request) + if err != nil || result != nil { + return result, nil, err + } + } client, err := deps.GetClient(ctx) if err != nil { @@ -187,6 +215,119 @@ func newAgentAutomationTool[Input any]( return tool } +func agentAutomationConfirmationResult( + ctx context.Context, + deps ToolDependencies, + req *mcp.CallToolRequest, + toolName string, + request agentAutomationRequest, +) (*mcp.CallToolResult, error) { + if req == nil || req.Params == nil { + return utils.NewToolResultError("Automation confirmation is unavailable without an MCP request."), nil + } + sealer := requestStateSealerFromDeps(deps) + if sealer == nil { + return utils.NewToolResultError("Automation confirmation is unavailable because request-state protection is not configured."), nil + } + digest, err := agentAutomationRequestDigest(request) + if err != nil { + return nil, fmt.Errorf("failed to fingerprint automation request: %w", err) + } + + response, hasResponse := req.Params.InputResponses[request.confirmation.id] + if !hasResponse { + state, err := json.Marshal(agentAutomationConfirmationState{ + ToolName: toolName, + RequestDigest: digest, + ConfirmationID: request.confirmation.id, + ConfirmationValue: request.confirmation.value, + ExpiresAt: time.Now().Add(agentAutomationConfirmationTTL).Unix(), + }) + if err != nil { + return nil, fmt.Errorf("failed to marshal automation confirmation state: %w", err) + } + requestState, err := sealer.Seal(ctx, state) + if err != nil { + return nil, fmt.Errorf("failed to seal automation confirmation state: %w", err) + } + return &mcp.CallToolResult{ + InputRequests: mcp.InputRequestMap{ + request.confirmation.id: &mcp.ElicitParams{ + Mode: "form", + Message: request.confirmation.message, + RequestedSchema: &jsonschema.Schema{ + Type: "object", + Properties: map[string]*jsonschema.Schema{ + agentAutomationConfirmationField: { + Type: "string", + Title: "Confirmation", + Description: fmt.Sprintf("Enter %q exactly to confirm this operation.", request.confirmation.value), + }, + }, + Required: []string{agentAutomationConfirmationField}, + }, + }, + }, + RequestState: requestState, + }, nil + } + + if req.Params.RequestState == "" { + return utils.NewToolResultError("Automation confirmation state is missing. The operation was not performed."), nil + } + stateJSON, err := sealer.Open(req.Params.RequestState) + if err != nil { + return utils.NewToolResultError("Automation confirmation state is invalid. The operation was not performed."), nil + } + var state agentAutomationConfirmationState + if err := json.Unmarshal(stateJSON, &state); err != nil { + return utils.NewToolResultError("Automation confirmation state is invalid. The operation was not performed."), nil + } + if state.ToolName != toolName || + state.RequestDigest != digest || + state.ConfirmationID != request.confirmation.id || + state.ConfirmationValue != request.confirmation.value { + return utils.NewToolResultError("Automation request changed after confirmation was requested. The operation was not performed."), nil + } + if state.ExpiresAt <= time.Now().Unix() { + return utils.NewToolResultError("Automation confirmation expired. The operation was not performed."), nil + } + + confirmation, ok := response.(*mcp.ElicitResult) + if !ok { + return utils.NewToolResultError("Automation confirmation response is invalid. The operation was not performed."), nil + } + if confirmation.Action != "accept" { + return utils.NewToolResultError("Automation operation was not confirmed."), nil + } + value, ok := confirmation.Content[agentAutomationConfirmationField].(string) + if !ok || value != request.confirmation.value { + return utils.NewToolResultError("Automation confirmation did not match the requested operation."), nil + } + return nil, nil +} + +func agentAutomationRequestDigest(request agentAutomationRequest) (string, error) { + body, err := json.Marshal(request.body) + if err != nil { + return "", err + } + payload := strings.Join([]string{ + request.method, + request.path, + request.query.Encode(), + string(body), + }, "\n") + digest := sha256.Sum256([]byte(payload)) + return hex.EncodeToString(digest[:]), nil +} + +func agentAutomationConfirmationRequired(tool inventory.ServerTool) inventory.ServerTool { + tool.MinimumProtocolVersion = inventory.ProtocolVersionMultiRoundTrip + tool.RequiredElicitationMode = inventory.ElicitationModeForm + return tool +} + func agentAutomationObjectOutputSchema() json.RawMessage { return json.RawMessage(`{"type":"object","additionalProperties":true}`) } @@ -677,11 +818,11 @@ func UpdateAutomation(t translations.TranslationHelperFunc) inventory.ServerTool } func DeleteAutomation(t translations.TranslationHelperFunc) inventory.ServerTool { - return newAgentAutomationTool[DeleteAutomationInput]( + return agentAutomationConfirmationRequired(newAgentAutomationTool[DeleteAutomationInput]( t, "delete_automation", "Delete a repository automation", - "Delete a Copilot automation from a repository.", + "Delete a Copilot automation from a repository after explicit user confirmation.", agentAutomationInputSchema(map[string]*jsonschema.Schema{ "owner": automationStringProperty(DescriptionRepositoryOwner), "repo": automationStringProperty(DescriptionRepositoryName), @@ -696,13 +837,19 @@ func DeleteAutomation(t translations.TranslationHelperFunc) inventory.ServerTool if args.AutomationID == "" { return agentAutomationRequest{}, errors.New("missing required parameter: automation_id") } + target := args.Owner + "/" + args.Repo + "/" + args.AutomationID return agentAutomationRequest{ method: http.MethodDelete, path: automationPath(args.Owner, args.Repo, url.PathEscape(args.AutomationID)), successStatus: http.StatusNoContent, noBody: true, successMessage: "Automation deleted.", + confirmation: &agentAutomationConfirmation{ + id: agentAutomationConfirmationIDPrefix + "delete", + value: "DELETE " + target, + message: fmt.Sprintf("Review the automation to delete: %s. Type %q to confirm.", target, "DELETE "+target), + }, }, nil }, - ) + )) } diff --git a/pkg/github/agent_automations_test.go b/pkg/github/agent_automations_test.go index 3ae4b43c3c..ffa1e2d10e 100644 --- a/pkg/github/agent_automations_test.go +++ b/pkg/github/agent_automations_test.go @@ -7,6 +7,7 @@ import ( "net/http" "testing" + "github.com/github/github-mcp-server/v2/internal/requeststate" "github.com/github/github-mcp-server/v2/internal/toolsnaps" "github.com/github/github-mcp-server/v2/pkg/inventory" "github.com/github/github-mcp-server/v2/pkg/translations" @@ -418,6 +419,7 @@ func TestAgentAutomationWriteTools(t *testing.T) { status int body string response string + confirm bool }{ { name: "create automation", @@ -454,6 +456,7 @@ func TestAgentAutomationWriteTools(t *testing.T) { endpoint: "/agents/repos/octo-org/octo-repo/automations/automation-id", status: http.StatusNoContent, response: `{"message":"Automation deleted."}`, + confirm: true, }, } @@ -478,11 +481,151 @@ func TestAgentAutomationWriteTools(t *testing.T) { } }) deps := BaseDeps{Client: mustNewGHClient(t, httpClient)} - request := createMCPRequest(tt.args) - result, err := tool.Handler(nil)(ContextWithDeps(context.Background(), deps), &request) - require.NoError(t, err) + var result *mcp.CallToolResult + if tt.confirm { + sealer, err := requeststate.NewRandom() + require.NoError(t, err) + deps.StateSealer = sealer + result = invokeConfirmedAutomation(t, tool, deps, tt.args, agentAutomationConfirmationIDPrefix+"delete", "DELETE octo-org/octo-repo/automation-id") + } else { + request := createMCPRequest(tt.args) + var err error + result, err = tool.Handler(nil)(ContextWithDeps(context.Background(), deps), &request) + require.NoError(t, err) + } require.False(t, result.IsError) assert.JSONEq(t, tt.response, getTextResult(t, result).Text) }) } } + +func TestDeleteAutomationRequiresRequestStateProtection(t *testing.T) { + t.Parallel() + + tool := DeleteAutomation(translations.NullTranslationHelper) + httpClient := MockHTTPClientWithHandler(func(http.ResponseWriter, *http.Request) { + t.Fatal("delete should not be sent without request-state protection") + }) + deps := BaseDeps{Client: mustNewGHClient(t, httpClient)} + request := createMCPRequest(map[string]any{ + "owner": "octo-org", "repo": "octo-repo", "automation_id": "automation-id", + }) + result, err := tool.Handler(deps)(ContextWithDeps(context.Background(), deps), &request) + require.NoError(t, err) + require.True(t, result.IsError) + assert.Contains(t, getErrorResult(t, result).Text, "request-state protection is not configured") +} + +func TestDeleteAutomationRequiresMatchingConfirmation(t *testing.T) { + t.Parallel() + + for _, tc := range []struct { + name string + action string + confirmation string + changeAutomationID bool + wantError string + }{ + { + name: "declined", + action: "decline", + confirmation: "DELETE octo-org/octo-repo/automation-id", + wantError: "was not confirmed", + }, + { + name: "incorrect confirmation", + action: "accept", + confirmation: "DELETE octo-org/octo-repo/another-automation", + wantError: "did not match", + }, + { + name: "changed target", + action: "accept", + confirmation: "DELETE octo-org/octo-repo/automation-id", + changeAutomationID: true, + wantError: "changed after confirmation", + }, + } { + t.Run(tc.name, func(t *testing.T) { + tool := DeleteAutomation(translations.NullTranslationHelper) + requestCount := 0 + httpClient := MockHTTPClientWithHandler(func(http.ResponseWriter, *http.Request) { + requestCount++ + }) + deps := BaseDeps{Client: mustNewGHClient(t, httpClient)} + sealer, err := requeststate.NewRandom() + require.NoError(t, err) + deps.StateSealer = sealer + + args := map[string]any{ + "owner": "octo-org", "repo": "octo-repo", "automation_id": "automation-id", + } + handler := tool.Handler(deps) + request := createMCPRequest(args) + result, err := handler(ContextWithDeps(context.Background(), deps), &request) + require.NoError(t, err) + require.NotNil(t, result) + + if tc.changeAutomationID { + args["automation_id"] = "another-automation" + } + retry := createMCPRequest(args) + retry.Params.RequestState = result.RequestState + retry.Params.InputResponses = mcp.InputResponseMap{ + agentAutomationConfirmationIDPrefix + "delete": &mcp.ElicitResult{ + Action: tc.action, + Content: map[string]any{ + agentAutomationConfirmationField: tc.confirmation, + }, + }, + } + result, err = handler(ContextWithDeps(context.Background(), deps), &retry) + require.NoError(t, err) + require.True(t, result.IsError) + assert.Contains(t, getErrorResult(t, result).Text, tc.wantError) + assert.Zero(t, requestCount) + }) + } +} + +func TestAutomationMutationsRequireFormElicitation(t *testing.T) { + t.Parallel() + + tool := DeleteAutomation(translations.NullTranslationHelper) + assert.Equal(t, inventory.ProtocolVersionMultiRoundTrip, tool.MinimumProtocolVersion) + assert.Equal(t, inventory.ElicitationModeForm, tool.RequiredElicitationMode) +} + +func invokeConfirmedAutomation( + t *testing.T, + tool inventory.ServerTool, + deps BaseDeps, + args map[string]any, + confirmationID, confirmationValue string, +) *mcp.CallToolResult { + t.Helper() + + handler := tool.Handler(deps) + request := createMCPRequest(args) + result, err := handler(ContextWithDeps(context.Background(), deps), &request) + require.NoError(t, err) + require.NotNil(t, result) + params, ok := result.InputRequests[confirmationID].(*mcp.ElicitParams) + require.True(t, ok) + assert.Equal(t, "form", params.Mode) + assert.Contains(t, params.Message, confirmationValue) + + retry := createMCPRequest(args) + retry.Params.RequestState = result.RequestState + retry.Params.InputResponses = mcp.InputResponseMap{ + confirmationID: &mcp.ElicitResult{ + Action: "accept", + Content: map[string]any{ + agentAutomationConfirmationField: confirmationValue, + }, + }, + } + result, err = handler(ContextWithDeps(context.Background(), deps), &retry) + require.NoError(t, err) + return result +} From 25edc647ab0fedbc75c612801bb97c20db869a87 Mon Sep 17 00:00:00 2001 From: Shaikhul Islam Date: Fri, 6 Nov 2026 16:35:40 -0500 Subject: [PATCH 3/7] fix: require confirmation for automation mutations Show the exact create/update request details for explicit approval and bind confirmation to the request before sending mutations. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../__toolsnaps__/create_automation.snap | 2 +- .../__toolsnaps__/update_automation.snap | 2 +- pkg/github/agent_automations.go | 43 +++++-- pkg/github/agent_automations_test.go | 121 +++++++++++++----- 4 files changed, 126 insertions(+), 42 deletions(-) diff --git a/pkg/github/__toolsnaps__/create_automation.snap b/pkg/github/__toolsnaps__/create_automation.snap index afa6419b4e..4c0171ff7c 100644 --- a/pkg/github/__toolsnaps__/create_automation.snap +++ b/pkg/github/__toolsnaps__/create_automation.snap @@ -4,7 +4,7 @@ "readOnlyHint": false, "title": "Create a repository automation" }, - "description": "Create a Copilot automation in a repository.", + "description": "Create a Copilot automation in a repository after explicit user confirmation.", "inputSchema": { "properties": { "continuous_history": { diff --git a/pkg/github/__toolsnaps__/update_automation.snap b/pkg/github/__toolsnaps__/update_automation.snap index 89df4dbebb..6e1d312823 100644 --- a/pkg/github/__toolsnaps__/update_automation.snap +++ b/pkg/github/__toolsnaps__/update_automation.snap @@ -4,7 +4,7 @@ "readOnlyHint": false, "title": "Update a repository automation" }, - "description": "Update a Copilot automation in a repository. Only the provided fields are changed.", + "description": "Update a Copilot automation in a repository after explicit user confirmation. Only the provided fields are changed.", "inputSchema": { "properties": { "automation_id": { diff --git a/pkg/github/agent_automations.go b/pkg/github/agent_automations.go index 65e5d477f9..8e776baad7 100644 --- a/pkg/github/agent_automations.go +++ b/pkg/github/agent_automations.go @@ -328,6 +328,19 @@ func agentAutomationConfirmationRequired(tool inventory.ServerTool) inventory.Se return tool } +func agentAutomationMutationConfirmation(action, target string, body any) (*agentAutomationConfirmation, error) { + requestBody, err := json.MarshalIndent(body, "", " ") + if err != nil { + return nil, fmt.Errorf("failed to prepare automation confirmation details: %w", err) + } + value := strings.ToUpper(action) + " " + target + return &agentAutomationConfirmation{ + id: agentAutomationConfirmationIDPrefix + action, + value: value, + message: fmt.Sprintf("Review the exact automation changes for %s:\n%s\nType %q to confirm.", target, requestBody, value), + }, nil +} + func agentAutomationObjectOutputSchema() json.RawMessage { return json.RawMessage(`{"type":"object","additionalProperties":true}`) } @@ -700,11 +713,11 @@ func CreateAutomation(t translations.TranslationHelperFunc) inventory.ServerTool properties := automationConfigurationProperties() properties["owner"] = automationStringProperty(DescriptionRepositoryOwner) properties["repo"] = automationStringProperty(DescriptionRepositoryName) - return newAgentAutomationTool[CreateAutomationInput]( + return agentAutomationConfirmationRequired(newAgentAutomationTool[CreateAutomationInput]( t, "create_automation", "Create a repository automation", - "Create a Copilot automation in a repository.", + "Create a Copilot automation in a repository after explicit user confirmation.", agentAutomationInputSchema(properties, "owner", "repo", "name", "prompt"), agentAutomationObjectOutputSchema(), mcp.ToolAnnotations{}, @@ -746,14 +759,20 @@ func CreateAutomation(t translations.TranslationHelperFunc) inventory.ServerTool if args.ContinuousHistory != nil { body["continuous_history"] = *args.ContinuousHistory } + target := args.Owner + "/" + args.Repo + confirmation, err := agentAutomationMutationConfirmation("create", target, body) + if err != nil { + return agentAutomationRequest{}, err + } return agentAutomationRequest{ method: http.MethodPost, path: automationPath(args.Owner, args.Repo, ""), body: body, successStatus: http.StatusCreated, + confirmation: confirmation, }, nil }, - ) + )) } func UpdateAutomation(t translations.TranslationHelperFunc) inventory.ServerTool { @@ -762,11 +781,11 @@ func UpdateAutomation(t translations.TranslationHelperFunc) inventory.ServerTool properties["repo"] = automationStringProperty(DescriptionRepositoryName) properties["automation_id"] = automationStringProperty("The automation identifier.") delete(properties, "type") - return newAgentAutomationTool[UpdateAutomationInput]( + return agentAutomationConfirmationRequired(newAgentAutomationTool[UpdateAutomationInput]( t, "update_automation", "Update a repository automation", - "Update a Copilot automation in a repository. Only the provided fields are changed.", + "Update a Copilot automation in a repository after explicit user confirmation. Only the provided fields are changed.", agentAutomationInputSchema(properties, "owner", "repo", "automation_id"), agentAutomationObjectOutputSchema(), mcp.ToolAnnotations{}, @@ -808,13 +827,19 @@ func UpdateAutomation(t translations.TranslationHelperFunc) inventory.ServerTool if len(body) == 0 { return agentAutomationRequest{}, errors.New("at least one automation field must be provided") } + target := args.Owner + "/" + args.Repo + "/" + args.AutomationID + confirmation, err := agentAutomationMutationConfirmation("update", target, body) + if err != nil { + return agentAutomationRequest{}, err + } return agentAutomationRequest{ - method: http.MethodPatch, - path: automationPath(args.Owner, args.Repo, url.PathEscape(args.AutomationID)), - body: body, + method: http.MethodPatch, + path: automationPath(args.Owner, args.Repo, url.PathEscape(args.AutomationID)), + body: body, + confirmation: confirmation, }, nil }, - ) + )) } func DeleteAutomation(t translations.TranslationHelperFunc) inventory.ServerTool { diff --git a/pkg/github/agent_automations_test.go b/pkg/github/agent_automations_test.go index ffa1e2d10e..510263e864 100644 --- a/pkg/github/agent_automations_test.go +++ b/pkg/github/agent_automations_test.go @@ -411,15 +411,18 @@ func TestAgentAutomationWriteTools(t *testing.T) { t.Parallel() tests := []struct { - name string - tool func(translations.TranslationHelperFunc) inventory.ServerTool - args map[string]any - method string - endpoint string - status int - body string - response string - confirm bool + name string + tool func(translations.TranslationHelperFunc) inventory.ServerTool + args map[string]any + method string + endpoint string + status int + body string + response string + confirm bool + confirmID string + confirmValue string + messageContents []string }{ { name: "create automation", @@ -429,11 +432,15 @@ func TestAgentAutomationWriteTools(t *testing.T) { "type": "shared", "enabled": false, "tools": []string{"github/issue_read"}, "triggers": map[string]any{"issue_opened": map[string]any{"query": "is:open"}}, }, - method: http.MethodPost, - endpoint: "/agents/repos/octo-org/octo-repo/automations", - status: http.StatusCreated, - body: `{"name":"Issue triage","prompt":"Triage new issues.","type":"shared","enabled":false,"tools":["github/issue_read"],"triggers":{"issue_opened":{"query":"is:open"}}}`, - response: `{"id":"automation-id","name":"Issue triage"}`, + method: http.MethodPost, + endpoint: "/agents/repos/octo-org/octo-repo/automations", + status: http.StatusCreated, + body: `{"name":"Issue triage","prompt":"Triage new issues.","type":"shared","enabled":false,"tools":["github/issue_read"],"triggers":{"issue_opened":{"query":"is:open"}}}`, + response: `{"id":"automation-id","name":"Issue triage"}`, + confirm: true, + confirmID: agentAutomationConfirmationIDPrefix + "create", + confirmValue: "CREATE octo-org/octo-repo", + messageContents: []string{`"name": "Issue triage"`, `"prompt": "Triage new issues."`}, }, { name: "update automation", @@ -442,21 +449,27 @@ func TestAgentAutomationWriteTools(t *testing.T) { "owner": "octo-org", "repo": "octo-repo", "automation_id": "automation-id", "enabled": false, "prompt": "Review new issues.", "tools": []string{}, }, - method: http.MethodPatch, - endpoint: "/agents/repos/octo-org/octo-repo/automations/automation-id", - status: http.StatusOK, - body: `{"enabled":false,"prompt":"Review new issues.","tools":[]}`, - response: `{"id":"automation-id","prompt":"Review new issues."}`, + method: http.MethodPatch, + endpoint: "/agents/repos/octo-org/octo-repo/automations/automation-id", + status: http.StatusOK, + body: `{"enabled":false,"prompt":"Review new issues.","tools":[]}`, + response: `{"id":"automation-id","prompt":"Review new issues."}`, + confirm: true, + confirmID: agentAutomationConfirmationIDPrefix + "update", + confirmValue: "UPDATE octo-org/octo-repo/automation-id", + messageContents: []string{`"enabled": false`, `"prompt": "Review new issues."`}, }, { - name: "delete automation", - tool: DeleteAutomation, - args: map[string]any{"owner": "octo-org", "repo": "octo-repo", "automation_id": "automation-id"}, - method: http.MethodDelete, - endpoint: "/agents/repos/octo-org/octo-repo/automations/automation-id", - status: http.StatusNoContent, - response: `{"message":"Automation deleted."}`, - confirm: true, + name: "delete automation", + tool: DeleteAutomation, + args: map[string]any{"owner": "octo-org", "repo": "octo-repo", "automation_id": "automation-id"}, + method: http.MethodDelete, + endpoint: "/agents/repos/octo-org/octo-repo/automations/automation-id", + status: http.StatusNoContent, + response: `{"message":"Automation deleted."}`, + confirm: true, + confirmID: agentAutomationConfirmationIDPrefix + "delete", + confirmValue: "DELETE octo-org/octo-repo/automation-id", }, } @@ -486,7 +499,7 @@ func TestAgentAutomationWriteTools(t *testing.T) { sealer, err := requeststate.NewRandom() require.NoError(t, err) deps.StateSealer = sealer - result = invokeConfirmedAutomation(t, tool, deps, tt.args, agentAutomationConfirmationIDPrefix+"delete", "DELETE octo-org/octo-repo/automation-id") + result = invokeConfirmedAutomation(t, tool, deps, tt.args, tt.confirmID, tt.confirmValue, tt.messageContents...) } else { request := createMCPRequest(tt.args) var err error @@ -499,6 +512,43 @@ func TestAgentAutomationWriteTools(t *testing.T) { } } +func TestAutomationCreateAndUpdateRequireRequestStateProtection(t *testing.T) { + t.Parallel() + + for _, tc := range []struct { + name string + tool inventory.ServerTool + args map[string]any + }{ + { + name: "create", + tool: CreateAutomation(translations.NullTranslationHelper), + args: map[string]any{ + "owner": "octo-org", "repo": "octo-repo", "name": "Issue triage", "prompt": "Triage new issues.", + }, + }, + { + name: "update", + tool: UpdateAutomation(translations.NullTranslationHelper), + args: map[string]any{ + "owner": "octo-org", "repo": "octo-repo", "automation_id": "automation-id", "enabled": false, + }, + }, + } { + t.Run(tc.name, func(t *testing.T) { + httpClient := MockHTTPClientWithHandler(func(http.ResponseWriter, *http.Request) { + t.Fatal("mutation should not be sent without request-state protection") + }) + deps := BaseDeps{Client: mustNewGHClient(t, httpClient)} + request := createMCPRequest(tc.args) + result, err := tc.tool.Handler(deps)(ContextWithDeps(context.Background(), deps), &request) + require.NoError(t, err) + require.True(t, result.IsError) + assert.Contains(t, getErrorResult(t, result).Text, "request-state protection is not configured") + }) + } +} + func TestDeleteAutomationRequiresRequestStateProtection(t *testing.T) { t.Parallel() @@ -591,9 +641,14 @@ func TestDeleteAutomationRequiresMatchingConfirmation(t *testing.T) { func TestAutomationMutationsRequireFormElicitation(t *testing.T) { t.Parallel() - tool := DeleteAutomation(translations.NullTranslationHelper) - assert.Equal(t, inventory.ProtocolVersionMultiRoundTrip, tool.MinimumProtocolVersion) - assert.Equal(t, inventory.ElicitationModeForm, tool.RequiredElicitationMode) + for _, tool := range []inventory.ServerTool{ + CreateAutomation(translations.NullTranslationHelper), + UpdateAutomation(translations.NullTranslationHelper), + DeleteAutomation(translations.NullTranslationHelper), + } { + assert.Equal(t, inventory.ProtocolVersionMultiRoundTrip, tool.MinimumProtocolVersion) + assert.Equal(t, inventory.ElicitationModeForm, tool.RequiredElicitationMode) + } } func invokeConfirmedAutomation( @@ -602,6 +657,7 @@ func invokeConfirmedAutomation( deps BaseDeps, args map[string]any, confirmationID, confirmationValue string, + messageContents ...string, ) *mcp.CallToolResult { t.Helper() @@ -614,6 +670,9 @@ func invokeConfirmedAutomation( require.True(t, ok) assert.Equal(t, "form", params.Mode) assert.Contains(t, params.Message, confirmationValue) + for _, content := range messageContents { + assert.Contains(t, params.Message, content) + } retry := createMCPRequest(args) retry.Params.RequestState = result.RequestState From 1d8150b26d1e73e09c9c2128e7f5773a9675b051 Mon Sep 17 00:00:00 2001 From: Shaikhul Islam Date: Fri, 6 Nov 2026 16:48:33 -0500 Subject: [PATCH 4/7] fix: keep untrusted automation values out of confirmations Keep request values out of MCP confirmation messages so untrusted prompt text cannot steer the confirmation step. Show only escaped targets and field names, while preserving the original REST payload. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- pkg/github/agent_automations.go | 40 ++++++++-------- pkg/github/agent_automations_test.go | 70 +++++++++++++++------------- 2 files changed, 59 insertions(+), 51 deletions(-) diff --git a/pkg/github/agent_automations.go b/pkg/github/agent_automations.go index 8e776baad7..9ca1c2b0b2 100644 --- a/pkg/github/agent_automations.go +++ b/pkg/github/agent_automations.go @@ -9,6 +9,7 @@ import ( "fmt" "net/http" "net/url" + "sort" "strconv" "strings" "time" @@ -328,17 +329,26 @@ func agentAutomationConfirmationRequired(tool inventory.ServerTool) inventory.Se return tool } -func agentAutomationMutationConfirmation(action, target string, body any) (*agentAutomationConfirmation, error) { - requestBody, err := json.MarshalIndent(body, "", " ") - if err != nil { - return nil, fmt.Errorf("failed to prepare automation confirmation details: %w", err) +func agentAutomationMutationConfirmation(action, target string, body map[string]any) *agentAutomationConfirmation { + fields := make([]string, 0, len(body)) + for field := range body { + fields = append(fields, field) } + sort.Strings(fields) value := strings.ToUpper(action) + " " + target return &agentAutomationConfirmation{ id: agentAutomationConfirmationIDPrefix + action, value: value, - message: fmt.Sprintf("Review the exact automation changes for %s:\n%s\nType %q to confirm.", target, requestBody, value), - }, nil + message: fmt.Sprintf("Review the proposed automation %s for %s. The request changes these fields: %s. Values are not shown here. Type %q to confirm.", action, target, strings.Join(fields, ", "), value), + } +} + +func agentAutomationTarget(owner, repo, automationID string) string { + target := url.PathEscape(owner) + "/" + url.PathEscape(repo) + if automationID != "" { + target += "/" + url.PathEscape(automationID) + } + return target } func agentAutomationObjectOutputSchema() json.RawMessage { @@ -759,17 +769,13 @@ func CreateAutomation(t translations.TranslationHelperFunc) inventory.ServerTool if args.ContinuousHistory != nil { body["continuous_history"] = *args.ContinuousHistory } - target := args.Owner + "/" + args.Repo - confirmation, err := agentAutomationMutationConfirmation("create", target, body) - if err != nil { - return agentAutomationRequest{}, err - } + target := agentAutomationTarget(args.Owner, args.Repo, "") return agentAutomationRequest{ method: http.MethodPost, path: automationPath(args.Owner, args.Repo, ""), body: body, successStatus: http.StatusCreated, - confirmation: confirmation, + confirmation: agentAutomationMutationConfirmation("create", target, body), }, nil }, )) @@ -827,16 +833,12 @@ func UpdateAutomation(t translations.TranslationHelperFunc) inventory.ServerTool if len(body) == 0 { return agentAutomationRequest{}, errors.New("at least one automation field must be provided") } - target := args.Owner + "/" + args.Repo + "/" + args.AutomationID - confirmation, err := agentAutomationMutationConfirmation("update", target, body) - if err != nil { - return agentAutomationRequest{}, err - } + target := agentAutomationTarget(args.Owner, args.Repo, args.AutomationID) return agentAutomationRequest{ method: http.MethodPatch, path: automationPath(args.Owner, args.Repo, url.PathEscape(args.AutomationID)), body: body, - confirmation: confirmation, + confirmation: agentAutomationMutationConfirmation("update", target, body), }, nil }, )) @@ -862,7 +864,7 @@ func DeleteAutomation(t translations.TranslationHelperFunc) inventory.ServerTool if args.AutomationID == "" { return agentAutomationRequest{}, errors.New("missing required parameter: automation_id") } - target := args.Owner + "/" + args.Repo + "/" + args.AutomationID + target := agentAutomationTarget(args.Owner, args.Repo, args.AutomationID) return agentAutomationRequest{ method: http.MethodDelete, path: automationPath(args.Owner, args.Repo, url.PathEscape(args.AutomationID)), diff --git a/pkg/github/agent_automations_test.go b/pkg/github/agent_automations_test.go index 510263e864..c2b11648e9 100644 --- a/pkg/github/agent_automations_test.go +++ b/pkg/github/agent_automations_test.go @@ -411,18 +411,19 @@ func TestAgentAutomationWriteTools(t *testing.T) { t.Parallel() tests := []struct { - name string - tool func(translations.TranslationHelperFunc) inventory.ServerTool - args map[string]any - method string - endpoint string - status int - body string - response string - confirm bool - confirmID string - confirmValue string - messageContents []string + name string + tool func(translations.TranslationHelperFunc) inventory.ServerTool + args map[string]any + method string + endpoint string + status int + body string + response string + confirm bool + confirmID string + confirmValue string + messageContents []string + messageOmissions []string }{ { name: "create automation", @@ -432,15 +433,16 @@ func TestAgentAutomationWriteTools(t *testing.T) { "type": "shared", "enabled": false, "tools": []string{"github/issue_read"}, "triggers": map[string]any{"issue_opened": map[string]any{"query": "is:open"}}, }, - method: http.MethodPost, - endpoint: "/agents/repos/octo-org/octo-repo/automations", - status: http.StatusCreated, - body: `{"name":"Issue triage","prompt":"Triage new issues.","type":"shared","enabled":false,"tools":["github/issue_read"],"triggers":{"issue_opened":{"query":"is:open"}}}`, - response: `{"id":"automation-id","name":"Issue triage"}`, - confirm: true, - confirmID: agentAutomationConfirmationIDPrefix + "create", - confirmValue: "CREATE octo-org/octo-repo", - messageContents: []string{`"name": "Issue triage"`, `"prompt": "Triage new issues."`}, + method: http.MethodPost, + endpoint: "/agents/repos/octo-org/octo-repo/automations", + status: http.StatusCreated, + body: `{"name":"Issue triage","prompt":"Triage new issues.","type":"shared","enabled":false,"tools":["github/issue_read"],"triggers":{"issue_opened":{"query":"is:open"}}}`, + response: `{"id":"automation-id","name":"Issue triage"}`, + confirm: true, + confirmID: agentAutomationConfirmationIDPrefix + "create", + confirmValue: "CREATE octo-org/octo-repo", + messageContents: []string{"enabled, name, prompt, tools, triggers, type"}, + messageOmissions: []string{"Issue triage", "Triage new issues."}, }, { name: "update automation", @@ -449,15 +451,16 @@ func TestAgentAutomationWriteTools(t *testing.T) { "owner": "octo-org", "repo": "octo-repo", "automation_id": "automation-id", "enabled": false, "prompt": "Review new issues.", "tools": []string{}, }, - method: http.MethodPatch, - endpoint: "/agents/repos/octo-org/octo-repo/automations/automation-id", - status: http.StatusOK, - body: `{"enabled":false,"prompt":"Review new issues.","tools":[]}`, - response: `{"id":"automation-id","prompt":"Review new issues."}`, - confirm: true, - confirmID: agentAutomationConfirmationIDPrefix + "update", - confirmValue: "UPDATE octo-org/octo-repo/automation-id", - messageContents: []string{`"enabled": false`, `"prompt": "Review new issues."`}, + method: http.MethodPatch, + endpoint: "/agents/repos/octo-org/octo-repo/automations/automation-id", + status: http.StatusOK, + body: `{"enabled":false,"prompt":"Review new issues.","tools":[]}`, + response: `{"id":"automation-id","prompt":"Review new issues."}`, + confirm: true, + confirmID: agentAutomationConfirmationIDPrefix + "update", + confirmValue: "UPDATE octo-org/octo-repo/automation-id", + messageContents: []string{"enabled, prompt, tools"}, + messageOmissions: []string{"Review new issues."}, }, { name: "delete automation", @@ -499,7 +502,7 @@ func TestAgentAutomationWriteTools(t *testing.T) { sealer, err := requeststate.NewRandom() require.NoError(t, err) deps.StateSealer = sealer - result = invokeConfirmedAutomation(t, tool, deps, tt.args, tt.confirmID, tt.confirmValue, tt.messageContents...) + result = invokeConfirmedAutomation(t, tool, deps, tt.args, tt.confirmID, tt.confirmValue, tt.messageContents, tt.messageOmissions) } else { request := createMCPRequest(tt.args) var err error @@ -657,7 +660,7 @@ func invokeConfirmedAutomation( deps BaseDeps, args map[string]any, confirmationID, confirmationValue string, - messageContents ...string, + messageContents, messageOmissions []string, ) *mcp.CallToolResult { t.Helper() @@ -673,6 +676,9 @@ func invokeConfirmedAutomation( for _, content := range messageContents { assert.Contains(t, params.Message, content) } + for _, omission := range messageOmissions { + assert.NotContains(t, params.Message, omission) + } retry := createMCPRequest(args) retry.Params.RequestState = result.RequestState From cc2004184ffe3e4a6202d9713217b243d030d7e1 Mon Sep 17 00:00:00 2001 From: Shaikhul Islam Date: Fri, 6 Nov 2026 17:27:59 -0500 Subject: [PATCH 5/7] fix: validate automation write path segments Apply shared automation ID and repository path checks before confirming create, update, and delete requests so dot segments and reserved API routes cannot retarget writes. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- pkg/github/agent_automations.go | 8 +++--- pkg/github/agent_automations_test.go | 38 ++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/pkg/github/agent_automations.go b/pkg/github/agent_automations.go index 9ca1c2b0b2..72c2f34bda 100644 --- a/pkg/github/agent_automations.go +++ b/pkg/github/agent_automations.go @@ -799,8 +799,8 @@ func UpdateAutomation(t translations.TranslationHelperFunc) inventory.ServerTool if err := requireAutomationRepository(args.Owner, args.Repo); err != nil { return agentAutomationRequest{}, err } - if args.AutomationID == "" { - return agentAutomationRequest{}, errors.New("missing required parameter: automation_id") + if err := requireAutomationID(args.AutomationID); err != nil { + return agentAutomationRequest{}, err } body := make(map[string]any) if args.Name != nil { @@ -861,8 +861,8 @@ func DeleteAutomation(t translations.TranslationHelperFunc) inventory.ServerTool if err := requireAutomationRepository(args.Owner, args.Repo); err != nil { return agentAutomationRequest{}, err } - if args.AutomationID == "" { - return agentAutomationRequest{}, errors.New("missing required parameter: automation_id") + if err := requireAutomationID(args.AutomationID); err != nil { + return agentAutomationRequest{}, err } target := agentAutomationTarget(args.Owner, args.Repo, args.AutomationID) return agentAutomationRequest{ diff --git a/pkg/github/agent_automations_test.go b/pkg/github/agent_automations_test.go index c2b11648e9..d2d4ca225e 100644 --- a/pkg/github/agent_automations_test.go +++ b/pkg/github/agent_automations_test.go @@ -552,6 +552,44 @@ func TestAutomationCreateAndUpdateRequireRequestStateProtection(t *testing.T) { } } +func TestAgentAutomationWriteToolsRejectUnsafePathSegments(t *testing.T) { + t.Parallel() + + for _, tc := range []struct { + name string + tool inventory.ServerTool + args map[string]any + }{ + { + name: "create rejects dot owner", + tool: CreateAutomation(translations.NullTranslationHelper), + args: map[string]any{"owner": ".", "repo": "octo-repo", "name": "Name", "prompt": "Prompt"}, + }, + { + name: "update rejects dot-dot automation ID", + tool: UpdateAutomation(translations.NullTranslationHelper), + args: map[string]any{"owner": "octo-org", "repo": "octo-repo", "automation_id": "..", "enabled": false}, + }, + { + name: "delete rejects reserved automation ID", + tool: DeleteAutomation(translations.NullTranslationHelper), + args: map[string]any{"owner": "octo-org", "repo": "octo-repo", "automation_id": "configuration"}, + }, + } { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + httpClient := MockHTTPClientWithHandler(func(http.ResponseWriter, *http.Request) { + t.Fatal("invalid path segment must not make a request") + }) + deps := BaseDeps{Client: mustNewGHClient(t, httpClient)} + request := createMCPRequest(tc.args) + result, err := tc.tool.Handler(deps)(ContextWithDeps(context.Background(), deps), &request) + require.NoError(t, err) + require.True(t, result.IsError) + }) + } +} + func TestDeleteAutomationRequiresRequestStateProtection(t *testing.T) { t.Parallel() From 709507ff4ccbf13a3e6fd5799c2ed44dc34fd471 Mon Sep 17 00:00:00 2001 From: Shaikhul Islam Date: Fri, 6 Nov 2026 17:37:30 -0500 Subject: [PATCH 6/7] fix: hide automation mutations without request state HTTP mode now excludes repository automation writes when the multi-round-trip request-state key is unavailable, matching the protected confirmation flow. Document the key requirement and cover inventory filtering. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- docs/streamable-http.md | 11 ++++++----- pkg/http/handler.go | 13 +++++++++++-- pkg/http/handler_test.go | 16 +++++++++++----- pkg/http/server.go | 6 ++++-- pkg/http/server_test.go | 4 +++- 5 files changed, 35 insertions(+), 15 deletions(-) diff --git a/docs/streamable-http.md b/docs/streamable-http.md index d5fc8a5d0d..e0fb461ef2 100644 --- a/docs/streamable-http.md +++ b/docs/streamable-http.md @@ -48,11 +48,12 @@ github-mcp-server http --scope-challenge When `--scope-challenge` is enabled, requests with insufficient scopes receive a `403 Forbidden` response with a `WWW-Authenticate` header indicating the required scopes. -### Repository deletion and request-state encryption +### Multi-round-trip mutations and request-state encryption -The `delete_repository` tool uses multi-round-trip elicitation and carries its -confirmed target through client-held request state. To expose this tool in HTTP -mode, configure a stable 32-byte encryption key encoded with standard Base64: +The `delete_repository` and repository automation mutation tools use +multi-round-trip elicitation and carry the confirmed request through +client-held request state. To expose these tools in HTTP mode, configure a +stable 32-byte encryption key encoded with standard Base64: ```bash export GITHUB_MCP_SERVER_MRTR_STATE_KEY="$(openssl rand -base64 32 | tr -d '\n')" @@ -61,7 +62,7 @@ github-mcp-server http Use the same key on every replica that may handle a retry. Keep it secret and stable during deployments; changing it invalidates confirmations already in -flight. If the variable is absent, `delete_repository` is not exposed by the +flight. If the variable is absent, these mutation tools are not exposed by the HTTP server. If it is present but malformed, the server refuses to start. This self-hosted key is independent of keys used by the hosted remote server. diff --git a/pkg/http/handler.go b/pkg/http/handler.go index 25c02f254c..0ef087c74f 100644 --- a/pkg/http/handler.go +++ b/pkg/http/handler.go @@ -399,11 +399,20 @@ func buildStaticInventory(cfg *ServerConfig, t translations.TranslationHelperFun opts := []github.ToolOption{github.WithHost(hostType)} tools := github.AllTools(t, opts...) filterUnavailable := func(tools []inventory.ServerTool) []inventory.ServerTool { - if !cfg.disableDeleteRepository { + if !cfg.disableDeleteRepository && !cfg.disableAgentAutomationMutations { return tools } return slices.DeleteFunc(tools, func(tool inventory.ServerTool) bool { - return tool.Tool.Name == github.DeleteRepositoryToolName + if cfg.disableDeleteRepository && tool.Tool.Name == github.DeleteRepositoryToolName { + return true + } + if cfg.disableAgentAutomationMutations { + switch tool.Tool.Name { + case "create_automation", "update_automation", "delete_automation": + return true + } + } + return false }) } diff --git a/pkg/http/handler_test.go b/pkg/http/handler_test.go index 953a564da4..9217c85ec6 100644 --- a/pkg/http/handler_test.go +++ b/pkg/http/handler_test.go @@ -811,8 +811,11 @@ func TestStaticInventoryPreservesPerRequestFeatureVariants(t *testing.T) { })) } -func TestStaticInventoryDisablesOnlyDeleteRepository(t *testing.T) { - cfg := &ServerConfig{disableDeleteRepository: true} +func TestStaticInventoryDisablesUnprotectedMutationTools(t *testing.T) { + cfg := &ServerConfig{ + disableDeleteRepository: true, + disableAgentAutomationMutations: true, + } tools, _, _, err := buildStaticInventory(cfg, translations.NullTranslationHelper) require.NoError(t, err) @@ -821,13 +824,16 @@ func TestStaticInventoryDisablesOnlyDeleteRepository(t *testing.T) { names = append(names, tool.Tool.Name) } assert.NotContains(t, names, github.DeleteRepositoryToolName) + assert.NotContains(t, names, "create_automation") + assert.NotContains(t, names, "update_automation") + assert.NotContains(t, names, "delete_automation") assert.Contains(t, names, "actions_list", "non-default toolsets must remain available for per-request selection") } -func TestStaticInventoryKeepsExplicitDeleteRepositoryDisabled(t *testing.T) { +func TestStaticInventoryKeepsExplicitUnprotectedMutationToolsDisabled(t *testing.T) { cfg := &ServerConfig{ - EnabledTools: []string{github.DeleteRepositoryToolName}, - disableDeleteRepository: true, + EnabledTools: []string{"create_automation"}, + disableAgentAutomationMutations: true, } tools, _, _, err := buildStaticInventory(cfg, translations.NullTranslationHelper) require.NoError(t, err) diff --git a/pkg/http/server.go b/pkg/http/server.go index 08e76b48e7..320df45ef0 100644 --- a/pkg/http/server.go +++ b/pkg/http/server.go @@ -119,7 +119,8 @@ type ServerConfig struct { // the MCP endpoints. When zero, middleware.DefaultMaxRequestBodyBytes is used. MaxRequestBodyBytes int64 - disableDeleteRepository bool + disableDeleteRepository bool + disableAgentAutomationMutations bool } func RunHTTPServer(cfg ServerConfig) error { @@ -283,7 +284,8 @@ func resolveListenAddress(host string, port int) string { func configureRequestState(cfg *ServerConfig, logger *slog.Logger) (github.RequestStateSealer, error) { if cfg.MRTRStateKey == "" { cfg.disableDeleteRepository = true - logger.Warn("delete_repository disabled: request-state encryption key is not configured", "environmentVariable", MRTRStateKeyEnv) + cfg.disableAgentAutomationMutations = true + logger.Warn("multi-round-trip mutation tools disabled: request-state encryption key is not configured", "environmentVariable", MRTRStateKeyEnv) return nil, nil } sealer, err := requeststate.New(cfg.MRTRStateKey) diff --git a/pkg/http/server_test.go b/pkg/http/server_test.go index 60b0df0da3..1b1f170c82 100644 --- a/pkg/http/server_test.go +++ b/pkg/http/server_test.go @@ -517,12 +517,13 @@ func TestResolveListenAddress(t *testing.T) { func TestConfigureRequestState(t *testing.T) { logger := slog.New(slog.NewTextHandler(io.Discard, nil)) - t.Run("missing key disables delete repository", func(t *testing.T) { + t.Run("missing key disables protected mutation tools", func(t *testing.T) { cfg := &ServerConfig{} sealer, err := configureRequestState(cfg, logger) require.NoError(t, err) assert.Nil(t, sealer) assert.True(t, cfg.disableDeleteRepository) + assert.True(t, cfg.disableAgentAutomationMutations) }) t.Run("valid key configures sealer", func(t *testing.T) { @@ -533,6 +534,7 @@ func TestConfigureRequestState(t *testing.T) { require.NoError(t, err) require.NotNil(t, sealer) assert.False(t, cfg.disableDeleteRepository) + assert.False(t, cfg.disableAgentAutomationMutations) token, err := sealer.Seal(context.Background(), []byte("state")) require.NoError(t, err) From 701369eb7b017c524156f306efc779ca96db9d8b Mon Sep 17 00:00:00 2001 From: Andrew Georgiou Date: Sun, 15 Nov 2026 23:39:36 +0000 Subject: [PATCH 7/7] test: exempt automation write tools from skills catalog coverage The skills catalog now requires every registered tool to map to a bundled skill or carry an explicit exemption. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: f921ed41-2ec0-4075-a572-7692f9529b7e --- pkg/skills/catalog/availability_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/skills/catalog/availability_test.go b/pkg/skills/catalog/availability_test.go index fa8291c81b..248ad6c798 100644 --- a/pkg/skills/catalog/availability_test.go +++ b/pkg/skills/catalog/availability_test.go @@ -44,6 +44,8 @@ var toolCoverageExemptions = map[string]string{ "update_issue_comment": "Editing existing issue comments is outside the current authoring and backlog workflows.", // Copilot Automation tools are opt-in behind the agent_automations feature flag. + "create_automation": "Copilot Automation management is an opt-in, feature-flagged workflow not covered by the current catalog.", + "delete_automation": "Copilot Automation management is an opt-in, feature-flagged workflow not covered by the current catalog.", "get_automation": "Copilot Automation management is an opt-in, feature-flagged workflow not covered by the current catalog.", "get_automation_revision": "Copilot Automation management is an opt-in, feature-flagged workflow not covered by the current catalog.", "get_automations_configuration_for_repository": "Copilot Automation management is an opt-in, feature-flagged workflow not covered by the current catalog.", @@ -51,6 +53,7 @@ var toolCoverageExemptions = map[string]string{ "list_automations": "Copilot Automation management is an opt-in, feature-flagged workflow not covered by the current catalog.", "list_available_automation_tools": "Copilot Automation management is an opt-in, feature-flagged workflow not covered by the current catalog.", "list_available_automation_triggers": "Copilot Automation management is an opt-in, feature-flagged workflow not covered by the current catalog.", + "update_automation": "Copilot Automation management is an opt-in, feature-flagged workflow not covered by the current catalog.", } func TestCatalogToolRequirementsAreRegistered(t *testing.T) {