@wrongstack/mcp 1.0.1 → 1.0.3

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
@@ -1262,7 +1262,7 @@ import { Agent as UndiciAgent, fetch as undiciFetch } from "undici";
1262
1262
  import * as dns2 from "node:dns/promises";
1263
1263
  import * as net2 from "node:net";
1264
1264
  import { ConfigError } from "@wrongstack/core/types";
1265
- import { isPrivateIPv4 as isPrivateIPv42, isPrivateIPv6 as isPrivateIPv62 } from "@wrongstack/core/utils";
1265
+ import { embeddedIPv4, expandIPv6, isPrivateIPv4 as isPrivateIPv42, isPrivateIPv6 as isPrivateIPv62 } from "@wrongstack/core/utils";
1266
1266
  function isTlsUnsafeAllowed() {
1267
1267
  return process.env["WRONGSTACK_UNSAFE_MCP_TLS"] === "1";
1268
1268
  }
@@ -1351,6 +1351,11 @@ function classifyTransportAddress(address, family) {
1351
1351
  }
1352
1352
  return "blocked";
1353
1353
  }
1354
+ const groups = expandIPv6(v6);
1355
+ if (groups !== null) {
1356
+ const embedded = embeddedIPv4(groups);
1357
+ if (embedded !== void 0) return classifyTransportAddress(embedded, 4);
1358
+ }
1354
1359
  return isPrivateIPv62(v6) ? "private" : "public";
1355
1360
  }
1356
1361
  return "blocked";
@@ -1425,6 +1430,9 @@ function makeAbortError(method) {
1425
1430
  err.name = "AbortError";
1426
1431
  return err;
1427
1432
  }
