@wrongstack/mcp 0.284.1 → 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.
@@ -0,0 +1,134 @@
1
+ export type Transport = 'stdio' | 'sse' | 'streamable-http';
2
+ export interface MCPClientOptions {
3
+ name: string;
4
+ transport: Transport;
5
+ command?: string | undefined;
6
+ args?: string[] | undefined;
7
+ env?: Record<string, string> | undefined;
8
+ url?: string | undefined;
9
+ headers?: Record<string, string> | undefined;
10
+ startupTimeoutMs?: number | undefined;
11
+ requestTimeoutMs?: number | undefined;
12
+ /**
13
+ * Allowlist of env var names to forward from the parent process (process.env)
14
+ * to the child. Values are resolved at spawn time and merged into `env`
15
+ * via the `extra` path of `buildChildEnv` (unfiltered). This is how built-in
16
+ * MCP server presets (GitHub, Slack, Brave Search, …) get their API tokens
17
+ * without storing them in config.json or being scrubbed by the secret filter.
18
+ */
19
+ passthroughEnv?: string[] | undefined;
20
+ }
21
+ export type ConnectionState = 'idle' | 'connecting' | 'connected' | 'disconnected' | 'reconnecting' | 'failed'
22
+ /** Lazy server: registered from a cached manifest, process not spawned. */
23
+ | 'dormant';
24
+ export interface MCPTool {
25
+ name: string;
26
+ description?: string | undefined;
27
+ inputSchema: Record<string, unknown>;
28
+ }
29
+ export interface ToolCallResult {
30
+ content: unknown;
31
+ isError: boolean;
32
+ }
33
+ export interface JsonRpcResponse {
34
+ jsonrpc: '2.0';
35
+ id: number;
36
+ result?: unknown | undefined;
37
+ error?: {
38
+ code: number | undefined;
39
+ message: string;
40
+ data?: unknown | undefined;
41
+ } | undefined;
42
+ }
43
+ type ExitListener = (name: string, code: number | null, signal: string | null) => void;
44
+ /**
45
+ * Fired when the server sends `notifications/tools/list_changed`. The
46
+ * client refreshes its cached tool list before invoking listeners, so
47
+ * subscribers can call `listTools()` for the fresh set.
48
+ */
49
+ type ToolsChangedListener = (name: string, tools: MCPTool[]) => void;
50
+ /**
51
+ * Lightweight MCP client supporting three transport types:
52
+ * - stdio: spawns a child process and communicates over pipes
53
+ * - sse: connects to an HTTP SSE endpoint for server events, POST for requests
54
+ * - streamable-http: session-based HTTP transport with NDJSON responses
55
+ */
56
+ export declare class MCPClient {
57
+ readonly opts: MCPClientOptions;
58
+ private state;
59
+ private child?;
60
+ private nextId;
61
+ /**
62
+ * In-flight JSON-RPC calls keyed by id. `resolve` settles the call; `reject`
63
+ * is invoked from {@link failPending} when the underlying transport dies
64
+ * (stdio child exit, `close()`) so callers don't hang forever.
65
+ */
66
+ private readonly pending;
67
+ private rxBuffer;
68
+ private _tools;
69
+ /** Cached tool list — survives reconnects so the registry can re-register without re-discovering. */
70
+ private _toolsCache?;
71
+ private _drainPending;
72
+ private _lastNotifySkipped;
73
+ private sseTransport?;
74
+ private httpTransport?;
75
+ /** Notified when the stdio child process exits so the registry can attempt reconnect. */
76
+ private readonly exitListeners;
77
+ /** Notified when the server announces a tools/list_changed notification. */
78
+ private readonly toolsChangedListeners;
79
+ /** Notified when an HTTP transport (SSE or streamable-http) disconnects. */
80
+ private readonly disconnectListeners;
81
+ constructor(opts: MCPClientOptions);
82
+ getState(): ConnectionState;
83
+ listTools(): MCPTool[];
84
+ /** Returns true if a prior notify() call was skipped due to backpressure. */
85
+ hadNotifySkipped(): boolean;
86
+ /**
87
+ * Register a listener for child-process exit events.
88
+ * The registry uses this to trigger reconnection.
89
+ */
90
+ addExitListener(listener: ExitListener): void;
91
+ removeExitListener(listener: ExitListener): void;
92
+ /**
93
+ * Register a listener for transport disconnect events (SSE / streamable-http).
94
+ * Used by the registry to trigger reconnection for HTTP-based servers.
95
+ */
96
+ addDisconnectListener(listener: () => void): void;
97
+ removeDisconnectListener(listener: () => void): void;
98
+ connect(): Promise<void>;
99
+ private connectStdio;
100
+ private connectSSE;
101
+ private connectStreamableHTTP;
102
+ callTool(name: string, input: unknown, opts?: {
103
+ signal?: AbortSignal | undefined;
104
+ }): Promise<ToolCallResult>;
105
+ close(): Promise<void>;
106
+ private request;
107
+ /**
108
+ * Reject every in-flight {@link request} call. Used when the underlying
109
+ * transport dies — without this, callers awaiting `tools/call` over a
110
+ * killed stdio child or a closed transport would hang indefinitely.
111
+ */
112
+ private failPending;
113
+ private notify;
114
+ private onData;
115
+ private onLine;
116
+ /**
117
+ * L2-C: refresh the cached tool list when the server announces a
118
+ * `tools/list_changed`. Listeners (the registry) re-wrap and
119
+ * re-register. Failures are swallowed — a stale cache is preferable
120
+ * to a hard crash on a transient notification glitch.
121
+ */
122
+ private handleToolsListChanged;
123
+ addToolsChangedListener(listener: ToolsChangedListener): void;
124
+ removeToolsChangedListener(listener: ToolsChangedListener): void;
125
+ }
126
+ /**
127
+ * Quote a single argument for `cmd.exe` when spawning with `shell: true` on
128
+ * Windows. Only args containing whitespace or quotes need wrapping; inside
129
+ * double quotes cmd.exe escapes a literal `"` as `""`. Backslashes are literal
130
+ * inside cmd quotes, so paths like `C:\Program Files\x` pass through unharmed.
131
+ */
132
+ export declare function quoteWindowsArg(arg: string): string;
133
+ export {};
134
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,KAAK,GAAG,iBAAiB,CAAC;AAE5D,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,SAAS,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAC5B,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;IACzC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;IAC7C,gBAAgB,CAAC,EAAE,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IAAI,OAAO,CAAC,IAAI,CAAC,CAsD3B;IAED,OAAO,CAAC,OAAO;IA0Ff;;;;OAIG;IACH,OAAO,CAAC,WAAW;YAcL,MAAM;IAsDpB,OAAO,CAAC,MAAM;IAWd,OAAO,CAAC,MAAM;IAyBd;;;;;OAKG;YACW,sBAAsB;IAoBpC,uBAAuB,CAAC,QAAQ,EAAE,oBAAoB,GAAG,IAAI,CAE5D;IAED,0BAA0B,CAAC,QAAQ,EAAE,oBAAoB,GAAG,IAAI,CAE/D;CACF;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAGnD"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Shared constants for the MCP package.
3
+ *
4
+ * Centralizing these values means:
5
+ * - Protocol version and client identity are updated in one place
6
+ * - Reconnect parameters can be overridden via config in the future
7
+ * - No scattered magic values across multiple files
8
+ */
9
+ export declare const MCP_CONSTANTS: Readonly<{
10
+ /** MCP protocol version advertised during handshake. */
11
+ readonly PROTOCOL_VERSION: '2024-11-05';
12
+ /** Identity announced to MCP servers during `initialize`. */
13
+ readonly CLIENT_INFO: Readonly<{
14
+ name: "wrongstack";
15
+ version: "0.1.10";
16
+ }>;
17
+ /** Reconnection behaviour when a transport disconnects. */
18
+ readonly RECONNECT: Readonly<{
19
+ /** Max full reconnect cycles before the slot is marked `failed`. */
20
+ MAX_CYCLES: 5;
21
+ /** Base delay between cycles (exponential backoff applied on top). */
22
+ BASE_DELAY_MS: 1000;
23
+ /** Jitter factor applied to the backoff (0 = no jitter, 1 = full). */
24
+ JITTER_FACTOR: 0.2;
25
+ /** Max connection attempts within a single cycle. */
26
+ MAX_ATTEMPTS: 3;
27
+ /** Base multiplier for the exponential backoff formula (`delay = BASE * multiplier^attempt`). */
28
+ BACKOFF_MULTIPLIER: 2;
29
+ }>;
30
+ /** Timing for graceful / forced disconnect. */
31
+ readonly DISCONNECT: Readonly<{
32
+ /** Ms to wait for in-flight requests to complete before force-closing. */
33
+ GRACEFUL_MS: 800;
34
+ /** Ms after which the force disconnect is triggered. */
35
+ FORCE_TIMEOUT_MS: 1200;
36
+ }>;
37
+ /** Lazy-connect idle lifecycle. */
38
+ readonly IDLE: Readonly<{
39
+ /** Default ms a lazy server stays connected with no tool calls before auto-sleep. */
40
+ DEFAULT_TIMEOUT_MS: 300000;
41
+ /** How often the idle sweep runs (kept well below the timeout). */
42
+ SWEEP_INTERVAL_MS: 30000;
43
+ }>;
44
+ /** JSON-RPC response timeout for outstanding requests. */
45
+ readonly RESPONSE_TIMEOUT_MS: 500;
46
+ /** Max buffer size for the SSE reader. */
47
+ readonly SSE_READER_MAX_BUFFER: number;
48
+ /** Max characters logged from a request body. */
49
+ readonly REQUEST_LOG_CAP: 1024;
50
+ }>;
51
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa;IACxB,wDAAwD;+BACtC,YAAY;IAE9B,6DAA6D;;;;;IAM7D,2DAA2D;;QAEzD,oEAAoE;;QAEpE,sEAAsE;;QAEtE,sEAAsE;;QAEtE,qDAAqD;;QAErD,iGAAiG;;;IAInG,+CAA+C;;QAE7C,0EAA0E;;QAE1E,wDAAwD;;;IAI1D,mCAAmC;;QAEjC,qFAAqF;;QAErF,mEAAmE;;;IAIrE,0DAA0D;kCACrC,GAAG;IAExB,0CAA0C;;IAG1C,iDAAiD;8BAChC,IAAI;EACZ,CAAC"}