From 3001c6f1e8660fa93c08641c206e758b311102cd Mon Sep 17 00:00:00 2001 From: Shaikhul Islam Date: Fri, 6 Nov 2026 13:05:20 -0500 Subject: [PATCH 01/19] feat: add public agent automation read tools Expose repository automation and revision reads plus the repository-scoped tool and trigger catalogs through the public REST API. Pin requests to the documented API version so these preview endpoints receive their published schemas. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- README.md | 39 ++ pkg/github/__toolsnaps__/get_automation.snap | 35 ++ .../get_automation_revision.snap | 40 ++ .../list_automation_revisions.snap | 45 +++ .../__toolsnaps__/list_automations.snap | 49 +++ .../list_available_automation_tools.snap | 30 ++ .../list_available_automation_triggers.snap | 33 ++ pkg/github/agent_automations.go | 352 ++++++++++++++++++ pkg/github/agent_automations_test.go | 134 +++++++ pkg/github/tools.go | 6 + 10 files changed, 763 insertions(+) create mode 100644 pkg/github/__toolsnaps__/get_automation.snap create mode 100644 pkg/github/__toolsnaps__/get_automation_revision.snap create mode 100644 pkg/github/__toolsnaps__/list_automation_revisions.snap create mode 100644 pkg/github/__toolsnaps__/list_automations.snap create mode 100644 pkg/github/__toolsnaps__/list_available_automation_tools.snap create mode 100644 pkg/github/__toolsnaps__/list_available_automation_triggers.snap create mode 100644 pkg/github/agent_automations.go create mode 100644 pkg/github/agent_automations_test.go diff --git a/README.md b/README.md index 1f297f7dd4..bc5dd143db 100644 --- a/README.md +++ b/README.md @@ -794,6 +794,45 @@ For negotiated supported protocol versions `2026-07-28` or newer, the consolidat - `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) + - `owner`: Repository owner (string, required) + - `repo`: Repository name (string, required) + +- **get_automation_revision** - Get an automation revision + - **OAuth Challenge Scopes**: `repo` + - `automation_id`: The automation identifier. (string, required) + - `owner`: Repository owner (string, required) + - `repo`: Repository name (string, required) + - `revision_id`: The revision identifier. (string, required) + +- **list_automation_revisions** - List automation revisions + - **OAuth Challenge Scopes**: `repo` + - `automation_id`: The automation identifier. (string, required) + - `cursor`: Opaque pagination cursor. (string, optional) + - `owner`: Repository owner (string, required) + - `perPage`: Results per page, from 1 to 100. (integer, optional) + - `repo`: Repository name (string, required) + +- **list_automations** - List repository automations + - **OAuth Challenge Scopes**: `repo` + - `owner`: Repository owner (string, required) + - `page`: Page number, starting at 1. (integer, optional) + - `perPage`: Results per page, from 1 to 100. (integer, optional) + - `repo`: Repository name (string, required) + - `type`: Filter automations by type. (string, optional) + +- **list_available_automation_tools** - List available automation tools + - **OAuth Challenge Scopes**: `repo` + - `owner`: Repository owner (string, required) + - `repo`: Repository name (string, required) + +- **list_available_automation_triggers** - List available automation triggers + - **OAuth Challenge Scopes**: `repo` + - `owner`: Repository owner (string, required) + - `repo`: Repository name (string, required) + - **request_copilot_review** - Request Copilot review - **OAuth Challenge Scopes**: `repo` - `owner`: Repository owner (string, required) diff --git a/pkg/github/__toolsnaps__/get_automation.snap b/pkg/github/__toolsnaps__/get_automation.snap new file mode 100644 index 0000000000..225e12b86a --- /dev/null +++ b/pkg/github/__toolsnaps__/get_automation.snap @@ -0,0 +1,35 @@ +{ + "annotations": { + "idempotentHint": false, + "readOnlyHint": true, + "title": "Get a repository automation" + }, + "description": "Get the configuration of a Copilot automation in 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": "get_automation", + "outputSchema": { + "additionalProperties": true, + "type": "object" + } +} \ No newline at end of file diff --git a/pkg/github/__toolsnaps__/get_automation_revision.snap b/pkg/github/__toolsnaps__/get_automation_revision.snap new file mode 100644 index 0000000000..e95fee3627 --- /dev/null +++ b/pkg/github/__toolsnaps__/get_automation_revision.snap @@ -0,0 +1,40 @@ +{ + "annotations": { + "idempotentHint": false, + "readOnlyHint": true, + "title": "Get an automation revision" + }, + "description": "Get a specific saved revision of a Copilot automation.", + "inputSchema": { + "properties": { + "automation_id": { + "description": "The automation identifier.", + "type": "string" + }, + "owner": { + "description": "Repository owner", + "type": "string" + }, + "repo": { + "description": "Repository name", + "type": "string" + }, + "revision_id": { + "description": "The revision identifier.", + "type": "string" + } + }, + "required": [ + "owner", + "repo", + "automation_id", + "revision_id" + ], + "type": "object" + }, + "name": "get_automation_revision", + "outputSchema": { + "additionalProperties": true, + "type": "object" + } +} \ No newline at end of file diff --git a/pkg/github/__toolsnaps__/list_automation_revisions.snap b/pkg/github/__toolsnaps__/list_automation_revisions.snap new file mode 100644 index 0000000000..d236f02c06 --- /dev/null +++ b/pkg/github/__toolsnaps__/list_automation_revisions.snap @@ -0,0 +1,45 @@ +{ + "annotations": { + "idempotentHint": false, + "readOnlyHint": true, + "title": "List automation revisions" + }, + "description": "List the saved revisions of a Copilot automation.", + "inputSchema": { + "properties": { + "automation_id": { + "description": "The automation identifier.", + "type": "string" + }, + "cursor": { + "description": "Opaque pagination cursor.", + "type": "string" + }, + "owner": { + "description": "Repository owner", + "type": "string" + }, + "perPage": { + "description": "Results per page, from 1 to 100.", + "maximum": 100, + "minimum": 1, + "type": "integer" + }, + "repo": { + "description": "Repository name", + "type": "string" + } + }, + "required": [ + "owner", + "repo", + "automation_id" + ], + "type": "object" + }, + "name": "list_automation_revisions", + "outputSchema": { + "additionalProperties": true, + "type": "object" + } +} \ No newline at end of file diff --git a/pkg/github/__toolsnaps__/list_automations.snap b/pkg/github/__toolsnaps__/list_automations.snap new file mode 100644 index 0000000000..0af1e21492 --- /dev/null +++ b/pkg/github/__toolsnaps__/list_automations.snap @@ -0,0 +1,49 @@ +{ + "annotations": { + "idempotentHint": false, + "readOnlyHint": true, + "title": "List repository automations" + }, + "description": "List Copilot automations for a repository.", + "inputSchema": { + "properties": { + "owner": { + "description": "Repository owner", + "type": "string" + }, + "page": { + "description": "Page number, starting at 1.", + "minimum": 1, + "type": "integer" + }, + "perPage": { + "description": "Results per page, from 1 to 100.", + "maximum": 100, + "minimum": 1, + "type": "integer" + }, + "repo": { + "description": "Repository name", + "type": "string" + }, + "type": { + "description": "Filter automations by type.", + "enum": [ + "personal", + "shared" + ], + "type": "string" + } + }, + "required": [ + "owner", + "repo" + ], + "type": "object" + }, + "name": "list_automations", + "outputSchema": { + "additionalProperties": true, + "type": "object" + } +} \ No newline at end of file diff --git a/pkg/github/__toolsnaps__/list_available_automation_tools.snap b/pkg/github/__toolsnaps__/list_available_automation_tools.snap new file mode 100644 index 0000000000..3308b48076 --- /dev/null +++ b/pkg/github/__toolsnaps__/list_available_automation_tools.snap @@ -0,0 +1,30 @@ +{ + "annotations": { + "idempotentHint": false, + "readOnlyHint": true, + "title": "List available automation tools" + }, + "description": "List the tools that can be used by automations in a repository.", + "inputSchema": { + "properties": { + "owner": { + "description": "Repository owner", + "type": "string" + }, + "repo": { + "description": "Repository name", + "type": "string" + } + }, + "required": [ + "owner", + "repo" + ], + "type": "object" + }, + "name": "list_available_automation_tools", + "outputSchema": { + "additionalProperties": true, + "type": "object" + } +} \ No newline at end of file diff --git a/pkg/github/__toolsnaps__/list_available_automation_triggers.snap b/pkg/github/__toolsnaps__/list_available_automation_triggers.snap new file mode 100644 index 0000000000..ed6b211e1c --- /dev/null +++ b/pkg/github/__toolsnaps__/list_available_automation_triggers.snap @@ -0,0 +1,33 @@ +{ + "annotations": { + "idempotentHint": false, + "readOnlyHint": true, + "title": "List available automation triggers" + }, + "description": "List the trigger types that can be used by automations in a repository.", + "inputSchema": { + "properties": { + "owner": { + "description": "Repository owner", + "type": "string" + }, + "repo": { + "description": "Repository name", + "type": "string" + } + }, + "required": [ + "owner", + "repo" + ], + "type": "object" + }, + "name": "list_available_automation_triggers", + "outputSchema": { + "items": { + "additionalProperties": true, + "type": "object" + }, + "type": "array" + } +} \ No newline at end of file diff --git a/pkg/github/agent_automations.go b/pkg/github/agent_automations.go new file mode 100644 index 0000000000..eb27a0cc5d --- /dev/null +++ b/pkg/github/agent_automations.go @@ -0,0 +1,352 @@ +package github + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "net/http" + "net/url" + "strconv" + + ghErrors "github.com/github/github-mcp-server/v2/pkg/errors" + "github.com/github/github-mcp-server/v2/pkg/inventory" + "github.com/github/github-mcp-server/v2/pkg/scopes" + "github.com/github/github-mcp-server/v2/pkg/translations" + "github.com/github/github-mcp-server/v2/pkg/utils" + "github.com/google/go-github/v92/github" + "github.com/google/jsonschema-go/jsonschema" + "github.com/modelcontextprotocol/go-sdk/mcp" +) + +const agentAutomationAPIVersion = "2026-03-10" + +type ListAutomationsInput struct { + Owner string `json:"owner"` + Repo string `json:"repo"` + Page int `json:"page,omitempty"` + PerPage int `json:"perPage,omitempty"` + Type string `json:"type,omitempty"` +} + +type GetAutomationInput struct { + Owner string `json:"owner"` + Repo string `json:"repo"` + AutomationID string `json:"automation_id"` +} + +type ListAutomationRevisionsInput struct { + Owner string `json:"owner"` + Repo string `json:"repo"` + AutomationID string `json:"automation_id"` + Cursor string `json:"cursor,omitempty"` + PerPage int `json:"perPage,omitempty"` +} + +type GetAutomationRevisionInput struct { + Owner string `json:"owner"` + Repo string `json:"repo"` + AutomationID string `json:"automation_id"` + RevisionID string `json:"revision_id"` +} + +type AutomationCatalogInput struct { + Owner string `json:"owner"` + Repo string `json:"repo"` +} + +type agentAutomationRequest struct { + method string + path string + query url.Values + body any +} + +type agentAutomationRequestBuilder[Input any] func(Input) (agentAutomationRequest, error) + +func newAgentAutomationTool[Input any]( + t translations.TranslationHelperFunc, + name, title, description string, + inputSchema *jsonschema.Schema, + outputSchema json.RawMessage, + build agentAutomationRequestBuilder[Input], +) inventory.ServerTool { + return NewTool[Input, json.RawMessage]( + ToolsetMetadataCopilot, + mcp.Tool{ + Name: name, + Description: t("TOOL_"+name+"_DESCRIPTION", description), + InputSchema: inputSchema, + OutputSchema: outputSchema, + Annotations: &mcp.ToolAnnotations{ + Title: t("TOOL_"+name+"_USER_TITLE", title), + ReadOnlyHint: true, + }, + }, + scopes.RequireAll(scopes.Repo), + func(ctx context.Context, deps ToolDependencies, _ *mcp.CallToolRequest, args Input) (*mcp.CallToolResult, json.RawMessage, error) { + request, err := build(args) + if err != nil { + return utils.NewToolResultError(err.Error()), nil, nil + } + + client, err := deps.GetClient(ctx) + if err != nil { + return utils.NewToolResultErrorFromErr("failed to get GitHub client", err), nil, err + } + + if len(request.query) > 0 { + request.path += "?" + request.query.Encode() + } + httpRequest, err := client.NewRequest(ctx, request.method, request.path, request.body, github.WithVersion(agentAutomationAPIVersion)) + if err != nil { + return utils.NewToolResultErrorFromErr("failed to create GitHub request", err), nil, nil + } + + var response json.RawMessage + httpResponse, err := client.Do(httpRequest, &response) + 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 { + return utils.NewToolResultError(fmt.Sprintf("GitHub agent automations returned unexpected status %d", httpResponse.StatusCode)), nil, nil + } + + result := utils.NewToolResultText(string(response)) + return result, response, nil + }, + ) +} + +func agentAutomationObjectOutputSchema() json.RawMessage { + return json.RawMessage(`{"type":"object","additionalProperties":true}`) +} + +func agentAutomationArrayOutputSchema() json.RawMessage { + return json.RawMessage(`{"type":"array","items":{"type":"object","additionalProperties":true}}`) +} + +func agentAutomationInputSchema(properties map[string]*jsonschema.Schema, required ...string) *jsonschema.Schema { + return &jsonschema.Schema{Type: "object", Properties: properties, Required: required} +} + +func automationStringProperty(description string) *jsonschema.Schema { + return &jsonschema.Schema{Type: "string", Description: description} +} + +func automationIntegerProperty(description string, minimum float64, maximum ...float64) *jsonschema.Schema { + property := &jsonschema.Schema{Type: "integer", Description: description, Minimum: &minimum} + if len(maximum) > 0 { + property.Maximum = &maximum[0] + } + return property +} + +func requireAutomationRepository(owner, repo string) error { + if owner == "" { + return errors.New("missing required parameter: owner") + } + if repo == "" { + return errors.New("missing required parameter: repo") + } + return nil +} + +func automationPath(owner, repo, suffix string) string { + path := "agents/repos/" + url.PathEscape(owner) + "/" + url.PathEscape(repo) + "/automations" + if suffix != "" { + path += "/" + suffix + } + return path +} + +func ListAutomations(t translations.TranslationHelperFunc) inventory.ServerTool { + return newAgentAutomationTool[ListAutomationsInput]( + t, + "list_automations", + "List repository automations", + "List Copilot automations for a repository.", + agentAutomationInputSchema(map[string]*jsonschema.Schema{ + "owner": automationStringProperty(DescriptionRepositoryOwner), + "repo": automationStringProperty(DescriptionRepositoryName), + "page": automationIntegerProperty("Page number, starting at 1.", 1), + "perPage": automationIntegerProperty("Results per page, from 1 to 100.", 1, 100), + "type": { + Type: "string", + Description: "Filter automations by type.", + Enum: []any{"personal", "shared"}, + }, + }, "owner", "repo"), + agentAutomationObjectOutputSchema(), + func(args ListAutomationsInput) (agentAutomationRequest, error) { + if err := requireAutomationRepository(args.Owner, args.Repo); err != nil { + return agentAutomationRequest{}, err + } + if args.Page < 0 || args.PerPage < 0 || args.PerPage > 100 { + return agentAutomationRequest{}, errors.New("page and perPage must be positive when provided; perPage cannot exceed 100") + } + query := make(url.Values) + if args.Page > 0 { + query.Set("page", strconv.Itoa(args.Page)) + } + if args.PerPage > 0 { + query.Set("per_page", strconv.Itoa(args.PerPage)) + } + if args.Type != "" { + query.Set("type", args.Type) + } + return agentAutomationRequest{ + method: http.MethodGet, + path: automationPath(args.Owner, args.Repo, ""), + query: query, + }, nil + }, + ) +} + +func GetAutomation(t translations.TranslationHelperFunc) inventory.ServerTool { + return newAgentAutomationTool[GetAutomationInput]( + t, + "get_automation", + "Get a repository automation", + "Get the configuration of a Copilot automation in a repository.", + agentAutomationInputSchema(map[string]*jsonschema.Schema{ + "owner": automationStringProperty(DescriptionRepositoryOwner), + "repo": automationStringProperty(DescriptionRepositoryName), + "automation_id": automationStringProperty("The automation identifier."), + }, "owner", "repo", "automation_id"), + agentAutomationObjectOutputSchema(), + func(args GetAutomationInput) (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.MethodGet, + path: automationPath(args.Owner, args.Repo, url.PathEscape(args.AutomationID)), + }, nil + }, + ) +} + +func ListAutomationRevisions(t translations.TranslationHelperFunc) inventory.ServerTool { + return newAgentAutomationTool[ListAutomationRevisionsInput]( + t, + "list_automation_revisions", + "List automation revisions", + "List the saved revisions of a Copilot automation.", + agentAutomationInputSchema(map[string]*jsonschema.Schema{ + "owner": automationStringProperty(DescriptionRepositoryOwner), + "repo": automationStringProperty(DescriptionRepositoryName), + "automation_id": automationStringProperty("The automation identifier."), + "cursor": automationStringProperty("Opaque pagination cursor."), + "perPage": automationIntegerProperty("Results per page, from 1 to 100.", 1, 100), + }, "owner", "repo", "automation_id"), + agentAutomationObjectOutputSchema(), + func(args ListAutomationRevisionsInput) (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.PerPage < 0 || args.PerPage > 100 { + return agentAutomationRequest{}, errors.New("perPage must be between 1 and 100") + } + query := make(url.Values) + if args.Cursor != "" { + query.Set("cursor", args.Cursor) + } + if args.PerPage > 0 { + query.Set("per_page", strconv.Itoa(args.PerPage)) + } + return agentAutomationRequest{ + method: http.MethodGet, + path: automationPath(args.Owner, args.Repo, url.PathEscape(args.AutomationID)+"/revisions"), + query: query, + }, nil + }, + ) +} + +func GetAutomationRevision(t translations.TranslationHelperFunc) inventory.ServerTool { + return newAgentAutomationTool[GetAutomationRevisionInput]( + t, + "get_automation_revision", + "Get an automation revision", + "Get a specific saved revision of a Copilot automation.", + agentAutomationInputSchema(map[string]*jsonschema.Schema{ + "owner": automationStringProperty(DescriptionRepositoryOwner), + "repo": automationStringProperty(DescriptionRepositoryName), + "automation_id": automationStringProperty("The automation identifier."), + "revision_id": automationStringProperty("The revision identifier."), + }, "owner", "repo", "automation_id", "revision_id"), + agentAutomationObjectOutputSchema(), + func(args GetAutomationRevisionInput) (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.RevisionID == "" { + return agentAutomationRequest{}, errors.New("missing required parameter: revision_id") + } + return agentAutomationRequest{ + method: http.MethodGet, + path: automationPath(args.Owner, args.Repo, url.PathEscape(args.AutomationID)+"/revisions/"+url.PathEscape(args.RevisionID)), + }, nil + }, + ) +} + +func ListAvailableAutomationTools(t translations.TranslationHelperFunc) inventory.ServerTool { + return newAgentAutomationTool[AutomationCatalogInput]( + t, + "list_available_automation_tools", + "List available automation tools", + "List the tools that can be used by automations in a repository.", + agentAutomationInputSchema(map[string]*jsonschema.Schema{ + "owner": automationStringProperty(DescriptionRepositoryOwner), + "repo": automationStringProperty(DescriptionRepositoryName), + }, "owner", "repo"), + agentAutomationObjectOutputSchema(), + func(args AutomationCatalogInput) (agentAutomationRequest, error) { + if err := requireAutomationRepository(args.Owner, args.Repo); err != nil { + return agentAutomationRequest{}, err + } + return agentAutomationRequest{ + method: http.MethodGet, + path: automationPath(args.Owner, args.Repo, "available-tools"), + }, nil + }, + ) +} + +func ListAvailableAutomationTriggers(t translations.TranslationHelperFunc) inventory.ServerTool { + return newAgentAutomationTool[AutomationCatalogInput]( + t, + "list_available_automation_triggers", + "List available automation triggers", + "List the trigger types that can be used by automations in a repository.", + agentAutomationInputSchema(map[string]*jsonschema.Schema{ + "owner": automationStringProperty(DescriptionRepositoryOwner), + "repo": automationStringProperty(DescriptionRepositoryName), + }, "owner", "repo"), + agentAutomationArrayOutputSchema(), + func(args AutomationCatalogInput) (agentAutomationRequest, error) { + if err := requireAutomationRepository(args.Owner, args.Repo); err != nil { + return agentAutomationRequest{}, err + } + return agentAutomationRequest{ + method: http.MethodGet, + path: automationPath(args.Owner, args.Repo, "available-triggers"), + }, nil + }, + ) +} diff --git a/pkg/github/agent_automations_test.go b/pkg/github/agent_automations_test.go new file mode 100644 index 0000000000..8d22c3bf77 --- /dev/null +++ b/pkg/github/agent_automations_test.go @@ -0,0 +1,134 @@ +package github + +import ( + "context" + "net/http" + "testing" + + "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" + "github.com/google/jsonschema-go/jsonschema" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestAgentAutomationReadToolSnapshots(t *testing.T) { + t.Parallel() + + for _, tool := range []inventory.ServerTool{ + ListAutomations(translations.NullTranslationHelper), + GetAutomation(translations.NullTranslationHelper), + ListAutomationRevisions(translations.NullTranslationHelper), + GetAutomationRevision(translations.NullTranslationHelper), + ListAvailableAutomationTools(translations.NullTranslationHelper), + ListAvailableAutomationTriggers(translations.NullTranslationHelper), + } { + require.NoError(t, toolsnaps.Test(tool.Tool.Name, tool.Tool)) + } +} + +func TestAgentAutomationReadTools(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + tool func(translations.TranslationHelperFunc) inventory.ServerTool + args map[string]any + endpoint string + query string + response string + }{ + { + name: "list automations", + tool: ListAutomations, + args: map[string]any{ + "owner": "octo-org", "repo": "octo-repo", "page": 2, "perPage": 20, "type": "shared", + }, + endpoint: "/agents/repos/octo-org/octo-repo/automations", + query: "page=2&per_page=20&type=shared", + response: `{"automations":[],"total_count":0}`, + }, + { + name: "get automation", + tool: GetAutomation, + args: map[string]any{"owner": "octo-org", "repo": "octo-repo", "automation_id": "automation-id"}, + endpoint: "/agents/repos/octo-org/octo-repo/automations/automation-id", + response: `{"id":"automation-id","name":"Issue triage"}`, + }, + { + name: "list automation revisions", + tool: ListAutomationRevisions, + args: map[string]any{ + "owner": "octo-org", "repo": "octo-repo", "automation_id": "automation-id", + "cursor": "next-cursor", "perPage": 10, + }, + endpoint: "/agents/repos/octo-org/octo-repo/automations/automation-id/revisions", + query: "cursor=next-cursor&per_page=10", + response: `{"revisions":[]}`, + }, + { + name: "get automation revision", + tool: GetAutomationRevision, + args: map[string]any{ + "owner": "octo-org", "repo": "octo-repo", "automation_id": "automation-id", "revision_id": "revision-id", + }, + endpoint: "/agents/repos/octo-org/octo-repo/automations/automation-id/revisions/revision-id", + response: `{"id":"revision-id","revision_number":1}`, + }, + { + name: "list available automation tools", + tool: ListAvailableAutomationTools, + args: map[string]any{"owner": "octo-org", "repo": "octo-repo"}, + endpoint: "/agents/repos/octo-org/octo-repo/automations/available-tools", + response: `{"tool_groups":[],"mcp_servers":[]}`, + }, + { + name: "list available automation triggers", + tool: ListAvailableAutomationTriggers, + args: map[string]any{"owner": "octo-org", "repo": "octo-repo"}, + endpoint: "/agents/repos/octo-org/octo-repo/automations/available-triggers", + response: `[]`, + }, + } + + 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.endpoint, r.URL.Path) + assert.Equal(t, tt.query, r.URL.RawQuery) + assert.Equal(t, agentAutomationAPIVersion, r.Header.Get("X-GitHub-Api-Version")) + w.WriteHeader(http.StatusOK) + _, _ = 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) + }) + } +} + +func TestAutomationCatalogToolsRequireRepository(t *testing.T) { + t.Parallel() + + for _, tool := range []struct { + name string + def func(translations.TranslationHelperFunc) inventory.ServerTool + }{ + {name: "available tools", def: ListAvailableAutomationTools}, + {name: "available triggers", def: ListAvailableAutomationTriggers}, + } { + t.Run(tool.name, func(t *testing.T) { + definition := tool.def(translations.NullTranslationHelper) + schema := definition.Tool.InputSchema.(*jsonschema.Schema) + assert.ElementsMatch(t, []string{"owner", "repo"}, schema.Required) + assert.Contains(t, schema.Properties, "owner") + assert.Contains(t, schema.Properties, "repo") + }) + } +} diff --git a/pkg/github/tools.go b/pkg/github/tools.go index 47189398b8..e0a3b92d52 100644 --- a/pkg/github/tools.go +++ b/pkg/github/tools.go @@ -295,6 +295,12 @@ func AllTools(t translations.TranslationHelperFunc, opts ...ToolOption) []invent // Copilot tools AssignCopilotToIssue(t), RequestCopilotReview(t), + ListAutomations(t), + GetAutomation(t), + ListAutomationRevisions(t), + GetAutomationRevision(t), + ListAvailableAutomationTools(t), + ListAvailableAutomationTriggers(t), // Copilot issue intents (non-default, opt-in) AssignCopilotToIssueWithIntent(t), From f8cfcc52b0c95b8dae33201ad9feb50ea0f43525 Mon Sep 17 00:00:00 2001 From: Shaikhul Islam Date: Fri, 6 Nov 2026 15:45:40 -0500 Subject: [PATCH 02/19] feat: gate agent automation tools by opt-in flag Keep the repository automation tool surface hidden unless users explicitly enable agent_automations, including in Insiders mode. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- README.md | 41 +------------ docs/feature-flags.md | 50 ++++++++++++++++ pkg/github/agent_automations.go | 4 +- pkg/github/agent_automations_test.go | 86 +++++++++++++++++++++++++--- pkg/github/feature_flags.go | 4 ++ pkg/github/feature_flags_test.go | 11 ++++ 6 files changed, 147 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index bc5dd143db..0a01a4875a 100644 --- a/README.md +++ b/README.md @@ -154,7 +154,7 @@ When no toolsets are specified, [default toolsets](#default-toolset) are used. -See [Remote Server Documentation](docs/remote-server.md#insiders-mode) for more details and examples, and [Insiders Features](docs/insiders-features.md) for a full list of what's available. +See [Remote Server Documentation](docs/remote-server.md#insiders-mode) for more details and examples, [Insiders Features](docs/insiders-features.md) for a full list of what's available, and [Feature Flags](docs/feature-flags.md) for user-opt-in tools such as repository automations. #### GitHub Enterprise @@ -794,45 +794,6 @@ For negotiated supported protocol versions `2026-07-28` or newer, the consolidat - `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) - - `owner`: Repository owner (string, required) - - `repo`: Repository name (string, required) - -- **get_automation_revision** - Get an automation revision - - **OAuth Challenge Scopes**: `repo` - - `automation_id`: The automation identifier. (string, required) - - `owner`: Repository owner (string, required) - - `repo`: Repository name (string, required) - - `revision_id`: The revision identifier. (string, required) - -- **list_automation_revisions** - List automation revisions - - **OAuth Challenge Scopes**: `repo` - - `automation_id`: The automation identifier. (string, required) - - `cursor`: Opaque pagination cursor. (string, optional) - - `owner`: Repository owner (string, required) - - `perPage`: Results per page, from 1 to 100. (integer, optional) - - `repo`: Repository name (string, required) - -- **list_automations** - List repository automations - - **OAuth Challenge Scopes**: `repo` - - `owner`: Repository owner (string, required) - - `page`: Page number, starting at 1. (integer, optional) - - `perPage`: Results per page, from 1 to 100. (integer, optional) - - `repo`: Repository name (string, required) - - `type`: Filter automations by type. (string, optional) - -- **list_available_automation_tools** - List available automation tools - - **OAuth Challenge Scopes**: `repo` - - `owner`: Repository owner (string, required) - - `repo`: Repository name (string, required) - -- **list_available_automation_triggers** - List available automation triggers - - **OAuth Challenge Scopes**: `repo` - - `owner`: Repository owner (string, required) - - `repo`: Repository name (string, required) - - **request_copilot_review** - Request Copilot review - **OAuth Challenge Scopes**: `repo` - `owner`: Repository owner (string, required) diff --git a/docs/feature-flags.md b/docs/feature-flags.md index f19886f1be..05584b8856 100644 --- a/docs/feature-flags.md +++ b/docs/feature-flags.md @@ -99,6 +99,15 @@ catalog per request and removes instructions when its feature checker enables ## Declaring tool availability +### Agent automations + +Enable `--features=agent_automations` (or `GITHUB_FEATURES=agent_automations`) +to expose the repository automation tools in the `copilot` toolset. This flag +is **off by default**, including in Insiders mode. The MCP flag only exposes +the tools; GitHub API access still depends on the authenticated client's +permissions and access to the explicitly named repository. Read-only mode +exposes only the read tools. + ### Issue artifacts Enable `--features=issue_artifacts` (or `GITHUB_FEATURES=issue_artifacts`) to @@ -518,6 +527,47 @@ as output formatting) won't appear here. - `repo`: Repository name (string, required) - `type`: (string, optional) +### `agent_automations` + +- **get_automation** - Get 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_revision** - Get an automation revision + - **OAuth Challenge Scopes**: `repo` + - `automation_id`: The automation identifier. (string, required) + - `owner`: Repository owner (string, required) + - `repo`: Repository name (string, required) + - `revision_id`: The revision identifier. (string, required) + +- **list_automation_revisions** - List automation revisions + - **OAuth Challenge Scopes**: `repo` + - `automation_id`: The automation identifier. (string, required) + - `cursor`: Opaque pagination cursor. (string, optional) + - `owner`: Repository owner (string, required) + - `perPage`: Results per page, from 1 to 100. (integer, optional) + - `repo`: Repository name (string, required) + +- **list_automations** - List repository automations + - **OAuth Challenge Scopes**: `repo` + - `owner`: Repository owner (string, required) + - `page`: Page number, starting at 1. (integer, optional) + - `perPage`: Results per page, from 1 to 100. (integer, optional) + - `repo`: Repository name (string, required) + - `type`: Filter automations by type. (string, optional) + +- **list_available_automation_tools** - List available automation tools + - **OAuth Challenge Scopes**: `repo` + - `owner`: Repository owner (string, required) + - `repo`: Repository name (string, required) + +- **list_available_automation_triggers** - List available automation triggers + - **OAuth Challenge Scopes**: `repo` + - `owner`: Repository owner (string, required) + - `repo`: Repository name (string, required) + ### `duplicate_detection` - **find_duplicate** - Find duplicate issues diff --git a/pkg/github/agent_automations.go b/pkg/github/agent_automations.go index eb27a0cc5d..b6e01b9a2e 100644 --- a/pkg/github/agent_automations.go +++ b/pkg/github/agent_automations.go @@ -71,7 +71,7 @@ func newAgentAutomationTool[Input any]( outputSchema json.RawMessage, build agentAutomationRequestBuilder[Input], ) inventory.ServerTool { - return NewTool[Input, json.RawMessage]( + tool := NewTool[Input, json.RawMessage]( ToolsetMetadataCopilot, mcp.Tool{ Name: name, @@ -119,6 +119,8 @@ func newAgentAutomationTool[Input any]( return result, response, nil }, ) + tool.FeatureRule = featureEnabledRule(FeatureFlagAgentAutomations) + return tool } func agentAutomationObjectOutputSchema() json.RawMessage { diff --git a/pkg/github/agent_automations_test.go b/pkg/github/agent_automations_test.go index 8d22c3bf77..1647ad200e 100644 --- a/pkg/github/agent_automations_test.go +++ b/pkg/github/agent_automations_test.go @@ -9,25 +9,95 @@ import ( "github.com/github/github-mcp-server/v2/pkg/inventory" "github.com/github/github-mcp-server/v2/pkg/translations" "github.com/google/jsonschema-go/jsonschema" + "github.com/modelcontextprotocol/go-sdk/mcp" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) +func agentAutomationToolsForTest() []inventory.ServerTool { + t := translations.NullTranslationHelper + return []inventory.ServerTool{ + ListAutomations(t), + GetAutomation(t), + ListAutomationRevisions(t), + GetAutomationRevision(t), + ListAvailableAutomationTools(t), + ListAvailableAutomationTriggers(t), + } +} + func TestAgentAutomationReadToolSnapshots(t *testing.T) { t.Parallel() - for _, tool := range []inventory.ServerTool{ - ListAutomations(translations.NullTranslationHelper), - GetAutomation(translations.NullTranslationHelper), - ListAutomationRevisions(translations.NullTranslationHelper), - GetAutomationRevision(translations.NullTranslationHelper), - ListAvailableAutomationTools(translations.NullTranslationHelper), - ListAvailableAutomationTriggers(translations.NullTranslationHelper), - } { + for _, tool := range agentAutomationToolsForTest() { require.NoError(t, toolsnaps.Test(tool.Tool.Name, tool.Tool)) } } +func TestAgentAutomationFeatureFlagAvailability(t *testing.T) { + t.Parallel() + + automationTools := agentAutomationToolsForTest() + var automationNames []string + for _, tool := range automationTools { + automationNames = append(automationNames, tool.Tool.Name) + assert.Equal(t, []inventory.FeatureFlag{FeatureFlagAgentAutomations}, tool.FeatureRule.Features()) + } + assert.Contains(t, AllowedFeatureFlags, FeatureFlagAgentAutomations) + assert.NotContains(t, InsidersFeatureFlags, FeatureFlagAgentAutomations) + + for _, tc := range []struct { + name string + enabledFeatures []string + insidersMode bool + wantAvailable bool + }{ + {name: "default with all toolsets"}, + {name: "insiders without explicit flag", insidersMode: true}, + { + name: "explicit opt-in", + enabledFeatures: []string{FeatureFlagAgentAutomations}, + wantAvailable: true, + }, + } { + t.Run(tc.name, func(t *testing.T) { + enabled := ResolveFeatureFlags(tc.enabledFeatures, tc.insidersMode)[FeatureFlagAgentAutomations] + var flags []inventory.FeatureFlag + if enabled { + flags = append(flags, FeatureFlagAgentAutomations) + } + inv, err := inventory.NewBuilder(). + SetTools(AllTools(translations.NullTranslationHelper)). + WithToolsets([]string{"all"}). + WithFeatureChecker(featureCheckerFor(flags...)). + Build() + require.NoError(t, err) + + var availableNames []string + for _, tool := range inv.AvailableTools(context.Background()) { + for _, name := range automationNames { + if tool.Tool.Name == name { + availableNames = append(availableNames, name) + } + } + } + if tc.wantAvailable { + assert.ElementsMatch(t, automationNames, availableNames) + return + } + assert.Empty(t, availableNames) + + server := mcp.NewServer(&mcp.Implementation{Name: "agent-automations-test", Version: "v1"}, nil) + inv.RegisterAll(context.Background(), server, BaseDeps{}) + session := connectCommentVisibilityClient(t, server, inventory.ProtocolVersionMultiRoundTrip) + for _, name := range automationNames { + _, err := session.CallTool(context.Background(), &mcp.CallToolParams{Name: name, Arguments: map[string]any{}}) + require.Error(t, err, "direct call to unavailable tool %q must fail", name) + } + }) + } +} + func TestAgentAutomationReadTools(t *testing.T) { t.Parallel() diff --git a/pkg/github/feature_flags.go b/pkg/github/feature_flags.go index b88ba7a512..88e7218af1 100644 --- a/pkg/github/feature_flags.go +++ b/pkg/github/feature_flags.go @@ -32,6 +32,9 @@ const FeatureFlagIssueDependencies = "issue_dependencies" // endpoints. Access requirements are unverified; insiders mode does not enable it. const FeatureFlagIssueArtifacts = "issue_artifacts" +// FeatureFlagAgentAutomations explicitly opts into the repository automation tools. +const FeatureFlagAgentAutomations = "agent_automations" + // FeatureFlagDuplicateDetection is the feature flag name for the find_duplicate // tool, which returns ranked duplicate candidates for an existing issue. It is // gated so the extra tool is not advertised by default, and is deliberately @@ -59,6 +62,7 @@ var AllowedFeatureFlags = []string{ FeatureFlagFileBlame, FeatureFlagIssueDependencies, FeatureFlagIssueArtifacts, + FeatureFlagAgentAutomations, FeatureFlagDuplicateDetection, FeatureFlagThreadResolutionReason, FeatureFlagSkillsExtension, diff --git a/pkg/github/feature_flags_test.go b/pkg/github/feature_flags_test.go index 173a8cfd12..dfa5828d26 100644 --- a/pkg/github/feature_flags_test.go +++ b/pkg/github/feature_flags_test.go @@ -206,12 +206,23 @@ func TestResolveFeatureFlags(t *testing.T) { enabledFeatures: []string{FeatureFlagThreadResolutionReason}, expectedFlags: []string{FeatureFlagThreadResolutionReason}, }, + { + name: "agent automations can be directly enabled", + enabledFeatures: []string{FeatureFlagAgentAutomations}, + expectedFlags: []string{FeatureFlagAgentAutomations}, + }, { name: "insiders does not enable user-only allowed flags", enabledFeatures: nil, insidersMode: true, unexpectedFlags: []string{FeatureFlagIssuesGranular, FeatureFlagPullRequestsGranular}, }, + { + name: "insiders does not enable agent automations", + enabledFeatures: nil, + insidersMode: true, + unexpectedFlags: []string{FeatureFlagAgentAutomations}, + }, { name: "explicit plus insiders deduplicates", enabledFeatures: []string{FeatureFlagCSVOutput}, From c2b05e7d0a68263d10326e1d1c89ad4649ad0bbb Mon Sep 17 00:00:00 2001 From: Shaikhul Islam Date: Fri, 6 Nov 2026 16:06:27 -0500 Subject: [PATCH 03/19] feat: add repository automation configuration tool Expose the repository's automation and trigger policies through the existing opt-in automation tool surface. Keep the read caller-specific by requesting it for every invocation. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- docs/feature-flags.md | 5 ++ ...omations_configuration_for_repository.snap | 50 ++++++++++++ pkg/github/agent_automations.go | 42 ++++++++++ pkg/github/agent_automations_test.go | 79 +++++++++++++++++++ pkg/github/tools.go | 1 + 5 files changed, 177 insertions(+) create mode 100644 pkg/github/__toolsnaps__/get_automations_configuration_for_repository.snap diff --git a/docs/feature-flags.md b/docs/feature-flags.md index 05584b8856..2b231cced0 100644 --- a/docs/feature-flags.md +++ b/docs/feature-flags.md @@ -542,6 +542,11 @@ as output formatting) won't appear here. - `repo`: Repository name (string, required) - `revision_id`: The revision identifier. (string, required) +- **get_automations_configuration_for_repository** - Get repository automation configuration + - **OAuth Challenge Scopes**: `repo` + - `owner`: Repository owner (string, required) + - `repo`: Repository name (string, required) + - **list_automation_revisions** - List automation revisions - **OAuth Challenge Scopes**: `repo` - `automation_id`: The automation identifier. (string, required) diff --git a/pkg/github/__toolsnaps__/get_automations_configuration_for_repository.snap b/pkg/github/__toolsnaps__/get_automations_configuration_for_repository.snap new file mode 100644 index 0000000000..31a35d395d --- /dev/null +++ b/pkg/github/__toolsnaps__/get_automations_configuration_for_repository.snap @@ -0,0 +1,50 @@ +{ + "annotations": { + "idempotentHint": false, + "readOnlyHint": true, + "title": "Get repository automation configuration" + }, + "description": "Get whether automations are enabled, whether you can manage them, and the repository's automation trigger and write-scope policies.", + "inputSchema": { + "properties": { + "owner": { + "description": "Repository owner", + "type": "string" + }, + "repo": { + "description": "Repository name", + "type": "string" + } + }, + "required": [ + "owner", + "repo" + ], + "type": "object" + }, + "name": "get_automations_configuration_for_repository", + "outputSchema": { + "additionalProperties": true, + "properties": { + "allow_read_access_triggers": { + "type": "boolean" + }, + "automations_enabled": { + "type": "boolean" + }, + "can_manage_automations": { + "type": "boolean" + }, + "require_trigger_scoped_writes": { + "type": "boolean" + } + }, + "required": [ + "automations_enabled", + "can_manage_automations", + "allow_read_access_triggers", + "require_trigger_scoped_writes" + ], + "type": "object" + } +} \ No newline at end of file diff --git a/pkg/github/agent_automations.go b/pkg/github/agent_automations.go index b6e01b9a2e..9dc1c52604 100644 --- a/pkg/github/agent_automations.go +++ b/pkg/github/agent_automations.go @@ -131,6 +131,25 @@ func agentAutomationArrayOutputSchema() json.RawMessage { return json.RawMessage(`{"type":"array","items":{"type":"object","additionalProperties":true}}`) } +func agentAutomationConfigurationOutputSchema() json.RawMessage { + return json.RawMessage(`{ + "type":"object", + "properties":{ + "automations_enabled":{"type":"boolean"}, + "can_manage_automations":{"type":"boolean"}, + "allow_read_access_triggers":{"type":"boolean"}, + "require_trigger_scoped_writes":{"type":"boolean"} + }, + "required":[ + "automations_enabled", + "can_manage_automations", + "allow_read_access_triggers", + "require_trigger_scoped_writes" + ], + "additionalProperties":true + }`) +} + func agentAutomationInputSchema(properties map[string]*jsonschema.Schema, required ...string) *jsonschema.Schema { return &jsonschema.Schema{Type: "object", Properties: properties, Required: required} } @@ -352,3 +371,26 @@ func ListAvailableAutomationTriggers(t translations.TranslationHelperFunc) inven }, ) } + +func GetAutomationsConfigurationForRepository(t translations.TranslationHelperFunc) inventory.ServerTool { + return newAgentAutomationTool[AutomationCatalogInput]( + t, + "get_automations_configuration_for_repository", + "Get repository automation configuration", + "Get whether automations are enabled, whether you can manage them, and the repository's automation trigger and write-scope policies.", + agentAutomationInputSchema(map[string]*jsonschema.Schema{ + "owner": automationStringProperty(DescriptionRepositoryOwner), + "repo": automationStringProperty(DescriptionRepositoryName), + }, "owner", "repo"), + agentAutomationConfigurationOutputSchema(), + func(args AutomationCatalogInput) (agentAutomationRequest, error) { + if err := requireAutomationRepository(args.Owner, args.Repo); err != nil { + return agentAutomationRequest{}, err + } + return agentAutomationRequest{ + method: http.MethodGet, + path: automationPath(args.Owner, args.Repo, "configuration"), + }, nil + }, + ) +} diff --git a/pkg/github/agent_automations_test.go b/pkg/github/agent_automations_test.go index 1647ad200e..2ea856fda7 100644 --- a/pkg/github/agent_automations_test.go +++ b/pkg/github/agent_automations_test.go @@ -2,6 +2,7 @@ package github import ( "context" + "encoding/json" "net/http" "testing" @@ -23,6 +24,7 @@ func agentAutomationToolsForTest() []inventory.ServerTool { GetAutomationRevision(t), ListAvailableAutomationTools(t), ListAvailableAutomationTriggers(t), + GetAutomationsConfigurationForRepository(t), } } @@ -160,6 +162,13 @@ func TestAgentAutomationReadTools(t *testing.T) { endpoint: "/agents/repos/octo-org/octo-repo/automations/available-triggers", response: `[]`, }, + { + name: "get repository automation configuration", + tool: GetAutomationsConfigurationForRepository, + args: map[string]any{"owner": "octo-org", "repo": "octo-repo"}, + endpoint: "/agents/repos/octo-org/octo-repo/automations/configuration", + response: `{"automations_enabled":true,"can_manage_automations":false,"allow_read_access_triggers":true,"require_trigger_scoped_writes":false}`, + }, } for _, tt := range tests { @@ -192,6 +201,7 @@ func TestAutomationCatalogToolsRequireRepository(t *testing.T) { }{ {name: "available tools", def: ListAvailableAutomationTools}, {name: "available triggers", def: ListAvailableAutomationTriggers}, + {name: "repository configuration", def: GetAutomationsConfigurationForRepository}, } { t.Run(tool.name, func(t *testing.T) { definition := tool.def(translations.NullTranslationHelper) @@ -202,3 +212,72 @@ func TestAutomationCatalogToolsRequireRepository(t *testing.T) { }) } } + +func TestGetAutomationsConfigurationForRepositoryOutputSchema(t *testing.T) { + t.Parallel() + + tool := GetAutomationsConfigurationForRepository(translations.NullTranslationHelper) + var schema struct { + Type string `json:"type"` + Properties map[string]struct { + Type string `json:"type"` + } `json:"properties"` + Required []string `json:"required"` + } + schemaJSON, err := json.Marshal(tool.Tool.OutputSchema) + require.NoError(t, err) + require.NoError(t, json.Unmarshal(schemaJSON, &schema)) + require.Equal(t, "object", schema.Type) + assert.ElementsMatch(t, []string{ + "automations_enabled", + "can_manage_automations", + "allow_read_access_triggers", + "require_trigger_scoped_writes", + }, schema.Required) + for _, field := range schema.Required { + assert.Equal(t, "boolean", schema.Properties[field].Type, field) + } +} + +func TestGetAutomationsConfigurationForRepositoryReturnsAPIError(t *testing.T) { + t.Parallel() + + tool := GetAutomationsConfigurationForRepository(translations.NullTranslationHelper) + httpClient := MockHTTPClientWithHandler(func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, http.MethodGet, r.Method) + assert.Equal(t, "/agents/repos/octo-org/octo-repo/automations/configuration", r.URL.Path) + w.WriteHeader(http.StatusForbidden) + _, _ = w.Write([]byte(`{"message":"Resource not accessible by integration"}`)) + }) + deps := BaseDeps{Client: mustNewGHClient(t, httpClient)} + request := createMCPRequest(map[string]any{"owner": "octo-org", "repo": "octo-repo"}) + result, err := tool.Handler(nil)(ContextWithDeps(context.Background(), deps), &request) + require.NoError(t, err) + require.True(t, result.IsError) + assert.NotEmpty(t, getErrorResult(t, result).Text) +} + +func TestGetAutomationsConfigurationForRepositoryDoesNotCacheResponses(t *testing.T) { + t.Parallel() + + tool := GetAutomationsConfigurationForRepository(translations.NullTranslationHelper) + responses := []string{ + `{"automations_enabled":true,"can_manage_automations":true,"allow_read_access_triggers":false,"require_trigger_scoped_writes":false}`, + `{"automations_enabled":true,"can_manage_automations":false,"allow_read_access_triggers":true,"require_trigger_scoped_writes":true}`, + } + calls := 0 + httpClient := MockHTTPClientWithHandler(func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, "/agents/repos/octo-org/octo-repo/automations/configuration", r.URL.Path) + _, _ = w.Write([]byte(responses[calls])) + calls++ + }) + deps := BaseDeps{Client: mustNewGHClient(t, httpClient)} + for _, response := range responses { + request := createMCPRequest(map[string]any{"owner": "octo-org", "repo": "octo-repo"}) + result, err := tool.Handler(nil)(ContextWithDeps(context.Background(), deps), &request) + require.NoError(t, err) + require.False(t, result.IsError) + assert.JSONEq(t, response, getTextResult(t, result).Text) + } + assert.Equal(t, len(responses), calls) +} diff --git a/pkg/github/tools.go b/pkg/github/tools.go index e0a3b92d52..381343aa80 100644 --- a/pkg/github/tools.go +++ b/pkg/github/tools.go @@ -301,6 +301,7 @@ func AllTools(t translations.TranslationHelperFunc, opts ...ToolOption) []invent GetAutomationRevision(t), ListAvailableAutomationTools(t), ListAvailableAutomationTriggers(t), + GetAutomationsConfigurationForRepository(t), // Copilot issue intents (non-default, opt-in) AssignCopilotToIssueWithIntent(t), From 9069bba78fa136151236f3cd74f079b1a50063f5 Mon Sep 17 00:00:00 2001 From: Shaikhul Islam Date: Fri, 6 Nov 2026 17:24:33 -0500 Subject: [PATCH 04/19] fix: validate automation route identifiers Reject path dot segments and reserved automation subroutes before building requests, and sanitize automation display names in the shared read response. Preserve identifiers, cursors, and prompt content. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- pkg/github/agent_automations.go | 82 +++++++++++++++++++++++--- pkg/github/agent_automations_test.go | 87 ++++++++++++++++++++++++++++ 2 files changed, 161 insertions(+), 8 deletions(-) diff --git a/pkg/github/agent_automations.go b/pkg/github/agent_automations.go index 9dc1c52604..c0fda58ba7 100644 --- a/pkg/github/agent_automations.go +++ b/pkg/github/agent_automations.go @@ -11,6 +11,7 @@ import ( ghErrors "github.com/github/github-mcp-server/v2/pkg/errors" "github.com/github/github-mcp-server/v2/pkg/inventory" + "github.com/github/github-mcp-server/v2/pkg/sanitize" "github.com/github/github-mcp-server/v2/pkg/scopes" "github.com/github/github-mcp-server/v2/pkg/translations" "github.com/github/github-mcp-server/v2/pkg/utils" @@ -115,8 +116,11 @@ func newAgentAutomationTool[Input any]( return utils.NewToolResultError(fmt.Sprintf("GitHub agent automations returned unexpected status %d", httpResponse.StatusCode)), nil, nil } - result := utils.NewToolResultText(string(response)) - return result, response, nil + sanitizedResponse, err := sanitizeAutomationNames(response) + if err != nil { + return utils.NewToolResultErrorFromErr("failed to sanitize GitHub agent automation response", err), nil, nil + } + return utils.NewToolResultText(string(sanitizedResponse)), sanitizedResponse, nil }, ) tool.FeatureRule = featureEnabledRule(FeatureFlagAgentAutomations) @@ -173,9 +177,68 @@ func requireAutomationRepository(owner, repo string) error { if repo == "" { return errors.New("missing required parameter: repo") } + if err := requireAutomationPathSegment("owner", owner); err != nil { + return err + } + if err := requireAutomationPathSegment("repo", repo); err != nil { + return err + } + return nil +} + +func requireAutomationPathSegment(name, value string) error { + if value == "." || value == ".." { + return fmt.Errorf("%s cannot be a dot path segment", name) + } + return nil +} + +func requireAutomationID(value string) error { + if value == "" { + return errors.New("missing required parameter: automation_id") + } + if err := requireAutomationPathSegment("automation_id", value); err != nil { + return err + } + switch value { + case "available-tools", "available-triggers", "configuration", "revisions": + return errors.New("automation_id cannot match a reserved automation endpoint") + } return nil } +func sanitizeAutomationNames(response json.RawMessage) (json.RawMessage, error) { + var payload any + if err := json.Unmarshal(response, &payload); err != nil { + return nil, fmt.Errorf("failed to decode response: %w", err) + } + sanitizeAutomationNamesValue(payload) + sanitizedResponse, err := json.Marshal(payload) + if err != nil { + return nil, fmt.Errorf("failed to encode sanitized response: %w", err) + } + return sanitizedResponse, nil +} + +func sanitizeAutomationNamesValue(value any) { + switch value := value.(type) { + case map[string]any: + for key, field := range value { + if key == "name" { + if name, ok := field.(string); ok { + value[key] = sanitize.PlainText(name) + continue + } + } + sanitizeAutomationNamesValue(field) + } + case []any: + for _, field := range value { + sanitizeAutomationNamesValue(field) + } + } +} + func automationPath(owner, repo, suffix string) string { path := "agents/repos/" + url.PathEscape(owner) + "/" + url.PathEscape(repo) + "/automations" if suffix != "" { @@ -244,8 +307,8 @@ func GetAutomation(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 } return agentAutomationRequest{ method: http.MethodGet, @@ -273,8 +336,8 @@ func ListAutomationRevisions(t translations.TranslationHelperFunc) inventory.Ser 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.PerPage < 0 || args.PerPage > 100 { return agentAutomationRequest{}, errors.New("perPage must be between 1 and 100") @@ -312,12 +375,15 @@ func GetAutomationRevision(t translations.TranslationHelperFunc) inventory.Serve 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.RevisionID == "" { return agentAutomationRequest{}, errors.New("missing required parameter: revision_id") } + if err := requireAutomationPathSegment("revision_id", args.RevisionID); err != nil { + return agentAutomationRequest{}, err + } return agentAutomationRequest{ method: http.MethodGet, path: automationPath(args.Owner, args.Repo, url.PathEscape(args.AutomationID)+"/revisions/"+url.PathEscape(args.RevisionID)), diff --git a/pkg/github/agent_automations_test.go b/pkg/github/agent_automations_test.go index 2ea856fda7..d34865ae56 100644 --- a/pkg/github/agent_automations_test.go +++ b/pkg/github/agent_automations_test.go @@ -192,6 +192,93 @@ func TestAgentAutomationReadTools(t *testing.T) { } } +func TestAgentAutomationReadToolsSanitizeNames(t *testing.T) { + t.Parallel() + + response := `{"automations":[{"id":"automation-id","name":"Issue\u202E triage","prompt":"preserved prompt"}],"next_cursor":"cursor"}` + expected := `{"automations":[{"id":"automation-id","name":"Issue triage","prompt":"preserved prompt"}],"next_cursor":"cursor"}` + httpClient := MockHTTPClientWithHandler(func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(response)) + }) + deps := BaseDeps{Client: mustNewGHClient(t, httpClient)} + tool := ListAutomations(translations.NullTranslationHelper) + inv, err := inventory.NewBuilder().SetTools([]inventory.ServerTool{tool}). + WithToolsets([]string{"all"}). + WithFeatureChecker(func(context.Context, string) (bool, error) { return true, nil }).Build() + require.NoError(t, err) + server := mcp.NewServer(&mcp.Implementation{Name: "agent-automations-test", Version: "v1"}, nil) + server.AddReceivingMiddleware(InjectDepsMiddleware(deps)) + inv.RegisterTools(context.Background(), server, deps) + session := connectCommentVisibilityClient(t, server, inventory.ProtocolVersionMultiRoundTrip) + result, err := session.CallTool(context.Background(), &mcp.CallToolParams{ + Name: tool.Tool.Name, + Arguments: map[string]any{"owner": "octo-org", "repo": "octo-repo"}, + }) + require.NoError(t, err) + require.False(t, result.IsError) + assert.JSONEq(t, expected, getTextResult(t, result).Text) + structuredContent, err := json.Marshal(result.StructuredContent) + require.NoError(t, err) + assert.JSONEq(t, expected, string(structuredContent)) +} + +func TestAgentAutomationReadToolsRejectUnsafeIDsAndPathSegments(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + tool func(translations.TranslationHelperFunc) inventory.ServerTool + args map[string]any + }{ + { + name: "dot owner", + tool: ListAutomations, + args: map[string]any{"owner": ".", "repo": "octo-repo"}, + }, + { + name: "dot-dot repo", + tool: ListAutomations, + args: map[string]any{"owner": "octo-org", "repo": ".."}, + }, + } + for _, automationID := range []string{".", "..", "available-tools", "available-triggers", "configuration", "revisions"} { + tests = append(tests, struct { + name string + tool func(translations.TranslationHelperFunc) inventory.ServerTool + args map[string]any + }{ + name: "reserved or dot automation ID " + automationID, + tool: GetAutomation, + args: map[string]any{"owner": "octo-org", "repo": "octo-repo", "automation_id": automationID}, + }) + } + tests = append(tests, struct { + name string + tool func(translations.TranslationHelperFunc) inventory.ServerTool + args map[string]any + }{ + name: "dot revision ID", + tool: GetAutomationRevision, + args: map[string]any{"owner": "octo-org", "repo": "octo-repo", "automation_id": "automation-id", "revision_id": ".."}, + }) + + for _, tt := range tests { + t.Run(tt.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(tt.args) + tool := tt.tool(translations.NullTranslationHelper) + result, err := tool.Handler(nil)(ContextWithDeps(context.Background(), deps), &request) + require.NoError(t, err) + require.True(t, result.IsError) + }) + } +} + func TestAutomationCatalogToolsRequireRepository(t *testing.T) { t.Parallel() From 86c51860e0499e9761fa7920e208fcaf0432501f Mon Sep 17 00:00:00 2001 From: Andrew Georgiou Date: Tue, 10 Nov 2026 23:23:46 +0000 Subject: [PATCH 05/19] refactor: move agent automation tools to copilot_automations toolset Register the repository automation tools in a dedicated, non-default copilot_automations toolset instead of the default copilot toolset, matching the toolset the remote server already uses for these tools. Using them now requires --toolsets=copilot_automations (or all) alongside --features=agent_automations. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: f921ed41-2ec0-4075-a572-7692f9529b7e --- README.md | 1 + docs/feature-flags.md | 3 ++- docs/remote-server.md | 1 + pkg/github/agent_automations.go | 2 +- pkg/github/agent_automations_test.go | 18 +++++++++++++++++- pkg/github/tools.go | 7 +++++++ 6 files changed, 29 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0a01a4875a..a39948106a 100644 --- a/README.md +++ b/README.md @@ -599,6 +599,7 @@ The following sets of tools are available: | code-square | `code_quality` | GitHub Code Quality related tools | | codescan | `code_security` | Code security related tools, such as GitHub Code Scanning | | copilot | `copilot` | Copilot related tools | +| workflow | `copilot_automations` | Manage Copilot Automations, their revisions, and the tools and triggers they can use | | copilot | `copilot_issue_intents` | Opt-in Copilot issue assignment tools that carry intent metadata (rationale, confidence, suggestion) | | dependabot | `dependabot` | Dependabot tools | | comment-discussion | `discussions` | GitHub Discussions related tools | diff --git a/docs/feature-flags.md b/docs/feature-flags.md index 2b231cced0..75dd92a88f 100644 --- a/docs/feature-flags.md +++ b/docs/feature-flags.md @@ -102,7 +102,8 @@ catalog per request and removes instructions when its feature checker enables ### Agent automations Enable `--features=agent_automations` (or `GITHUB_FEATURES=agent_automations`) -to expose the repository automation tools in the `copilot` toolset. This flag +to expose the repository automation tools in the opt-in `copilot_automations` +toolset (enable it with `--toolsets=copilot_automations` or `all`). This flag is **off by default**, including in Insiders mode. The MCP flag only exposes the tools; GitHub API access still depends on the authenticated client's permissions and access to the explicitly named repository. Read-only mode diff --git a/docs/remote-server.md b/docs/remote-server.md index be91009148..38617cb147 100644 --- a/docs/remote-server.md +++ b/docs/remote-server.md @@ -25,6 +25,7 @@ Below is a table of available toolsets for the remote GitHub MCP Server. Each to | code-square
`code_quality` | GitHub Code Quality related tools | https://api.githubcopilot.com/mcp/x/code_quality | [Install](https://insiders.vscode.dev/redirect/mcp/install?name=gh-code_quality&config=%7B%22type%22%3A%20%22http%22%2C%22url%22%3A%20%22https%3A%2F%2Fapi.githubcopilot.com%2Fmcp%2Fx%2Fcode_quality%22%7D) | [read-only](https://api.githubcopilot.com/mcp/x/code_quality/readonly) | [Install read-only](https://insiders.vscode.dev/redirect/mcp/install?name=gh-code_quality&config=%7B%22type%22%3A%20%22http%22%2C%22url%22%3A%20%22https%3A%2F%2Fapi.githubcopilot.com%2Fmcp%2Fx%2Fcode_quality%2Freadonly%22%7D) | | codescan
`code_security` | Code security related tools, such as GitHub Code Scanning | https://api.githubcopilot.com/mcp/x/code_security | [Install](https://insiders.vscode.dev/redirect/mcp/install?name=gh-code_security&config=%7B%22type%22%3A%20%22http%22%2C%22url%22%3A%20%22https%3A%2F%2Fapi.githubcopilot.com%2Fmcp%2Fx%2Fcode_security%22%7D) | [read-only](https://api.githubcopilot.com/mcp/x/code_security/readonly) | [Install read-only](https://insiders.vscode.dev/redirect/mcp/install?name=gh-code_security&config=%7B%22type%22%3A%20%22http%22%2C%22url%22%3A%20%22https%3A%2F%2Fapi.githubcopilot.com%2Fmcp%2Fx%2Fcode_security%2Freadonly%22%7D) | | copilot
`copilot` | Copilot related tools | https://api.githubcopilot.com/mcp/x/copilot | [Install](https://insiders.vscode.dev/redirect/mcp/install?name=gh-copilot&config=%7B%22type%22%3A%20%22http%22%2C%22url%22%3A%20%22https%3A%2F%2Fapi.githubcopilot.com%2Fmcp%2Fx%2Fcopilot%22%7D) | [read-only](https://api.githubcopilot.com/mcp/x/copilot/readonly) | [Install read-only](https://insiders.vscode.dev/redirect/mcp/install?name=gh-copilot&config=%7B%22type%22%3A%20%22http%22%2C%22url%22%3A%20%22https%3A%2F%2Fapi.githubcopilot.com%2Fmcp%2Fx%2Fcopilot%2Freadonly%22%7D) | +| workflow
`copilot_automations` | Manage Copilot Automations, their revisions, and the tools and triggers they can use | https://api.githubcopilot.com/mcp/x/copilot_automations | [Install](https://insiders.vscode.dev/redirect/mcp/install?name=gh-copilot_automations&config=%7B%22type%22%3A%20%22http%22%2C%22url%22%3A%20%22https%3A%2F%2Fapi.githubcopilot.com%2Fmcp%2Fx%2Fcopilot_automations%22%7D) | [read-only](https://api.githubcopilot.com/mcp/x/copilot_automations/readonly) | [Install read-only](https://insiders.vscode.dev/redirect/mcp/install?name=gh-copilot_automations&config=%7B%22type%22%3A%20%22http%22%2C%22url%22%3A%20%22https%3A%2F%2Fapi.githubcopilot.com%2Fmcp%2Fx%2Fcopilot_automations%2Freadonly%22%7D) | | copilot
`copilot_issue_intents` | Opt-in Copilot issue assignment tools that carry intent metadata (rationale, confidence, suggestion) | https://api.githubcopilot.com/mcp/x/copilot_issue_intents | [Install](https://insiders.vscode.dev/redirect/mcp/install?name=gh-copilot_issue_intents&config=%7B%22type%22%3A%20%22http%22%2C%22url%22%3A%20%22https%3A%2F%2Fapi.githubcopilot.com%2Fmcp%2Fx%2Fcopilot_issue_intents%22%7D) | [read-only](https://api.githubcopilot.com/mcp/x/copilot_issue_intents/readonly) | [Install read-only](https://insiders.vscode.dev/redirect/mcp/install?name=gh-copilot_issue_intents&config=%7B%22type%22%3A%20%22http%22%2C%22url%22%3A%20%22https%3A%2F%2Fapi.githubcopilot.com%2Fmcp%2Fx%2Fcopilot_issue_intents%2Freadonly%22%7D) | | dependabot
`dependabot` | Dependabot tools | https://api.githubcopilot.com/mcp/x/dependabot | [Install](https://insiders.vscode.dev/redirect/mcp/install?name=gh-dependabot&config=%7B%22type%22%3A%20%22http%22%2C%22url%22%3A%20%22https%3A%2F%2Fapi.githubcopilot.com%2Fmcp%2Fx%2Fdependabot%22%7D) | [read-only](https://api.githubcopilot.com/mcp/x/dependabot/readonly) | [Install read-only](https://insiders.vscode.dev/redirect/mcp/install?name=gh-dependabot&config=%7B%22type%22%3A%20%22http%22%2C%22url%22%3A%20%22https%3A%2F%2Fapi.githubcopilot.com%2Fmcp%2Fx%2Fdependabot%2Freadonly%22%7D) | | comment-discussion
`discussions` | GitHub Discussions related tools | https://api.githubcopilot.com/mcp/x/discussions | [Install](https://insiders.vscode.dev/redirect/mcp/install?name=gh-discussions&config=%7B%22type%22%3A%20%22http%22%2C%22url%22%3A%20%22https%3A%2F%2Fapi.githubcopilot.com%2Fmcp%2Fx%2Fdiscussions%22%7D) | [read-only](https://api.githubcopilot.com/mcp/x/discussions/readonly) | [Install read-only](https://insiders.vscode.dev/redirect/mcp/install?name=gh-discussions&config=%7B%22type%22%3A%20%22http%22%2C%22url%22%3A%20%22https%3A%2F%2Fapi.githubcopilot.com%2Fmcp%2Fx%2Fdiscussions%2Freadonly%22%7D) | diff --git a/pkg/github/agent_automations.go b/pkg/github/agent_automations.go index c0fda58ba7..0cb9a7bf71 100644 --- a/pkg/github/agent_automations.go +++ b/pkg/github/agent_automations.go @@ -73,7 +73,7 @@ func newAgentAutomationTool[Input any]( build agentAutomationRequestBuilder[Input], ) inventory.ServerTool { tool := NewTool[Input, json.RawMessage]( - ToolsetMetadataCopilot, + ToolsetMetadataCopilotAutomations, mcp.Tool{ Name: name, Description: t("TOOL_"+name+"_DESCRIPTION", description), diff --git a/pkg/github/agent_automations_test.go b/pkg/github/agent_automations_test.go index d34865ae56..abdd6a0f04 100644 --- a/pkg/github/agent_automations_test.go +++ b/pkg/github/agent_automations_test.go @@ -51,6 +51,7 @@ func TestAgentAutomationFeatureFlagAvailability(t *testing.T) { for _, tc := range []struct { name string enabledFeatures []string + toolsets []string insidersMode bool wantAvailable bool }{ @@ -61,6 +62,17 @@ func TestAgentAutomationFeatureFlagAvailability(t *testing.T) { enabledFeatures: []string{FeatureFlagAgentAutomations}, wantAvailable: true, }, + { + name: "explicit opt-in with default toolsets", + enabledFeatures: []string{FeatureFlagAgentAutomations}, + toolsets: []string{"default"}, + }, + { + name: "explicit opt-in with copilot_automations toolset", + enabledFeatures: []string{FeatureFlagAgentAutomations}, + toolsets: []string{"copilot_automations"}, + wantAvailable: true, + }, } { t.Run(tc.name, func(t *testing.T) { enabled := ResolveFeatureFlags(tc.enabledFeatures, tc.insidersMode)[FeatureFlagAgentAutomations] @@ -68,9 +80,13 @@ func TestAgentAutomationFeatureFlagAvailability(t *testing.T) { if enabled { flags = append(flags, FeatureFlagAgentAutomations) } + toolsets := tc.toolsets + if toolsets == nil { + toolsets = []string{"all"} + } inv, err := inventory.NewBuilder(). SetTools(AllTools(translations.NullTranslationHelper)). - WithToolsets([]string{"all"}). + WithToolsets(toolsets). WithFeatureChecker(featureCheckerFor(flags...)). Build() require.NoError(t, err) diff --git a/pkg/github/tools.go b/pkg/github/tools.go index 381343aa80..d2d0cc2fb1 100644 --- a/pkg/github/tools.go +++ b/pkg/github/tools.go @@ -148,6 +148,13 @@ var ( Icon: "copilot", } + // ToolsetMetadataCopilotAutomations is a non-default toolset for the opt-in Copilot Automations tools. + ToolsetMetadataCopilotAutomations = inventory.ToolsetMetadata{ + ID: "copilot_automations", + Description: "Manage Copilot Automations, their revisions, and the tools and triggers they can use", + Icon: "workflow", + } + // ToolsetMetadataCopilotIssueIntents is a non-default toolset that gates the // opt-in intent-aware Copilot issue assignment tool. Kept out of the default // configuration so its inputs (rationale, confidence, is_suggestion) do not From d979558d8c5317a6a9bc8882ffc3585a1fd9b3e0 Mon Sep 17 00:00:00 2001 From: Andrew Georgiou Date: Sun, 15 Nov 2026 23:38:52 +0000 Subject: [PATCH 06/19] test: exempt automation read 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 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/skills/catalog/availability_test.go b/pkg/skills/catalog/availability_test.go index e95571ef4a..fa8291c81b 100644 --- a/pkg/skills/catalog/availability_test.go +++ b/pkg/skills/catalog/availability_test.go @@ -42,6 +42,15 @@ var toolCoverageExemptions = map[string]string{ "unhide_pull_request_review_comment": "Review moderation is outside the current pull-request authoring and review workflows.", "update_gist": "Gist lifecycle is separate from the repository workflows covered by the current catalog.", "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. + "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.", + "list_automation_revisions": "Copilot Automation management is an opt-in, feature-flagged workflow not covered by the current catalog.", + "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.", } func TestCatalogToolRequirementsAreRegistered(t *testing.T) { From 03bb1b6806755bfaa9e0d581b5a5df89faa9a96b Mon Sep 17 00:00:00 2001 From: Shaikhul Islam Date: Fri, 6 Nov 2026 13:31:28 -0500 Subject: [PATCH 07/19] 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 08/19] 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 09/19] 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 10/19] 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 11/19] 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 12/19] 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 13/19] 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) { From caf2f7f0626545cd488f2481771e2f9b87acc9cd Mon Sep 17 00:00:00 2001 From: Shaikhul Islam Date: Fri, 6 Nov 2026 13:52:05 -0500 Subject: [PATCH 14/19] 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 15/19] 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 16/19] 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 17/19] 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 18/19] 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 19/19] 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.", }