mcp-pentester-cli 1.0.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/LICENSE +75 -0
- package/README.md +327 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +183 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp-client.d.ts +23 -0
- package/dist/mcp-client.d.ts.map +1 -0
- package/dist/mcp-client.js +163 -0
- package/dist/mcp-client.js.map +1 -0
- package/dist/transport/base.d.ts +18 -0
- package/dist/transport/base.d.ts.map +1 -0
- package/dist/transport/base.js +64 -0
- package/dist/transport/base.js.map +1 -0
- package/dist/transport/http.d.ts +14 -0
- package/dist/transport/http.d.ts.map +1 -0
- package/dist/transport/http.js +137 -0
- package/dist/transport/http.js.map +1 -0
- package/dist/transport/stdio.d.ts +15 -0
- package/dist/transport/stdio.d.ts.map +1 -0
- package/dist/transport/stdio.js +89 -0
- package/dist/transport/stdio.js.map +1 -0
- package/dist/transport/websocket.d.ts +15 -0
- package/dist/transport/websocket.d.ts.map +1 -0
- package/dist/transport/websocket.js +109 -0
- package/dist/transport/websocket.js.map +1 -0
- package/dist/types.d.ts +103 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/ui/tui.d.ts +43 -0
- package/dist/ui/tui.d.ts.map +1 -0
- package/dist/ui/tui.js +872 -0
- package/dist/ui/tui.js.map +1 -0
- package/examples/http-burp-config.json +9 -0
- package/examples/https-burp-config.json +13 -0
- package/examples/stdio-config.json +10 -0
- package/examples/tor-config.json +9 -0
- package/examples/websocket-config.json +9 -0
- package/package.json +44 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MCPClient = void 0;
|
|
4
|
+
const events_1 = require("events");
|
|
5
|
+
const stdio_1 = require("./transport/stdio");
|
|
6
|
+
const http_1 = require("./transport/http");
|
|
7
|
+
const websocket_1 = require("./transport/websocket");
|
|
8
|
+
class MCPClient extends events_1.EventEmitter {
|
|
9
|
+
constructor(config) {
|
|
10
|
+
super();
|
|
11
|
+
this.config = config;
|
|
12
|
+
this.state = {
|
|
13
|
+
connected: false,
|
|
14
|
+
tools: [],
|
|
15
|
+
resources: [],
|
|
16
|
+
prompts: [],
|
|
17
|
+
trafficLog: [],
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
async connect() {
|
|
21
|
+
// Create appropriate transport
|
|
22
|
+
switch (this.config.type) {
|
|
23
|
+
case 'stdio':
|
|
24
|
+
if (!this.config.command) {
|
|
25
|
+
throw new Error('Command required for stdio transport');
|
|
26
|
+
}
|
|
27
|
+
this.transport = new stdio_1.StdioTransport(this.config.command, this.config.args || [], this.config.env || {});
|
|
28
|
+
break;
|
|
29
|
+
case 'http':
|
|
30
|
+
case 'https':
|
|
31
|
+
if (!this.config.url) {
|
|
32
|
+
throw new Error('URL required for HTTP transport');
|
|
33
|
+
}
|
|
34
|
+
this.transport = new http_1.HttpTransport(this.config.url, this.config.proxy);
|
|
35
|
+
break;
|
|
36
|
+
case 'ws':
|
|
37
|
+
case 'wss':
|
|
38
|
+
if (!this.config.url) {
|
|
39
|
+
throw new Error('URL required for WebSocket transport');
|
|
40
|
+
}
|
|
41
|
+
this.transport = new websocket_1.WebSocketTransport(this.config.url, this.config.proxy);
|
|
42
|
+
break;
|
|
43
|
+
default:
|
|
44
|
+
throw new Error(`Unsupported transport type: ${this.config.type}`);
|
|
45
|
+
}
|
|
46
|
+
// Set up event handlers
|
|
47
|
+
this.transport.on('send', (data) => {
|
|
48
|
+
this.logTraffic('sent', data);
|
|
49
|
+
this.emit('traffic', { direction: 'sent', data });
|
|
50
|
+
});
|
|
51
|
+
this.transport.on('receive', (data) => {
|
|
52
|
+
this.logTraffic('received', data);
|
|
53
|
+
this.emit('traffic', { direction: 'received', data });
|
|
54
|
+
});
|
|
55
|
+
this.transport.on('error', (error) => {
|
|
56
|
+
this.emit('error', error);
|
|
57
|
+
});
|
|
58
|
+
this.transport.on('notification', (notification) => {
|
|
59
|
+
this.emit('notification', notification);
|
|
60
|
+
});
|
|
61
|
+
// Connect transport
|
|
62
|
+
await this.transport.connect();
|
|
63
|
+
// Initialize MCP protocol
|
|
64
|
+
const result = await this.initialize();
|
|
65
|
+
this.state.connected = true;
|
|
66
|
+
this.state.serverInfo = result.serverInfo;
|
|
67
|
+
this.state.capabilities = result.capabilities;
|
|
68
|
+
this.emit('connected', result);
|
|
69
|
+
// Fetch initial data
|
|
70
|
+
await this.refreshAll();
|
|
71
|
+
}
|
|
72
|
+
async disconnect() {
|
|
73
|
+
if (this.transport) {
|
|
74
|
+
await this.transport.disconnect();
|
|
75
|
+
this.state.connected = false;
|
|
76
|
+
this.emit('disconnected');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async initialize() {
|
|
80
|
+
const result = await this.transport.request('initialize', {
|
|
81
|
+
protocolVersion: '2024-11-05',
|
|
82
|
+
capabilities: {
|
|
83
|
+
roots: {
|
|
84
|
+
listChanged: true,
|
|
85
|
+
},
|
|
86
|
+
sampling: {},
|
|
87
|
+
},
|
|
88
|
+
clientInfo: {
|
|
89
|
+
name: 'mcp-pentester-cli',
|
|
90
|
+
version: '1.0.0',
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
// Send initialized notification
|
|
94
|
+
await this.transport.notify('notifications/initialized');
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
async listTools() {
|
|
98
|
+
const result = await this.transport.request('tools/list');
|
|
99
|
+
this.state.tools = result.tools || [];
|
|
100
|
+
return this.state.tools;
|
|
101
|
+
}
|
|
102
|
+
async callTool(name, args = {}) {
|
|
103
|
+
return await this.transport.request('tools/call', {
|
|
104
|
+
name,
|
|
105
|
+
arguments: args,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
async listResources() {
|
|
109
|
+
const result = await this.transport.request('resources/list');
|
|
110
|
+
this.state.resources = result.resources || [];
|
|
111
|
+
return this.state.resources;
|
|
112
|
+
}
|
|
113
|
+
async readResource(uri) {
|
|
114
|
+
return await this.transport.request('resources/read', { uri });
|
|
115
|
+
}
|
|
116
|
+
async listPrompts() {
|
|
117
|
+
const result = await this.transport.request('prompts/list');
|
|
118
|
+
this.state.prompts = result.prompts || [];
|
|
119
|
+
return this.state.prompts;
|
|
120
|
+
}
|
|
121
|
+
async getPrompt(name, args = {}) {
|
|
122
|
+
return await this.transport.request('prompts/get', {
|
|
123
|
+
name,
|
|
124
|
+
arguments: args,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
async refreshAll() {
|
|
128
|
+
try {
|
|
129
|
+
await Promise.all([
|
|
130
|
+
this.listTools().catch(() => []),
|
|
131
|
+
this.listResources().catch(() => []),
|
|
132
|
+
this.listPrompts().catch(() => []),
|
|
133
|
+
]);
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
// Ignore errors during refresh
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
getState() {
|
|
140
|
+
return { ...this.state };
|
|
141
|
+
}
|
|
142
|
+
getTrafficLog() {
|
|
143
|
+
return [...this.state.trafficLog];
|
|
144
|
+
}
|
|
145
|
+
clearTrafficLog() {
|
|
146
|
+
this.state.trafficLog = [];
|
|
147
|
+
}
|
|
148
|
+
logTraffic(direction, data) {
|
|
149
|
+
this.state.trafficLog.push({
|
|
150
|
+
timestamp: new Date(),
|
|
151
|
+
direction,
|
|
152
|
+
transport: this.config.type,
|
|
153
|
+
data,
|
|
154
|
+
raw: JSON.stringify(data, null, 2),
|
|
155
|
+
});
|
|
156
|
+
// Keep only last 1000 entries
|
|
157
|
+
if (this.state.trafficLog.length > 1000) {
|
|
158
|
+
this.state.trafficLog = this.state.trafficLog.slice(-1000);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
exports.MCPClient = MCPClient;
|
|
163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|
+
import { JsonRpcRequest, JsonRpcResponse, JsonRpcNotification } from '../types';
|
|
3
|
+
export declare abstract class Transport extends EventEmitter {
|
|
4
|
+
protected requestId: number;
|
|
5
|
+
protected pendingRequests: Map<string | number, {
|
|
6
|
+
resolve: (value: any) => void;
|
|
7
|
+
reject: (error: any) => void;
|
|
8
|
+
}>;
|
|
9
|
+
abstract connect(): Promise<void>;
|
|
10
|
+
abstract disconnect(): Promise<void>;
|
|
11
|
+
abstract send(data: JsonRpcRequest | JsonRpcNotification): Promise<void>;
|
|
12
|
+
protected generateRequestId(): number;
|
|
13
|
+
request(method: string, params?: any): Promise<any>;
|
|
14
|
+
notify(method: string, params?: any): Promise<void>;
|
|
15
|
+
protected handleResponse(response: JsonRpcResponse): void;
|
|
16
|
+
protected handleNotification(notification: JsonRpcNotification): void;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/transport/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEhF,8BAAsB,SAAU,SAAQ,YAAY;IAClD,SAAS,CAAC,SAAS,SAAK;IACxB,SAAS,CAAC,eAAe;iBACd,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI;gBACrB,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI;OACzB;IAEL,QAAQ,CAAC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IACjC,QAAQ,CAAC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IACpC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,cAAc,GAAG,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAExE,SAAS,CAAC,iBAAiB,IAAI,MAAM;IAI/B,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IA2BnD,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAUzD,SAAS,CAAC,cAAc,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI;IAczD,SAAS,CAAC,kBAAkB,CAAC,YAAY,EAAE,mBAAmB,GAAG,IAAI;CAGtE"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Transport = void 0;
|
|
4
|
+
const events_1 = require("events");
|
|
5
|
+
class Transport extends events_1.EventEmitter {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.requestId = 0;
|
|
9
|
+
this.pendingRequests = new Map();
|
|
10
|
+
}
|
|
11
|
+
generateRequestId() {
|
|
12
|
+
return ++this.requestId;
|
|
13
|
+
}
|
|
14
|
+
async request(method, params) {
|
|
15
|
+
const id = this.generateRequestId();
|
|
16
|
+
const request = {
|
|
17
|
+
jsonrpc: '2.0',
|
|
18
|
+
method,
|
|
19
|
+
params,
|
|
20
|
+
id,
|
|
21
|
+
};
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
this.pendingRequests.set(id, { resolve, reject });
|
|
24
|
+
this.send(request).catch((error) => {
|
|
25
|
+
this.pendingRequests.delete(id);
|
|
26
|
+
reject(error);
|
|
27
|
+
});
|
|
28
|
+
// Timeout after 30 seconds
|
|
29
|
+
setTimeout(() => {
|
|
30
|
+
if (this.pendingRequests.has(id)) {
|
|
31
|
+
this.pendingRequests.delete(id);
|
|
32
|
+
reject(new Error(`Request timeout for method: ${method}`));
|
|
33
|
+
}
|
|
34
|
+
}, 30000);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
async notify(method, params) {
|
|
38
|
+
const notification = {
|
|
39
|
+
jsonrpc: '2.0',
|
|
40
|
+
method,
|
|
41
|
+
params,
|
|
42
|
+
};
|
|
43
|
+
await this.send(notification);
|
|
44
|
+
}
|
|
45
|
+
handleResponse(response) {
|
|
46
|
+
if (response.id !== null && response.id !== undefined) {
|
|
47
|
+
const pending = this.pendingRequests.get(response.id);
|
|
48
|
+
if (pending) {
|
|
49
|
+
this.pendingRequests.delete(response.id);
|
|
50
|
+
if (response.error) {
|
|
51
|
+
pending.reject(response.error);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
pending.resolve(response.result);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
handleNotification(notification) {
|
|
60
|
+
this.emit('notification', notification);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.Transport = Transport;
|
|
64
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/transport/base.ts"],"names":[],"mappings":";;;AAAA,mCAAsC;AAGtC,MAAsB,SAAU,SAAQ,qBAAY;IAApD;;QACY,cAAS,GAAG,CAAC,CAAC;QACd,oBAAe,GAAG,IAAI,GAAG,EAG/B,CAAC;IAgEP,CAAC;IA1DW,iBAAiB;QACzB,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,MAAc,EAAE,MAAY;QACxC,MAAM,EAAE,GAAG,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACpC,MAAM,OAAO,GAAmB;YAC9B,OAAO,EAAE,KAAK;YACd,MAAM;YACN,MAAM;YACN,EAAE;SACH,CAAC;QAEF,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CA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C,MAAM,CAAC,CAAC;gBACnC,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAES,kBAAkB,CAAC,YAAiC;QAC5D,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC;IAC1C,CAAC;CACF;AArED,8BAqEC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Transport } from './base';
|
|
2
|
+
import { JsonRpcRequest, JsonRpcNotification, ProxyConfig } from '../types';
|
|
3
|
+
export declare class HttpTransport extends Transport {
|
|
4
|
+
private url;
|
|
5
|
+
private proxyConfig?;
|
|
6
|
+
private agent?;
|
|
7
|
+
private isHttps;
|
|
8
|
+
constructor(url: string, proxyConfig?: ProxyConfig | undefined);
|
|
9
|
+
private setupAgent;
|
|
10
|
+
connect(): Promise<void>;
|
|
11
|
+
disconnect(): Promise<void>;
|
|
12
|
+
send(data: JsonRpcRequest | JsonRpcNotification): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/transport/http.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,cAAc,EAAmB,mBAAmB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE7F,qBAAa,aAAc,SAAQ,SAAS;IAKxC,OAAO,CAAC,GAAG;IACX,OAAO,CAAC,WAAW,CAAC;IALtB,OAAO,CAAC,KAAK,CAAC,CAA2B;IACzC,OAAO,CAAC,OAAO,CAAU;gBAGf,GAAG,EAAE,MAAM,EACX,WAAW,CAAC,EAAE,WAAW,YAAA;IAOnC,OAAO,CAAC,UAAU;IAwBZ,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAKxB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAM3B,IAAI,CAAC,IAAI,EAAE,cAAc,GAAG,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;CA6DtE"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.HttpTransport = void 0;
|
|
37
|
+
const http = __importStar(require("http"));
|
|
38
|
+
const https = __importStar(require("https"));
|
|
39
|
+
const http_proxy_agent_1 = require("http-proxy-agent");
|
|
40
|
+
const https_proxy_agent_1 = require("https-proxy-agent");
|
|
41
|
+
const socks_proxy_agent_1 = require("socks-proxy-agent");
|
|
42
|
+
const base_1 = require("./base");
|
|
43
|
+
class HttpTransport extends base_1.Transport {
|
|
44
|
+
constructor(url, proxyConfig) {
|
|
45
|
+
super();
|
|
46
|
+
this.url = url;
|
|
47
|
+
this.proxyConfig = proxyConfig;
|
|
48
|
+
this.isHttps = url.startsWith('https://');
|
|
49
|
+
this.setupAgent();
|
|
50
|
+
}
|
|
51
|
+
setupAgent() {
|
|
52
|
+
if (!this.proxyConfig) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const proxyAuth = this.proxyConfig.auth
|
|
56
|
+
? `${this.proxyConfig.auth.username}:${this.proxyConfig.auth.password}@`
|
|
57
|
+
: '';
|
|
58
|
+
const proxyProtocol = this.proxyConfig.protocol || 'http';
|
|
59
|
+
if (proxyProtocol === 'socks' || proxyProtocol === 'socks5') {
|
|
60
|
+
const proxyUrl = `socks5://${proxyAuth}${this.proxyConfig.host}:${this.proxyConfig.port}`;
|
|
61
|
+
this.agent = new socks_proxy_agent_1.SocksProxyAgent(proxyUrl);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
const proxyUrl = `${proxyProtocol}://${proxyAuth}${this.proxyConfig.host}:${this.proxyConfig.port}`;
|
|
65
|
+
if (this.isHttps) {
|
|
66
|
+
this.agent = new https_proxy_agent_1.HttpsProxyAgent(proxyUrl);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
this.agent = new http_proxy_agent_1.HttpProxyAgent(proxyUrl);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async connect() {
|
|
74
|
+
// HTTP transport doesn't need explicit connection
|
|
75
|
+
this.emit('connected');
|
|
76
|
+
}
|
|
77
|
+
async disconnect() {
|
|
78
|
+
if (this.agent) {
|
|
79
|
+
this.agent.destroy();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
async send(data) {
|
|
83
|
+
const payload = JSON.stringify(data);
|
|
84
|
+
this.emit('send', data);
|
|
85
|
+
return new Promise((resolve, reject) => {
|
|
86
|
+
const urlObj = new URL(this.url);
|
|
87
|
+
const httpModule = this.isHttps ? https : http;
|
|
88
|
+
const options = {
|
|
89
|
+
hostname: urlObj.hostname,
|
|
90
|
+
port: urlObj.port || (this.isHttps ? 443 : 80),
|
|
91
|
+
path: urlObj.pathname + urlObj.search,
|
|
92
|
+
method: 'POST',
|
|
93
|
+
headers: {
|
|
94
|
+
'Content-Type': 'application/json',
|
|
95
|
+
'Content-Length': Buffer.byteLength(payload),
|
|
96
|
+
},
|
|
97
|
+
agent: this.agent,
|
|
98
|
+
};
|
|
99
|
+
const req = httpModule.request(options, (res) => {
|
|
100
|
+
let responseData = '';
|
|
101
|
+
res.on('data', (chunk) => {
|
|
102
|
+
responseData += chunk;
|
|
103
|
+
});
|
|
104
|
+
res.on('end', () => {
|
|
105
|
+
try {
|
|
106
|
+
// If there's no response data, just resolve (for notifications)
|
|
107
|
+
if (!responseData.trim()) {
|
|
108
|
+
resolve();
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const response = JSON.parse(responseData);
|
|
112
|
+
this.emit('receive', response);
|
|
113
|
+
if ('result' in response || 'error' in response) {
|
|
114
|
+
this.handleResponse(response);
|
|
115
|
+
}
|
|
116
|
+
else if ('method' in response && !('id' in response)) {
|
|
117
|
+
this.handleNotification(response);
|
|
118
|
+
}
|
|
119
|
+
resolve();
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
123
|
+
reject(new Error(`Failed to process HTTP response: ${errorMessage}`));
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
req.on('error', (error) => {
|
|
128
|
+
this.emit('error', error);
|
|
129
|
+
reject(error);
|
|
130
|
+
});
|
|
131
|
+
req.write(payload);
|
|
132
|
+
req.end();
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.HttpTransport = HttpTransport;
|
|
137
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/transport/http.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAC7B,6CAA+B;AAC/B,uDAAkD;AAClD,yDAAoD;AACpD,yDAAoD;AACpD,iCAAmC;AAGnC,MAAa,aAAc,SAAQ,gBAAS;IAI1C,YACU,GAAW,EACX,WAAyB;QAEjC,KAAK,EAAE,CAAC;QAHA,QAAG,GAAH,GAAG,CAAQ;QACX,gBAAW,GAAX,WAAW,CAAc;QAGjC,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;QAC1C,IAAI,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC;IAEO,UAAU;QAChB,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACtB,OAAO;QACT,CAAC;QAED,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI;YACrC,CAAC,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,GAAG;YACxE,CAAC,CAAC,EAAE,CAAC;QAEP,MAAM,aAAa,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,IAAI,MAAM,CAAC;QAE1D,IAAI,aAAa,KAAK,OAAO,IAAI,aAAa,KAAK,QAAQ,EAAE,CAAC;YAC5D,MAAM,QAAQ,GAAG,YAAY,SAAS,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,IAAI,IAAI,C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AAC;oBAAC,OAAO,KAAK,EAAE,CAAC;wBACf,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;wBAC5E,MAAM,CAAC,IAAI,KAAK,CAAC,oCAAoC,YAAY,EAAE,CAAC,CAAC,CAAC;oBACxE,CAAC;gBACH,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;YAEH,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;gBACxB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;gBAC1B,MAAM,CAAC,KAAK,CAAC,CAAC;YAChB,CAAC,CAAC,CAAC;YAEH,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YACnB,GAAG,CAAC,GAAG,EAAE,CAAC;QACZ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA7GD,sCA6GC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Transport } from './base';
|
|
2
|
+
import { JsonRpcRequest, JsonRpcNotification } from '../types';
|
|
3
|
+
export declare class StdioTransport extends Transport {
|
|
4
|
+
private command;
|
|
5
|
+
private args;
|
|
6
|
+
private env;
|
|
7
|
+
private process?;
|
|
8
|
+
private buffer;
|
|
9
|
+
constructor(command: string, args?: string[], env?: Record<string, string>);
|
|
10
|
+
connect(): Promise<void>;
|
|
11
|
+
disconnect(): Promise<void>;
|
|
12
|
+
send(data: JsonRpcRequest | JsonRpcNotification): Promise<void>;
|
|
13
|
+
private handleData;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=stdio.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stdio.d.ts","sourceRoot":"","sources":["../../src/transport/stdio.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,cAAc,EAAmB,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEhF,qBAAa,cAAe,SAAQ,SAAS;IAKzC,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,GAAG;IANb,OAAO,CAAC,OAAO,CAAC,CAAe;IAC/B,OAAO,CAAC,MAAM,CAAM;gBAGV,OAAO,EAAE,MAAM,EACf,IAAI,GAAE,MAAM,EAAO,EACnB,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM;IAKpC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA8BxB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAO3B,IAAI,CAAC,IAAI,EAAE,cAAc,GAAG,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBrE,OAAO,CAAC,UAAU;CAyBnB"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StdioTransport = void 0;
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
const base_1 = require("./base");
|
|
6
|
+
class StdioTransport extends base_1.Transport {
|
|
7
|
+
constructor(command, args = [], env = {}) {
|
|
8
|
+
super();
|
|
9
|
+
this.command = command;
|
|
10
|
+
this.args = args;
|
|
11
|
+
this.env = env;
|
|
12
|
+
this.buffer = '';
|
|
13
|
+
}
|
|
14
|
+
async connect() {
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
this.process = (0, child_process_1.spawn)(this.command, this.args, {
|
|
17
|
+
env: { ...process.env, ...this.env },
|
|
18
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
19
|
+
shell: process.platform === 'win32',
|
|
20
|
+
});
|
|
21
|
+
this.process.stdout?.on('data', (data) => {
|
|
22
|
+
this.handleData(data.toString());
|
|
23
|
+
});
|
|
24
|
+
this.process.stderr?.on('data', (data) => {
|
|
25
|
+
this.emit('stderr', data.toString());
|
|
26
|
+
});
|
|
27
|
+
this.process.on('error', (error) => {
|
|
28
|
+
this.emit('error', error);
|
|
29
|
+
reject(error);
|
|
30
|
+
});
|
|
31
|
+
this.process.on('exit', (code) => {
|
|
32
|
+
this.emit('exit', code);
|
|
33
|
+
});
|
|
34
|
+
// Give the process a moment to start
|
|
35
|
+
setTimeout(() => resolve(), 100);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
async disconnect() {
|
|
39
|
+
if (this.process) {
|
|
40
|
+
this.process.kill();
|
|
41
|
+
this.process = undefined;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async send(data) {
|
|
45
|
+
if (!this.process || !this.process.stdin || this.process.stdin.destroyed) {
|
|
46
|
+
throw new Error('Transport not connected');
|
|
47
|
+
}
|
|
48
|
+
const message = JSON.stringify(data) + '\n';
|
|
49
|
+
this.emit('send', data);
|
|
50
|
+
return new Promise((resolve, reject) => {
|
|
51
|
+
this.process.stdin.write(message, (error) => {
|
|
52
|
+
if (error) {
|
|
53
|
+
reject(error);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
resolve();
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
handleData(data) {
|
|
62
|
+
this.buffer += data;
|
|
63
|
+
const lines = this.buffer.split('\n');
|
|
64
|
+
this.buffer = lines.pop() || '';
|
|
65
|
+
for (const line of lines) {
|
|
66
|
+
if (line.trim()) {
|
|
67
|
+
try {
|
|
68
|
+
const message = JSON.parse(line);
|
|
69
|
+
this.emit('receive', message);
|
|
70
|
+
if ('result' in message || 'error' in message) {
|
|
71
|
+
this.handleResponse(message);
|
|
72
|
+
}
|
|
73
|
+
else if ('method' in message && !('id' in message)) {
|
|
74
|
+
this.handleNotification(message);
|
|
75
|
+
}
|
|
76
|
+
else if ('method' in message && 'id' in message) {
|
|
77
|
+
// This is a request from the server
|
|
78
|
+
this.emit('request', message);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
this.emit('error', new Error(`Failed to parse JSON: ${line}`));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.StdioTransport = StdioTransport;
|
|
89
|
+
//# sourceMappingURL=stdio.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stdio.js","sourceRoot":"","sources":["../../src/transport/stdio.ts"],"names":[],"mappings":";;;AAAA,iDAAoD;AACpD,iCAAmC;AAGnC,MAAa,cAAe,SAAQ,gBAAS;IAI3C,YACU,OAAe,EACf,OAAiB,EAAE,EACnB,MAA8B,EAAE;QAExC,KAAK,EAAE,CAAC;QAJA,YAAO,GAAP,OAAO,CAAQ;QACf,SAAI,GAAJ,IAAI,CAAe;QACnB,QAAG,GAAH,GAAG,CAA6B;QALlC,WAAM,GAAG,EAAE,CAAC;IAQpB,CAAC;IAED,KAAK,CAAC,OAAO;QACX,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,IAAI,CAAC,OAAO,GAAG,IAAA,qBAAK,EAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,EAAE;gBAC5C,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE;gBACpC,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;gBAC/B,KAAK,EAAE,OAAO,CAAC,QAAQ,KAAK,OAAO;aACpC,CAAC,CAAC;YAEH,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,IAAY,EAAE,EAAE;gBAC/C,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;YACnC,CAAC,CAAC,CAAC;YAEH,IAAI,CAAC,OAAO,CAAC,MA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;gBACH,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,KAAK,CAAC,yBAAyB,IAAI,EAAE,CAAC,CAAC,CAAC;gBACjE,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;CACF;AA7FD,wCA6FC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Transport } from './base';
|
|
2
|
+
import { JsonRpcRequest, JsonRpcNotification, ProxyConfig } from '../types';
|
|
3
|
+
export declare class WebSocketTransport extends Transport {
|
|
4
|
+
private url;
|
|
5
|
+
private proxyConfig?;
|
|
6
|
+
private ws?;
|
|
7
|
+
private agent?;
|
|
8
|
+
constructor(url: string, proxyConfig?: ProxyConfig | undefined);
|
|
9
|
+
private setupAgent;
|
|
10
|
+
connect(): Promise<void>;
|
|
11
|
+
disconnect(): Promise<void>;
|
|
12
|
+
send(data: JsonRpcRequest | JsonRpcNotification): Promise<void>;
|
|
13
|
+
private handleMessage;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=websocket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websocket.d.ts","sourceRoot":"","sources":["../../src/transport/websocket.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,cAAc,EAAmB,mBAAmB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE7F,qBAAa,kBAAmB,SAAQ,SAAS;IAK7C,OAAO,CAAC,GAAG;IACX,OAAO,CAAC,WAAW,CAAC;IALtB,OAAO,CAAC,EAAE,CAAC,CAAY;IACvB,OAAO,CAAC,KAAK,CAAC,CAAM;gBAGV,GAAG,EAAE,MAAM,EACX,WAAW,CAAC,EAAE,WAAW,YAAA;IAMnC,OAAO,CAAC,UAAU;IAyBZ,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA8BxB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAO3B,IAAI,CAAC,IAAI,EAAE,cAAc,GAAG,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBrE,OAAO,CAAC,aAAa;CAiBtB"}
|