copilot-agents-mcp 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +58 -158
- package/dist/cli.js +38 -98
- package/dist/compact.js +23 -0
- package/dist/delivery.js +17 -0
- package/dist/errors.js +81 -4
- package/dist/follow-up.js +47 -0
- package/dist/github-hosts.js +61 -0
- package/dist/github.js +29 -46
- package/dist/notify.js +22 -93
- package/dist/selection.js +16 -112
- package/dist/server.js +370 -149
- package/dist/state.js +20 -2
- package/dist/status-local.js +67 -0
- package/dist/swe-models.js +44 -8
- package/dist/task-present.js +78 -0
- package/dist/task-status.js +124 -0
- package/dist/task-urls.js +24 -0
- package/dist/tasks.js +227 -0
- package/dist/time-format.js +3 -0
- package/dist/watch.js +39 -17
- package/package.json +14 -2
- package/dist/http.js +0 -77
package/README.md
CHANGED
|
@@ -1,162 +1,96 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<img src="assets/logo.svg" width="128" alt="copilot-agents-mcp">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/daniel-saezv/copilot-agents-mcp/main/assets/logo.svg" width="128" alt="copilot-agents-mcp">
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
5
|
# copilot-agents-mcp
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
It runs on your machine over stdio or local HTTP. Version 0.0.1 requires Node.js 26 or later.
|
|
7
|
+
Local [Model Context Protocol](https://modelcontextprotocol.io/) server for launching and managing GitHub Copilot **cloud agent** tasks. It speaks MCP over **stdio only** and runs on your machine (Node.js **26+**).
|
|
9
8
|
|
|
10
9
|
```mermaid
|
|
11
10
|
flowchart LR
|
|
12
11
|
C[MCP client] -->|stdio| M[copilot-agents-mcp]
|
|
13
12
|
M -->|GitHub App device flow or PAT| A[GitHub authentication]
|
|
14
|
-
M -->|
|
|
13
|
+
M -->|Agent tasks API| G[GitHub]
|
|
15
14
|
M --> N[Local state and watcher]
|
|
16
|
-
N -->|
|
|
15
|
+
N -->|optional POST webhook| W[Your receiver]
|
|
17
16
|
```
|
|
18
17
|
|
|
19
|
-
##
|
|
18
|
+
## Requirements
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
npx -y github:daniel-saezv/copilot-agents-mcp
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
The default server uses stdio. To use local HTTP, run:
|
|
28
|
-
|
|
29
|
-
```bash
|
|
30
|
-
npx -y github:daniel-saezv/copilot-agents-mcp --http --port 3333
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
The HTTP endpoint is `http://127.0.0.1:3333/mcp`.
|
|
20
|
+
- **Node.js 26** or later (`engines.node` in `package.json`).
|
|
21
|
+
- GitHub credentials: GitHub App **login** (preferred) or `GITHUB_PERSONAL_ACCESS_TOKEN`.
|
|
34
22
|
|
|
35
23
|
## Authentication
|
|
36
24
|
|
|
37
|
-
Use one of these credential modes:
|
|
38
|
-
|
|
39
|
-
- **Personal access token.** Set `GITHUB_PERSONAL_ACCESS_TOKEN` in the MCP process environment.
|
|
40
|
-
- **GitHub App.** Run `npx -y github:daniel-saezv/copilot-agents-mcp login`, complete the device flow, and leave `GITHUB_PERSONAL_ACCESS_TOKEN` unset.
|
|
41
|
-
|
|
42
|
-
Check the active credential with:
|
|
43
|
-
|
|
44
25
|
```bash
|
|
26
|
+
npx -y github:daniel-saezv/copilot-agents-mcp login
|
|
45
27
|
npx -y github:daniel-saezv/copilot-agents-mcp auth status
|
|
46
28
|
```
|
|
47
29
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
## Configure your MCP client
|
|
51
|
-
|
|
52
|
-
Every example below has two variants:
|
|
30
|
+
Complete the device flow in the browser. `auth status` shows the active credential without printing tokens, then **local diagnostics** (no network, never reading notify secret values): state file and lock directory writability (non-writable → exit code 1); webhook env set yes/no only (both unset → info: optional; exactly one set → warning); `DBUS_SESSION_BUS_ADDRESS` yes/no plus an info line on Linux when unset. Optional webhook and notify warnings do not change the exit code. Alternatively set `GITHUB_PERSONAL_ACCESS_TOKEN` in the MCP server process environment (never commit tokens in project config).
|
|
53
31
|
|
|
54
|
-
|
|
55
|
-
- GitHub App: run `login`, then remove the `env` block.
|
|
32
|
+
Optional: `COPILOT_AGENTS_GITHUB_APP_CLIENT_ID`, `COPILOT_AGENTS_GITHUB_API_BASE_URL` (GitHub Enterprise).
|
|
56
33
|
|
|
57
|
-
|
|
34
|
+
## Environment variables
|
|
58
35
|
|
|
59
|
-
|
|
36
|
+
| Variable | Purpose |
|
|
37
|
+
| --- | --- |
|
|
38
|
+
| `GITHUB_PERSONAL_ACCESS_TOKEN` | PAT; takes precedence over keyring session |
|
|
39
|
+
| `COPILOT_AGENTS_NOTIFY_URL` | Webhook URL; watcher POSTs JSON when a task finishes |
|
|
40
|
+
| `COPILOT_AGENTS_NOTIFY_AUTHORIZATION` | Literal `Authorization` header on the notify POST: `Bearer <routine-key>` (not the webhook URL) |
|
|
41
|
+
| `COPILOT_AGENTS_STATE_PATH` | Isolated state file (default `~/.copilot-agents-mcp/state.json`) |
|
|
42
|
+
| `COPILOT_AGENTS_LOG` | Optional watcher log file |
|
|
43
|
+
| `COPILOT_AGENTS_GITHUB_API_BASE_URL` | Enterprise API base |
|
|
44
|
+
| `DBUS_SESSION_BUS_ADDRESS` | On headless Linux, points the OS keyring (`secret-service`) at the session bus (e.g. `unix:path=/tmp/xdg-runtime-box/bus` on a Grok Bot box). If unset and login fails, use `GITHUB_PERSONAL_ACCESS_TOKEN` instead |
|
|
60
45
|
|
|
61
|
-
|
|
46
|
+
Watcher poll interval and task freshness are **fixed internally** (15s poll, 60s freshness).
|
|
62
47
|
|
|
63
|
-
|
|
64
|
-
{
|
|
65
|
-
"servers": {
|
|
66
|
-
"copilot-agents": {
|
|
67
|
-
"type": "stdio",
|
|
68
|
-
"command": "npx",
|
|
69
|
-
"args": ["-y", "github:daniel-saezv/copilot-agents-mcp"],
|
|
70
|
-
"env": {
|
|
71
|
-
"GITHUB_PERSONAL_ACCESS_TOKEN": "github_pat_..."
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
```
|
|
48
|
+
## Tools
|
|
77
49
|
|
|
78
|
-
|
|
50
|
+
<!-- START AUTOMATED TOOLS -->
|
|
51
|
+
| Tool | Read-only | Description |
|
|
52
|
+
| --- | --- | --- |
|
|
53
|
+
| `create_agent_task` | no | Launch a GitHub Copilot cloud agent task. The model is sent unchanged. If the model was already rejected, the tool skips the API call and lists accepted models observed so far. Returns immediately with task_id. Pass owner=<your agent name> unless this server runs a single agent. Follow next_step. |
|
|
54
|
+
| `get_agent_task` | yes | Read one task once. Returns status, terminal and a one-line summary. Do not call repeatedly; use list_agent_tasks for periodic checks. |
|
|
55
|
+
| `list_agent_tasks` | yes | One call to check all tracked tasks. Use it for scheduled checks. When all_terminal is true, stop checking. Several agents may share this server; owner is a labeling convention, not a security boundary. |
|
|
56
|
+
| `steer_agent_task` | no | [Experimental] Undocumented internal GitHub endpoint that can change without notice. Each steer consumes credits. The agent applies the instruction after its current tool call finishes. Send an instruction to a task with an open pull request. |
|
|
57
|
+
| `abort_agent_task` | no | [Experimental] Undocumented internal GitHub endpoint that can change without notice. Send {type: "abort"} to the steer endpoint, as VS Code does in tasksClient.ts, to stop the task. This has not been verified against GitHub. |
|
|
58
|
+
| `list_copilot_models` | yes | Read /agents/swe/models and return the ID, name, vendor, preview flag, token prices or multiplier, and promotion when present. |
|
|
59
|
+
<!-- END AUTOMATED TOOLS -->
|
|
79
60
|
|
|
80
|
-
|
|
81
|
-
{
|
|
82
|
-
"servers": {
|
|
83
|
-
"copilot-agents": {
|
|
84
|
-
"type": "stdio",
|
|
85
|
-
"command": "npx",
|
|
86
|
-
"args": ["-y", "github:daniel-saezv/copilot-agents-mcp"]
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
```
|
|
61
|
+
After `create_agent_task`, end your turn. The server returns `follow_up` and `next_step`: either wake on a webhook or schedule `list_agent_tasks` (not before `check_after`).
|
|
91
62
|
|
|
92
|
-
|
|
63
|
+
## Client setup
|
|
93
64
|
|
|
94
|
-
|
|
65
|
+
Run the same stdio command everywhere:
|
|
95
66
|
|
|
96
67
|
```json
|
|
97
68
|
{
|
|
98
|
-
"
|
|
99
|
-
|
|
100
|
-
"command": "npx",
|
|
101
|
-
"args": ["-y", "github:daniel-saezv/copilot-agents-mcp"],
|
|
102
|
-
"env": {
|
|
103
|
-
"GITHUB_PERSONAL_ACCESS_TOKEN": "github_pat_..."
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
69
|
+
"command": "npx",
|
|
70
|
+
"args": ["-y", "github:daniel-saezv/copilot-agents-mcp"]
|
|
107
71
|
}
|
|
108
72
|
```
|
|
109
73
|
|
|
110
|
-
|
|
74
|
+
### (a) Grok Bot
|
|
111
75
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
```
|
|
76
|
+
1. Add a **local stdio MCP server** with the command and args above.
|
|
77
|
+
2. Optional: set `COPILOT_AGENTS_STATE_PATH` in the server environment so this bot does not share state with other agents.
|
|
78
|
+
3. On headless Linux, set `DBUS_SESSION_BUS_ADDRESS` (for example `unix:path=/tmp/xdg-runtime-box/bus`) so GitHub App `login` can use the keyring; otherwise set `GITHUB_PERSONAL_ACCESS_TOKEN` in the server env.
|
|
79
|
+
4. **Webhook routine (recommended):** Create a **Routine** with a **Webhook** trigger in the Grok Bot UI. The **human who owns the routine** configures the MCP server’s masked secret fields; the bot cannot read those values itself. Set `COPILOT_AGENTS_NOTIFY_URL` to the routine’s **webhook URL** from the panel (`https://…`).
|
|
80
|
+
5. Set `COPILOT_AGENTS_NOTIFY_AUTHORIZATION` to the literal string `Bearer <routine-key>`: the word `Bearer` exactly once, one space, then the routine’s **Authorization key** from the panel. The server sends this value verbatim as the HTTP `Authorization` header. Do **not** paste the webhook URL here—that belongs only in `COPILOT_AGENTS_NOTIFY_URL`.
|
|
81
|
+
6. When a Copilot task reaches a terminal state, the background watcher POSTs JSON to the routine; the bot can wake and call `get_agent_task` once. Without the webhook, follow the `check_later` text in `next_step`.
|
|
122
82
|
|
|
123
|
-
### Claude Code
|
|
83
|
+
### (b) Claude Code and Claude Desktop
|
|
124
84
|
|
|
125
|
-
|
|
85
|
+
**Claude Code:**
|
|
126
86
|
|
|
127
87
|
```bash
|
|
128
|
-
claude mcp add --transport stdio copilot-agents
|
|
129
|
-
-e GITHUB_PERSONAL_ACCESS_TOKEN=github_pat_... \
|
|
130
|
-
-- npx -y github:daniel-saezv/copilot-agents-mcp
|
|
88
|
+
claude mcp add --transport stdio copilot-agents -- npx -y github:daniel-saezv/copilot-agents-mcp
|
|
131
89
|
```
|
|
132
90
|
|
|
133
|
-
For
|
|
134
|
-
|
|
135
|
-
```bash
|
|
136
|
-
npx -y github:daniel-saezv/copilot-agents-mcp login
|
|
137
|
-
claude mcp add --transport stdio copilot-agents \
|
|
138
|
-
-- npx -y github:daniel-saezv/copilot-agents-mcp
|
|
139
|
-
```
|
|
91
|
+
For a PAT: add `-e GITHUB_PERSONAL_ACCESS_TOKEN=…` (stored in your private `~/.claude.json`).
|
|
140
92
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
Create `.cursor/mcp.json`:
|
|
144
|
-
|
|
145
|
-
```json
|
|
146
|
-
{
|
|
147
|
-
"mcpServers": {
|
|
148
|
-
"copilot-agents": {
|
|
149
|
-
"command": "npx",
|
|
150
|
-
"args": ["-y", "github:daniel-saezv/copilot-agents-mcp"],
|
|
151
|
-
"env": {
|
|
152
|
-
"GITHUB_PERSONAL_ACCESS_TOKEN": "github_pat_..."
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
For GitHub App authentication, run `login` once and use this variant:
|
|
93
|
+
**Claude Desktop:** user-level `claude_desktop_config.json`:
|
|
160
94
|
|
|
161
95
|
```json
|
|
162
96
|
{
|
|
@@ -169,25 +103,9 @@ For GitHub App authentication, run `login` once and use this variant:
|
|
|
169
103
|
}
|
|
170
104
|
```
|
|
171
105
|
|
|
172
|
-
###
|
|
173
|
-
|
|
174
|
-
Configure Grok Bot as a local MCP server over stdio with:
|
|
175
|
-
|
|
176
|
-
```json
|
|
177
|
-
{
|
|
178
|
-
"mcpServers": {
|
|
179
|
-
"copilot-agents": {
|
|
180
|
-
"command": "npx",
|
|
181
|
-
"args": ["-y", "github:daniel-saezv/copilot-agents-mcp"],
|
|
182
|
-
"env": {
|
|
183
|
-
"GITHUB_PERSONAL_ACCESS_TOKEN": "github_pat_..."
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
```
|
|
106
|
+
### (c) Cursor
|
|
189
107
|
|
|
190
|
-
|
|
108
|
+
`~/.cursor/mcp.json` (global) or project `.cursor/mcp.json` (no secrets in committed project files):
|
|
191
109
|
|
|
192
110
|
```json
|
|
193
111
|
{
|
|
@@ -200,38 +118,21 @@ For GitHub App authentication, run `login` once and use this variant:
|
|
|
200
118
|
}
|
|
201
119
|
```
|
|
202
120
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
<!-- START AUTOMATED TOOLS -->
|
|
206
|
-
| Tool | Toolset | Read-only | Description |
|
|
207
|
-
| --- | --- | --- | --- |
|
|
208
|
-
| `create_agent_task` | copilot_tasks | no | Launch a GitHub Copilot cloud agent task. The model is sent unchanged. If the model was already rejected, the tool skips the API call and lists accepted models observed so far. |
|
|
209
|
-
| `get_agent_task` | copilot_tasks | yes | Read a GitHub Copilot agent task once. |
|
|
210
|
-
| `steer_agent_task` | copilot_tasks | no | [Experimental] Undocumented internal GitHub endpoint that can change without notice. Each steer consumes credits. The agent applies the instruction after its current tool call finishes. Send an instruction to a task with an open pull request. |
|
|
211
|
-
| `abort_agent_task` | copilot_tasks | no | [Experimental] Undocumented internal GitHub endpoint that can change without notice. Send {type: "abort"} to the steer endpoint, as VS Code does in tasksClient.ts, to stop the task. This has not been verified against GitHub. |
|
|
212
|
-
| `get_agent_task_events` | copilot_tasks | yes | [Experimental] Undocumented internal GitHub endpoint that can change without notice. Read one page of task events (read-only). |
|
|
213
|
-
| `list_copilot_models` | copilot_models | yes | Read /agents/swe/models and return the ID, name, vendor, preview flag, token prices or multiplier, and promotion when present. |
|
|
214
|
-
<!-- END AUTOMATED TOOLS -->
|
|
121
|
+
### (d) Generic `npx` / any MCP client
|
|
215
122
|
|
|
216
|
-
|
|
123
|
+
Point stdio transport at `npx -y github:daniel-saezv/copilot-agents-mcp`. Pass auth and notification env vars in the client’s server environment.
|
|
217
124
|
|
|
218
125
|
## Watch tasks
|
|
219
126
|
|
|
220
|
-
`create_agent_task` starts a detached watcher. You can also start it directly:
|
|
221
|
-
|
|
222
127
|
```bash
|
|
223
128
|
npx -y github:daniel-saezv/copilot-agents-mcp watch
|
|
224
129
|
```
|
|
225
130
|
|
|
226
|
-
The watcher polls pending tasks,
|
|
227
|
-
|
|
228
|
-
## Release
|
|
229
|
-
|
|
230
|
-
Push a tag `vMAJOR.MINOR.PATCH`. The release workflow checks that the tag (without the leading `v`) matches `version` in `package.json`, then runs typecheck, lint, tests, build, and a package smoke test on Node 26 before publishing to npm with `--provenance --access public`.
|
|
131
|
+
`create_agent_task` also starts a detached watcher when `COPILOT_AGENTS_NOTIFY_URL` is set. The watcher polls pending tasks, updates local state under a directory lock, and POSTs completion notices once per terminal state.
|
|
231
132
|
|
|
232
|
-
|
|
133
|
+
Several agents can share one server; pass a stable `owner` on create and filter with `list_agent_tasks` (labeling convention, not a security boundary).
|
|
233
134
|
|
|
234
|
-
##
|
|
135
|
+
## Develop
|
|
235
136
|
|
|
236
137
|
```bash
|
|
237
138
|
bash scripts/setup
|
|
@@ -239,11 +140,10 @@ npm test
|
|
|
239
140
|
npm run typecheck
|
|
240
141
|
npm run lint
|
|
241
142
|
npm run build
|
|
242
|
-
node scripts/pack-smoke.mjs
|
|
243
143
|
```
|
|
244
144
|
|
|
245
|
-
|
|
145
|
+
See [AGENTS.md](AGENTS.md) for agent maintenance notes.
|
|
246
146
|
|
|
247
147
|
## License
|
|
248
148
|
|
|
249
|
-
[MIT](LICENSE)
|
|
149
|
+
[MIT](LICENSE)
|
package/dist/cli.js
CHANGED
|
@@ -5,15 +5,15 @@ import { fileURLToPath } from "node:url";
|
|
|
5
5
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
6
6
|
import { authLockPath, createAppSession, createMemoryStore, githubAppClientId, ignoredTokenWarning, loginWithDeviceFlow, logoutLocal, logoutMessage, personalAccessToken, readActiveToken, readGitHubApp, statusReport, systemAccount, } from "./auth.js";
|
|
7
7
|
import { createGitHubClient } from "./github.js";
|
|
8
|
-
import { startHttpServer } from "./http.js";
|
|
9
8
|
import { NO_SESSION_MESSAGE, ToolFailure } from "./errors.js";
|
|
10
9
|
import { readSweModels } from "./swe-models.js";
|
|
11
|
-
import { assertSelection, splitList } from "./selection.js";
|
|
12
10
|
import { buildServer, defaultLaunchWatcher, packageVersion } from "./server.js";
|
|
11
|
+
import { buildLocalStatusDiagnostics } from "./status-local.js";
|
|
13
12
|
import { defaultStatePath } from "./state.js";
|
|
14
13
|
import { deliverNotice } from "./notify.js";
|
|
15
14
|
import { acquireWatcher, releaseWatcher, runWatcher, watcherLockPath } from "./watch.js";
|
|
16
|
-
export
|
|
15
|
+
export const WATCH_POLL_INTERVAL_MS = 15_000;
|
|
16
|
+
export function parseArgs(argv) {
|
|
17
17
|
const args = [...argv];
|
|
18
18
|
if (args.includes("--version"))
|
|
19
19
|
return { command: "version" };
|
|
@@ -37,87 +37,15 @@ export function parseArgs(argv, env) {
|
|
|
37
37
|
throw new Error("Use `auth status`.");
|
|
38
38
|
return { command: "status" };
|
|
39
39
|
}
|
|
40
|
-
let http = false;
|
|
41
|
-
let port;
|
|
42
|
-
let toolsets;
|
|
43
|
-
let tools;
|
|
44
|
-
let exclude;
|
|
45
|
-
let readOnly = false;
|
|
46
|
-
let features;
|
|
47
40
|
for (let index = 0; index < args.length; index += 1) {
|
|
48
41
|
const arg = args[index];
|
|
49
42
|
if (!arg)
|
|
50
43
|
continue;
|
|
51
44
|
if (arg === "--help" || arg === "-h")
|
|
52
45
|
throw new Help();
|
|
53
|
-
if (arg === "--http") {
|
|
54
|
-
http = true;
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
if (arg === "--read-only") {
|
|
58
|
-
readOnly = true;
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
const value = valueOf(arg, args, index);
|
|
62
|
-
if (value.consumed)
|
|
63
|
-
index += 1;
|
|
64
|
-
if (value.name === "--port") {
|
|
65
|
-
port = Number(value.text);
|
|
66
|
-
if (!Number.isInteger(port) || port < 0 || port > 65535)
|
|
67
|
-
throw new Error("--port must be an integer from 0 to 65535.");
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
if (value.name === "--toolsets") {
|
|
71
|
-
toolsets = splitList(value.text);
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
if (value.name === "--tools") {
|
|
75
|
-
tools = splitList(value.text);
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
if (value.name === "--exclude-tools") {
|
|
79
|
-
exclude = splitList(value.text);
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
if (value.name === "--features") {
|
|
83
|
-
features = splitList(value.text);
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
46
|
throw new Error(`Unknown argument: ${arg}`);
|
|
87
47
|
}
|
|
88
|
-
|
|
89
|
-
exclude: exclude ?? (env.GITHUB_EXCLUDE_TOOLS ? splitList(env.GITHUB_EXCLUDE_TOOLS) : []),
|
|
90
|
-
readOnly: readOnly || /^(1|true)$/i.test(env.GITHUB_READ_ONLY ?? ""),
|
|
91
|
-
features: features ?? [],
|
|
92
|
-
};
|
|
93
|
-
if (toolsets)
|
|
94
|
-
selection.toolsets = toolsets;
|
|
95
|
-
else if (env.GITHUB_TOOLSETS)
|
|
96
|
-
selection.toolsets = splitList(env.GITHUB_TOOLSETS);
|
|
97
|
-
if (tools)
|
|
98
|
-
selection.tools = tools;
|
|
99
|
-
else if (env.GITHUB_TOOLS)
|
|
100
|
-
selection.tools = splitList(env.GITHUB_TOOLS);
|
|
101
|
-
assertSelection(selection);
|
|
102
|
-
if (http)
|
|
103
|
-
return { command: "serve", http: true, port: port ?? 3333, selection };
|
|
104
|
-
if (port !== undefined)
|
|
105
|
-
throw new Error("--port can only be used with --http.");
|
|
106
|
-
return { command: "serve", http: false, selection };
|
|
107
|
-
}
|
|
108
|
-
function valueOf(arg, args, index) {
|
|
109
|
-
const names = ["--port", "--toolsets", "--tools", "--exclude-tools", "--features"];
|
|
110
|
-
for (const name of names) {
|
|
111
|
-
if (arg === name) {
|
|
112
|
-
const text = args[index + 1];
|
|
113
|
-
if (!text || text.startsWith("--"))
|
|
114
|
-
throw new Error(`Missing value for ${name}.`);
|
|
115
|
-
return { name, text, consumed: true };
|
|
116
|
-
}
|
|
117
|
-
if (arg.startsWith(`${name}=`))
|
|
118
|
-
return { name, text: arg.slice(name.length + 1), consumed: false };
|
|
119
|
-
}
|
|
120
|
-
return { name: undefined, text: "", consumed: false };
|
|
48
|
+
return { command: "serve" };
|
|
121
49
|
}
|
|
122
50
|
class Help extends Error {
|
|
123
51
|
constructor() {
|
|
@@ -131,8 +59,6 @@ function helpText() {
|
|
|
131
59
|
" MCP server over stdio.",
|
|
132
60
|
"copilot-agents-mcp --version",
|
|
133
61
|
" Print the version from package.json.",
|
|
134
|
-
"copilot-agents-mcp --http [--port 3333]",
|
|
135
|
-
" MCP server over HTTP on 127.0.0.1.",
|
|
136
62
|
"copilot-agents-mcp watch",
|
|
137
63
|
" Watch pending tasks and notify once when they finish.",
|
|
138
64
|
"copilot-agents-mcp login",
|
|
@@ -140,16 +66,31 @@ function helpText() {
|
|
|
140
66
|
"copilot-agents-mcp logout",
|
|
141
67
|
" Delete the keyring session.",
|
|
142
68
|
"copilot-agents-mcp auth status",
|
|
143
|
-
" Show which credential is active without showing the token.",
|
|
69
|
+
" Show which credential is active without showing the token, plus local diagnostics (state, notify env, D-Bus).",
|
|
144
70
|
"",
|
|
145
|
-
"Options: --toolsets, --tools, --exclude-tools, --read-only, --features",
|
|
146
71
|
"Environment: GITHUB_PERSONAL_ACCESS_TOKEN, COPILOT_AGENTS_GITHUB_APP_CLIENT_ID,",
|
|
147
|
-
"
|
|
148
|
-
"
|
|
72
|
+
"COPILOT_AGENTS_NOTIFY_URL, COPILOT_AGENTS_NOTIFY_AUTHORIZATION, COPILOT_AGENTS_STATE_PATH,",
|
|
73
|
+
"COPILOT_AGENTS_GITHUB_API_BASE_URL",
|
|
149
74
|
].join("\n");
|
|
150
75
|
}
|
|
151
|
-
|
|
76
|
+
import { githubApiBase } from "./github-hosts.js";
|
|
77
|
+
export { githubApiBase };
|
|
78
|
+
export function warnGithubApiBase(env) {
|
|
79
|
+
const base = githubApiBase(env);
|
|
80
|
+
if (base)
|
|
81
|
+
console.error(`Using COPILOT_AGENTS_GITHUB_API_BASE_URL=${base}`);
|
|
82
|
+
}
|
|
83
|
+
function githubClient(token, env, session) {
|
|
84
|
+
const baseUrl = githubApiBase(env);
|
|
85
|
+
return createGitHubClient({
|
|
86
|
+
token,
|
|
87
|
+
tokens: session ?? undefined,
|
|
88
|
+
...(baseUrl ? { baseUrl } : {}),
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
async function serve() {
|
|
152
92
|
warnIgnored(process.env);
|
|
93
|
+
warnGithubApiBase(process.env);
|
|
153
94
|
const statePath = defaultStatePath();
|
|
154
95
|
const pat = personalAccessToken(process.env);
|
|
155
96
|
const session = pat ? null : await openAppSession(process.env, statePath);
|
|
@@ -157,7 +98,7 @@ async function serve(command) {
|
|
|
157
98
|
const deps = {
|
|
158
99
|
statePath,
|
|
159
100
|
readToken,
|
|
160
|
-
clientForToken: (token) =>
|
|
101
|
+
clientForToken: (token) => githubClient(token, process.env, session),
|
|
161
102
|
readModels: async () => {
|
|
162
103
|
const token = readToken();
|
|
163
104
|
if (!token)
|
|
@@ -166,16 +107,12 @@ async function serve(command) {
|
|
|
166
107
|
},
|
|
167
108
|
launchWatcher: defaultLaunchWatcher,
|
|
168
109
|
};
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
await mcp.connect(new StdioServerTransport());
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
const http = await startHttpServer({ port: command.port, selection: command.selection, deps });
|
|
175
|
-
console.error(`copilot-agents-mcp listening at ${http.url}`);
|
|
110
|
+
const mcp = buildServer(deps);
|
|
111
|
+
await mcp.connect(new StdioServerTransport());
|
|
176
112
|
}
|
|
177
113
|
async function watch() {
|
|
178
114
|
warnIgnored(process.env);
|
|
115
|
+
warnGithubApiBase(process.env);
|
|
179
116
|
const statePath = defaultStatePath();
|
|
180
117
|
const pat = personalAccessToken(process.env);
|
|
181
118
|
const session = pat ? null : await openAppSession(process.env, statePath);
|
|
@@ -190,12 +127,11 @@ async function watch() {
|
|
|
190
127
|
if (!acquired)
|
|
191
128
|
return;
|
|
192
129
|
try {
|
|
193
|
-
const interval = Number(process.env.COPILOT_AGENTS_POLL_INTERVAL_MS ?? "15000");
|
|
194
130
|
await runWatcher({
|
|
195
|
-
client:
|
|
131
|
+
client: githubClient(token, process.env, session),
|
|
196
132
|
statePath,
|
|
197
133
|
deliver: (notice) => deliverNotice(notice),
|
|
198
|
-
intervalMs:
|
|
134
|
+
intervalMs: WATCH_POLL_INTERVAL_MS,
|
|
199
135
|
});
|
|
200
136
|
}
|
|
201
137
|
finally {
|
|
@@ -213,7 +149,7 @@ async function main() {
|
|
|
213
149
|
return;
|
|
214
150
|
}
|
|
215
151
|
try {
|
|
216
|
-
const command = parseArgs(process.argv.slice(2)
|
|
152
|
+
const command = parseArgs(process.argv.slice(2));
|
|
217
153
|
if (command.command === "watch")
|
|
218
154
|
await watch();
|
|
219
155
|
else if (command.command === "login")
|
|
@@ -225,7 +161,7 @@ async function main() {
|
|
|
225
161
|
else if (command.command === "version")
|
|
226
162
|
console.log(packageVersion());
|
|
227
163
|
else
|
|
228
|
-
await serve(
|
|
164
|
+
await serve();
|
|
229
165
|
}
|
|
230
166
|
catch (error) {
|
|
231
167
|
console.error(error instanceof Error ? error.message : "Error.");
|
|
@@ -303,14 +239,18 @@ async function status() {
|
|
|
303
239
|
stored = session.stored();
|
|
304
240
|
}
|
|
305
241
|
const app = !pat && stored ? await readGitHubApp(stored.access_token, fetch) : null;
|
|
306
|
-
|
|
242
|
+
const credential = statusReport({
|
|
307
243
|
env: process.env,
|
|
308
244
|
stored,
|
|
309
245
|
keyring: opened.persistent ? "ready" : "memory",
|
|
310
246
|
account: systemAccount(),
|
|
311
247
|
appName: app?.name ?? null,
|
|
312
248
|
appNotInstalled: app?.empty === true,
|
|
313
|
-
})
|
|
249
|
+
});
|
|
250
|
+
const local = await buildLocalStatusDiagnostics(process.env);
|
|
251
|
+
console.log(`${credential}\n\n${local.text}`);
|
|
252
|
+
if (local.failed)
|
|
253
|
+
process.exitCode = 1;
|
|
314
254
|
}
|
|
315
255
|
function invokedDirectly() {
|
|
316
256
|
const entry = process.argv[1];
|
package/dist/compact.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export function compactValue(value) {
|
|
2
|
+
if (value === undefined)
|
|
3
|
+
return undefined;
|
|
4
|
+
if (value === null)
|
|
5
|
+
return undefined;
|
|
6
|
+
if (Array.isArray(value)) {
|
|
7
|
+
const items = value.map((item) => compactValue(item)).filter((item) => item !== undefined);
|
|
8
|
+
return items;
|
|
9
|
+
}
|
|
10
|
+
if (typeof value === "object") {
|
|
11
|
+
const out = {};
|
|
12
|
+
for (const [key, raw] of Object.entries(value)) {
|
|
13
|
+
const next = compactValue(raw);
|
|
14
|
+
if (next !== undefined)
|
|
15
|
+
out[key] = next;
|
|
16
|
+
}
|
|
17
|
+
return out;
|
|
18
|
+
}
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
export function compactStringify(value) {
|
|
22
|
+
return JSON.stringify(compactValue(value));
|
|
23
|
+
}
|
package/dist/delivery.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { mapRawState } from "./task-status.js";
|
|
2
|
+
export function deliveryForTask(task, activeChannels) {
|
|
3
|
+
if (task.notified_at || task.delivery_record?.status === "delivered")
|
|
4
|
+
return "delivered";
|
|
5
|
+
if (task.delivery_record?.status === "failed")
|
|
6
|
+
return "failed";
|
|
7
|
+
if (activeChannels.length === 0)
|
|
8
|
+
return "not_configured";
|
|
9
|
+
return "pending";
|
|
10
|
+
}
|
|
11
|
+
export function shouldSpawnWatcher(activeChannels) {
|
|
12
|
+
return activeChannels.length > 0;
|
|
13
|
+
}
|
|
14
|
+
export function webhookPayloadId(taskId, rawState) {
|
|
15
|
+
const mapped = mapRawState(rawState);
|
|
16
|
+
return `${taskId}:${mapped.status}`;
|
|
17
|
+
}
|