@wrongstack/mcp 0.285.0 → 0.287.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 +31 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/content-selection.d.ts +33 -0
- package/dist/content-selection.d.ts.map +1 -0
- package/dist/index.d.ts +13 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3085 -619
- package/dist/index.js.map +4 -4
- package/dist/manage.d.ts +3 -1
- package/dist/manage.d.ts.map +1 -1
- package/dist/manifest-cache.d.ts +15 -0
- package/dist/manifest-cache.d.ts.map +1 -1
- 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 +73 -0
- package/dist/registry.d.ts.map +1 -1
- package/dist/server.d.ts +25 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/sse-reader.d.ts +17 -0
- package/dist/sse-reader.d.ts.map +1 -0
- package/dist/token-store.d.ts +56 -0
- package/dist/token-store.d.ts.map +1 -0
- package/dist/transport-base.d.ts +90 -0
- package/dist/transport-base.d.ts.map +1 -0
- package/dist/transport-jsonrpc.d.ts +32 -0
- package/dist/transport-jsonrpc.d.ts.map +1 -0
- package/dist/transport-security.d.ts +13 -0
- package/dist/transport-security.d.ts.map +1 -0
- package/dist/transport-sse.d.ts +31 -0
- package/dist/transport-sse.d.ts.map +1 -0
- package/dist/transport-streamable.d.ts +27 -0
- package/dist/transport-streamable.d.ts.map +1 -0
- package/dist/transport.d.ts +7 -144
- package/dist/transport.d.ts.map +1 -1
- package/dist/wrap-tool.d.ts +8 -1
- package/dist/wrap-tool.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import * as https from 'node:https';
|
|
2
|
+
import { type MCPAuthorizationProvider } from './authorization.js';
|
|
3
|
+
import type { ConnectionState, MCPTool } from './client.js';
|
|
4
|
+
import type { MCPServerMetadata } from './protocol.js';
|
|
5
|
+
export interface HttpTransportOptions {
|
|
6
|
+
name: string;
|
|
7
|
+
url: string;
|
|
8
|
+
headers?: Record<string, string> | undefined;
|
|
9
|
+
startupTimeoutMs?: number | undefined;
|
|
10
|
+
requestTimeoutMs?: number | undefined;
|
|
11
|
+
authorizationProvider?: MCPAuthorizationProvider | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Per-request TLS configuration. When set, an https.Agent is created
|
|
14
|
+
* and passed to fetch via the `dispatch` option. This avoids globally
|
|
15
|
+
* disabling certificate validation (NODE_TLS_REJECT_UNAUTHORIZED) which
|
|
16
|
+
* would affect all provider API calls in the same process.
|
|
17
|
+
*
|
|
18
|
+
* ⚠️ Security gate: `rejectUnauthorized: false` REQUIRES
|
|
19
|
+
* `WRONGSTACK_UNSAFE_MCP_TLS=1` as an explicit opt-in.
|
|
20
|
+
*
|
|
21
|
+
* Without this gate, an active network attacker between the client and the
|
|
22
|
+
* MCP server can read and modify tool calls and responses. Only use this
|
|
23
|
+
* for local development with self-signed certificates; production MCP
|
|
24
|
+
* servers must present a valid certificate.
|
|
25
|
+
*/
|
|
26
|
+
tls?: {
|
|
27
|
+
ca?: string | undefined;
|
|
28
|
+
rejectUnauthorized?: boolean | undefined;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Abort error whose `name` is `'AbortError'` so the core executor's
|
|
33
|
+
* classifyToolError maps it to FATAL / not-retryable (user cancellation).
|
|
34
|
+
*/
|
|
35
|
+
export declare function makeAbortError(method: string): Error;
|
|
36
|
+
export declare function createTimeoutSignal(parent: AbortSignal | undefined, timeoutMs: number): {
|
|
37
|
+
signal: AbortSignal;
|
|
38
|
+
dispose: () => void;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Fields and methods shared by all HTTP-based MCP transports.
|
|
42
|
+
* Subclasses override `connect()`, `close()`, `callTool()`, `request()`.
|
|
43
|
+
*/
|
|
44
|
+
export declare abstract class BaseHTTPTransport {
|
|
45
|
+
protected state: ConnectionState;
|
|
46
|
+
protected readonly url: string;
|
|
47
|
+
protected readonly headers: Record<string, string>;
|
|
48
|
+
protected readonly timeout: number;
|
|
49
|
+
protected readonly requestTimeout: number;
|
|
50
|
+
protected readonly name: string;
|
|
51
|
+
protected readonly authorizationProvider?: MCPAuthorizationProvider | undefined;
|
|
52
|
+
protected readonly authorizationResource: string;
|
|
53
|
+
/** Per-request TLS agent — created once from HttpTransportOptions.tls */
|
|
54
|
+
protected readonly tlsAgent?: https.Agent | undefined;
|
|
55
|
+
protected readonly tools: MCPTool[];
|
|
56
|
+
protected serverMetadata?: MCPServerMetadata | undefined;
|
|
57
|
+
protected abortController?: AbortController | undefined;
|
|
58
|
+
protected readonly disconnectHandlers: Array<() => void>;
|
|
59
|
+
protected readonly toolsChangedListeners: Set<(tools: MCPTool[]) => void>;
|
|
60
|
+
protected readonly resourcesChangedListeners: Set<() => void>;
|
|
61
|
+
protected readonly promptsChangedListeners: Set<() => void>;
|
|
62
|
+
protected protocolVersion?: string | undefined;
|
|
63
|
+
constructor(opts: HttpTransportOptions, transportName: string);
|
|
64
|
+
getState(): ConnectionState;
|
|
65
|
+
protected fetchWithAuthorization(input: string, init: RequestInit, signal?: AbortSignal | undefined): Promise<Response>;
|
|
66
|
+
listTools(): MCPTool[];
|
|
67
|
+
getServerMetadata(): MCPServerMetadata | undefined;
|
|
68
|
+
onDisconnect(cb: () => void): () => void;
|
|
69
|
+
onToolsChanged(cb: (tools: MCPTool[]) => void): () => void;
|
|
70
|
+
onResourcesChanged(cb: () => void): () => void;
|
|
71
|
+
onPromptsChanged(cb: () => void): () => void;
|
|
72
|
+
/**
|
|
73
|
+
* Fire all disconnect handlers. Subclasses call this when the connection
|
|
74
|
+
* drops so the registry can schedule reconnects.
|
|
75
|
+
*/
|
|
76
|
+
protected notifyDisconnect(): void;
|
|
77
|
+
protected notifyResourcesChanged(): void;
|
|
78
|
+
protected notifyPromptsChanged(): void;
|
|
79
|
+
/**
|
|
80
|
+
* Apply the pinned TLS agent (if configured) to a `RequestInit` object.
|
|
81
|
+
* Uses `HttpDispatcher` from `@wrongstack/core`'s dispatcher-types shim,
|
|
82
|
+
* which declares `https.Agent` compatible with `RequestInit.dispatcher`.
|
|
83
|
+
* Verified safe: https.Agent implements the `dispatch(req, opts)` method
|
|
84
|
+
* that fetch requires at runtime.
|
|
85
|
+
*/
|
|
86
|
+
protected applyTlsAgent(fetchOpts: RequestInit): void;
|
|
87
|
+
/** Generate the next JSON-RPC request id. Subclasses provide the counter. */
|
|
88
|
+
protected abstract genId(): number;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=transport-base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport-base.d.ts","sourceRoot":"","sources":["../src/transport-base.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AAEpC,OAAO,EAGL,KAAK,wBAAwB,EAE9B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAGvD,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;IAC7C,gBAAgB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC,gBAAgB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC,qBAAqB,CAAC,EAAE,wBAAwB,GAAG,SAAS,CAAC;IAC7D;;;;;;;;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AAM,CAAC;CACpC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export type JsonRpcResult = {
|
|
2
|
+
jsonrpc: string;
|
|
3
|
+
id?: number | undefined;
|
|
4
|
+
result?: unknown | undefined;
|
|
5
|
+
error?: {
|
|
6
|
+
code: number | undefined;
|
|
7
|
+
message: string;
|
|
8
|
+
data?: unknown | undefined;
|
|
9
|
+
} | undefined;
|
|
10
|
+
};
|
|
11
|
+
type JsonRpcMethodEnvelope = {
|
|
12
|
+
jsonrpc: '2.0';
|
|
13
|
+
id?: number | string | undefined;
|
|
14
|
+
method: string;
|
|
15
|
+
params?: unknown | undefined;
|
|
16
|
+
};
|
|
17
|
+
type JsonRpcEnvelope = JsonRpcResult | JsonRpcMethodEnvelope;
|
|
18
|
+
export declare function isJsonRpcResult(v: unknown): v is JsonRpcResult;
|
|
19
|
+
/**
|
|
20
|
+
* Extract JSON-RPC envelopes from a streamable-http response body. Handles BOTH
|
|
21
|
+
* plain NDJSON (one JSON object per line) AND SSE framing
|
|
22
|
+
* (`event: message\ndata: {...}` blocks) — modern MCP servers (e.g. Context7)
|
|
23
|
+
* reply with `text/event-stream` even on a single POST, so the data must be
|
|
24
|
+
* un-prefixed before parsing. Multi-line `data:` values within one event are
|
|
25
|
+
* joined per the SSE spec.
|
|
26
|
+
*/
|
|
27
|
+
export declare function extractJsonRpcEnvelopes(text: string): JsonRpcEnvelope[];
|
|
28
|
+
/** Extract only response envelopes; notifications and server requests are not responses. */
|
|
29
|
+
export declare function extractJsonRpcResults(text: string): JsonRpcResult[];
|
|
30
|
+
export declare function assertMatchingJsonRpcResult(data: unknown, expectedId: number, method: string): JsonRpcResult;
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=transport-jsonrpc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport-jsonrpc.d.ts","sourceRoot":"","sources":["../src/transport-jsonrpc.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACxB,MAAM,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC7B,KAAK,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;KAAE,GAAG,SAAS,CAAC;CAC/F,CAAC;AAEF,KAAK,qBAAqB,GAAG;IAC3B,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAC9B,CAAC;AAEF,KAAK,eAAe,GAAG,aAAa,GAAG,qBAAqB,CAAC;AAE7D,wBAAgB,eAAe,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,aAAa,CAmB9D;AAUD;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,EAAE,CA4CvE;AAED,4FAA4F;AAC5F,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,EAAE,CAEnE;AAED,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,OAAO,EACb,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,GACb,aAAa,CAkBf"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare function isTlsUnsafeAllowed(): boolean;
|
|
2
|
+
/**
|
|
3
|
+
* Validate that an MCP transport URL is not targeting private/internal
|
|
4
|
+
* addresses. This is a defense-in-depth SSRF check — MCP servers are
|
|
5
|
+
* typically local or LAN, but config manipulation could point to metadata
|
|
6
|
+
* endpoints (169.254.169.254) or internal services.
|
|
7
|
+
*
|
|
8
|
+
* The check is intentionally lighter than fetch.ts's assertNotPrivate:
|
|
9
|
+
* MCP URLs are admin-configured, not LLM-supplied, so we only block
|
|
10
|
+
* the most obvious attack vectors.
|
|
11
|
+
*/
|
|
12
|
+
export declare function validateTransportUrl(rawUrl: string): void;
|
|
13
|
+
//# sourceMappingURL=transport-security.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport-security.d.ts","sourceRoot":"","sources":["../src/transport-security.ts"],"names":[],"mappings":"AAGA,wBAAgB,kBAAkB,IAAI,OAAO,CAE5C;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAsEzD"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { JsonRpcResponse, ToolCallResult } from './client.js';
|
|
2
|
+
import { BaseHTTPTransport, type HttpTransportOptions } from './transport-base.js';
|
|
3
|
+
/**
|
|
4
|
+
* SSE transport for MCP over HTTP.
|
|
5
|
+
*
|
|
6
|
+
* Uses native fetch API with ReadableStream to consume SSE events.
|
|
7
|
+
* HTTP POST is used to send JSON-RPC requests.
|
|
8
|
+
*/
|
|
9
|
+
export declare class SSETransport extends BaseHTTPTransport {
|
|
10
|
+
private _nextId;
|
|
11
|
+
private readerDone;
|
|
12
|
+
private readLoopAbort?;
|
|
13
|
+
private reader?;
|
|
14
|
+
constructor(opts: HttpTransportOptions);
|
|
15
|
+
protected genId(): number;
|
|
16
|
+
/** Refresh tool list when server sends notifications/tools/list_changed. */
|
|
17
|
+
private handleToolsListChanged;
|
|
18
|
+
connect(): Promise<void>;
|
|
19
|
+
private readSSEBody;
|
|
20
|
+
private buildSSEUrl;
|
|
21
|
+
private httpPost;
|
|
22
|
+
callTool(name: string, input: unknown, opts?: {
|
|
23
|
+
signal?: AbortSignal | undefined;
|
|
24
|
+
}): Promise<ToolCallResult>;
|
|
25
|
+
/** Generic JSON-RPC request — used by MCPClient.request() for SSE transports. */
|
|
26
|
+
request(method: string, params: unknown, timeoutMs?: number, opts?: {
|
|
27
|
+
signal?: AbortSignal | undefined;
|
|
28
|
+
}): Promise<JsonRpcResponse>;
|
|
29
|
+
close(): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=transport-sse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport-sse.d.ts","sourceRoot":"","sources":["../src/transport-sse.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAInE,OAAO,EACL,iBAAiB,EAEjB,KAAK,oBAAoB,EAE1B,MAAM,qBAAqB,CAAC;AAQ7B;;;;;GAKG;AACH,qBAAa,YAAa,SAAQ,iBAAiB;IACjD,OAAO,CAAC,OAAO,CAAK;IACpB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,aAAa,CAAC,CAA8B;IACpD,OAAO,CAAC,MAAM,CAAC,CAA6D;IAE5E,YAAY,IAAI,EAAE,oBAAoB,EAErC;IAED,UAAmB,KAAK,IAAI,MAAM,CAEjC;IAED,4EAA4E;YAC9D,sBAAsB;IAsB9B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAkG7B;YAEa,WAAW;IAuBzB,OAAO,CAAC,WAAW;YAaL,QAAQ;IAyEhB,QAAQ,CACZ,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,EACd,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAA;KAAE,GAC1C,OAAO,CAAC,cAAc,CAAC,CAoBzB;IAED,iFAAiF;IAC3E,OAAO,CACX,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,OAAO,EACf,SAAS,CAAC,EAAE,MAAM,EAClB,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAA;KAAE,GAC1C,OAAO,CAAC,eAAe,CAAC,CAmE1B;IAEK,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAkB3B;CACF"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { JsonRpcResponse, ToolCallResult } from './client.js';
|
|
2
|
+
import { BaseHTTPTransport, type HttpTransportOptions } from './transport-base.js';
|
|
3
|
+
/**
|
|
4
|
+
* Streamable HTTP transport for MCP.
|
|
5
|
+
*
|
|
6
|
+
* Uses session-based HTTP with NDJSON responses.
|
|
7
|
+
*/
|
|
8
|
+
export declare class StreamableHTTPTransport extends BaseHTTPTransport {
|
|
9
|
+
private _nextId;
|
|
10
|
+
private sessionId?;
|
|
11
|
+
constructor(opts: HttpTransportOptions);
|
|
12
|
+
protected genId(): number;
|
|
13
|
+
private consumeResponseText;
|
|
14
|
+
private handleNotification;
|
|
15
|
+
private refreshTools;
|
|
16
|
+
connect(): Promise<void>;
|
|
17
|
+
private postRaw;
|
|
18
|
+
/** Generic JSON-RPC request — used by MCPClient.request() for SSE/streamable-http transports. */
|
|
19
|
+
request(method: string, params: unknown, timeoutMs?: number, opts?: {
|
|
20
|
+
signal?: AbortSignal | undefined;
|
|
21
|
+
}): Promise<JsonRpcResponse>;
|
|
22
|
+
callTool(name: string, input: unknown, opts?: {
|
|
23
|
+
signal?: AbortSignal | undefined;
|
|
24
|
+
}): Promise<ToolCallResult>;
|
|
25
|
+
close(): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=transport-streamable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport-streamable.d.ts","sourceRoot":"","sources":["../src/transport-streamable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAGnE,OAAO,EACL,iBAAiB,EAEjB,KAAK,oBAAoB,EAE1B,MAAM,qBAAqB,CAAC;AAc7B;;;;GAIG;AACH,qBAAa,uBAAwB,SAAQ,iBAAiB;IAC5D,OAAO,CAAC,OAAO,CAAK;IACpB,OAAO,CAAC,SAAS,CAAC,CAAqB;IAEvC,YAAY,IAAI,EAAE,oBAAoB,EAErC;IAED,UAAmB,KAAK,IAAI,MAAM,CAEjC;IAED,OAAO,CAAC,mBAAmB;IAe3B,OAAO,CAAC,kBAAkB;YAUZ,YAAY;IAoBpB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CA8E7B;YAEa,OAAO;IA6DrB,iGAAiG;IAC3F,OAAO,CACX,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,OAAO,EACf,SAAS,CAAC,EAAE,MAAM,EAClB,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAA;KAAE,GAC1C,OAAO,CAAC,eAAe,CAAC,CAwD1B;IAEK,QAAQ,CACZ,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,EACd,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAA;KAAE,GAC1C,OAAO,CAAC,cAAc,CAAC,CAezB;IAEK,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAO3B;CACF"}
|
package/dist/transport.d.ts
CHANGED
|
@@ -1,145 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
code: number | undefined;
|
|
9
|
-
message: string;
|
|
10
|
-
data?: unknown | undefined;
|
|
11
|
-
} | undefined;
|
|
12
|
-
};
|
|
13
|
-
export interface HttpTransportOptions {
|
|
14
|
-
name: string;
|
|
15
|
-
url: string;
|
|
16
|
-
headers?: Record<string, string> | undefined;
|
|
17
|
-
startupTimeoutMs?: number | undefined;
|
|
18
|
-
requestTimeoutMs?: number | undefined;
|
|
19
|
-
/**
|
|
20
|
-
* Per-request TLS configuration. When set, an https.Agent is created
|
|
21
|
-
* and passed to fetch via the `dispatch` option. This avoids globally
|
|
22
|
-
* disabling certificate validation (NODE_TLS_REJECT_UNAUTHORIZED) which
|
|
23
|
-
* would affect all provider API calls in the same process.
|
|
24
|
-
*
|
|
25
|
-
* ⚠️ Security gate: `rejectUnauthorized: false` REQUIRES
|
|
26
|
-
* `WRONGSTACK_UNSAFE_MCP_TLS=1` as an explicit opt-in.
|
|
27
|
-
*
|
|
28
|
-
* Without this gate, an active network attacker between the client and the
|
|
29
|
-
* MCP server can read and modify tool calls and responses. Only use this
|
|
30
|
-
* for local development with self-signed certificates; production MCP
|
|
31
|
-
* servers must present a valid certificate.
|
|
32
|
-
*/
|
|
33
|
-
tls?: {
|
|
34
|
-
ca?: string | undefined;
|
|
35
|
-
rejectUnauthorized?: boolean | undefined;
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
export declare class SSEReader {
|
|
39
|
-
private buffer;
|
|
40
|
-
private dataLines;
|
|
41
|
-
private listeners;
|
|
42
|
-
onMessage(cb: (data: {
|
|
43
|
-
jsonrpc?: string | undefined;
|
|
44
|
-
method?: string | undefined;
|
|
45
|
-
params?: unknown | undefined;
|
|
46
|
-
id?: number | undefined;
|
|
47
|
-
}) => void): () => void;
|
|
48
|
-
feed(chunk: string): void;
|
|
49
|
-
private processLine;
|
|
50
|
-
private flush;
|
|
51
|
-
private dispatch;
|
|
52
|
-
reset(): void;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Extract JSON-RPC envelopes from a streamable-http response body. Handles BOTH
|
|
56
|
-
* plain NDJSON (one JSON object per line) AND SSE framing
|
|
57
|
-
* (`event: message\ndata: {...}` blocks) — modern MCP servers (e.g. Context7)
|
|
58
|
-
* reply with `text/event-stream` even on a single POST, so the data must be
|
|
59
|
-
* un-prefixed before parsing. Multi-line `data:` values within one event are
|
|
60
|
-
* joined per the SSE spec.
|
|
61
|
-
*/
|
|
62
|
-
export declare function extractJsonRpcResults(text: string): JsonRpcResult[];
|
|
63
|
-
/**
|
|
64
|
-
* Fields and methods shared by all HTTP-based MCP transports.
|
|
65
|
-
* Subclasses override `connect()`, `close()`, `callTool()`, `request()`.
|
|
66
|
-
*/
|
|
67
|
-
export declare abstract class BaseHTTPTransport {
|
|
68
|
-
protected state: ConnectionState;
|
|
69
|
-
protected readonly url: string;
|
|
70
|
-
protected readonly headers: Record<string, string>;
|
|
71
|
-
protected readonly timeout: number;
|
|
72
|
-
protected readonly requestTimeout: number;
|
|
73
|
-
/** Per-request TLS agent — created once from HttpTransportOptions.tls */
|
|
74
|
-
protected readonly tlsAgent?: https.Agent | undefined;
|
|
75
|
-
protected readonly tools: MCPTool[];
|
|
76
|
-
protected abortController?: AbortController | undefined;
|
|
77
|
-
protected readonly disconnectHandlers: Array<() => void>;
|
|
78
|
-
protected readonly toolsChangedListeners: Set<(tools: MCPTool[]) => void>;
|
|
79
|
-
constructor(opts: HttpTransportOptions, transportName: string);
|
|
80
|
-
getState(): ConnectionState;
|
|
81
|
-
listTools(): MCPTool[];
|
|
82
|
-
onDisconnect(cb: () => void): () => void;
|
|
83
|
-
onToolsChanged(cb: (tools: MCPTool[]) => void): () => void;
|
|
84
|
-
/**
|
|
85
|
-
* Fire all disconnect handlers. Subclasses call this when the connection
|
|
86
|
-
* drops so the registry can schedule reconnects.
|
|
87
|
-
*/
|
|
88
|
-
protected notifyDisconnect(): void;
|
|
89
|
-
/**
|
|
90
|
-
* Apply the pinned TLS agent (if configured) to a `RequestInit` object.
|
|
91
|
-
* Uses `HttpDispatcher` from `@wrongstack/core`'s dispatcher-types shim,
|
|
92
|
-
* which declares `https.Agent` compatible with `RequestInit.dispatcher`.
|
|
93
|
-
* Verified safe: https.Agent implements the `dispatch(req, opts)` method
|
|
94
|
-
* that fetch requires at runtime.
|
|
95
|
-
*/
|
|
96
|
-
protected applyTlsAgent(fetchOpts: RequestInit): void;
|
|
97
|
-
/** Generate the next JSON-RPC request id. Subclasses provide the counter. */
|
|
98
|
-
protected abstract genId(): number;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* SSE transport for MCP over HTTP.
|
|
102
|
-
*
|
|
103
|
-
* Uses native fetch API with ReadableStream to consume SSE events.
|
|
104
|
-
* HTTP POST is used to send JSON-RPC requests.
|
|
105
|
-
*/
|
|
106
|
-
export declare class SSETransport extends BaseHTTPTransport {
|
|
107
|
-
private _nextId;
|
|
108
|
-
private readerDone;
|
|
109
|
-
private readLoopAbort?;
|
|
110
|
-
private reader?;
|
|
111
|
-
constructor(opts: HttpTransportOptions);
|
|
112
|
-
protected genId(): number;
|
|
113
|
-
/** Refresh tool list when server sends notifications/tools/list_changed. */
|
|
114
|
-
private handleToolsListChanged;
|
|
115
|
-
connect(): Promise<void>;
|
|
116
|
-
private readSSEBody;
|
|
117
|
-
private buildSSEUrl;
|
|
118
|
-
private httpPost;
|
|
119
|
-
callTool(name: string, input: unknown, opts?: {
|
|
120
|
-
signal?: AbortSignal | undefined;
|
|
121
|
-
}): Promise<ToolCallResult>;
|
|
122
|
-
/** Generic JSON-RPC request — used by MCPClient.request() for SSE transports. */
|
|
123
|
-
request(method: string, params: unknown, timeoutMs?: number): Promise<JsonRpcResponse>;
|
|
124
|
-
close(): Promise<void>;
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Streamable HTTP transport for MCP.
|
|
128
|
-
*
|
|
129
|
-
* Uses session-based HTTP with NDJSON responses.
|
|
130
|
-
*/
|
|
131
|
-
export declare class StreamableHTTPTransport extends BaseHTTPTransport {
|
|
132
|
-
private _nextId;
|
|
133
|
-
private sessionId?;
|
|
134
|
-
constructor(opts: HttpTransportOptions);
|
|
135
|
-
protected genId(): number;
|
|
136
|
-
connect(): Promise<void>;
|
|
137
|
-
private postRaw;
|
|
138
|
-
/** Generic JSON-RPC request — used by MCPClient.request() for SSE/streamable-http transports. */
|
|
139
|
-
request(method: string, params: unknown, timeoutMs?: number): Promise<JsonRpcResponse>;
|
|
140
|
-
callTool(name: string, input: unknown, opts?: {
|
|
141
|
-
signal?: AbortSignal | undefined;
|
|
142
|
-
}): Promise<ToolCallResult>;
|
|
143
|
-
close(): Promise<void>;
|
|
144
|
-
}
|
|
1
|
+
export type { JsonRpcResult } from './transport-jsonrpc.js';
|
|
2
|
+
export { extractJsonRpcResults } from './transport-jsonrpc.js';
|
|
3
|
+
export { SSEReader } from './sse-reader.js';
|
|
4
|
+
export type { HttpTransportOptions } from './transport-base.js';
|
|
5
|
+
export { BaseHTTPTransport } from './transport-base.js';
|
|
6
|
+
export { SSETransport } from './transport-sse.js';
|
|
7
|
+
export { StreamableHTTPTransport } from './transport-streamable.js';
|
|
145
8
|
//# sourceMappingURL=transport.d.ts.map
|
package/dist/transport.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,YAAY,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC"}
|
package/dist/wrap-tool.d.ts
CHANGED
|
@@ -6,5 +6,12 @@ import type { MCPClient, MCPTool } from './client.js';
|
|
|
6
6
|
* registry passes `() => this.ensureConnected(name)`).
|
|
7
7
|
*/
|
|
8
8
|
export type MCPClientResolver = MCPClient | (() => Promise<MCPClient>);
|
|
9
|
-
export
|
|
9
|
+
export interface MCPToolCallObserver {
|
|
10
|
+
onStart(): void;
|
|
11
|
+
onFinish(result: {
|
|
12
|
+
durationMs: number;
|
|
13
|
+
ok: boolean;
|
|
14
|
+
}): void;
|
|
15
|
+
}
|
|
16
|
+
export declare function wrapMCPTool(serverName: string, mcpTool: MCPTool, client: MCPClientResolver, permission?: Permission, observer?: MCPToolCallObserver | undefined): Tool;
|
|
10
17
|
//# sourceMappingURL=wrap-tool.d.ts.map
|
package/dist/wrap-tool.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrap-tool.d.ts","sourceRoot":"","sources":["../src/wrap-tool.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"wrap-tool.d.ts","sourceRoot":"","sources":["../src/wrap-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,IAAI,EAAoB,MAAM,kBAAkB,CAAC;AAChF,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAwBtD;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG,SAAS,GAAG,CAAC,MAAM,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;AAEvE,MAAM,WAAW,mBAAmB;IAClC,OAAO,IAAI,IAAI,CAAC;IAChB,QAAQ,CAAC,MAAM,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;CAC7D;AAED,wBAAgB,WAAW,CACzB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,iBAAiB,EACzB,UAAU,GAAE,UAAsB,EAClC,QAAQ,CAAC,EAAE,mBAAmB,GAAG,SAAS,GACzC,IAAI,CAgCN"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wrongstack/mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.287.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "WrongStack Model Context Protocol client and registry: stdio, SSE, and streamable HTTP transports.",
|
|
6
6
|
"repository": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"dist"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@wrongstack/core": "0.
|
|
28
|
+
"@wrongstack/core": "0.287.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/node": "^26.0.1",
|