@mcpc-tech/cli 0.1.52 → 0.1.54

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/app.mjs CHANGED
@@ -548,10 +548,9 @@ var ProgressTokenSchema = z.union([z.string(), z.number().int()]);
548
548
  var CursorSchema = z.string();
549
549
  var TaskCreationParamsSchema = z.looseObject({
550
550
  /**
551
- * Time in milliseconds to keep task results available after completion.
552
- * If null, the task has unlimited lifetime until manually cleaned up.
551
+ * Requested duration in milliseconds to retain task from creation.
553
552
  */
554
- ttl: z.union([z.number(), z.null()]).optional(),
553
+ ttl: z.number().optional(),
555
554
  /**
556
555
  * Time in milliseconds to wait between task status requests.
557
556
  */
@@ -851,7 +850,11 @@ var ClientCapabilitiesSchema = z.object({
851
850
  /**
852
851
  * Present if the client supports task creation.
853
852
  */
854
- tasks: ClientTasksCapabilitySchema.optional()
853
+ tasks: ClientTasksCapabilitySchema.optional(),
854
+ /**
855
+ * Extensions that the client supports. Keys are extension identifiers (vendor-prefix/extension-name).
856
+ */
857
+ extensions: z.record(z.string(), AssertObjectSchema).optional()
855
858
  });
856
859
  var InitializeRequestParamsSchema = BaseRequestParamsSchema.extend({
857
860
  /**
@@ -913,7 +916,11 @@ var ServerCapabilitiesSchema = z.object({
913
916
  /**
914
917
  * Present if the server supports task creation.
915
918
  */
916
- tasks: ServerTasksCapabilitySchema.optional()
919
+ tasks: ServerTasksCapabilitySchema.optional(),
920
+ /**
921
+ * Extensions that the server supports. Keys are extension identifiers (vendor-prefix/extension-name).
922
+ */
923
+ extensions: z.record(z.string(), AssertObjectSchema).optional()
917
924
  });
918
925
  var InitializeResultSchema = ResultSchema.extend({
919
926
  /**
@@ -1106,6 +1113,12 @@ var ResourceSchema = z.object({
1106
1113
  * The MIME type of this resource, if known.
1107
1114
  */
1108
1115
  mimeType: z.optional(z.string()),
1116
+ /**
1117
+ * The size of the raw resource content, in bytes (i.e., before base64 encoding or any tokenization), if known.
1118
+ *
1119
+ * This can be used by Hosts to display file sizes and estimate context window usage.
1120
+ */
1121
+ size: z.optional(z.number()),
1109
1122
  /**
1110
1123
  * Optional annotations for the client.
1111
1124
  */
@@ -2670,6 +2683,10 @@ var Protocol = class {
2670
2683
  this._progressHandlers.clear();
2671
2684
  this._taskProgressTokens.clear();
2672
2685
  this._pendingDebouncedNotifications.clear();
2686
+ for (const info of this._timeoutInfo.values()) {
2687
+ clearTimeout(info.timeoutId);
2688
+ }
2689
+ this._timeoutInfo.clear();
2673
2690
  for (const controller of this._requestHandlerAbortControllers.values()) {
2674
2691
  controller.abort();
2675
2692
  }
@@ -2800,7 +2817,9 @@ var Protocol = class {
2800
2817
  await capturedTransport?.send(errorResponse);
2801
2818
  }
2802
2819
  }).catch((error) => this._onerror(new Error(`Failed to send response: ${error}`))).finally(() => {
2803
- this._requestHandlerAbortControllers.delete(request.id);
2820
+ if (this._requestHandlerAbortControllers.get(request.id) === abortController) {
2821
+ this._requestHandlerAbortControllers.delete(request.id);
2822
+ }
2804
2823
  });
2805
2824
  }
2806
2825
  _onprogress(notification) {
@@ -4924,7 +4943,7 @@ var StdioClientTransport = class {
4924
4943
  },
4925
4944
  stdio: ["pipe", "pipe", this._serverParams.stderr ?? "inherit"],
4926
4945
  shell: false,
4927
- windowsHide: process2.platform === "win32" && isElectron(),
4946
+ windowsHide: process2.platform === "win32",
4928
4947
  cwd: this._serverParams.cwd
4929
4948
  });
4930
4949
  this._process.on("error", (error) => {
@@ -5031,9 +5050,6 @@ var StdioClientTransport = class {
5031
5050
  });
5032
5051
  }
5033
5052
  };
