@wrongstack/mcp 0.284.1 → 0.286.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/authorization-manager.d.ts +65 -0
- package/dist/authorization-manager.d.ts.map +1 -0
- package/dist/authorization.d.ts +128 -0
- package/dist/authorization.d.ts.map +1 -0
- package/dist/client.d.ts +165 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/constants.d.ts +51 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/content-selection.d.ts +33 -0
- package/dist/content-selection.d.ts.map +1 -0
- package/dist/index.d.ts +15 -665
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3006 -515
- package/dist/index.js.map +7 -1
- package/dist/manage.d.ts +84 -0
- package/dist/manage.d.ts.map +1 -0
- package/dist/manifest-cache.d.ts +31 -0
- package/dist/manifest-cache.d.ts.map +1 -0
- package/dist/operations.d.ts +100 -0
- package/dist/operations.d.ts.map +1 -0
- package/dist/protocol.d.ts +91 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/registry.d.ts +224 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/server.d.ts +134 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/test-helpers/mock-server.d.ts +34 -0
- package/dist/test-helpers/mock-server.d.ts.map +1 -0
- package/dist/token-store.d.ts +56 -0
- package/dist/token-store.d.ts.map +1 -0
- package/dist/tool-schema.d.ts +3 -0
- package/dist/tool-schema.d.ts.map +1 -0
- package/dist/transport.d.ts +161 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/wrap-tool.d.ts +17 -0
- package/dist/wrap-tool.d.ts.map +1 -0
- package/package.json +4 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,665 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
* Allowlist of env var names to forward from the parent process (process.env)
|
|
17
|
-
* to the child. Values are resolved at spawn time and merged into `env`
|
|
18
|
-
* via the `extra` path of `buildChildEnv` (unfiltered). This is how built-in
|
|
19
|
-
* MCP server presets (GitHub, Slack, Brave Search, …) get their API tokens
|
|
20
|
-
* without storing them in config.json or being scrubbed by the secret filter.
|
|
21
|
-
*/
|
|
22
|
-
passthroughEnv?: string[] | undefined;
|
|
23
|
-
}
|
|
24
|
-
type ConnectionState = 'idle' | 'connecting' | 'connected' | 'disconnected' | 'reconnecting' | 'failed'
|
|
25
|
-
/** Lazy server: registered from a cached manifest, process not spawned. */
|
|
26
|
-
| 'dormant';
|
|
27
|
-
interface MCPTool {
|
|
28
|
-
name: string;
|
|
29
|
-
description?: string | undefined;
|
|
30
|
-
inputSchema: Record<string, unknown>;
|
|
31
|
-
}
|
|
32
|
-
interface ToolCallResult {
|
|
33
|
-
content: unknown;
|
|
34
|
-
isError: boolean;
|
|
35
|
-
}
|
|
36
|
-
interface JsonRpcResponse {
|
|
37
|
-
jsonrpc: '2.0';
|
|
38
|
-
id: number;
|
|
39
|
-
result?: unknown | undefined;
|
|
40
|
-
error?: {
|
|
41
|
-
code: number | undefined;
|
|
42
|
-
message: string;
|
|
43
|
-
data?: unknown | undefined;
|
|
44
|
-
} | undefined;
|
|
45
|
-
}
|
|
46
|
-
type ExitListener = (name: string, code: number | null, signal: string | null) => void;
|
|
47
|
-
/**
|
|
48
|
-
* Fired when the server sends `notifications/tools/list_changed`. The
|
|
49
|
-
* client refreshes its cached tool list before invoking listeners, so
|
|
50
|
-
* subscribers can call `listTools()` for the fresh set.
|
|
51
|
-
*/
|
|
52
|
-
type ToolsChangedListener = (name: string, tools: MCPTool[]) => void;
|
|
53
|
-
/**
|
|
54
|
-
* Lightweight MCP client supporting three transport types:
|
|
55
|
-
* - stdio: spawns a child process and communicates over pipes
|
|
56
|
-
* - sse: connects to an HTTP SSE endpoint for server events, POST for requests
|
|
57
|
-
* - streamable-http: session-based HTTP transport with NDJSON responses
|
|
58
|
-
*/
|
|
59
|
-
declare class MCPClient {
|
|
60
|
-
readonly opts: MCPClientOptions;
|
|
61
|
-
private state;
|
|
62
|
-
private child?;
|
|
63
|
-
private nextId;
|
|
64
|
-
/**
|
|
65
|
-
* In-flight JSON-RPC calls keyed by id. `resolve` settles the call; `reject`
|
|
66
|
-
* is invoked from {@link failPending} when the underlying transport dies
|
|
67
|
-
* (stdio child exit, `close()`) so callers don't hang forever.
|
|
68
|
-
*/
|
|
69
|
-
private readonly pending;
|
|
70
|
-
private rxBuffer;
|
|
71
|
-
private _tools;
|
|
72
|
-
/** Cached tool list — survives reconnects so the registry can re-register without re-discovering. */
|
|
73
|
-
private _toolsCache?;
|
|
74
|
-
private _drainPending;
|
|
75
|
-
private _lastNotifySkipped;
|
|
76
|
-
private sseTransport?;
|
|
77
|
-
private httpTransport?;
|
|
78
|
-
/** Notified when the stdio child process exits so the registry can attempt reconnect. */
|
|
79
|
-
private readonly exitListeners;
|
|
80
|
-
/** Notified when the server announces a tools/list_changed notification. */
|
|
81
|
-
private readonly toolsChangedListeners;
|
|
82
|
-
/** Notified when an HTTP transport (SSE or streamable-http) disconnects. */
|
|
83
|
-
private readonly disconnectListeners;
|
|
84
|
-
constructor(opts: MCPClientOptions);
|
|
85
|
-
getState(): ConnectionState;
|
|
86
|
-
listTools(): MCPTool[];
|
|
87
|
-
/** Returns true if a prior notify() call was skipped due to backpressure. */
|
|
88
|
-
hadNotifySkipped(): boolean;
|
|
89
|
-
/**
|
|
90
|
-
* Register a listener for child-process exit events.
|
|
91
|
-
* The registry uses this to trigger reconnection.
|
|
92
|
-
*/
|
|
93
|
-
addExitListener(listener: ExitListener): void;
|
|
94
|
-
removeExitListener(listener: ExitListener): void;
|
|
95
|
-
/**
|
|
96
|
-
* Register a listener for transport disconnect events (SSE / streamable-http).
|
|
97
|
-
* Used by the registry to trigger reconnection for HTTP-based servers.
|
|
98
|
-
*/
|
|
99
|
-
addDisconnectListener(listener: () => void): void;
|
|
100
|
-
removeDisconnectListener(listener: () => void): void;
|
|
101
|
-
connect(): Promise<void>;
|
|
102
|
-
private connectStdio;
|
|
103
|
-
private connectSSE;
|
|
104
|
-
private connectStreamableHTTP;
|
|
105
|
-
callTool(name: string, input: unknown, opts?: {
|
|
106
|
-
signal?: AbortSignal | undefined;
|
|
107
|
-
}): Promise<ToolCallResult>;
|
|
108
|
-
close(): Promise<void>;
|
|
109
|
-
private request;
|
|
110
|
-
/**
|
|
111
|
-
* Reject every in-flight {@link request} call. Used when the underlying
|
|
112
|
-
* transport dies — without this, callers awaiting `tools/call` over a
|
|
113
|
-
* killed stdio child or a closed transport would hang indefinitely.
|
|
114
|
-
*/
|
|
115
|
-
private failPending;
|
|
116
|
-
private notify;
|
|
117
|
-
private onData;
|
|
118
|
-
private onLine;
|
|
119
|
-
/**
|
|
120
|
-
* L2-C: refresh the cached tool list when the server announces a
|
|
121
|
-
* `tools/list_changed`. Listeners (the registry) re-wrap and
|
|
122
|
-
* re-register. Failures are swallowed — a stale cache is preferable
|
|
123
|
-
* to a hard crash on a transient notification glitch.
|
|
124
|
-
*/
|
|
125
|
-
private handleToolsListChanged;
|
|
126
|
-
addToolsChangedListener(listener: ToolsChangedListener): void;
|
|
127
|
-
removeToolsChangedListener(listener: ToolsChangedListener): void;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Resolves the live client for a tool call. A plain {@link MCPClient} for eager
|
|
132
|
-
* servers, or a thunk that connects-on-demand for lazy/dormant servers (the
|
|
133
|
-
* registry passes `() => this.ensureConnected(name)`).
|
|
134
|
-
*/
|
|
135
|
-
type MCPClientResolver = MCPClient | (() => Promise<MCPClient>);
|
|
136
|
-
declare function wrapMCPTool(serverName: string, mcpTool: MCPTool, client: MCPClientResolver, permission?: Permission): Tool;
|
|
137
|
-
|
|
138
|
-
interface MCPRegistryOptions {
|
|
139
|
-
toolRegistry: ToolRegistry;
|
|
140
|
-
events: EventBus;
|
|
141
|
-
log: Logger;
|
|
142
|
-
/**
|
|
143
|
-
* Directory for the on-disk tool-manifest cache (lazy-connect). Without it,
|
|
144
|
-
* `lazy` servers cannot register tools cold and fall back to eager connect.
|
|
145
|
-
* Typically `wpaths.cacheDir` (`~/.wrongstack/cache`).
|
|
146
|
-
*/
|
|
147
|
-
cacheDir?: string | undefined;
|
|
148
|
-
/**
|
|
149
|
-
* Idle window (ms) after which a connected lazy server is auto-stopped and
|
|
150
|
-
* re-woken on the next tool call. 0 disables idle auto-sleep.
|
|
151
|
-
* Default: {@link MCP_CONSTANTS.IDLE.DEFAULT_TIMEOUT_MS}.
|
|
152
|
-
*/
|
|
153
|
-
idleTimeoutMs?: number | undefined;
|
|
154
|
-
/**
|
|
155
|
-
* Lazy mode: when true, MCP server tools are NOT registered into the
|
|
156
|
-
* tool registry on connect. They are cached internally and can be
|
|
157
|
-
* activated on demand via `activateServer(name)`. This is used in
|
|
158
|
-
* token-saving mode to avoid bloating the system prompt with 50-100+
|
|
159
|
-
* MCP tool descriptions. The model uses `mcp_control({ action: "activate", server: "..." })`
|
|
160
|
-
* to temporarily enable tools when needed.
|
|
161
|
-
* Default: false.
|
|
162
|
-
*/
|
|
163
|
-
lazyMode?: boolean | undefined;
|
|
164
|
-
}
|
|
165
|
-
declare class MCPRegistry {
|
|
166
|
-
private readonly servers;
|
|
167
|
-
private readonly toolRegistry;
|
|
168
|
-
private readonly events;
|
|
169
|
-
private readonly log;
|
|
170
|
-
private readonly lazyMode;
|
|
171
|
-
private readonly cacheDir?;
|
|
172
|
-
private readonly idleTimeoutMs;
|
|
173
|
-
/** Single shared idle sweep timer (started lazily; unref'd; cleared on stopAll). */
|
|
174
|
-
private idleTimer?;
|
|
175
|
-
constructor(opts: MCPRegistryOptions);
|
|
176
|
-
start(cfg: MCPServerConfig): Promise<void>;
|
|
177
|
-
/**
|
|
178
|
-
* Boot a lazy server WITHOUT spawning it. If a tool manifest is cached (from a
|
|
179
|
-
* prior connect with matching config), register resolver-backed wrappers and
|
|
180
|
-
* go `dormant` — the process spawns on the first tool call. If there is no
|
|
181
|
-
* cache yet, do a one-time cold discovery connect to learn + cache the tools.
|
|
182
|
-
*/
|
|
183
|
-
private startLazy;
|
|
184
|
-
/**
|
|
185
|
-
* Ensure a lazy server is connected, spawning it on demand. Single-flight:
|
|
186
|
-
* concurrent first-calls share one connect. Resolver wrappers call this.
|
|
187
|
-
*/
|
|
188
|
-
ensureConnected(name: string): Promise<MCPClient>;
|
|
189
|
-
/**
|
|
190
|
-
* Register all cached tools for a given server into the tool registry.
|
|
191
|
-
* No-op if tools are already registered or the server is not connected.
|
|
192
|
-
* The server connection stays alive — this only toggles tool visibility.
|
|
193
|
-
*/
|
|
194
|
-
activateServer(name: string): void;
|
|
195
|
-
/**
|
|
196
|
-
* Unregister all tools for a given server from the tool registry.
|
|
197
|
-
* The server connection stays alive — this only toggles tool visibility.
|
|
198
|
-
* Returns the number of tools that were deactivated.
|
|
199
|
-
*/
|
|
200
|
-
deactivateServer(name: string): number;
|
|
201
|
-
/**
|
|
202
|
-
* Check whether a server's tools are currently registered.
|
|
203
|
-
*/
|
|
204
|
-
isActivated(name: string): boolean;
|
|
205
|
-
stop(name: string): Promise<void>;
|
|
206
|
-
restart(name: string): Promise<void>;
|
|
207
|
-
list(): {
|
|
208
|
-
name: string;
|
|
209
|
-
state: ConnectionState;
|
|
210
|
-
toolCount: number;
|
|
211
|
-
tools: string[];
|
|
212
|
-
}[];
|
|
213
|
-
/**
|
|
214
|
-
* Resolve the live tool names for a slot — the registered names in normal
|
|
215
|
-
* mode, or the cached lazy-tool names when running in lazy mode (where
|
|
216
|
-
* tools are connected but intentionally not registered).
|
|
217
|
-
*/
|
|
218
|
-
private toolNamesForSlot;
|
|
219
|
-
/**
|
|
220
|
-
* Wrap + register (or cache) a server's tools. Lazy servers get resolver-backed
|
|
221
|
-
* wrappers that spawn the process on first use; eager servers bind the live
|
|
222
|
-
* client directly. Honours token-saving `lazyMode` (cache, don't register) and
|
|
223
|
-
* a register-once guard for lazy resolver wrappers (so a wake/reconnect reuses
|
|
224
|
-
* the existing registrations rather than churning the tool list).
|
|
225
|
-
*/
|
|
226
|
-
private applyTools;
|
|
227
|
-
/** Start the shared idle sweep timer once (unref'd so it never holds the process). */
|
|
228
|
-
private ensureIdleSweep;
|
|
229
|
-
/** Auto-sleep connected lazy servers that have been idle past the timeout. */
|
|
230
|
-
private sweepIdle;
|
|
231
|
-
/**
|
|
232
|
-
* Soft stop: close the server process but KEEP its resolver wrappers and
|
|
233
|
-
* cached manifest registered, so the next tool call transparently re-wakes it.
|
|
234
|
-
* Distinct from {@link stop} (full teardown for disable/remove).
|
|
235
|
-
*/
|
|
236
|
-
private sleepIdle;
|
|
237
|
-
/**
|
|
238
|
-
* Catalog of every server ever registered with this registry — includes
|
|
239
|
-
* servers that are stopped, failed, or not yet started.
|
|
240
|
-
* Useful for the `mcp_control` tool to show all known servers without
|
|
241
|
-
* triggering connections.
|
|
242
|
-
*/
|
|
243
|
-
describe(): {
|
|
244
|
-
name: string;
|
|
245
|
-
state: ConnectionState;
|
|
246
|
-
toolCount: number;
|
|
247
|
-
enabled: boolean;
|
|
248
|
-
tools: string[];
|
|
249
|
-
}[];
|
|
250
|
-
stopAll(): Promise<void>;
|
|
251
|
-
/**
|
|
252
|
-
* Health check — returns 'ok' for connected servers, the current state otherwise.
|
|
253
|
-
* For HTTP-based transports this could also ping the server.
|
|
254
|
-
*/
|
|
255
|
-
health(): {
|
|
256
|
-
name: string;
|
|
257
|
-
alive: boolean;
|
|
258
|
-
latencyMs?: number | undefined;
|
|
259
|
-
}[];
|
|
260
|
-
/**
|
|
261
|
-
* L2-C: handle `notifications/tools/list_changed` from the server.
|
|
262
|
-
* Unregister the previous wrapper set, then re-register the fresh
|
|
263
|
-
* tool list. The client has already refreshed its cache before
|
|
264
|
-
* dispatching — we just need to re-wrap and re-register.
|
|
265
|
-
* In lazy mode, only update the internal cache without registering.
|
|
266
|
-
*/
|
|
267
|
-
private readonly onToolsChanged;
|
|
268
|
-
private readonly onChildExit;
|
|
269
|
-
/** Handles SSE / streamable-http disconnect — same recovery as stdio child exit. */
|
|
270
|
-
private readonly onTransportDisconnect;
|
|
271
|
-
/**
|
|
272
|
-
* L2-B: maximum number of reconnect cycles before staying `failed`.
|
|
273
|
-
* One cycle = one full `attemptConnect` (which itself may try up to 3
|
|
274
|
-
* times). Caps total reconnect storm at ~5 cycles, then the slot
|
|
275
|
-
* needs an explicit `restart()` to re-engage.
|
|
276
|
-
*/
|
|
277
|
-
private static readonly MAX_RECONNECT_CYCLES;
|
|
278
|
-
/** Base delay between cycles, in ms. Real delay adds jitter. */
|
|
279
|
-
private static readonly BASE_RECONNECT_DELAY_MS;
|
|
280
|
-
/** Hard ceiling on the inter-cycle delay so the user doesn't wait minutes. */
|
|
281
|
-
private static readonly MAX_RECONNECT_DELAY_MS;
|
|
282
|
-
private scheduleReconnect;
|
|
283
|
-
private attemptReconnect;
|
|
284
|
-
private attemptConnect;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
/** Transport values accepted from UI surfaces (UI also offers a bare "http"). */
|
|
288
|
-
type TransportInput = 'stdio' | 'sse' | 'streamable-http' | 'http';
|
|
289
|
-
/** Loosely-typed server input as it arrives from a UI or command surface. */
|
|
290
|
-
interface McpServerInput {
|
|
291
|
-
name: string;
|
|
292
|
-
transport?: TransportInput | string | undefined;
|
|
293
|
-
description?: string | undefined;
|
|
294
|
-
enabled?: boolean | undefined;
|
|
295
|
-
command?: string | undefined;
|
|
296
|
-
args?: string[] | undefined;
|
|
297
|
-
env?: Record<string, string> | undefined;
|
|
298
|
-
url?: string | undefined;
|
|
299
|
-
headers?: Record<string, string> | undefined;
|
|
300
|
-
allowedTools?: string[] | undefined;
|
|
301
|
-
permission?: Permission | undefined;
|
|
302
|
-
/** Lazy connect — spawn the process only on first tool call (see config). */
|
|
303
|
-
lazy?: boolean | undefined;
|
|
304
|
-
/** Env var names to forward from parent process at spawn time. */
|
|
305
|
-
passthroughEnv?: string[] | undefined;
|
|
306
|
-
}
|
|
307
|
-
/** Projected view of one server, merging disk config with live registry state. */
|
|
308
|
-
interface McpServerInfo {
|
|
309
|
-
name: string;
|
|
310
|
-
transport: MCPServerConfig['transport'];
|
|
311
|
-
description?: string | undefined;
|
|
312
|
-
enabled: boolean;
|
|
313
|
-
/** Raw registry state ('connected' | 'connecting' | … | 'failed'), or 'stopped' when not running. */
|
|
314
|
-
status: string;
|
|
315
|
-
/** Real tool names discovered from the live server (empty when not connected). */
|
|
316
|
-
tools: string[];
|
|
317
|
-
url?: string | undefined;
|
|
318
|
-
command?: string | undefined;
|
|
319
|
-
/** Lazy-connect opt-in (spawn on first tool call). */
|
|
320
|
-
lazy?: boolean | undefined;
|
|
321
|
-
}
|
|
322
|
-
interface McpOpResult {
|
|
323
|
-
ok: boolean;
|
|
324
|
-
message: string;
|
|
325
|
-
/** The affected server's projected view, when applicable. */
|
|
326
|
-
server?: McpServerInfo | undefined;
|
|
327
|
-
/** Raw registry state after a start/restart attempt. */
|
|
328
|
-
state?: string | undefined;
|
|
329
|
-
/** Real tool names after a start/restart attempt. */
|
|
330
|
-
tools?: string[] | undefined;
|
|
331
|
-
/** Set when a config change persisted but the registry start/stop failed. */
|
|
332
|
-
registryError?: string | undefined;
|
|
333
|
-
}
|
|
334
|
-
interface McpManageDeps {
|
|
335
|
-
/** Absolute path to the global config.json that owns `mcpServers`. */
|
|
336
|
-
configPath: string;
|
|
337
|
-
/** Live registry for runtime start/stop/restart. */
|
|
338
|
-
registry: MCPRegistry;
|
|
339
|
-
/** Built-in presets (from core `allServers()`), used by name-only `add`. */
|
|
340
|
-
presets?: Record<string, MCPServerConfig> | undefined;
|
|
341
|
-
}
|
|
342
|
-
/** List all configured servers, merged with live registry status + tool names. */
|
|
343
|
-
declare function listMcp(deps: McpManageDeps): Promise<McpServerInfo[]>;
|
|
344
|
-
/**
|
|
345
|
-
* Add a new server. `input` may be a fully-specified config, or just a `name`
|
|
346
|
-
* matching a known preset (`deps.presets`). Fails if the server already exists.
|
|
347
|
-
* When enabled, the server is started immediately via the registry.
|
|
348
|
-
*/
|
|
349
|
-
declare function addMcp(input: McpServerInput, deps: McpManageDeps): Promise<McpOpResult>;
|
|
350
|
-
/** Update an existing server's config, then re-apply it to the live registry. */
|
|
351
|
-
declare function updateMcp(input: McpServerInput, deps: McpManageDeps): Promise<McpOpResult>;
|
|
352
|
-
/** Remove a server from config and stop it if running. */
|
|
353
|
-
declare function removeMcp(name: string, deps: McpManageDeps): Promise<McpOpResult>;
|
|
354
|
-
/** Enable a server in config and start it. */
|
|
355
|
-
declare function enableMcp(name: string, deps: McpManageDeps): Promise<McpOpResult>;
|
|
356
|
-
/** Disable a server in config and stop it. */
|
|
357
|
-
declare function disableMcp(name: string, deps: McpManageDeps): Promise<McpOpResult>;
|
|
358
|
-
/** Restart a running server (or start it from config if registered but stopped). */
|
|
359
|
-
declare function restartMcp(name: string, deps: McpManageDeps): Promise<McpOpResult>;
|
|
360
|
-
/**
|
|
361
|
-
* Discover a server's tools. Tools are discovered on connect, so this ensures
|
|
362
|
-
* the server is running and returns its live tool list.
|
|
363
|
-
*/
|
|
364
|
-
declare function discoverMcp(name: string, deps: McpManageDeps): Promise<McpOpResult>;
|
|
365
|
-
|
|
366
|
-
/**
|
|
367
|
-
* Server-side MCP. The mirror image of `MCPClient`: instead of consuming a
|
|
368
|
-
* remote MCP server, this lets WrongStack *be* an MCP server — exposing its
|
|
369
|
-
* tools to any MCP client (Claude Desktop, another agent, an IDE) over a
|
|
370
|
-
* JSON-RPC 2.0 stream.
|
|
371
|
-
*
|
|
372
|
-
* The protocol core (`MCPServer`) is transport-agnostic: feed it a raw JSON
|
|
373
|
-
* line via `handleMessage`, get back a response string (or `null` for
|
|
374
|
-
* notifications). `serveStdio` wires it to stdin/stdout for the canonical
|
|
375
|
-
* stdio transport.
|
|
376
|
-
*/
|
|
377
|
-
/** A tool descriptor advertised over `tools/list`. */
|
|
378
|
-
interface MCPServerTool {
|
|
379
|
-
name: string;
|
|
380
|
-
description?: string | undefined;
|
|
381
|
-
inputSchema: Record<string, unknown>;
|
|
382
|
-
}
|
|
383
|
-
/** The result of a `tools/call`, as the host produces it. */
|
|
384
|
-
interface MCPServerCallResult {
|
|
385
|
-
/** Text or pre-built MCP content blocks. Strings are wrapped as a text block. */
|
|
386
|
-
content: unknown;
|
|
387
|
-
isError: boolean;
|
|
388
|
-
}
|
|
389
|
-
/**
|
|
390
|
-
* Bridges the MCP server to a tool backend (in the CLI, the `ToolRegistry`).
|
|
391
|
-
* Kept narrow so the protocol core has no dependency on `@wrongstack/core`.
|
|
392
|
-
*/
|
|
393
|
-
interface MCPServerToolHost {
|
|
394
|
-
listTools(): MCPServerTool[] | Promise<MCPServerTool[]>;
|
|
395
|
-
callTool(name: string, args: Record<string, unknown>): Promise<MCPServerCallResult>;
|
|
396
|
-
}
|
|
397
|
-
interface MCPServerLogger {
|
|
398
|
-
warn?(msg: string): void;
|
|
399
|
-
info?(msg: string): void;
|
|
400
|
-
}
|
|
401
|
-
interface MCPServerOptions {
|
|
402
|
-
host: MCPServerToolHost;
|
|
403
|
-
/** Advertised in the `initialize` handshake. Defaults to the wrongstack identity. */
|
|
404
|
-
serverInfo?: {
|
|
405
|
-
name: string;
|
|
406
|
-
version: string;
|
|
407
|
-
};
|
|
408
|
-
logger?: MCPServerLogger | undefined;
|
|
409
|
-
}
|
|
410
|
-
declare class MCPServer {
|
|
411
|
-
private readonly host;
|
|
412
|
-
private readonly serverInfo;
|
|
413
|
-
private readonly logger?;
|
|
414
|
-
constructor(opts: MCPServerOptions);
|
|
415
|
-
/**
|
|
416
|
-
* Handle one raw JSON-RPC line. Returns the response JSON string for
|
|
417
|
-
* requests, or `null` for notifications (no `id`) and for blank input —
|
|
418
|
-
* the caller should write the string to its output stream when non-null.
|
|
419
|
-
*/
|
|
420
|
-
handleMessage(raw: string): Promise<string | null>;
|
|
421
|
-
private dispatch;
|
|
422
|
-
private encodeError;
|
|
423
|
-
}
|
|
424
|
-
/** Normalize a host result's content into MCP content blocks. */
|
|
425
|
-
declare function toContentBlocks(content: unknown): Array<{
|
|
426
|
-
type: 'text';
|
|
427
|
-
text: string;
|
|
428
|
-
}>;
|
|
429
|
-
interface ServeStdioHandle {
|
|
430
|
-
/** Stop reading and detach listeners. Does not exit the process. */
|
|
431
|
-
close(): void;
|
|
432
|
-
/** Resolves when the input stream ends (EOF). */
|
|
433
|
-
done: Promise<void>;
|
|
434
|
-
}
|
|
435
|
-
interface ServeStdioOptions {
|
|
436
|
-
stdin?: NodeJS.ReadableStream | undefined;
|
|
437
|
-
stdout?: NodeJS.WritableStream | undefined;
|
|
438
|
-
}
|
|
439
|
-
/**
|
|
440
|
-
* Run an `MCPServer` over stdio: newline-delimited JSON-RPC in on stdin,
|
|
441
|
-
* responses out on stdout. CRITICAL: nothing else may write to stdout while
|
|
442
|
-
* this runs — it is the JSON-RPC channel. Route all logging to stderr.
|
|
443
|
-
*/
|
|
444
|
-
declare function serveStdio(server: MCPServer, opts?: ServeStdioOptions): ServeStdioHandle;
|
|
445
|
-
interface ServeHttpOptions {
|
|
446
|
-
/** TCP port. 0 picks an ephemeral port (resolved in the handle). Default 0. */
|
|
447
|
-
port?: number | undefined;
|
|
448
|
-
/** Bind address. Default '127.0.0.1' (loopback only). */
|
|
449
|
-
host?: string | undefined;
|
|
450
|
-
/**
|
|
451
|
-
* Bearer token required on every request (`Authorization: Bearer <token>`).
|
|
452
|
-
* REQUIRED when binding to a non-loopback host — `serveHttp` refuses to
|
|
453
|
-
* expose tools to the network without one.
|
|
454
|
-
*/
|
|
455
|
-
token?: string | undefined;
|
|
456
|
-
logger?: MCPServerLogger | undefined;
|
|
457
|
-
}
|
|
458
|
-
interface ServeHttpHandle {
|
|
459
|
-
port: number;
|
|
460
|
-
host: string;
|
|
461
|
-
url: string;
|
|
462
|
-
close(): Promise<void>;
|
|
463
|
-
}
|
|
464
|
-
/**
|
|
465
|
-
* Run an `MCPServer` over HTTP: POST a single JSON-RPC request, get the JSON
|
|
466
|
-
* response (notifications → 202 with no body). Reuses `handleMessage`, so the
|
|
467
|
-
* protocol is identical to the stdio transport.
|
|
468
|
-
*
|
|
469
|
-
* Security: binds to loopback by default. Binding to any other host (e.g.
|
|
470
|
-
* `0.0.0.0`) REQUIRES a `token` — otherwise this rejects, because it would
|
|
471
|
-
* otherwise expose tool execution to the whole network unauthenticated.
|
|
472
|
-
*/
|
|
473
|
-
declare function serveHttp(server: MCPServer, opts?: ServeHttpOptions): Promise<ServeHttpHandle>;
|
|
474
|
-
|
|
475
|
-
/**
|
|
476
|
-
* Shared constants for the MCP package.
|
|
477
|
-
*
|
|
478
|
-
* Centralizing these values means:
|
|
479
|
-
* - Protocol version and client identity are updated in one place
|
|
480
|
-
* - Reconnect parameters can be overridden via config in the future
|
|
481
|
-
* - No scattered magic values across multiple files
|
|
482
|
-
*/
|
|
483
|
-
declare const MCP_CONSTANTS: Readonly<{
|
|
484
|
-
/** MCP protocol version advertised during handshake. */
|
|
485
|
-
readonly PROTOCOL_VERSION: "2024-11-05";
|
|
486
|
-
/** Identity announced to MCP servers during `initialize`. */
|
|
487
|
-
readonly CLIENT_INFO: Readonly<{
|
|
488
|
-
name: "wrongstack";
|
|
489
|
-
version: "0.1.10";
|
|
490
|
-
}>;
|
|
491
|
-
/** Reconnection behaviour when a transport disconnects. */
|
|
492
|
-
readonly RECONNECT: Readonly<{
|
|
493
|
-
/** Max full reconnect cycles before the slot is marked `failed`. */
|
|
494
|
-
MAX_CYCLES: 5;
|
|
495
|
-
/** Base delay between cycles (exponential backoff applied on top). */
|
|
496
|
-
BASE_DELAY_MS: 1000;
|
|
497
|
-
/** Jitter factor applied to the backoff (0 = no jitter, 1 = full). */
|
|
498
|
-
JITTER_FACTOR: 0.2;
|
|
499
|
-
/** Max connection attempts within a single cycle. */
|
|
500
|
-
MAX_ATTEMPTS: 3;
|
|
501
|
-
/** Base multiplier for the exponential backoff formula (`delay = BASE * multiplier^attempt`). */
|
|
502
|
-
BACKOFF_MULTIPLIER: 2;
|
|
503
|
-
}>;
|
|
504
|
-
/** Timing for graceful / forced disconnect. */
|
|
505
|
-
readonly DISCONNECT: Readonly<{
|
|
506
|
-
/** Ms to wait for in-flight requests to complete before force-closing. */
|
|
507
|
-
GRACEFUL_MS: 800;
|
|
508
|
-
/** Ms after which the force disconnect is triggered. */
|
|
509
|
-
FORCE_TIMEOUT_MS: 1200;
|
|
510
|
-
}>;
|
|
511
|
-
/** Lazy-connect idle lifecycle. */
|
|
512
|
-
readonly IDLE: Readonly<{
|
|
513
|
-
/** Default ms a lazy server stays connected with no tool calls before auto-sleep. */
|
|
514
|
-
DEFAULT_TIMEOUT_MS: 300000;
|
|
515
|
-
/** How often the idle sweep runs (kept well below the timeout). */
|
|
516
|
-
SWEEP_INTERVAL_MS: 30000;
|
|
517
|
-
}>;
|
|
518
|
-
/** JSON-RPC response timeout for outstanding requests. */
|
|
519
|
-
readonly RESPONSE_TIMEOUT_MS: 500;
|
|
520
|
-
/** Max buffer size for the SSE reader. */
|
|
521
|
-
readonly SSE_READER_MAX_BUFFER: number;
|
|
522
|
-
/** Max characters logged from a request body. */
|
|
523
|
-
readonly REQUEST_LOG_CAP: 1024;
|
|
524
|
-
}>;
|
|
525
|
-
|
|
526
|
-
/** Stable hash of the fields that define how/where we connect to a server. */
|
|
527
|
-
declare function manifestConfigHash(cfg: {
|
|
528
|
-
transport: string;
|
|
529
|
-
command?: string | undefined;
|
|
530
|
-
args?: string[] | undefined;
|
|
531
|
-
url?: string | undefined;
|
|
532
|
-
}): string;
|
|
533
|
-
/**
|
|
534
|
-
* Read a server's cached tools. Returns null when there is no cache or when the
|
|
535
|
-
* stored `configHash` no longer matches (server config changed → stale).
|
|
536
|
-
*/
|
|
537
|
-
declare function readManifest(cacheDir: string, name: string, configHash: string): Promise<MCPTool[] | null>;
|
|
538
|
-
/** Persist a server's discovered tools. Best-effort — IO errors are swallowed. */
|
|
539
|
-
declare function writeManifest(cacheDir: string, name: string, configHash: string, tools: MCPTool[]): Promise<void>;
|
|
540
|
-
|
|
541
|
-
interface HttpTransportOptions {
|
|
542
|
-
name: string;
|
|
543
|
-
url: string;
|
|
544
|
-
headers?: Record<string, string> | undefined;
|
|
545
|
-
startupTimeoutMs?: number | undefined;
|
|
546
|
-
requestTimeoutMs?: number | undefined;
|
|
547
|
-
/**
|
|
548
|
-
* Per-request TLS configuration. When set, an https.Agent is created
|
|
549
|
-
* and passed to fetch via the `dispatch` option. This avoids globally
|
|
550
|
-
* disabling certificate validation (NODE_TLS_REJECT_UNAUTHORIZED) which
|
|
551
|
-
* would affect all provider API calls in the same process.
|
|
552
|
-
*
|
|
553
|
-
* ⚠️ Security gate: `rejectUnauthorized: false` REQUIRES
|
|
554
|
-
* `WRONGSTACK_UNSAFE_MCP_TLS=1` as an explicit opt-in.
|
|
555
|
-
*
|
|
556
|
-
* Without this gate, an active network attacker between the client and the
|
|
557
|
-
* MCP server can read and modify tool calls and responses. Only use this
|
|
558
|
-
* for local development with self-signed certificates; production MCP
|
|
559
|
-
* servers must present a valid certificate.
|
|
560
|
-
*/
|
|
561
|
-
tls?: {
|
|
562
|
-
ca?: string | undefined;
|
|
563
|
-
rejectUnauthorized?: boolean | undefined;
|
|
564
|
-
};
|
|
565
|
-
}
|
|
566
|
-
declare class SSEReader {
|
|
567
|
-
private buffer;
|
|
568
|
-
private dataLines;
|
|
569
|
-
private listeners;
|
|
570
|
-
onMessage(cb: (data: {
|
|
571
|
-
jsonrpc?: string | undefined;
|
|
572
|
-
method?: string | undefined;
|
|
573
|
-
params?: unknown | undefined;
|
|
574
|
-
id?: number | undefined;
|
|
575
|
-
}) => void): () => void;
|
|
576
|
-
feed(chunk: string): void;
|
|
577
|
-
private processLine;
|
|
578
|
-
private flush;
|
|
579
|
-
private dispatch;
|
|
580
|
-
reset(): void;
|
|
581
|
-
}
|
|
582
|
-
/**
|
|
583
|
-
* Fields and methods shared by all HTTP-based MCP transports.
|
|
584
|
-
* Subclasses override `connect()`, `close()`, `callTool()`, `request()`.
|
|
585
|
-
*/
|
|
586
|
-
declare abstract class BaseHTTPTransport {
|
|
587
|
-
protected state: ConnectionState;
|
|
588
|
-
protected readonly url: string;
|
|
589
|
-
protected readonly headers: Record<string, string>;
|
|
590
|
-
protected readonly timeout: number;
|
|
591
|
-
protected readonly requestTimeout: number;
|
|
592
|
-
/** Per-request TLS agent — created once from HttpTransportOptions.tls */
|
|
593
|
-
protected readonly tlsAgent?: https.Agent | undefined;
|
|
594
|
-
protected readonly tools: MCPTool[];
|
|
595
|
-
protected abortController?: AbortController | undefined;
|
|
596
|
-
protected readonly disconnectHandlers: Array<() => void>;
|
|
597
|
-
protected readonly toolsChangedListeners: Set<(tools: MCPTool[]) => void>;
|
|
598
|
-
constructor(opts: HttpTransportOptions, transportName: string);
|
|
599
|
-
getState(): ConnectionState;
|
|
600
|
-
listTools(): MCPTool[];
|
|
601
|
-
onDisconnect(cb: () => void): () => void;
|
|
602
|
-
onToolsChanged(cb: (tools: MCPTool[]) => void): () => void;
|
|
603
|
-
/**
|
|
604
|
-
* Fire all disconnect handlers. Subclasses call this when the connection
|
|
605
|
-
* drops so the registry can schedule reconnects.
|
|
606
|
-
*/
|
|
607
|
-
protected notifyDisconnect(): void;
|
|
608
|
-
/**
|
|
609
|
-
* Apply the pinned TLS agent (if configured) to a `RequestInit` object.
|
|
610
|
-
* Uses `HttpDispatcher` from `@wrongstack/core`'s dispatcher-types shim,
|
|
611
|
-
* which declares `https.Agent` compatible with `RequestInit.dispatcher`.
|
|
612
|
-
* Verified safe: https.Agent implements the `dispatch(req, opts)` method
|
|
613
|
-
* that fetch requires at runtime.
|
|
614
|
-
*/
|
|
615
|
-
protected applyTlsAgent(fetchOpts: RequestInit): void;
|
|
616
|
-
/** Generate the next JSON-RPC request id. Subclasses provide the counter. */
|
|
617
|
-
protected abstract genId(): number;
|
|
618
|
-
}
|
|
619
|
-
/**
|
|
620
|
-
* SSE transport for MCP over HTTP.
|
|
621
|
-
*
|
|
622
|
-
* Uses native fetch API with ReadableStream to consume SSE events.
|
|
623
|
-
* HTTP POST is used to send JSON-RPC requests.
|
|
624
|
-
*/
|
|
625
|
-
declare class SSETransport extends BaseHTTPTransport {
|
|
626
|
-
private _nextId;
|
|
627
|
-
private readerDone;
|
|
628
|
-
private readLoopAbort?;
|
|
629
|
-
private reader?;
|
|
630
|
-
constructor(opts: HttpTransportOptions);
|
|
631
|
-
protected genId(): number;
|
|
632
|
-
/** Refresh tool list when server sends notifications/tools/list_changed. */
|
|
633
|
-
private handleToolsListChanged;
|
|
634
|
-
connect(): Promise<void>;
|
|
635
|
-
private readSSEBody;
|
|
636
|
-
private buildSSEUrl;
|
|
637
|
-
private httpPost;
|
|
638
|
-
callTool(name: string, input: unknown, opts?: {
|
|
639
|
-
signal?: AbortSignal | undefined;
|
|
640
|
-
}): Promise<ToolCallResult>;
|
|
641
|
-
/** Generic JSON-RPC request — used by MCPClient.request() for SSE transports. */
|
|
642
|
-
request(method: string, params: unknown, timeoutMs?: number): Promise<JsonRpcResponse>;
|
|
643
|
-
close(): Promise<void>;
|
|
644
|
-
}
|
|
645
|
-
/**
|
|
646
|
-
* Streamable HTTP transport for MCP.
|
|
647
|
-
*
|
|
648
|
-
* Uses session-based HTTP with NDJSON responses.
|
|
649
|
-
*/
|
|
650
|
-
declare class StreamableHTTPTransport extends BaseHTTPTransport {
|
|
651
|
-
private _nextId;
|
|
652
|
-
private sessionId?;
|
|
653
|
-
constructor(opts: HttpTransportOptions);
|
|
654
|
-
protected genId(): number;
|
|
655
|
-
connect(): Promise<void>;
|
|
656
|
-
private postRaw;
|
|
657
|
-
/** Generic JSON-RPC request — used by MCPClient.request() for SSE/streamable-http transports. */
|
|
658
|
-
request(method: string, params: unknown, timeoutMs?: number): Promise<JsonRpcResponse>;
|
|
659
|
-
callTool(name: string, input: unknown, opts?: {
|
|
660
|
-
signal?: AbortSignal | undefined;
|
|
661
|
-
}): Promise<ToolCallResult>;
|
|
662
|
-
close(): Promise<void>;
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
export { type ConnectionState, type HttpTransportOptions, MCPClient, type MCPClientOptions, MCPRegistry, type MCPRegistryOptions, MCPServer, type MCPServerCallResult, type MCPServerLogger, type MCPServerOptions, type MCPServerTool, type MCPServerToolHost, type MCPTool, MCP_CONSTANTS, type McpManageDeps, type McpOpResult, type McpServerInfo, type McpServerInput, SSEReader, SSETransport, type ServeHttpHandle, type ServeHttpOptions, type ServeStdioHandle, type ServeStdioOptions, StreamableHTTPTransport, type ToolCallResult, type Transport, addMcp, disableMcp, discoverMcp, enableMcp, listMcp, manifestConfigHash, readManifest, removeMcp, restartMcp, serveHttp, serveStdio, toContentBlocks, updateMcp, wrapMCPTool, writeManifest };
|
|
1
|
+
export { authorizationHeaderForToken, authorizationServerMetadataUrls, canonicalMcpResource, createMcpAuthorizationRequest, discoverMcpAuthorization, exchangeMcpAuthorizationCode, type MCPAccessToken, type MCPAuthorizationChallenge, type MCPAuthorizationContext, type MCPAuthorizationDiscoveryOptions, type MCPAuthorizationDiscoveryResult, type MCPAuthorizationJsonFetcher, type MCPAuthorizationProvider, type MCPAuthorizationRequestOptions, type MCPAuthorizationServerMetadata, type MCPAuthorizationSession, type MCPProtectedResourceMetadata, type MCPTokenExchangeOptions, type MCPTokenRefreshOptions, type MCPTokenSet, parseAuthorizationServerMetadata, parseMcpAuthorizationCallback, parseMcpBearerChallenge, parseProtectedResourceMetadata, protectedResourceMetadataUrls, refreshMcpAccessToken, validateMcpAuthorizationServerMetadata, } from './authorization.js';
|
|
2
|
+
export { type MCPAuthorizationCompleteInput, MCPAuthorizationManager, type MCPAuthorizationManagerOptions, type MCPAuthorizationStartInput, type MCPAuthorizationStartResult, type MCPAuthorizationStatus, } from './authorization-manager.js';
|
|
3
|
+
export { type ConnectionState, MCPClient, type MCPClientOptions, type MCPListChangedListener, type MCPPageOptions, type MCPRequestOptions, type MCPTool, type ToolCallResult, type Transport, } from './client.js';
|
|
4
|
+
export { MCP_CONSTANTS } from './constants.js';
|
|
5
|
+
export { DEFAULT_MCP_INSERTION_MAX_BYTES, DEFAULT_MCP_RESOURCE_SCHEMES, type MCPContentProvenance, type MCPInsertionPolicy, type MCPPromptInsertion, type MCPResourceInsertion, preparePromptInsertion, prepareResourceInsertion, } from './content-selection.js';
|
|
6
|
+
export { addMcp, disableMcp, discoverMcp, enableMcp, listMcp, type McpManageDeps, type McpOpResult, type McpServerInfo, type McpServerInput, removeMcp, restartMcp, updateMcp, } from './manage.js';
|
|
7
|
+
export { type MCPCapabilityManifest, manifestConfigHash, readCapabilityManifest, readManifest, writeCapabilityManifest, writeManifest, } from './manifest-cache.js';
|
|
8
|
+
export { MCP_OPERATION_LIMITS, type MCPFailureKind, type MCPHealthState, type MCPLatencySummary, type MCPOperationEvent, type MCPOperationKind, type MCPServerOperationalHealth, } from './operations.js';
|
|
9
|
+
export { type MCPGetPromptResult, type MCPImplementationInfo, type MCPListPromptsResult, type MCPListResourcesResult, type MCPListResourceTemplatesResult, type MCPPrompt, type MCPPromptArgument, type MCPPromptMessage, type MCPReadResourceResult, type MCPResource, type MCPResourceContents, type MCPResourceTemplate, type MCPServerCapabilities, type MCPServerMetadata, parseGetPromptResult, parseListPromptsResult, parseListResourcesResult, parseListResourceTemplatesResult, parseReadResourceResult, parseServerMetadata, } from './protocol.js';
|
|
10
|
+
export { MCPRegistry, type MCPRegistryCatalog, type MCPRegistryOptions } from './registry.js';
|
|
11
|
+
export { MCPServer, type MCPServerCallResult, type MCPServerLogger, type MCPServerOptions, type MCPServerPrompt, type MCPServerResource, type MCPServerTool, type MCPServerToolHost, type ServeHttpHandle, type ServeHttpOptions, type ServeStdioHandle, type ServeStdioOptions, serveHttp, serveStdio, toContentBlocks, } from './server.js';
|
|
12
|
+
export { createVaultBackedMcpAuthorizationProviderFactory, type MCPAuthorizationStateEvent, MCPRefreshingAuthorizationProvider, type MCPRefreshingAuthorizationProviderOptions, type MCPStoredAuthorization, type MCPVaultProviderFactoryOptions, MCPVaultTokenStore, } from './token-store.js';
|
|
13
|
+
export { type HttpTransportOptions, SSEReader, SSETransport, StreamableHTTPTransport, } from './transport.js';
|
|
14
|
+
export { type MCPToolCallObserver, wrapMCPTool } from './wrap-tool.js';
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|