1433
+ function nextJsonRpcId(id) {
1434
+ return id >= Number.MAX_SAFE_INTEGER ? 1 : id + 1;
1435
+ }
1428
1436
  function createTimeoutSignal(parent, timeoutMs) {
1429
1437
  const ctrl = new AbortController();
1430
1438
  const onAbort = () => ctrl.abort(parent?.reason);
@@ -1807,7 +1815,9 @@ var SSETransport = class extends BaseHTTPTransport {
1807
1815
  super(opts, "SSETransport");
1808
1816
  }
1809
1817
  genId() {
1810
- return this._nextId++;
1818
+ const id = this._nextId;
1819
+ this._nextId = nextJsonRpcId(id);
1820
+ return id;
1811
1821
  }
1812
1822
  /** Refresh tool list when server sends notifications/tools/list_changed. */
1813
1823
  async handleToolsListChanged() {
@@ -2121,7 +2131,9 @@ var StreamableHTTPTransport = class _StreamableHTTPTransport extends BaseHTTPTra
2121
2131
  super(opts, "StreamableHTTP");
2122
2132
  }
2123
2133
  genId() {
2124
- return this._nextId++;
2134
+ const id = this._nextId;
2135
+ this._nextId = nextJsonRpcId(id);
2136
+ return id;
2125
2137
  }
2126
2138
  consumeResponseText(text, requestId) {
2127
2139
  const envelopes = extractJsonRpcEnvelopes(text);
@@ -2166,6 +2178,7 @@ var StreamableHTTPTransport = class _StreamableHTTPTransport extends BaseHTTPTra
2166
2178
  const signal = this.abortController.signal;
2167
2179
  const startupTimer = setTimeout(() => this.abortController?.abort(), this.timeout);
2168
2180
  try {
2181
+ const initializeId = this.genId();
2169
2182
  const initFetchOpts = {
2170
2183
  method: "POST",
2171
2184
  headers: {
@@ -2175,7 +2188,7 @@ var StreamableHTTPTransport = class _StreamableHTTPTransport extends BaseHTTPTra
2175
2188
  },
2176
2189
  body: JSON.stringify({
2177
2190
  jsonrpc: "2.0",
2178
- id: this.genId(),
2191
+ id: initializeId,
2179
2192
  method: "initialize",
2180
2193
  params: {
2181
2194
  protocolVersion: MCP_CONSTANTS.PROTOCOL_VERSION,
@@ -2201,7 +2214,7 @@ var StreamableHTTPTransport = class _StreamableHTTPTransport extends BaseHTTPTra
2201
2214
  if (!data) {
2202
2215
  throw new Error("Could not parse initialize response");
2203
2216
  }
2204
- data = assertMatchingJsonRpcResult(data, this._nextId - 1, "initialize");
2217
+ data = assertMatchingJsonRpcResult(data, initializeId, "initialize");
2205
2218
  if (data.error) {
2206
2219
  throw new Error(`initialize failed: ${data.error.message}`);
2207
2220
  }
@@ -2794,7 +2807,7 @@ var MCPClient = class _MCPClient {
2794
2807
  gracefulTimer.unref?.();
2795
2808
  })
2796
2809
  ]);
2797
- if (gracefulTimer) clearTimeout(gracefulTimer);
2810
+ clearTimeout(gracefulTimer);
2798
2811
  if (gracefulRace === "timeout") {
2799
2812
  forceKillTree(child);
2800
2813
  let forceTimer;
@@ -2805,7 +2818,7 @@ var MCPClient = class _MCPClient {
2805
2818
  forceTimer.unref?.();
2806
2819
  })
2807
2820
  ]);
2808
- if (forceTimer) clearTimeout(forceTimer);
2821
+ clearTimeout(forceTimer);
2809
2822
  }
2810
2823
  child.stdout?.removeAllListeners();
2811
2824
  child.stderr?.removeAllListeners();
@@ -2826,7 +2839,8 @@ var MCPClient = class _MCPClient {
2826
2839
  err.name = "AbortError";
2827
2840
  return Promise.reject(err);
2828
2841
  }
2829
- const id = this.nextId++;
2842
+ const id = this.nextId;
2843
+ this.nextId = nextJsonRpcId(id);
2830
2844
  const req = { jsonrpc: "2.0", id, method, params };
2831
2845
  return new Promise((resolve, reject) => {
2832
2846
  const onAbort = signal ? () => {
@@ -5420,11 +5434,9 @@ async function handleHttpRequest(server, req, res, token, log, boundHost) {
5420
5434
  req.on("end", () => {
5421
5435
  if (aborted) return;
5422
5436
  void server.handleMessage(body).then((out) => {
5423
- if (aborted) return;
5424
5437
  if (out === null) return send(202, "");
5425
5438
  return send(200, out);
5426
5439
  }).catch((err) => {
5427
- if (aborted) return;
5428
5440
  log?.warn?.(`MCP http handler error: ${toErrorMessage2(err)}`);
5429
5441
  send(500, JSON.stringify({ error: "internal error" }));
5430
5442
  });
package/dist/server.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { type IncomingMessage, type ServerResponse } from 'node:http';
1
2
  import type { MCPPromptArgument, MCPPromptMessage, MCPResourceContents } from './protocol.js';
2
3
  /**
3
4
  * Server-side MCP. The mirror image of `MCPClient`: instead of consuming a
@@ -164,4 +165,5 @@ export interface ServeHttpHandle {
164
165
  * otherwise expose tool execution to the whole network unauthenticated.
165
166
  */
166
167
  export declare function serveHttp(server: MCPServer, opts?: ServeHttpOptions): Promise<ServeHttpHandle>;
168
+ export declare function handleHttpRequest(server: MCPServer, req: IncomingMessage, res: ServerResponse, token: string | undefined, log: MCPServerLogger | undefined, boundHost: string): Promise<void>;
167
169
  //# sourceMappingURL=server.d.ts.map
@@ -49,6 +49,8 @@ export interface HttpTransportOptions {
49
49
  * classifyToolError maps it to FATAL / not-retryable (user cancellation).
50
50
  */
51
51
  export declare function makeAbortError(method: string): Error;
52
+ /** Advance a JSON-RPC number id without leaving JavaScript's safe-integer range. */
53
+ export declare function nextJsonRpcId(id: number): number;
52
54
  export declare function createTimeoutSignal(parent: AbortSignal | undefined, timeoutMs: number): {
53
55
  signal: AbortSignal;
54
56
  dispose: () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wrongstack/mcp",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "license": "MIT",
5
5
  "description": "WrongStack Model Context Protocol client and registry: stdio, SSE, and streamable HTTP transports.",
6
6
  "repository": {
@@ -26,7 +26,7 @@
26
26
  "!dist/**/*.map"
27
27
  ],
28
28
  "dependencies": {
29
- "@wrongstack/core": "1.0.1",
29
+ "@wrongstack/core": "1.0.3",
30
30
  "undici": "^8.10.0"
31
31
  },
32
32
  "devDependencies": {