5034
- function isElectron() {
5035
- return "type" in process2;
5036
- }
5037
5053
 
5038
5054
  // __mcpc__cli_latest/node_modules/eventsource-parser/dist/index.js
5039
5055
  var ParseError = class extends Error {
@@ -5778,12 +5794,12 @@ var AUTHORIZATION_CODE_RESPONSE_TYPE = "code";
5778
5794
  var AUTHORIZATION_CODE_CHALLENGE_METHOD = "S256";
5779
5795
  function selectClientAuthMethod(clientInformation, supportedMethods) {
5780
5796
  const hasClientSecret = clientInformation.client_secret !== void 0;
5781
- if (supportedMethods.length === 0) {
5782
- return hasClientSecret ? "client_secret_post" : "none";
5783
- }
5784
- if ("token_endpoint_auth_method" in clientInformation && clientInformation.token_endpoint_auth_method && isClientAuthMethod(clientInformation.token_endpoint_auth_method) && supportedMethods.includes(clientInformation.token_endpoint_auth_method)) {
5797
+ if ("token_endpoint_auth_method" in clientInformation && clientInformation.token_endpoint_auth_method && isClientAuthMethod(clientInformation.token_endpoint_auth_method) && (supportedMethods.length === 0 || supportedMethods.includes(clientInformation.token_endpoint_auth_method))) {
5785
5798
  return clientInformation.token_endpoint_auth_method;
5786
5799
  }
5800
+ if (supportedMethods.length === 0) {
5801
+ return hasClientSecret ? "client_secret_basic" : "none";
5802
+ }
5787
5803
  if (hasClientSecret && supportedMethods.includes("client_secret_basic")) {
5788
5804
  return "client_secret_basic";
5789
5805
  }
@@ -5894,6 +5910,7 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope, res
5894
5910
  });
5895
5911
  }
5896
5912
  const resource = await selectResourceURL(serverUrl, provider, resourceMetadata);
5913
+ const resolvedScope = scope || resourceMetadata?.scopes_supported?.join(" ") || provider.clientMetadata.scope;
5897
5914
  let clientInformation = await Promise.resolve(provider.clientInformation());
5898
5915
  if (!clientInformation) {
5899
5916
  if (authorizationCode !== void 0) {
@@ -5917,6 +5934,7 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope, res
5917
5934
  const fullInformation = await registerClient(authorizationServerUrl, {
5918
5935
  metadata,
5919
5936
  clientMetadata: provider.clientMetadata,
5937
+ scope: resolvedScope,
5920
5938
  fetchFn
5921
5939
  });
5922
5940
  await provider.saveClientInformation(fullInformation);
@@ -5960,7 +5978,7 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope, res
5960
5978
  clientInformation,
5961
5979
  state,
5962
5980
  redirectUrl: provider.redirectUrl,
5963
- scope: scope || resourceMetadata?.scopes_supported?.join(" ") || provider.clientMetadata.scope,
5981
+ scope: resolvedScope,
5964
5982
  resource
5965
5983
  });
5966
5984
  await provider.saveCodeVerifier(codeVerifier);
@@ -6278,7 +6296,7 @@ async function fetchToken(provider, authorizationServerUrl, { metadata, resource
6278
6296
  fetchFn
6279
6297
  });
6280
6298
  }
