diff --git a/README.md b/README.md
index 1f297f7dd4..a39948106a 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
@@ -599,6 +599,7 @@ The following sets of tools are available:
|
| `code_quality` | GitHub Code Quality related tools |
|
| `code_security` | Code security related tools, such as GitHub Code Scanning |
|
| `copilot` | Copilot related tools |
+|
| `copilot_automations` | Manage Copilot Automations, their revisions, and the tools and triggers they can use |
|
| `copilot_issue_intents` | Opt-in Copilot issue assignment tools that carry intent metadata (rationale, confidence, suggestion) |
|
| `dependabot` | Dependabot tools |
|
| `discussions` | GitHub Discussions related tools |
diff --git a/docs/feature-flags.md b/docs/feature-flags.md
index f19886f1be..c7dcb30e7a 100644
--- a/docs/feature-flags.md
+++ b/docs/feature-flags.md
@@ -99,6 +99,16 @@ 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 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
+exposes only the read tools.
+
### Issue artifacts
Enable `--features=issue_artifacts` (or `GITHUB_FEATURES=issue_artifacts`) to
@@ -518,6 +528,96 @@ as output formatting) won't appear here.
- `repo`: Repository name (string, required)
- `type`: (string, optional)
+### `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)
+ - `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)
+
+- **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)
+ - `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)
+
+- **run_automation** - Run a repository automation
+ - **OAuth Challenge Scopes**: `repo`
+ - `automation_id`: The automation identifier. (string, required)
+ - `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)
+
+- **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/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_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) |
| 
`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 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) |
+| 
`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_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 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) |
| 
`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/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/github/__toolsnaps__/create_automation.snap b/pkg/github/__toolsnaps__/create_automation.snap
new file mode 100644
index 0000000000..4c0171ff7c
--- /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 after explicit user confirmation.",
+ "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..13a78a67d5
--- /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 after explicit user confirmation.",
+ "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__/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__/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/__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/__toolsnaps__/run_automation.snap b/pkg/github/__toolsnaps__/run_automation.snap
new file mode 100644
index 0000000000..5be2b1761e
--- /dev/null
+++ b/pkg/github/__toolsnaps__/run_automation.snap
@@ -0,0 +1,49 @@
+{
+ "annotations": {
+ "destructiveHint": true,
+ "idempotentHint": false,
+ "readOnlyHint": false,
+ "title": "Run a repository automation"
+ },
+ "description": "Start a manual run of a Copilot automation in a repository after explicit user confirmation.",
+ "inputSchema": {
+ "properties": {
+ "automation_id": {
+ "description": "The automation identifier.",
+ "type": "string"
+ },
+ "context": {
+ "description": "Optional context for the automation run, up to 10,000 characters.",
+ "maxLength": 10000,
+ "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/__toolsnaps__/update_automation.snap b/pkg/github/__toolsnaps__/update_automation.snap
new file mode 100644
index 0000000000..6e1d312823
--- /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 after explicit user confirmation. 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
new file mode 100644
index 0000000000..df0bdcd478
--- /dev/null
+++ b/pkg/github/agent_automations.go
@@ -0,0 +1,964 @@
+package github
+
+import (
+ "context"
+ "crypto/sha256"
+ "encoding/hex"
+ "encoding/json"
+ "errors"
+ "fmt"
+ "net/http"
+ "net/url"
+ "sort"
+ "strconv"
+ "strings"
+ "time"
+ "unicode/utf8"
+
+ 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"
+ "github.com/google/go-github/v92/github"
+ "github.com/google/jsonschema-go/jsonschema"
+ "github.com/modelcontextprotocol/go-sdk/mcp"
+)
+
+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"`
+ 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 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 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
+ query url.Values
+ body any
+ 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)
+
+func newAgentAutomationTool[Input any](
+ t translations.TranslationHelperFunc,
+ 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{
+ Name: name,
+ Description: t("TOOL_"+name+"_DESCRIPTION", description),
+ InputSchema: inputSchema,
+ OutputSchema: outputSchema,
+ Annotations: &mcp.ToolAnnotations{
+ Title: annotations.Title,
+ ReadOnlyHint: annotations.ReadOnlyHint,
+ DestructiveHint: annotations.DestructiveHint,
+ IdempotentHint: annotations.IdempotentHint,
+ OpenWorldHint: annotations.OpenWorldHint,
+ },
+ },
+ scopes.RequireAll(scopes.Repo),
+ 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 {
+ 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
+ var responseTarget any = &response
+ 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
+ }
+ 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
+ }
+ }
+ 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)
+ 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)
+ 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 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 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 {
+ return json.RawMessage(`{"type":"object","additionalProperties":true}`)
+}
+
+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}
+}
+
+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 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")
+ }
+ 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 != "" {
+ 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(),
+ mcp.ToolAnnotations{ReadOnlyHint: true},
+ 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(),
+ mcp.ToolAnnotations{ReadOnlyHint: true},
+ func(args GetAutomationInput) (agentAutomationRequest, error) {
+ if err := requireAutomationRepository(args.Owner, args.Repo); err != nil {
+ return agentAutomationRequest{}, err
+ }
+ if err := requireAutomationID(args.AutomationID); err != nil {
+ return agentAutomationRequest{}, err
+ }
+ 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(),
+ mcp.ToolAnnotations{ReadOnlyHint: true},
+ func(args ListAutomationRevisionsInput) (agentAutomationRequest, error) {
+ if err := requireAutomationRepository(args.Owner, args.Repo); err != nil {
+ return agentAutomationRequest{}, err
+ }
+ 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")
+ }
+ 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(),
+ mcp.ToolAnnotations{ReadOnlyHint: true},
+ func(args GetAutomationRevisionInput) (agentAutomationRequest, error) {
+ if err := requireAutomationRepository(args.Owner, args.Repo); err != nil {
+ return agentAutomationRequest{}, err
+ }
+ 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)),
+ }, 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(),
+ mcp.ToolAnnotations{ReadOnlyHint: true},
+ 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(),
+ mcp.ToolAnnotations{ReadOnlyHint: true},
+ 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
+ },
+ )
+}
+
+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(),
+ mcp.ToolAnnotations{ReadOnlyHint: true},
+ 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
+ },
+ )
+}
+
+func CreateAutomation(t translations.TranslationHelperFunc) inventory.ServerTool {
+ properties := automationConfigurationProperties()
+ properties["owner"] = automationStringProperty(DescriptionRepositoryOwner)
+ properties["repo"] = automationStringProperty(DescriptionRepositoryName)
+ return agentAutomationConfirmationRequired(newAgentAutomationTool[CreateAutomationInput](
+ t,
+ "create_automation",
+ "Create a repository automation",
+ "Create a Copilot automation in a repository after explicit user confirmation.",
+ 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
+ }
+ target := agentAutomationTarget(args.Owner, args.Repo, "")
+ return agentAutomationRequest{
+ method: http.MethodPost,
+ path: automationPath(args.Owner, args.Repo, ""),
+ body: body,
+ successStatus: http.StatusCreated,
+ confirmation: agentAutomationMutationConfirmation("create", target, body),
+ }, 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 agentAutomationConfirmationRequired(newAgentAutomationTool[UpdateAutomationInput](
+ t,
+ "update_automation",
+ "Update a repository automation",
+ "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{},
+ func(args UpdateAutomationInput) (agentAutomationRequest, error) {
+ if err := requireAutomationRepository(args.Owner, args.Repo); err != nil {
+ return agentAutomationRequest{}, err
+ }
+ if err := requireAutomationID(args.AutomationID); err != nil {
+ return agentAutomationRequest{}, err
+ }
+ 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")
+ }
+ 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: agentAutomationMutationConfirmation("update", target, body),
+ }, nil
+ },
+ ))
+}
+
+func DeleteAutomation(t translations.TranslationHelperFunc) inventory.ServerTool {
+ return agentAutomationConfirmationRequired(newAgentAutomationTool[DeleteAutomationInput](
+ t,
+ "delete_automation",
+ "Delete a repository automation",
+ "Delete a Copilot automation from a repository after explicit user confirmation.",
+ 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 err := requireAutomationID(args.AutomationID); err != nil {
+ return agentAutomationRequest{}, err
+ }
+ target := agentAutomationTarget(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
+ },
+ ))
+}
+
+func RunAutomation(t translations.TranslationHelperFunc) inventory.ServerTool {
+ return agentAutomationConfirmationRequired(newAgentAutomationTool[RunAutomationInput](
+ t,
+ "run_automation",
+ "Run a repository automation",
+ "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),
+ "automation_id": automationStringProperty("The automation identifier."),
+ "event": {
+ Type: "string",
+ Description: "The event to trigger. Only manual runs are supported.",
+ Enum: []any{"manual"},
+ },
+ "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)},
+ func(args RunAutomationInput) (agentAutomationRequest, error) {
+ if err := requireAutomationRepository(args.Owner, args.Repo); err != nil {
+ return agentAutomationRequest{}, err
+ }
+ if err := requireAutomationID(args.AutomationID); err != nil {
+ return agentAutomationRequest{}, err
+ }
+ 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 := agentAutomationTarget(args.Owner, args.Repo, args.AutomationID)
+ message := fmt.Sprintf("Review the automation run request for %s.", target)
+ if args.Context != nil {
+ 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)
+ 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
new file mode 100644
index 0000000000..71359d5c72
--- /dev/null
+++ b/pkg/github/agent_automations_test.go
@@ -0,0 +1,918 @@
+package github
+
+import (
+ "context"
+ "encoding/json"
+ "io"
+ "net/http"
+ "strings"
+ "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"
+ "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),
+ GetAutomationsConfigurationForRepository(t),
+ CreateAutomation(t),
+ UpdateAutomation(t),
+ DeleteAutomation(t),
+ RunAutomation(t),
+ }
+}
+
+func TestAgentAutomationReadToolSnapshots(t *testing.T) {
+ t.Parallel()
+
+ 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
+ toolsets []string
+ insidersMode bool
+ readOnly bool
+ wantAvailable bool
+ }{
+ {name: "default with all toolsets"},
+ {name: "insiders without explicit flag", insidersMode: true},
+ {
+ name: "explicit opt-in",
+ 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},
+ 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]
+ var flags []inventory.FeatureFlag
+ if enabled {
+ flags = append(flags, FeatureFlagAgentAutomations)
+ }
+ toolsets := tc.toolsets
+ if toolsets == nil {
+ toolsets = []string{"all"}
+ }
+ inv, err := inventory.NewBuilder().
+ SetTools(AllTools(translations.NullTranslationHelper)).
+ WithToolsets(toolsets).
+ WithReadOnly(tc.readOnly).
+ 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 {
+ 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)
+
+ 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()
+
+ 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: `[]`,
+ },
+ {
+ 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 {
+ 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 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()
+
+ for _, tool := range []struct {
+ name string
+ def func(translations.TranslationHelperFunc) inventory.ServerTool
+ }{
+ {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)
+ 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")
+ })
+ }
+}
+
+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)
+}
+
+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
+ messageOmissions []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"}`,
+ 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",
+ 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."}`,
+ 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",
+ 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",
+ },
+ }
+
+ 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)}
+ 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, tt.confirmID, tt.confirmValue, tt.messageContents, tt.messageOmissions)
+ } 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 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 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 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)}
+ 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.",
+ }, 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)
+ }
+ 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)}
+ 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", nil, nil)
+ require.True(t, result.IsError)
+ 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) {
+ 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, "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) {
+ 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()
+
+ for _, tool := range []inventory.ServerTool{
+ 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)
+ }
+}
+
+func invokeConfirmedAutomation(
+ t *testing.T,
+ tool inventory.ServerTool,
+ deps BaseDeps,
+ args map[string]any,
+ confirmationID, confirmationValue string,
+ messageContents, messageOmissions []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)
+ 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
+ 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
+}
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},
diff --git a/pkg/github/tools.go b/pkg/github/tools.go
index 47189398b8..8a640b9eb8 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
@@ -295,6 +302,17 @@ 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),
+ GetAutomationsConfigurationForRepository(t),
+ CreateAutomation(t),
+ UpdateAutomation(t),
+ DeleteAutomation(t),
+ RunAutomation(t),
// Copilot issue intents (non-default, opt-in)
AssignCopilotToIssueWithIntent(t),
diff --git a/pkg/http/handler.go b/pkg/http/handler.go
index 25c02f254c..f1607bdf95 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", "run_automation":
+ return true
+ }
+ }
+ return false
})
}
diff --git a/pkg/http/handler_test.go b/pkg/http/handler_test.go
index 953a564da4..6c91df7f0b 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,17 @@ 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.NotContains(t, names, "run_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)
diff --git a/pkg/skills/catalog/availability_test.go b/pkg/skills/catalog/availability_test.go
index e95571ef4a..4e60f3561d 100644
--- a/pkg/skills/catalog/availability_test.go
+++ b/pkg/skills/catalog/availability_test.go
@@ -42,6 +42,19 @@ 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.
+ "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.",
+ "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.",
+ "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.",
}
func TestCatalogToolRequirementsAreRegistered(t *testing.T) {