@agentclientprotocol/claude-agent-acp 0.110.1 → 0.110.2-preview.2

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.
@@ -134,7 +134,7 @@ async function forkTranscript(params, dependencies) {
134
134
  const upToMessageId = forkPointOf(params.cursorId, history);
135
135
  timing.phase("cursor", ` resolution=${upToMessageId ? "found" : "missing"}`);
136
136
  if (upToMessageId === undefined) {
137
- throw RequestError.invalidParams({ cursorId: params.cursorId }, `Session ${params.sessionId} has no cursor ${params.cursorId} that a fork can start at. Use a cursor that the session announced with the \`fork\` capability, or send the request without \`cursorId\` to fork the whole session.`);
137
+ throw RequestError.invalidParams({ cursorId: params.cursorId }, `Session ${params.sessionId} has no cursor ${params.cursorId} that a fork can start at. Use a cursor that the session announced with the fork capability, or send the request without cursorId to fork the whole session.`);
138
138
  }
139
139
  const forked = await forkClaudeSession(params.sessionId, { upToMessageId });
140
140
  timing.phase("sdk-fork");
@@ -20,7 +20,7 @@ export function initialConfigOptions(entries) {
20
20
  const seen = new Set();
21
21
  for (const { configId } of entries ?? []) {
22
22
  if (seen.has(configId)) {
23
- throw RequestError.invalidParams({ configId }, `\`configOptions\` sets ${configId} more than once. Send one entry for each config option.`);
23
+ throw RequestError.invalidParams({ configId }, `configOptions sets ${configId} more than once. Send one entry for each config option.`);
24
24
  }
25
25
  seen.add(configId);
26
26
  }
@@ -1,5 +1,5 @@
1
1
  import { type HasConnectionContext, type McpServer, type McpServerAcp } from "@agentclientprotocol/sdk/unstable";
2
- import type { McpHttpServerConfig, McpServerConfig } from "@anthropic-ai/claude-agent-sdk";
2
+ import type { HookCallbackMatcher, McpHttpServerConfig, McpServerConfig } from "@anthropic-ai/claude-agent-sdk";
3
3
  /**
4
4
  * Makes the SDK config of an MCP server that the client serves over the ACP
5
5
  * connection (`"type": "acp"`): {@link McpOverAcp.sdkConfig} for a connection.
@@ -44,10 +44,83 @@ export declare function sdkMcpServers(servers: readonly McpServer[] | null | und
44
44
  * `MCP_PROTOCOL_NEGOTIATION=legacy` or its
45
45
  * `tengu_mcp_protocol_negotiation_http` flag turns that off. Then it sends
46
46
  * `initialize`, and the server is listed as failed.
47
+ *
48
+ * An `mcp/message` request names the ACP session and the tool call that it is
49
+ * sent for (`sessionId` and `toolCallId`), when the adapter knows them. An
50
+ * HTTP request does not say them. It carries the id of its tool use (see
51
+ * {@link TOOL_USE_ID_META}), and the adapter learns each tool use of an `acp`
52
+ * server's tool from a PreToolUse hook, before Claude Code runs the tool
53
+ * ({@link toolUseHooks}). Both cores report a tool call under the id of its
54
+ * tool use, so that id is the `toolCallId`.
55
+ *
56
+ * When a `session/update` reported a tool call of that id ({@link sending}),
57
+ * the request names the session of that report, and the tool call. Before
58
+ * the report, and without one, it names by the agent that runs the tool:
59
+ *
60
+ * - the main conversation: the root session, and the tool call;
61
+ * - a subagent with an announced child session: that session, and the tool
62
+ * call;
63
+ * - a subagent of a client without child sessions: the root session, which
64
+ * reports the subagent's tool calls, and the tool call;
65
+ * - an agent that never gets a child session: the root session, whose work
66
+ * it does, and no tool call, since no session reports one. These are an
67
+ * agent that a workflow runs, and any agent of a client without child
68
+ * sessions that the core does not know as a subagent;
69
+ * - a subagent whose child session is not announced yet, because the session
70
+ * has not read its start or a replay holds its `subagent_update`: the
71
+ * request waits for that announcement, for at most
72
+ * {@link announcementWaitMs}, and then names the child session and the tool
73
+ * call. When the time passes first, it names nothing;
74
+ * - any other agent: nothing, without a wait. The core forgot its child
75
+ * session, or no `subagent_update` announces one for it.
76
+ *
77
+ * The root session never stands in for a child session.
78
+ *
79
+ * A request names neither when one of these holds:
80
+ *
81
+ * - it has no tool use id, as `server/discover` and `tools/list` have none;
82
+ * - no PreToolUse hook reported its tool use, as for a server that a resume
83
+ * gave the session's running query ({@link sessionServersChanged}), or the
84
+ * tool use ended;
85
+ * - the client closed the root session, or its last setup request did not
86
+ * declare the request's server;
87
+ * - the session of the agent is a child session that no `subagent_update`
88
+ * announced to the client: one of AIR's draft, one that a conversation
89
+ * reset made the core forget, or one whose announcement did not go out
90
+ * within {@link announcementWaitMs};
91
+ * - the agent has the type of a workflow's agents, the client gets child
92
+ * sessions, and the session defines an agent of that name: the agent can
93
+ * be a subagent whose child session is not announced yet.
94
+ *
95
+ * Nothing orders the tool call's report before the request. Claude Code
96
+ * streams a tool use before it runs the tool, but the session can read its
97
+ * stream after the HTTP request arrives. The request then names a tool call
98
+ * that the client does not hold yet.
47
99
  */
48
100
  export declare class McpOverAcp {
49
101
  private readonly caller;
50
102
  private readonly bridge;
103
+ /** The `acp` servers of each active session that has any, or whose query started with any. */
104
+ private readonly sessions;
105
+ /** The child sessions that a `subagent_update` announced to the client (see {@link sending}). */
106
+ private readonly children;
107
+ /** The tool uses of `acp` servers' tools that Claude Code runs, by id (see {@link toolUseHooks}). */
108
+ private readonly toolUses;
109
+ /**
110
+ * The session of each tool call that the client holds without a final
111
+ * status, by tool call id (see {@link sending}).
112
+ */
113
+ private readonly toolCalls;
114
+ /**
115
+ * The requests that wait for the announcement of their agent's child
116
+ * session, by tool use id: what ends each one's wait (see {@link held}).
117
+ */
118
+ private readonly waiting;
119
+ /**
120
+ * How long a request waits for the announcement of its agent's child
121
+ * session (see {@link ANNOUNCEMENT_WAIT_MS}). Mutable so tests can change it.
122
+ */
123
+ announcementWaitMs: number;
51
124
  /**
52
125
  * Hands an `mcp/message` notification of the client (such as the progress
53
126
  * of a tool call) to the HTTP response of the MCP request that it names. An
@@ -63,5 +136,145 @@ export declare class McpOverAcp {
63
136
  * connection is closed. The next call tries to open the listener again.
64
137
  */
65
138
  sdkConfig(client: HasConnectionContext, server: McpServerAcp): Promise<McpHttpServerConfig>;
139
+ /**
140
+ * A setup request (`session/new`, `load`, `resume` or `fork`) made the
141
+ * session `sessionId` active with `servers`, on a query that started with
142
+ * the hooks of {@link toolUseHooks} for them.
143
+ */
144
+ sessionStarted(sessionId: string, servers: readonly McpServer[] | null | undefined): void;
145
+ /**
146
+ * A setup request gave the active session `sessionId` the servers
147
+ * `servers` in place of its earlier ones, on its running query. Returns
148
+ * the names of the `acp` servers among them that the query did not start
149
+ * with. Its hooks cannot change, so no hook reports the tool uses of these
150
+ * servers, and their requests name no session until the session's next
151
+ * query starts.
152
+ */
153
+ sessionServersChanged(sessionId: string, servers: readonly McpServer[] | null | undefined): string[];
154
+ /**
155
+ * The client ended the session `sessionId` (`session/close`, or a request
156
+ * that closes it too, such as `session/delete`): its requests and those of
157
+ * its child sessions name no session from now on. Forgets its servers, its
158
+ * announced children, its tool uses and its tool calls.
159
+ */
160
+ sessionClosed(sessionId: string): void;
161
+ /**
162
+ * Takes a session update that goes to the client. A `subagent_update`
163
+ * announces a child session. A `tool_call`, or a `tool_call_update` with a
164
+ * status, reports a tool call of its session, which is kept until an update
165
+ * of that session or of another one under the same root gives the tool call
166
+ * a final status. That update also ends the tool use of the same id. An
167
+ * announcement, and a tool call's report, end the wait of the requests
168
+ * that they let name a session (see {@link held}).
169
+ *
170
+ * Only the tool calls of an active session with `acp` servers
171
+ * ({@link sessionStarted}) and of its announced child sessions are kept. The
172
+ * tool calls of a child session of AIR's draft, which a `subagent_spawned`
173
+ * announces, are not.
174
+ */
175
+ sending(notification: SentUpdate): void;
176
+ /**
177
+ * The hooks of the query of the root session `sessionId`, which starts with
178
+ * `servers`, or undefined when none of them is an `acp` server: such a
179
+ * query has no MCP request to name a session for. They record each tool
180
+ * use of a tool of the `acp` servers before Claude Code runs it
181
+ * (PreToolUse), with the session of the agent that runs it (see the class
182
+ * doc), until the tool returned or failed (PostToolUse,
183
+ * PostToolUseFailure). Claude Code runs them for no other tool, and they
184
+ * make no decision.
185
+ *
186
+ * A tool use that neither hook ends, such as one that Claude Code does not
187
+ * run after all, stays until its tool call gets a final status
188
+ * ({@link sending}) or the client closes the session
189
+ * ({@link sessionClosed}).
190
+ */
191
+ toolUseHooks(sessionId: string, servers: readonly McpServer[] | null | undefined, agents: SessionAgents): Record<"PreToolUse" | "PostToolUse" | "PostToolUseFailure", HookCallbackMatcher> | undefined;
192
+ /** The root session of the announced child session `sessionId`, or `sessionId` itself. */
193
+ private rootOf;
194
+ /**
195
+ * Forgets the tool use `id` and its tool call, when they are of the root
196
+ * session `root`, and ends the wait of the tool use's requests. A fork
197
+ * replays the tool calls of its original under their ids: its updates
198
+ * leave those of the original alone.
199
+ */
200
+ private toolEnded;
201
+ /**
202
+ * Resolves when a request of the tool use `toolUseId` need wait no longer
203
+ * for the announcement of its agent's child session: {@link release} ended
204
+ * the wait, or {@link announcementWaitMs} passed. It never rejects.
205
+ *
206
+ * Nothing that an announcement needs waits for the request. The hook that
207
+ * recorded the tool use has answered. The session reads Claude Code's
208
+ * stream whatever its tools do, and Claude Code wrote the subagent's start
209
+ * to that stream before it ran the subagent's tool. A replay ends without
210
+ * the request too.
211
+ */
212
+ private held;
213
+ /**
214
+ * Ends the wait of the requests of the tool use `toolUseId` ({@link held}):
215
+ * its agent's child session is announced, its tool call is reported, or it
216
+ * ended, also with the close of its session. Each request then names what
217
+ * it can.
218
+ */
219
+ private release;
220
+ /**
221
+ * The session and tool call that the `mcp/message` request of the MCP
222
+ * request `request` names, or undefined when it names none (see the class
223
+ * doc). A request of a subagent whose child session is not announced yet
224
+ * resolves once it is, or names nothing after {@link announcementWaitMs}.
225
+ * It neither throws nor rejects: the bridge would answer Claude Code with
226
+ * HTTP 500 instead of sending the request.
227
+ *
228
+ * It does not read `request.connection`. Each agent app (`v1AgentApp`,
229
+ * `v2AgentApp`) makes its own `McpOverAcp` for its one connection, so every
230
+ * request and every recorded session is of that connection.
231
+ */
232
+ private attribution;
233
+ /**
234
+ * What a request of the tool use `toolUseId` to the server `serverId` names
235
+ * now, or `unannounced` when it names nothing because the child session of
236
+ * its agent, which a `subagent_update` announces, is not announced yet.
237
+ */
238
+ private named;
66
239
  }
240
+ /**
241
+ * What {@link McpOverAcp.toolUseHooks} asks the core of a session about the
242
+ * agents of its query.
243
+ */
244
+ export type SessionAgents = {
245
+ /**
246
+ * Whether the client gets a child session per subagent. Without child
247
+ * sessions, the root session's updates carry the work of every agent.
248
+ */
249
+ childSessions: boolean;
250
+ /**
251
+ * The session whose updates report the tool calls of the subagent `agentId`
252
+ * as the core routes them now: its announced child session, or the root
253
+ * session for a client without child sessions. Undefined for an agent that
254
+ * the core does not know as a subagent (it has not read its
255
+ * `task_started`, which an agent that a workflow runs never gets), and for
256
+ * one whose child session is not announced.
257
+ */
258
+ reporting(agentId: string): string | undefined;
259
+ /**
260
+ * The id of the child session that a `subagent_update` announces for the
261
+ * subagent `agentId`, whether it went out yet or not. Undefined for a
262
+ * client that gets no child session from a `subagent_update`: one without
263
+ * child sessions, or with those of AIR's draft.
264
+ */
265
+ childSessionId(agentId: string): string | undefined;
266
+ /** Whether the session had an agent definition of the name `name` when its query started. */
267
+ definesAgent(name: string): boolean;
268
+ };
269
+ /** A session update that goes to the client, as far as {@link McpOverAcp.sending} reads it. */
270
+ type SentUpdate = {
271
+ sessionId: string;
272
+ update: {
273
+ sessionUpdate: string;
274
+ sessionId?: unknown;
275
+ toolCallId?: unknown;
276
+ status?: unknown;
277
+ };
278
+ };
279
+ export {};
67
280
  //# sourceMappingURL=mcp-servers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mcp-servers.d.ts","sourceRoot":"","sources":["../src/mcp-servers.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,oBAAoB,EACzB,KAAK,SAAS,EACd,KAAK,YAAY,EAClB,MAAM,mCAAmC,CAAC;AAE3C,OAAO,KAAK,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAE3F;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE,YAAY,KAAK,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAEtF;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAA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