6281
- async function registerClient(authorizationServerUrl, { metadata, clientMetadata, fetchFn }) {
6299
+ async function registerClient(authorizationServerUrl, { metadata, clientMetadata, scope, fetchFn }) {
6282
6300
  let registrationUrl;
6283
6301
  if (metadata) {
6284
6302
  if (!metadata.registration_endpoint) {
@@ -6293,7 +6311,10 @@ async function registerClient(authorizationServerUrl, { metadata, clientMetadata
6293
6311
  headers: {
6294
6312
  "Content-Type": "application/json"
6295
6313
  },
6296
- body: JSON.stringify(clientMetadata)
6314
+ body: JSON.stringify({
6315
+ ...clientMetadata,
6316
+ ...scope !== void 0 ? { scope } : {}
6317
+ })
6297
6318
  });
6298
6319
  if (!response.ok) {
6299
6320
  throw await parseErrorResponse(response);
@@ -7388,7 +7409,7 @@ var SystemPrompts = {
7388
7409
  </rules>
7389
7410
 
7390
7411
  <format>
7391
- Get tool schemas: \`{ "tool": "man", "args": { "tools": ["tool1", "tool2"] } }\`
7412
+ Get tool definitions: \`{ "tool": "man", "args": { "tools": ["tool1", "tool2"] } }\`
7392
7413
  Execute a tool: \`{ "tool": "tool_name", "args": { /* parameters */ } }\`
7393
7414
  </format>`,
7394
7415
  /**
@@ -7513,7 +7534,7 @@ function createArgsDefFactory(_name, _allToolNames, _depGroups, _predefinedSteps
7513
7534
  *
7514
7535
  * Only two fields:
7515
7536
  * - `tool`: which tool to execute (enum includes "man" + all tool names)
7516
- * - `args`: object with parameters. For "man": { tools: ["a", "b"] }. For others: tool parameters.
7537
+ * - `args`: object with parameters. For "man": { tools: ["a", "b"] } to fetch tool definitions (including input/output schemas). For others: tool parameters.
7517
7538
  */
7518
7539
  forAgentic: function(allToolNames) {
7519
7540
  const toolEnum = [
@@ -9464,11 +9485,12 @@ var ToolManager = class {
9464
9485
  /**
9465
9486
  * Register a tool in the registry
9466
9487
  */
9467
- registerTool(name, description, schema, callback, options = {}) {
9488
+ registerTool(name, description, inputSchema, callback, options = {}) {
9468
9489
  this.toolRegistry.set(name, {
9469
9490
  callback,
9470
9491
  description,
9471
- schema
9492
+ inputSchema,
9493
+ outputSchema: options.outputSchema
9472
9494
  });
9473
9495
  if (options.hidden) {
9474
9496
  this.toolConfigs.set(name, {
@@ -9481,13 +9503,16 @@ var ToolManager = class {
9481
9503
  /**
9482
9504
  * Explicitly mark a tool as public (exposed to MCP clients)
9483
9505
  */
9484
- addPublicTool(name, description, schema) {
9506
+ addPublicTool(name, description, inputSchema, outputSchema) {
9485
9507
  const existingTool = this.publicTools.find((t) => t.name === name);
9486
9508
  if (!existingTool) {
9487
9509
  this.publicTools.push({
9488
9510
  name,
9489
9511
  description,
9490
- inputSchema: schema
9512
+ inputSchema,
9513
+ ...outputSchema ? {
9514
+ outputSchema
9515
+ } : {}
9491
9516
  });
9492
9517
  }
9493
9518
  this.toolConfigs.set(name, {
@@ -9613,10 +9638,13 @@ var ToolManager = class {
9613
9638
  getHiddenToolSchema(name) {
9614
9639
  const tool2 = this.toolRegistry.get(name);
9615
9640
  const config = this.toolConfigs.get(name);
9616
- if (tool2 && config?.visibility?.hidden && tool2.schema) {
9641
+ if (tool2 && config?.visibility?.hidden && tool2.inputSchema) {
9617
9642
  return {
9618
9643
  description: tool2.description,
9619
- schema: tool2.schema
9644
+ inputSchema: tool2.inputSchema,
9645
+ ...tool2.outputSchema ? {
9646
+ outputSchema: tool2.outputSchema
9647
+ } : {}
9620
9648
  };
9621
9649
  }
9622
9650
  return void 0;
@@ -9652,10 +9680,13 @@ var ToolManager = class {
9652
9680
  composedTools[name] = {
9653
9681
  name,
9654
9682
  description: tool2.description,
9655
- inputSchema: jsonSchema(tool2.schema || {
9683
+ inputSchema: jsonSchema(tool2.inputSchema || {
9656
9684
  type: "object",
9657
9685
  properties: {}
9658
9686
  }),
9687
+ ...tool2.outputSchema ? {
9688
+ outputSchema: jsonSchema(tool2.outputSchema)
9689
+ } : {},
9659
9690
  execute: tool2.callback
9660
9691
  };
9661
9692
  }
@@ -9672,10 +9703,13 @@ var ToolManager = class {
9672
9703
  return {
9673
9704
  name,
9674
9705
  description: tool2.description,
9675
- inputSchema: tool2.schema ?? {
9706
+ inputSchema: tool2.inputSchema ?? {
9676
9707
  type: "object",
9677
9708
  properties: {}
9678
9709
  },
9710
+ ...tool2.outputSchema ? {
9711
+ outputSchema: tool2.outputSchema
9712
+ } : {},
9679
9713
  execute: tool2.callback
9680
9714
  };
9681
9715
  }
@@ -9689,10 +9723,13 @@ var ToolManager = class {
9689
9723
  composedTools.push({
9690
9724
  name,
9691
9725
  description: tool2.description,
9692
- inputSchema: tool2.schema ?? {
9726
+ inputSchema: tool2.inputSchema ?? {
9693
9727
  type: "object",
9694
9728
  properties: {}
9695
9729
  },
9730
+ ...tool2.outputSchema ? {
9731
+ outputSchema: tool2.outputSchema
9732
+ } : {},
9696
9733
  execute: tool2.callback
9697
9734
  });
9698
9735
  }
@@ -9745,7 +9782,10 @@ async function processToolsWithPlugins(server, _externalTools, mode) {
9745
9782
  const tempTool = {
9746
9783
  name: toolId,
9747
9784
  description: toolData.description,
9748
- inputSchema: toolData.schema || defaultSchema,
9785
+ inputSchema: toolData.inputSchema || defaultSchema,
9786
+ ...toolData.outputSchema ? {
9787
+ outputSchema: toolData.outputSchema
9788
+ } : {},
9749
9789
  execute: toolData.callback
9750
9790
  };
9751
9791
  const processedTool = await pluginManager.applyTransformToolHooks(tempTool, {
@@ -9757,7 +9797,9 @@ async function processToolsWithPlugins(server, _externalTools, mode) {
9757
9797
  },
9758
9798
  transformationIndex: 0
9759
9799
  });
9760
- toolManager.registerTool(toolId, processedTool.description || toolData.description, processedTool.inputSchema, processedTool.execute);
9800
+ toolManager.registerTool(toolId, processedTool.description || toolData.description, processedTool.inputSchema, processedTool.execute, {
9801
+ outputSchema: processedTool.outputSchema
9802
+ });
9761
9803
  }
9762
9804
  }
9763
9805
  function buildDependencyGroups(toolNameToDetailList, hiddenToolNames, publicToolNames, server) {
@@ -9803,6 +9845,7 @@ var ComposableMCPServer = class extends Server {
9803
9845
  toolManager;
9804
9846
  logger = createLogger("mcpc.compose");
9805
9847
  fileLoaders = /* @__PURE__ */ new Map();
9848
+ pluginsDisposed = false;
9806
9849
  // Legacy property for backward compatibility
9807
9850
  get toolNameMapping() {
9808
9851
  return this.toolManager.getToolNameMapping();
@@ -9931,9 +9974,13 @@ var ComposableMCPServer = class extends Server {
9931
9974
  }
9932
9975
  tool(name, description, paramsSchema, cb, options = {}) {
9933
9976
  const jsonSchemaObj = extractJsonSchema(paramsSchema);
9934
- this.toolManager.registerTool(name, description, jsonSchemaObj, cb, options);
9977
+ const outputSchemaObj = options.outputSchema ? extractJsonSchema(options.outputSchema) : void 0;
9978
+ this.toolManager.registerTool(name, description, jsonSchemaObj, cb, {
9979
+ ...options,
9980
+ outputSchema: outputSchemaObj
9981
+ });
9935
9982
  if (!options.internal) {
9936
- this.toolManager.addPublicTool(name, description, jsonSchemaObj);
9983
+ this.toolManager.addPublicTool(name, description, jsonSchemaObj, outputSchemaObj);
9937
9984
  }
9938
9985
  if (options.plugins) {
9939
9986
  for (const plugin of options.plugins) {
@@ -10190,9 +10237,12 @@ var ComposableMCPServer = class extends Server {
10190
10237
  return {
10191
10238
  name,
10192
10239
  description: tool2?.description || "",
10193
- inputSchema: tool2?.schema || {
10240
+ inputSchema: tool2?.inputSchema || {
10194
10241
  type: "object"
10195
- }
10242
+ },
10243
+ ...tool2?.outputSchema ? {
10244
+ outputSchema: tool2.outputSchema
10245
+ } : {}
10196
10246
  };
10197
10247
  });
10198
10248
  }
@@ -10217,9 +10267,12 @@ var ComposableMCPServer = class extends Server {
10217
10267
  return Array.from(registry.entries()).map(([name, tool2]) => ({
10218
10268
  name,
10219
10269
  description: tool2?.description || "",
10220
- inputSchema: tool2?.schema || {
10270
+ inputSchema: tool2?.inputSchema || {
10221
10271
  type: "object"
10222
- }
10272
+ },
10273
+ ...tool2?.outputSchema ? {
10274
+ outputSchema: tool2.outputSchema
10275
+ } : {}
10223
10276
  }));
10224
10277
  }
10225
10278
  /**
@@ -10278,11 +10331,21 @@ var ComposableMCPServer = class extends Server {
10278
10331
  async disposePlugins() {
10279
10332
  await this.pluginManager.dispose();
10280
10333
  }
10334
+ /**
10335
+ * Dispose plugins only once to avoid duplicated cleanup in chained handlers.
10336
+ */
10337
+ async disposePluginsOnce() {
10338
+ if (this.pluginsDisposed) {
10339
+ return;
10340
+ }
10341
+ this.pluginsDisposed = true;
10342
+ await this.disposePlugins();
10343
+ }
10281
10344
  /**
10282
10345
  * Close the server and ensure all plugins are disposed
10283
10346
  */
10284
10347
  async close() {
10285
- await this.disposePlugins();
10348
+ await this.disposePluginsOnce();
10286
10349
  await super.close();
10287
10350
  }
10288
10351
  async compose(name, description, depsConfig = {
@@ -10351,7 +10414,9 @@ var ComposableMCPServer = class extends Server {
10351
10414
  });
10352
10415
  });
10353
10416
  Object.entries(tools).forEach(([toolId, tool2]) => {
10354
- this.toolManager.registerTool(toolId, tool2.description || "", tool2.inputSchema, tool2.execute);
10417
+ this.toolManager.registerTool(toolId, tool2.description || "", tool2.inputSchema, tool2.execute, {
10418
+ outputSchema: tool2.outputSchema
10419
+ });
10355
10420
  });
10356
10421
  const registeredTools = this.toolManager.getRegisteredToolsAsComposed();
10357
10422
  const allTools = {
@@ -10387,16 +10452,20 @@ var ComposableMCPServer = class extends Server {
10387
10452
  server: this,
10388
10453
  toolNames: Object.keys(allTools)
10389
10454
  });
10455
+ const previousOnClose = this.onclose;
10390
10456
  this.onclose = async () => {
10391
10457
  await cleanupClients();
10392
- await this.disposePlugins();
10458
+ await this.disposePluginsOnce();
10393
10459
  await this.logger.info(`[${name}] Event: closed - cleaned up dependent clients and plugins`);
10460
+ previousOnClose?.();
10394
10461
  };
10462
+ const previousOnError = this.onerror;
10395
10463
  this.onerror = async (error) => {
10396
10464
  await this.logger.error(`[${name}] Event: error - ${error?.stack ?? String(error)}`);
10397
10465
  await cleanupClients();
10398
- await this.disposePlugins();
10466
+ await this.disposePluginsOnce();
10399
10467
  await this.logger.info(`[${name}] Action: cleaned up dependent clients and plugins`);
10468
+ previousOnError?.(error);
10400
10469
  };
10401
10470
  const toolNameToDetailList = Object.entries(allTools);
10402
10471
  const publicToolNames = this.getPublicToolNames();
@@ -10408,7 +10477,8 @@ var ComposableMCPServer = class extends Server {
10408
10477
  return;
10409
10478
  }
10410
10479
  this.tool(toolId, tool2.description || "", jsonSchema(tool2.inputSchema), tool2.execute, {
10411
- internal: false
10480
+ internal: false,
10481
+ outputSchema: tool2.outputSchema
10412
10482
  });
10413
10483
  });
10414
10484
  await this.pluginManager.triggerComposeEnd({
@@ -13378,7 +13448,7 @@ var coreHandler = (app) => {
13378
13448
  };
13379
13449
 
13380
13450
  // __mcpc__cli_latest/node_modules/@hono/node-server/dist/index.mjs
13381
- import { Http2ServerRequest as Http2ServerRequest2 } from "http2";
13451
+ import { Http2ServerRequest as Http2ServerRequest2, constants as h2constants } from "http2";
13382
13452
  import { Http2ServerRequest } from "http2";
13383
13453
  import { Readable } from "stream";
13384
13454
  import crypto3 from "crypto";
@@ -13592,15 +13662,17 @@ var Response2 = class _Response {
13592
13662
  this.#init = init;
13593
13663
  }
13594
13664
  if (typeof body === "string" || typeof body?.getReader !== "undefined" || body instanceof Blob || body instanceof Uint8Array) {
13595
- headers ||= init?.headers || { "content-type": "text/plain; charset=UTF-8" };
13596
- this[cacheKey] = [init?.status || 200, body, headers];
13665
+ ;
13666
+ this[cacheKey] = [init?.status || 200, body, headers || init?.headers];
13597
13667
  }
13598
13668
  }
13599
13669
  get headers() {
13600
13670
  const cache = this[cacheKey];
13601
13671
  if (cache) {
13602
13672
  if (!(cache[2] instanceof Headers)) {
13603
- cache[2] = new Headers(cache[2]);
13673
+ cache[2] = new Headers(
13674
+ cache[2] || { "content-type": "text/plain; charset=UTF-8" }
13675
+ );
13604
13676
  }
13605
13677
  return cache[2];
13606
13678
  }
@@ -13699,6 +13771,50 @@ if (typeof global.crypto === "undefined") {
13699
13771
  global.crypto = crypto3;
13700
13772
  }
13701
13773
  var outgoingEnded = Symbol("outgoingEnded");
13774
+ var incomingDraining = Symbol("incomingDraining");
13775
+ var DRAIN_TIMEOUT_MS = 500;
13776
+ var MAX_DRAIN_BYTES = 64 * 1024 * 1024;
13777
+ var drainIncoming = (incoming) => {
13778
+ const incomingWithDrainState = incoming;
13779
+ if (incoming.destroyed || incomingWithDrainState[incomingDraining]) {
13780
+ return;
13781
+ }
13782
+ incomingWithDrainState[incomingDraining] = true;
13783
+ if (incoming instanceof Http2ServerRequest2) {
13784
+ try {
13785
+ ;
13786
+ incoming.stream?.close?.(h2constants.NGHTTP2_NO_ERROR);
13787
+ } catch {
13788
+ }
13789
+ return;
13790
+ }
13791
+ let bytesRead = 0;
13792
+ const cleanup = () => {
13793
+ clearTimeout(timer);
13794
+ incoming.off("data", onData);
13795
+ incoming.off("end", cleanup);
13796
+ incoming.off("error", cleanup);
13797
+ };
13798
+ const forceClose = () => {
13799
+ cleanup();
13800
+ const socket = incoming.socket;
13801
+ if (socket && !socket.destroyed) {
13802
+ socket.destroySoon();
13803
+ }
13804
+ };
13805
+ const timer = setTimeout(forceClose, DRAIN_TIMEOUT_MS);
13806
+ timer.unref?.();
13807
+ const onData = (chunk) => {
13808
+ bytesRead += chunk.length;
13809
+ if (bytesRead > MAX_DRAIN_BYTES) {
13810
+ forceClose();
13811
+ }
13812
+ };
13813
+ incoming.on("data", onData);
13814
+ incoming.on("end", cleanup);
13815
+ incoming.on("error", cleanup);
13816
+ incoming.resume();
13817
+ };
13702
13818
  var handleRequestError = () => new Response(null, {
13703
13819
  status: 400
13704
13820
  });
@@ -13725,15 +13841,32 @@ var flushHeaders = (outgoing) => {
13725
13841
  };
13726
13842
  var responseViaCache = async (res, outgoing) => {
13727
13843
  let [status, body, header] = res[cacheKey];
13728
- if (header instanceof Headers) {
13844
+ let hasContentLength = false;
13845
+ if (!header) {
13846
+ header = { "content-type": "text/plain; charset=UTF-8" };
13847
+ } else if (header instanceof Headers) {
13848
+ hasContentLength = header.has("content-length");
13729
13849
  header = buildOutgoingHttpHeaders(header);
13850
+ } else if (Array.isArray(header)) {
13851
+ const headerObj = new Headers(header);
13852
+ hasContentLength = headerObj.has("content-length");
13853
+ header = buildOutgoingHttpHeaders(headerObj);
13854
+ } else {
13855
+ for (const key in header) {
13856
+ if (key.length === 14 && key.toLowerCase() === "content-length") {
13857
+ hasContentLength = true;
13858
+ break;
13859
+ }
13860
+ }
13730
13861
  }
13731
- if (typeof body === "string") {
13732
- header["Content-Length"] = Buffer.byteLength(body);
13733
- } else if (body instanceof Uint8Array) {
13734
- header["Content-Length"] = body.byteLength;
13735
- } else if (body instanceof Blob) {
13736
- header["Content-Length"] = body.size;
13862
+ if (!hasContentLength) {
13863
+ if (typeof body === "string") {
13864
+ header["Content-Length"] = Buffer.byteLength(body);
13865
+ } else if (body instanceof Uint8Array) {
13866
+ header["Content-Length"] = body.byteLength;
13867
+ } else if (body instanceof Blob) {
13868
+ header["Content-Length"] = body.size;
13869
+ }
13737
13870
  }
13738
13871
  outgoing.writeHead(status, header);
13739
13872
  if (typeof body === "string" || body instanceof Uint8Array) {
@@ -13853,14 +13986,18 @@ var getRequestListener = (fetchCallback, options = {}) => {
13853
13986
  setTimeout(() => {
13854
13987
  if (!incomingEnded) {
13855
13988
  setTimeout(() => {
13856
- incoming.destroy();
13857
- outgoing.destroy();
13989
+ drainIncoming(incoming);
13858
13990
  });
13859
13991
  }
13860
13992
  });
13861
13993
  }
13862
13994
  };
13863
13995
  }
13996
+ outgoing.on("finish", () => {
13997
+ if (!incomingEnded) {
13998
+ drainIncoming(incoming);
13999
+ }
14000
+ });
13864
14001
  }
13865
14002
  outgoing.on("close", () => {
13866
14003
  const abortController = req[abortControllerKey];
@@ -13875,7 +14012,7 @@ var getRequestListener = (fetchCallback, options = {}) => {
13875
14012
  setTimeout(() => {
13876
14013
  if (!incomingEnded) {
13877
14014
  setTimeout(() => {
13878
- incoming.destroy();
14015
+ drainIncoming(incoming);
13879
14016
  });
13880
14017
  }
13881
14018
  });
@@ -14887,7 +15024,7 @@ import { mkdir, readFile as readFile3, writeFile as writeFile2 } from "node:fs/p
14887
15024
  import { homedir } from "node:os";
14888
15025
  import { dirname, join as join3, resolve as resolve4 } from "node:path";
14889
15026
  import process10 from "node:process";
14890
- var CLI_VERSION = "0.1.52";
15027
+ var CLI_VERSION = "0.1.54";
14891
15028
  function extractServerName(command, commandArgs) {
14892
15029
  for (const arg of commandArgs) {
14893
15030
  if (!arg.startsWith("-")) {
@@ -15310,7 +15447,7 @@ function applyModeOverride(config, mode) {
15310
15447
  agent.options.mode = mode;
15311
15448
  if (mode === "ai_acp" && !agent.options.acpSettings) {
15312
15449
  agent.options.acpSettings = {
15313
- command: "claude-code-acp",
15450
+ command: "claude-agent-acp",
15314
15451
  args: [],
15315
15452
  session: {}
15316
15453
  };