From caf2f7f0626545cd488f2481771e2f9b87acc9cd Mon Sep 17 00:00:00 2001 From: Shaikhul Islam Date: Fri, 6 Nov 2026 13:52:05 -0500 Subject: [PATCH 1/6] feat: add public agent automation run tool Starts a manual automation task through the repository-scoped REST endpoint and returns GitHub's accepted task response. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- docs/feature-flags.md | 8 +++ pkg/github/__toolsnaps__/run_automation.snap | 48 ++++++++++++++ pkg/github/agent_automations.go | 70 ++++++++++++++++++-- pkg/github/agent_automations_test.go | 62 +++++++++++++++++ pkg/github/tools.go | 1 + 5 files changed, 183 insertions(+), 6 deletions(-) create mode 100644 pkg/github/__toolsnaps__/run_automation.snap diff --git a/docs/feature-flags.md b/docs/feature-flags.md index 0740d1a9bd..d961d64af4 100644 --- a/docs/feature-flags.md +++ b/docs/feature-flags.md @@ -595,6 +595,14 @@ as output formatting) won't appear here. - `owner`: Repository owner (string, required) - `repo`: Repository name (string, required) +- **run_automation** - Run a repository automation + - **OAuth Challenge Scopes**: `repo` + - `automation_id`: The automation identifier. (string, required) + - `context`: Optional context for the automation run. (string, optional) + - `event`: The event to trigger. Only manual runs are supported. (string, required) + - `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) diff --git a/pkg/github/__toolsnaps__/run_automation.snap b/pkg/github/__toolsnaps__/run_automation.snap new file mode 100644 index 0000000000..8bc5ad3f18 --- /dev/null +++ b/pkg/github/__toolsnaps__/run_automation.snap @@ -0,0 +1,48 @@ +{ + "annotations": { + "destructiveHint": true, + "idempotentHint": false, + "readOnlyHint": false, + "title": "Run a repository automation" + }, + "description": "Start a manual run of a Copilot automation in a repository.", + "inputSchema": { + "properties": { + "automation_id": { + "description": "The automation identifier.", + "type": "string" + }, + "context": { + "description": "Optional context for the automation run.", + "type": "string" + }, + "event": { + "description": "The event to trigger. Only manual runs are supported.", + "enum": [ + "manual" + ], + "type": "string" + }, + "owner": { + "description": "Repository owner", + "type": "string" + }, + "repo": { + "description": "Repository name", + "type": "string" + } + }, + "required": [ + "owner", + "repo", + "automation_id", + "event" + ], + "type": "object" + }, + "name": "run_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 72c2f34bda..226bdd89e8 100644 --- a/pkg/github/agent_automations.go +++ b/pkg/github/agent_automations.go @@ -100,6 +100,14 @@ type DeleteAutomationInput struct { AutomationID string `json:"automation_id"` } +type RunAutomationInput struct { + Owner string `json:"owner"` + Repo string `json:"repo"` + AutomationID string `json:"automation_id"` + Event string `json:"event"` + Context *string `json:"context,omitempty"` +} + type agentAutomationRequest struct { method string path string @@ -182,17 +190,23 @@ func newAgentAutomationTool[Input any]( if request.noBody { responseTarget = nil } + successStatus := request.successStatus + if successStatus == 0 { + successStatus = http.StatusOK + } httpResponse, err := client.Do(httpRequest, responseTarget) if httpResponse != nil { defer func() { _ = httpResponse.Body.Close() }() } + if httpResponse != nil && httpResponse.StatusCode == http.StatusAccepted && successStatus == http.StatusAccepted { + if acceptedError, ok := errors.AsType[*github.AcceptedError](err); ok { + response = acceptedError.Raw + err = nil + } + } if err != nil { return ghErrors.NewGitHubAPIErrorResponse(ctx, "failed to access GitHub agent automations", httpResponse, err), nil, nil } - 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 } @@ -202,8 +216,9 @@ func newAgentAutomationTool[Input any]( if err != nil { return utils.NewToolResultErrorFromErr("failed to marshal success response", err), nil, err } - } else if len(response) == 0 { - response = json.RawMessage(`{}`) + } + if len(response) == 0 { + return utils.NewToolResultError("GitHub agent automations returned an empty response"), nil, nil } sanitizedResponse, err := sanitizeAutomationNames(response) if err != nil { @@ -880,3 +895,46 @@ func DeleteAutomation(t translations.TranslationHelperFunc) inventory.ServerTool }, )) } + +func RunAutomation(t translations.TranslationHelperFunc) inventory.ServerTool { + return newAgentAutomationTool[RunAutomationInput]( + t, + "run_automation", + "Run a repository automation", + "Start a manual run of a Copilot automation in a repository.", + agentAutomationInputSchema(map[string]*jsonschema.Schema{ + "owner": automationStringProperty(DescriptionRepositoryOwner), + "repo": automationStringProperty(DescriptionRepositoryName), + "automation_id": automationStringProperty("The automation identifier."), + "event": { + Type: "string", + Description: "The event to trigger. Only manual runs are supported.", + Enum: []any{"manual"}, + }, + "context": automationStringProperty("Optional context for the automation run."), + }, "owner", "repo", "automation_id", "event"), + agentAutomationObjectOutputSchema(), + mcp.ToolAnnotations{DestructiveHint: new(true)}, + func(args RunAutomationInput) (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") + } + if args.Event != "manual" { + return agentAutomationRequest{}, errors.New("event must be manual") + } + body := map[string]any{"event": args.Event} + if args.Context != nil { + body["context"] = *args.Context + } + return agentAutomationRequest{ + method: http.MethodPost, + path: automationPath(args.Owner, args.Repo, url.PathEscape(args.AutomationID)+"/tasks"), + body: body, + successStatus: http.StatusAccepted, + }, nil + }, + ) +} diff --git a/pkg/github/agent_automations_test.go b/pkg/github/agent_automations_test.go index d2d4ca225e..265cd521e2 100644 --- a/pkg/github/agent_automations_test.go +++ b/pkg/github/agent_automations_test.go @@ -30,6 +30,7 @@ func agentAutomationToolsForTest() []inventory.ServerTool { CreateAutomation(t), UpdateAutomation(t), DeleteAutomation(t), + RunAutomation(t), } } @@ -590,6 +591,67 @@ func TestAgentAutomationWriteToolsRejectUnsafePathSegments(t *testing.T) { } } +func TestRunAutomation(t *testing.T) { + t.Parallel() + + tool := RunAutomation(translations.NullTranslationHelper) + httpClient := MockHTTPClientWithHandler(func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, http.MethodPost, r.Method) + assert.Equal(t, "/agents/repos/octo-org/octo-repo/automations/automation-id/tasks", r.URL.Path) + assert.Equal(t, agentAutomationAPIVersion, r.Header.Get("X-GitHub-Api-Version")) + body, err := io.ReadAll(r.Body) + require.NoError(t, err) + assert.JSONEq(t, `{"event":"manual","context":"Please focus on recently opened issues."}`, string(body)) + w.WriteHeader(http.StatusAccepted) + _, _ = w.Write([]byte(`{"task_id":"task-id","automation_id":"automation-id","event":"manual"}`)) + }) + deps := BaseDeps{Client: mustNewGHClient(t, httpClient)} + request := createMCPRequest(map[string]any{ + "owner": "octo-org", "repo": "octo-repo", "automation_id": "automation-id", + "event": "manual", "context": "Please focus on recently opened issues.", + }) + result, err := tool.Handler(nil)(ContextWithDeps(context.Background(), deps), &request) + require.NoError(t, err) + if result.IsError { + t.Fatal(getErrorResult(t, result).Text) + } + assert.JSONEq(t, `{"task_id":"task-id","automation_id":"automation-id","event":"manual"}`, getTextResult(t, result).Text) +} + +func TestRunAutomationRejectsUnsupportedEvents(t *testing.T) { + t.Parallel() + + tool := RunAutomation(translations.NullTranslationHelper) + httpClient := MockHTTPClientWithHandler(func(http.ResponseWriter, *http.Request) { + t.Fatal("unsupported event should not make a request") + }) + deps := BaseDeps{Client: mustNewGHClient(t, httpClient)} + request := createMCPRequest(map[string]any{ + "owner": "octo-org", "repo": "octo-repo", "automation_id": "automation-id", "event": "interval", + }) + result, err := tool.Handler(nil)(ContextWithDeps(context.Background(), deps), &request) + require.NoError(t, err) + require.True(t, result.IsError) + assert.Contains(t, getErrorResult(t, result).Text, "event must be manual") +} + +func TestRunAutomationRejectsEmptyAcceptedResponse(t *testing.T) { + t.Parallel() + + tool := RunAutomation(translations.NullTranslationHelper) + httpClient := MockHTTPClientWithHandler(func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusAccepted) + }) + deps := BaseDeps{Client: mustNewGHClient(t, httpClient)} + request := createMCPRequest(map[string]any{ + "owner": "octo-org", "repo": "octo-repo", "automation_id": "automation-id", "event": "manual", + }) + result, err := tool.Handler(nil)(ContextWithDeps(context.Background(), deps), &request) + require.NoError(t, err) + require.True(t, result.IsError) + assert.Contains(t, getErrorResult(t, result).Text, "returned an empty response") +} + func TestDeleteAutomationRequiresRequestStateProtection(t *testing.T) { t.Parallel() diff --git a/pkg/github/tools.go b/pkg/github/tools.go index 60a5084e97..8a640b9eb8 100644 --- a/pkg/github/tools.go +++ b/pkg/github/tools.go @@ -312,6 +312,7 @@ func AllTools(t translations.TranslationHelperFunc, opts ...ToolOption) []invent CreateAutomation(t), UpdateAutomation(t), DeleteAutomation(t), + RunAutomation(t), // Copilot issue intents (non-default, opt-in) AssignCopilotToIssueWithIntent(t), From 378a2a859393f26f384071818c8deb1c2632ee2a Mon Sep 17 00:00:00 2001 From: Shaikhul Islam Date: Fri, 6 Nov 2026 16:32:30 -0500 Subject: [PATCH 2/6] fix: require confirmation before running automations Show the target and supplied context in MCP form elicitation, bind approval to the exact run request, and enforce the public API context length limit before submitting the task. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- docs/feature-flags.md | 2 +- pkg/github/__toolsnaps__/run_automation.snap | 5 +- pkg/github/agent_automations.go | 29 +++++- pkg/github/agent_automations_test.go | 93 ++++++++++++++++++-- 4 files changed, 116 insertions(+), 13 deletions(-) diff --git a/docs/feature-flags.md b/docs/feature-flags.md index d961d64af4..c7dcb30e7a 100644 --- a/docs/feature-flags.md +++ b/docs/feature-flags.md @@ -598,7 +598,7 @@ as output formatting) won't appear here. - **run_automation** - Run a repository automation - **OAuth Challenge Scopes**: `repo` - `automation_id`: The automation identifier. (string, required) - - `context`: Optional context for the automation run. (string, optional) + - `context`: Optional context for the automation run, up to 10,000 characters. (string, optional) - `event`: The event to trigger. Only manual runs are supported. (string, required) - `owner`: Repository owner (string, required) - `repo`: Repository name (string, required) diff --git a/pkg/github/__toolsnaps__/run_automation.snap b/pkg/github/__toolsnaps__/run_automation.snap index 8bc5ad3f18..5be2b1761e 100644 --- a/pkg/github/__toolsnaps__/run_automation.snap +++ b/pkg/github/__toolsnaps__/run_automation.snap @@ -5,7 +5,7 @@ "readOnlyHint": false, "title": "Run a repository automation" }, - "description": "Start a manual run of a Copilot automation in a repository.", + "description": "Start a manual run of a Copilot automation in a repository after explicit user confirmation.", "inputSchema": { "properties": { "automation_id": { @@ -13,7 +13,8 @@ "type": "string" }, "context": { - "description": "Optional context for the automation run.", + "description": "Optional context for the automation run, up to 10,000 characters.", + "maxLength": 10000, "type": "string" }, "event": { diff --git a/pkg/github/agent_automations.go b/pkg/github/agent_automations.go index 226bdd89e8..85e5759aeb 100644 --- a/pkg/github/agent_automations.go +++ b/pkg/github/agent_automations.go @@ -13,6 +13,7 @@ import ( "strconv" "strings" "time" + "unicode/utf8" ghErrors "github.com/github/github-mcp-server/v2/pkg/errors" "github.com/github/github-mcp-server/v2/pkg/inventory" @@ -29,6 +30,7 @@ const agentAutomationAPIVersion = "2026-03-10" const agentAutomationConfirmationIDPrefix = "agent_automation_confirmation_" const agentAutomationConfirmationField = "confirmation" const agentAutomationConfirmationTTL = 10 * time.Minute +const maxAutomationRunContextLength = 10000 type ListAutomationsInput struct { Owner string `json:"owner"` @@ -897,11 +899,11 @@ func DeleteAutomation(t translations.TranslationHelperFunc) inventory.ServerTool } func RunAutomation(t translations.TranslationHelperFunc) inventory.ServerTool { - return newAgentAutomationTool[RunAutomationInput]( + return agentAutomationConfirmationRequired(newAgentAutomationTool[RunAutomationInput]( t, "run_automation", "Run a repository automation", - "Start a manual run of a Copilot automation in a repository.", + "Start a manual run of a Copilot automation in a repository after explicit user confirmation.", agentAutomationInputSchema(map[string]*jsonschema.Schema{ "owner": automationStringProperty(DescriptionRepositoryOwner), "repo": automationStringProperty(DescriptionRepositoryName), @@ -911,7 +913,11 @@ func RunAutomation(t translations.TranslationHelperFunc) inventory.ServerTool { Description: "The event to trigger. Only manual runs are supported.", Enum: []any{"manual"}, }, - "context": automationStringProperty("Optional context for the automation run."), + "context": { + Type: "string", + Description: "Optional context for the automation run, up to 10,000 characters.", + MaxLength: new(maxAutomationRunContextLength), + }, }, "owner", "repo", "automation_id", "event"), agentAutomationObjectOutputSchema(), mcp.ToolAnnotations{DestructiveHint: new(true)}, @@ -925,16 +931,31 @@ func RunAutomation(t translations.TranslationHelperFunc) inventory.ServerTool { if args.Event != "manual" { return agentAutomationRequest{}, errors.New("event must be manual") } + if args.Context != nil && (!utf8.ValidString(*args.Context) || utf8.RuneCountInString(*args.Context) > maxAutomationRunContextLength) { + return agentAutomationRequest{}, fmt.Errorf("context must be valid UTF-8 and no more than %d characters", maxAutomationRunContextLength) + } body := map[string]any{"event": args.Event} if args.Context != nil { body["context"] = *args.Context } + target := args.Owner + "/" + args.Repo + "/" + args.AutomationID + message := fmt.Sprintf("Review the automation run request for %s.", target) + if args.Context != nil { + message += "\nContext to be sent: " + *args.Context + } + confirmationValue := "RUN " + target + message += fmt.Sprintf("\nType %q to start this run.", confirmationValue) return agentAutomationRequest{ method: http.MethodPost, path: automationPath(args.Owner, args.Repo, url.PathEscape(args.AutomationID)+"/tasks"), body: body, successStatus: http.StatusAccepted, + confirmation: &agentAutomationConfirmation{ + id: agentAutomationConfirmationIDPrefix + "run", + value: confirmationValue, + message: message, + }, }, nil }, - ) + )) } diff --git a/pkg/github/agent_automations_test.go b/pkg/github/agent_automations_test.go index 265cd521e2..0621504eb5 100644 --- a/pkg/github/agent_automations_test.go +++ b/pkg/github/agent_automations_test.go @@ -5,6 +5,7 @@ import ( "encoding/json" "io" "net/http" + "strings" "testing" "github.com/github/github-mcp-server/v2/internal/requeststate" @@ -606,12 +607,13 @@ func TestRunAutomation(t *testing.T) { _, _ = w.Write([]byte(`{"task_id":"task-id","automation_id":"automation-id","event":"manual"}`)) }) deps := BaseDeps{Client: mustNewGHClient(t, httpClient)} - request := createMCPRequest(map[string]any{ + sealer, err := requeststate.NewRandom() + require.NoError(t, err) + deps.StateSealer = sealer + result := invokeConfirmedAutomation(t, tool, deps, map[string]any{ "owner": "octo-org", "repo": "octo-repo", "automation_id": "automation-id", "event": "manual", "context": "Please focus on recently opened issues.", - }) - result, err := tool.Handler(nil)(ContextWithDeps(context.Background(), deps), &request) - require.NoError(t, err) + }, agentAutomationConfirmationIDPrefix+"run", "RUN octo-org/octo-repo/automation-id", "Please focus on recently opened issues.") if result.IsError { t.Fatal(getErrorResult(t, result).Text) } @@ -643,13 +645,91 @@ func TestRunAutomationRejectsEmptyAcceptedResponse(t *testing.T) { w.WriteHeader(http.StatusAccepted) }) deps := BaseDeps{Client: mustNewGHClient(t, httpClient)} - request := createMCPRequest(map[string]any{ + sealer, err := requeststate.NewRandom() + require.NoError(t, err) + deps.StateSealer = sealer + result := invokeConfirmedAutomation(t, tool, deps, map[string]any{ "owner": "octo-org", "repo": "octo-repo", "automation_id": "automation-id", "event": "manual", + }, agentAutomationConfirmationIDPrefix+"run", "RUN octo-org/octo-repo/automation-id") + require.True(t, result.IsError) + assert.Contains(t, getErrorResult(t, result).Text, "returned an empty response") +} + +func TestRunAutomationRejectsOversizedContext(t *testing.T) { + t.Parallel() + + tool := RunAutomation(translations.NullTranslationHelper) + httpClient := MockHTTPClientWithHandler(func(http.ResponseWriter, *http.Request) { + t.Fatal("oversized context should not make a request") + }) + deps := BaseDeps{Client: mustNewGHClient(t, httpClient)} + request := createMCPRequest(map[string]any{ + "owner": "octo-org", "repo": "octo-repo", "automation_id": "automation-id", + "event": "manual", "context": strings.Repeat("x", maxAutomationRunContextLength+1), }) result, err := tool.Handler(nil)(ContextWithDeps(context.Background(), deps), &request) require.NoError(t, err) require.True(t, result.IsError) - assert.Contains(t, getErrorResult(t, result).Text, "returned an empty response") + assert.Contains(t, getErrorResult(t, result).Text, "no more than 10000 characters") +} + +func TestRunAutomationConfirmationBindsRequest(t *testing.T) { + t.Parallel() + + tool := RunAutomation(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", + "event": "manual", "context": "Please focus on recently opened issues.", + } + handler := tool.Handler(deps) + request := createMCPRequest(args) + result, err := handler(ContextWithDeps(context.Background(), deps), &request) + require.NoError(t, err) + require.NotNil(t, result) + require.Contains(t, result.InputRequests, agentAutomationConfirmationIDPrefix+"run") + + args["context"] = "Run against a different set of issues." + retry := createMCPRequest(args) + retry.Params.RequestState = result.RequestState + retry.Params.InputResponses = mcp.InputResponseMap{ + agentAutomationConfirmationIDPrefix + "run": &mcp.ElicitResult{ + Action: "accept", + Content: map[string]any{ + agentAutomationConfirmationField: "RUN octo-org/octo-repo/automation-id", + }, + }, + } + result, err = handler(ContextWithDeps(context.Background(), deps), &retry) + require.NoError(t, err) + require.True(t, result.IsError) + assert.Contains(t, getErrorResult(t, result).Text, "changed after confirmation") + assert.Zero(t, requestCount) +} + +func TestRunAutomationRequiresRequestStateProtection(t *testing.T) { + t.Parallel() + + tool := RunAutomation(translations.NullTranslationHelper) + httpClient := MockHTTPClientWithHandler(func(http.ResponseWriter, *http.Request) { + t.Fatal("run 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", "event": "manual", + }) + 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 TestDeleteAutomationRequiresRequestStateProtection(t *testing.T) { @@ -748,6 +828,7 @@ func TestAutomationMutationsRequireFormElicitation(t *testing.T) { CreateAutomation(translations.NullTranslationHelper), UpdateAutomation(translations.NullTranslationHelper), DeleteAutomation(translations.NullTranslationHelper), + RunAutomation(translations.NullTranslationHelper), } { assert.Equal(t, inventory.ProtocolVersionMultiRoundTrip, tool.MinimumProtocolVersion) assert.Equal(t, inventory.ElicitationModeForm, tool.RequiredElicitationMode) From 8baab933aca042012f336c01970c173b2eb28e19 Mon Sep 17 00:00:00 2001 From: Shaikhul Islam Date: Fri, 6 Nov 2026 16:51:39 -0500 Subject: [PATCH 3/6] fix: omit run context from confirmation text Keep caller-controlled run context out of the MCP confirmation message while preserving the original task request. Show only its character count so untrusted instructions are not echoed into the approval prompt. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- pkg/github/agent_automations.go | 4 ++-- pkg/github/agent_automations_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/github/agent_automations.go b/pkg/github/agent_automations.go index 85e5759aeb..63b3c431cd 100644 --- a/pkg/github/agent_automations.go +++ b/pkg/github/agent_automations.go @@ -938,10 +938,10 @@ func RunAutomation(t translations.TranslationHelperFunc) inventory.ServerTool { if args.Context != nil { body["context"] = *args.Context } - target := args.Owner + "/" + args.Repo + "/" + args.AutomationID + target := agentAutomationTarget(args.Owner, args.Repo, args.AutomationID) message := fmt.Sprintf("Review the automation run request for %s.", target) if args.Context != nil { - message += "\nContext to be sent: " + *args.Context + message += fmt.Sprintf("\nA run context is included (%d characters).", utf8.RuneCountInString(*args.Context)) } confirmationValue := "RUN " + target message += fmt.Sprintf("\nType %q to start this run.", confirmationValue) diff --git a/pkg/github/agent_automations_test.go b/pkg/github/agent_automations_test.go index 0621504eb5..e0553fdedd 100644 --- a/pkg/github/agent_automations_test.go +++ b/pkg/github/agent_automations_test.go @@ -613,7 +613,7 @@ func TestRunAutomation(t *testing.T) { result := invokeConfirmedAutomation(t, tool, deps, map[string]any{ "owner": "octo-org", "repo": "octo-repo", "automation_id": "automation-id", "event": "manual", "context": "Please focus on recently opened issues.", - }, agentAutomationConfirmationIDPrefix+"run", "RUN octo-org/octo-repo/automation-id", "Please focus on recently opened issues.") + }, agentAutomationConfirmationIDPrefix+"run", "RUN octo-org/octo-repo/automation-id", []string{"39 characters"}, []string{"Please focus on recently opened issues."}) if result.IsError { t.Fatal(getErrorResult(t, result).Text) } @@ -650,7 +650,7 @@ func TestRunAutomationRejectsEmptyAcceptedResponse(t *testing.T) { deps.StateSealer = sealer result := invokeConfirmedAutomation(t, tool, deps, map[string]any{ "owner": "octo-org", "repo": "octo-repo", "automation_id": "automation-id", "event": "manual", - }, agentAutomationConfirmationIDPrefix+"run", "RUN octo-org/octo-repo/automation-id") + }, agentAutomationConfirmationIDPrefix+"run", "RUN octo-org/octo-repo/automation-id", nil, nil) require.True(t, result.IsError) assert.Contains(t, getErrorResult(t, result).Text, "returned an empty response") } From e93df005f9c3c22969a89ebf93bc3417b0d924b2 Mon Sep 17 00:00:00 2001 From: Shaikhul Islam Date: Fri, 6 Nov 2026 17:32:23 -0500 Subject: [PATCH 4/6] fix: validate automation run targets Reject invalid and reserved path segments before requesting run confirmation. If the task endpoint accepts a request but returns no task body, report the HTTP status and advise verifying the outcome before retrying. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- pkg/github/agent_automations.go | 7 +++-- pkg/github/agent_automations_test.go | 43 +++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/pkg/github/agent_automations.go b/pkg/github/agent_automations.go index 63b3c431cd..df0bdcd478 100644 --- a/pkg/github/agent_automations.go +++ b/pkg/github/agent_automations.go @@ -220,6 +220,9 @@ func newAgentAutomationTool[Input any]( } } if len(response) == 0 { + if request.method != http.MethodGet { + return utils.NewToolResultError(fmt.Sprintf("GitHub agent automations returned an empty response after HTTP %d; the operation may have succeeded. Verify its status before retrying.", httpResponse.StatusCode)), nil, nil + } return utils.NewToolResultError("GitHub agent automations returned an empty response"), nil, nil } sanitizedResponse, err := sanitizeAutomationNames(response) @@ -925,8 +928,8 @@ func RunAutomation(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 } if args.Event != "manual" { return agentAutomationRequest{}, errors.New("event must be manual") diff --git a/pkg/github/agent_automations_test.go b/pkg/github/agent_automations_test.go index e0553fdedd..71359d5c72 100644 --- a/pkg/github/agent_automations_test.go +++ b/pkg/github/agent_automations_test.go @@ -652,7 +652,48 @@ func TestRunAutomationRejectsEmptyAcceptedResponse(t *testing.T) { "owner": "octo-org", "repo": "octo-repo", "automation_id": "automation-id", "event": "manual", }, agentAutomationConfirmationIDPrefix+"run", "RUN octo-org/octo-repo/automation-id", nil, nil) require.True(t, result.IsError) - assert.Contains(t, getErrorResult(t, result).Text, "returned an empty response") + assert.Contains(t, getErrorResult(t, result).Text, "empty response after HTTP 202") + assert.Contains(t, getErrorResult(t, result).Text, "may have succeeded") + assert.Contains(t, getErrorResult(t, result).Text, "Verify its status before retrying") +} + +func TestRunAutomationRejectsUnsafePathSegments(t *testing.T) { + t.Parallel() + + for _, tc := range []struct { + name string + args map[string]any + }{ + { + name: "dot owner", + args: map[string]any{"owner": ".", "repo": "octo-repo", "automation_id": "automation-id", "event": "manual"}, + }, + { + name: "dot-dot repo", + args: map[string]any{"owner": "octo-org", "repo": "..", "automation_id": "automation-id", "event": "manual"}, + }, + { + name: "dot automation ID", + args: map[string]any{"owner": "octo-org", "repo": "octo-repo", "automation_id": ".", "event": "manual"}, + }, + { + name: "reserved automation ID", + args: map[string]any{"owner": "octo-org", "repo": "octo-repo", "automation_id": "revisions", "event": "manual"}, + }, + } { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + tool := RunAutomation(translations.NullTranslationHelper) + 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 := tool.Handler(deps)(ContextWithDeps(context.Background(), deps), &request) + require.NoError(t, err) + require.True(t, result.IsError) + }) + } } func TestRunAutomationRejectsOversizedContext(t *testing.T) { From cb1faeb9dcf8b29cfa7c31afcc960535882a1a26 Mon Sep 17 00:00:00 2001 From: Shaikhul Islam Date: Fri, 6 Nov 2026 17:40:11 -0500 Subject: [PATCH 5/6] fix: require request state for automation runs Hide run_automation in HTTP mode when multi-round-trip request-state protection is unavailable, alongside the automation management mutations. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- pkg/http/handler.go | 2 +- pkg/http/handler_test.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/http/handler.go b/pkg/http/handler.go index 0ef087c74f..f1607bdf95 100644 --- a/pkg/http/handler.go +++ b/pkg/http/handler.go @@ -408,7 +408,7 @@ func buildStaticInventory(cfg *ServerConfig, t translations.TranslationHelperFun } if cfg.disableAgentAutomationMutations { switch tool.Tool.Name { - case "create_automation", "update_automation", "delete_automation": + case "create_automation", "update_automation", "delete_automation", "run_automation": return true } } diff --git a/pkg/http/handler_test.go b/pkg/http/handler_test.go index 9217c85ec6..6c91df7f0b 100644 --- a/pkg/http/handler_test.go +++ b/pkg/http/handler_test.go @@ -827,6 +827,7 @@ func TestStaticInventoryDisablesUnprotectedMutationTools(t *testing.T) { assert.NotContains(t, names, "create_automation") assert.NotContains(t, names, "update_automation") assert.NotContains(t, names, "delete_automation") + assert.NotContains(t, names, "run_automation") assert.Contains(t, names, "actions_list", "non-default toolsets must remain available for per-request selection") } From 53613704dbcb14625589a3ef57a058dde0cf9d75 Mon Sep 17 00:00:00 2001 From: Andrew Georgiou Date: Sun, 15 Nov 2026 23:39:36 +0000 Subject: [PATCH 6/6] test: exempt automation run tool 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 | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/skills/catalog/availability_test.go b/pkg/skills/catalog/availability_test.go index 248ad6c798..4e60f3561d 100644 --- a/pkg/skills/catalog/availability_test.go +++ b/pkg/skills/catalog/availability_test.go @@ -53,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.", + "run_automation": "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.", }