You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -30,35 +30,75 @@ The Agent Client Protocol (ACP) is a protocol that standardizes communication be
30
30
31
31
## Starting the ACP server
32
32
33
-
{% data variables.copilot.copilot_cli %} can be started as an ACP server using the `--acp` flag. The server supports two modes, `stdio` and `TCP`.
33
+
Use the `--acp` option of the `copilot` command to start the CLI's ACP server. You can specify the transport mode with either the `--stdio` or `--port` options. If no transport mode is specified, the server defaults to stdio mode.
34
34
35
-
> [!NOTE]
36
-
> When running in ACP mode, the tool-filtering flags (`--available-tools`, `--excluded-tools`) and the reasoning flag (`--effort`, `--reasoning-effort`) are applied to each session started by the ACP client.
35
+
### Options applied to every session
36
+
37
+
The ACP `session/new` request only lets a client set a few session parameters, such as the working directory and the MCP servers to use. It does not carry tool-filtering or reasoning settings. To configure those, pass the corresponding options when you **start the server**. The server stores the values and applies them as the initial configuration for every session it creates or loads, for any client that connects. A connecting client does not choose these values—whoever launches the server does.
37
38
38
-
### stdio mode (recommended for IDE integration)
39
+
| Server option | Accepted value | Effect on every session |
Every session the connected client opens against that server inherits those settings. Because the values are fixed when the server starts, a client cannot change them per session through `session/new`.
52
+
53
+
### stdio mode
54
+
55
+
stdio mode is inferred by default when you start the ACP server. You can also use the `--stdio` option for disambiguation.
41
56
42
57
```bash
43
58
copilot --acp --stdio
44
59
```
45
60
46
61
### TCP mode
47
62
48
-
If the `--port`flag is provided in combination with the `--acp`flag, the server is started in TCP mode.
63
+
If the `--port`option is provided in combination with the `--acp`option, the server is started in TCP mode.
49
64
50
65
```bash
51
66
copilot --acp --port 3000
52
67
```
53
68
54
-
## Integrating with the ACP server
69
+
### Choosing between stdio and TCP
70
+
71
+
Both transport modes carry the same ACP messages, encoded as newline-delimited JSON (NDJSON). They differ only in how a client connects to the server and how the server's lifecycle is managed. The two modes are mutually exclusive: passing both `--stdio` and `--port` is rejected.
72
+
73
+
| Aspect | stdio mode | TCP mode |
74
+
|---|---|---|
75
+
|**How the client connects**| The client launches `copilot --acp` as a child process and exchanges messages over the process's standard input and output. | The server opens a TCP listener that clients connect to over a network socket. By default it binds to the loopback address `127.0.0.1`. |
76
+
|**Number of clients**| A single client—the process that spawned the server and owns the pipe. | The listener accepts socket connections, each handled as its own agent connection. |
77
+
|**Lifecycle**| Tied to the parent process. When the input stream closes—because the parent exits or closes the pipe—the server shuts down automatically. | Independent of any single client. The server keeps listening on the port until it is stopped, for example with <kbd>Ctrl</kbd>+<kbd>C</kbd>. |
78
+
|**Standard output**| Reserved for the NDJSON protocol stream, so it can't be used for logs or other text. | Free for other use, because protocol traffic travels over the socket. |
79
+
80
+
When to use each mode:
55
81
56
-
There is a growing ecosystem of libraries to programmatically interact with ACP servers. Given {% data variables.copilot.copilot_cli %} is correctly installed and authenticated, the following example demonstrates using the [typescript](https://agentclientprotocol.com/libraries/typescript) client to send a single prompt and print the AI response.
82
+
* Use **stdio mode** when an editor, IDE, or script spawns {% data variables.copilot.copilot_cli_short %} directly as a subprocess. This is the default and the recommended setup for IDE integration, because the transport is established automatically when the process starts and torn down when it exits.
83
+
* Use **TCP mode** when a client needs to reach the server over a socket instead of a pipe—for example, from a separate process or container, or when connecting to a longer-lived server on a known port.
57
84
58
-
```typescript
85
+
## Example: integrating with the ACP server
86
+
87
+
The following example is a client application that uses {% data variables.product.prodname_copilot_short %} by interacting with {% data variables.copilot.copilot_cli %}'s ACP server. It starts the ACP server in stdio mode, opens a session, asks you to enter a prompt, sends it, and prints the streamed response.
88
+
89
+
There is a growing ecosystem of libraries for interacting with ACP servers programmatically. This example uses the [ACP TypeScript library](https://agentclientprotocol.com/libraries/typescript).
90
+
91
+
To run this example, you need the following dependencies:
92
+
93
+
*[Node.js](https://nodejs.org) version 18 or later.
94
+
* {% data variables.copilot.copilot_cli %}, installed and authenticated.
95
+
* The `@agentclientprotocol/sdk` package, which provides the ACP TypeScript library. Install it by running `npm install @agentclientprotocol/sdk`.
// Ask the user to enter a prompt instead of using a hard-coded one.
150
+
const rl =readline.createInterface({
151
+
input: process.stdin,
152
+
output: process.stdout,
153
+
});
154
+
const promptText =awaitrl.question("Enter a prompt: ");
155
+
rl.close();
110
156
111
157
const promptResult =awaitconnection.prompt({
112
158
sessionId: sessionResult.sessionId,
@@ -134,7 +180,71 @@ main().catch((error) => {
134
180
});
135
181
```
136
182
183
+
To run the example:
184
+
185
+
1. Save the code above to a file named `acp-client.ts`.
186
+
1. Run the file with `npx tsx`, which runs the TypeScript directly without a separate build step:
187
+
188
+
```bash
189
+
npx tsx acp-client.ts
190
+
```
191
+
192
+
## Using slash commands
193
+
194
+
{% data variables.copilot.copilot_cli %}'s built-in slash commands can be run over ACP. To invoke one, send it as an ordinary prompt whose text is the command, passed as a single text content block—for example, `/context` or `/session info`. The server recognizes the command and runs it directly: informational commands such as `/usage` or `/context` return their output without invoking the model, while action commands such as `/plan` or `/review` start the corresponding agent task. Either way, the command text is not sent to the model as a question.
195
+
196
+
### Discovering available commands
197
+
198
+
The server advertises the commands it supports through the standard ACP `available_commands_update` session notification. It is sent after a session is created or loaded, and again whenever the set changes—for example, when skills finish loading. This advertised list is the authoritative, always-current set of commands you can run over ACP, and clients typically surface it in a command menu.
199
+
200
+
The advertised list contains:
201
+
202
+
***Built-in commands**, such as `/compact`, `/context`, `/usage`, `/env`, `/model`, `/mcp`, `/plan`, `/review`, `/research`, `/session`, and `/rename`.
203
+
***Enabled, user-invocable skills**, which appear as `/SKILL-NAME` commands.
204
+
205
+
Commands that the client itself registers are not advertised back to it.
206
+
207
+
### Accessing the list from your client
208
+
209
+
Because the list arrives as a notification rather than in response to a request, there is no method to fetch it on demand. Your client accesses it by handling the `session/update` notification and reacting to updates whose type is `available_commands_update`. Each entry has a `name` (without the leading slash), a `description`, and an optional `input.hint` that describes the command's arguments. The notification is re-sent whenever the set changes, so treat each one as a complete replacement of any list you have cached.
210
+
211
+
The following `sessionUpdate` handler captures the advertised commands, extending the `client` object from the example shown earlier.
212
+
213
+
```typescript copy
214
+
// Track the latest advertised commands for the session.
215
+
let availableCommands:acp.AvailableCommand[] = [];
216
+
217
+
const client:acp.Client= {
218
+
async sessionUpdate(params) {
219
+
const update =params.update;
220
+
221
+
if (update.sessionUpdate==="available_commands_update") {
222
+
// This notification is a full snapshot—replace any cached list.
223
+
availableCommands=update.availableCommands;
224
+
for (const command ofavailableCommands) {
225
+
// command.name has no leading slash; invoke it by sending "/<name>" as a prompt.
// ...handle other updates, such as agent_message_chunk
232
+
},
233
+
234
+
// ...other client methods, such as requestPermission
235
+
};
236
+
```
237
+
238
+
To run one of the advertised commands, send its name as a prompt in a single text content block—for example, `{ type: "text", text: "/context" }`—as described in [Using slash commands](#using-slash-commands).
239
+
240
+
### Commands that cannot be used over ACP
241
+
242
+
Slash commands that depend on the interactive terminal interface are not handled by the ACP server. This includes commands that open a picker, dialog, or full-screen view, such as `/diff`, `/resume`, `/theme`, `/settings`, `/login`, `/help`, `/tasks`, and `/undo`. As a rule, if a command does not appear in the `available_commands_update` list, it will not run over ACP: the server treats the text as an ordinary prompt and forwards it to the model instead of executing it.
243
+
244
+
Because ACP clients have no interactive pickers, a built-in command that would normally open a submenu instead returns its options as text. Provide the subcommand explicitly to get a direct result—for example, `/session info` or `/mcp list` rather than `/session` or `/mcp` on its own.
245
+
246
+
For a complete list of slash commands for {% data variables.copilot.copilot_cli_short %}, see [AUTOTITLE](/copilot/reference/copilot-cli-reference/cli-command-reference#slash-commands-in-the-interactive-interface).
Copy file name to clipboardExpand all lines: content/copilot/reference/copilot-cli-reference/cli-command-reference.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -193,6 +193,8 @@ When diff mode is open (entered via `/diff`):
193
193
194
194
## Slash commands in the interactive interface
195
195
196
+
These are the slash commands you can use from within an interactive CLI session. A subset of these slash commands is available to clients that use the CLI via its ACP server. For more information, see [AUTOTITLE](/copilot/reference/copilot-cli-reference/acp-server).
0 commit comments