@wrongstack/mcp 0.284.0 → 0.285.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/dist/index.js CHANGED
@@ -1,14 +1,7 @@
1
- import { spawn } from 'child_process';
2
- import { expectDefined, ToolCapabilities, buildChildEnv, ToolError, ConfigError } from '@wrongstack/core';
3
- import { toErrorMessage } from '@wrongstack/core/utils';
4
- import { createHash, randomBytes } from 'crypto';
5
- import * as https from 'https';
6
- import * as net from 'net';
7
- import * as fs from 'fs/promises';
8
- import * as path from 'path';
9
- import { createServer } from 'http';
10
-
11
1
  // src/client.ts
2
+ import { spawn } from "node:child_process";
3
+ import { buildChildEnv } from "@wrongstack/core";
4
+ import { toErrorMessage } from "@wrongstack/core/utils";
12
5
 
13
6
  // src/constants.ts
14
7
  var MCP_CONSTANTS = Object.freeze({
@@ -80,6 +73,12 @@ function normalizeMCPTools(value) {
80
73
  }
81
74
  return tools;
82
75
  }
76
+
77
+ // src/transport.ts
78
+ import { randomBytes } from "node:crypto";
79
+ import * as https from "node:https";
80
+ import * as net from "node:net";
81
+ import { ConfigError, ToolError } from "@wrongstack/core";
83
82
  function isTlsUnsafeAllowed() {
84
83
  return process.env["WRONGSTACK_UNSAFE_MCP_TLS"] === "1";
85
84
  }
@@ -184,7 +183,8 @@ var SSEReader = class {
184
183
  const field = colonIdx === -1 ? line : line.slice(0, colonIdx);
185
184
  let value = colonIdx === -1 ? "" : line.slice(colonIdx + 1);
186
185
  if (value.startsWith(" ")) value = value.slice(1);
187
- if (field === "event") ; else if (field === "data") {
186
+ if (field === "event") {
187
+ } else if (field === "data") {
188
188
  if (this.dataLines.length >= SSE_READER_MAX_DATA_LINES) {
189
189
  throw new ToolError({
190
190
  message: `SSE: exceeded ${SSE_READER_MAX_DATA_LINES} data lines per event \u2014 upstream is not sending blank-line delimiters`,
@@ -1366,6 +1366,9 @@ function quoteWindowsArg(arg) {
1366
1366
  if (!/[\s"]/.test(arg)) return arg;
1367
1367
  return `"${arg.replace(/"/g, '""')}"`;
1368
1368
  }
1369
+
1370
+ // src/wrap-tool.ts
1371
+ import { ToolCapabilities } from "@wrongstack/core";
1369
1372
  var MUTATING_RE = /create|update|delete|write|send|set|put|post|patch|remove|rename|move/i;
1370
1373
  function isMutatingTool(mcpTool) {
1371
1374
  if (MUTATING_RE.test(mcpTool.name)) return true;
@@ -1420,6 +1423,14 @@ function stringify(c) {
1420
1423
  }
1421
1424
  return String(c ?? "");
1422
1425
  }
1426
+
1427
+ // src/registry.ts
1428
+ import { expectDefined } from "@wrongstack/core";
1429
+
1430
+ // src/manifest-cache.ts
1431
+ import { createHash } from "node:crypto";
1432
+ import * as fs from "node:fs/promises";
1433
+ import * as path from "node:path";
1423
1434
  function manifestConfigHash(cfg) {
1424
1435
  const basis = JSON.stringify({
1425
1436
  transport: cfg.transport,
@@ -1979,21 +1990,25 @@ var MCPRegistry = class _MCPRegistry {
1979
1990
  }
1980
1991
  }
1981
1992
  };
1993
+
1994
+ // src/manage.ts
1995
+ import { randomBytes as randomBytes2 } from "node:crypto";
1996
+ import * as fs2 from "node:fs/promises";
1982
1997
  async function readConfig(path2) {
1983
1998
  try {
1984
- return JSON.parse(await fs.readFile(path2, "utf8"));
1999
+ return JSON.parse(await fs2.readFile(path2, "utf8"));
1985
2000
  } catch {
1986
2001
  return {};
1987
2002
  }
1988
2003
  }
1989
2004
  async function writeConfig(path2, cfg) {
1990
2005
  const raw = JSON.stringify(cfg, null, 2);
1991
- const tmp = `${path2}.${process.pid}.${randomBytes(6).toString("hex")}.tmp`;
1992
- await fs.writeFile(tmp, raw, "utf8");
2006
+ const tmp = `${path2}.${process.pid}.${randomBytes2(6).toString("hex")}.tmp`;
2007
+ await fs2.writeFile(tmp, raw, "utf8");
1993
2008
  try {
1994
- await fs.rename(tmp, path2);
2009
+ await fs2.rename(tmp, path2);
1995
2010
  } catch (err) {
1996
- await fs.rm(tmp, { force: true }).catch(() => void 0);
2011
+ await fs2.rm(tmp, { force: true }).catch(() => void 0);
1997
2012
  throw err;
1998
2013
  }
1999
2014
  }
@@ -2068,7 +2083,7 @@ function errMessage(err) {
2068
2083
  async function listMcp(deps) {
2069
2084
  const { servers } = await readServers(deps.configPath);
2070
2085
  return Object.entries(servers).map(
2071
- ([name, cfg]) => projectServer(name, { ...cfg}, deps.registry)
2086
+ ([name, cfg]) => projectServer(name, { ...cfg, name }, deps.registry)
2072
2087
  );
2073
2088
  }
2074
2089
  async function addMcp(input, deps) {
@@ -2217,6 +2232,11 @@ async function safeStop(name, deps) {
2217
2232
  } catch {
2218
2233
  }
2219
2234
  }
2235
+
2236
+ // src/server.ts
2237
+ import { createServer } from "node:http";
2238
+ import { expectDefined as expectDefined2 } from "@wrongstack/core";
2239
+ import { toErrorMessage as toErrorMessage2 } from "@wrongstack/core/utils";
2220
2240
  var PARSE_ERROR = -32700;
2221
2241
  var INVALID_REQUEST = -32600;
2222
2242
  var METHOD_NOT_FOUND = -32601;
@@ -2259,16 +2279,16 @@ var MCPServer = class {
2259
2279
  const result = await this.dispatch(msg.method, msg.params);
2260
2280
  if (result === METHOD_NOT_FOUND_SENTINEL) {
2261
2281
  return this.encodeError(
2262
- expectDefined(msg.id),
2282
+ expectDefined2(msg.id),
2263
2283
  METHOD_NOT_FOUND,
2264
2284
  `Method not found: ${msg.method}`
2265
2285
  );
2266
2286
  }
2267
2287
  return JSON.stringify({ jsonrpc: "2.0", id: msg.id, result });
2268
2288
  } catch (err) {
2269
- const message = toErrorMessage(err);
2289
+ const message = toErrorMessage2(err);
2270
2290
  this.logger?.warn?.(`MCP server: method "${msg.method}" threw: ${message}`);
2271
- return this.encodeError(expectDefined(msg.id), INTERNAL_ERROR, message);
2291
+ return this.encodeError(expectDefined2(msg.id), INTERNAL_ERROR, message);
2272
2292
  }
2273
2293
  }
2274
2294
  async dispatch(method, params) {
@@ -2337,7 +2357,7 @@ function serveStdio(server, opts = {}) {
2337
2357
  `, () => resolve());
2338
2358
  })
2339
2359
  ).catch((err) => {
2340
- const msg = toErrorMessage(err);
2360
+ const msg = toErrorMessage2(err);
2341
2361
  console.error(
2342
2362
  JSON.stringify({
2343
2363
  level: "error",
@@ -2383,7 +2403,7 @@ function serveStdio(server, opts = {}) {
2383
2403
  JSON.stringify({
2384
2404
  level: "error",
2385
2405
  event: "mcp_server.handle_message_failed",
2386
- message: toErrorMessage(err),
2406
+ message: toErrorMessage2(err),
2387
2407
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
2388
2408
  })
2389
2409
  );
@@ -2487,12 +2507,33 @@ async function handleHttpRequest(server, req, res, token, log) {
2487
2507
  if (out === null) return send(202, "");
2488
2508
  return send(200, out);
2489
2509
  }).catch((err) => {
2490
- log?.warn?.(`MCP http handler error: ${toErrorMessage(err)}`);
2510
+ log?.warn?.(`MCP http handler error: ${toErrorMessage2(err)}`);
2491
2511
  send(500, JSON.stringify({ error: "internal error" }));
2492
2512
  });
2493
2513
  });
2494
2514
  }
2495
-
2496
- export { MCPClient, MCPRegistry, MCPServer, MCP_CONSTANTS, SSEReader, SSETransport, StreamableHTTPTransport, addMcp, disableMcp, discoverMcp, enableMcp, listMcp, manifestConfigHash, readManifest, removeMcp, restartMcp, serveHttp, serveStdio, toContentBlocks, updateMcp, wrapMCPTool, writeManifest };
2515
+ export {
2516
+ MCPClient,
2517
+ MCPRegistry,
2518
+ MCPServer,
2519
+ MCP_CONSTANTS,
2520
+ SSEReader,
2521
+ SSETransport,
2522
+ StreamableHTTPTransport,
2523
+ addMcp,
2524
+ disableMcp,
2525
+ discoverMcp,
2526
+ enableMcp,
2527
+ listMcp,
2528
+ manifestConfigHash,
2529
+ readManifest,
2530
+ removeMcp,
2531
+ restartMcp,
2532
+ serveHttp,
2533
+ serveStdio,
2534
+ toContentBlocks,
2535
+ updateMcp,
2536
+ wrapMCPTool,
2537
+ writeManifest
2538
+ };
2497
2539
  //# sourceMappingURL=index.js.map
2498
- //# sourceMappingURL=index.js.map