@monoes/mcp 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/README.md +127 -0
- package/dist/connection-pool.d.ts +36 -0
- package/dist/connection-pool.d.ts.map +1 -0
- package/dist/connection-pool.js +273 -0
- package/dist/connection-pool.js.map +1 -0
- package/dist/index.d.ts +75 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +85 -0
- package/dist/index.js.map +1 -0
- package/dist/oauth.d.ts +146 -0
- package/dist/oauth.d.ts.map +1 -0
- package/dist/oauth.js +318 -0
- package/dist/oauth.js.map +1 -0
- package/dist/prompt-registry.d.ts +90 -0
- package/dist/prompt-registry.d.ts.map +1 -0
- package/dist/prompt-registry.js +209 -0
- package/dist/prompt-registry.js.map +1 -0
- package/dist/rate-limiter.d.ts +86 -0
- package/dist/rate-limiter.d.ts.map +1 -0
- package/dist/rate-limiter.js +197 -0
- package/dist/rate-limiter.js.map +1 -0
- package/dist/resource-registry.d.ts +144 -0
- package/dist/resource-registry.d.ts.map +1 -0
- package/dist/resource-registry.js +405 -0
- package/dist/resource-registry.js.map +1 -0
- package/dist/sampling.d.ts +102 -0
- package/dist/sampling.d.ts.map +1 -0
- package/dist/sampling.js +268 -0
- package/dist/sampling.js.map +1 -0
- package/dist/schema-validator.d.ts +30 -0
- package/dist/schema-validator.d.ts.map +1 -0
- package/dist/schema-validator.js +182 -0
- package/dist/schema-validator.js.map +1 -0
- package/dist/server.d.ts +122 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +829 -0
- package/dist/server.js.map +1 -0
- package/dist/session-manager.d.ts +55 -0
- package/dist/session-manager.d.ts.map +1 -0
- package/dist/session-manager.js +252 -0
- package/dist/session-manager.js.map +1 -0
- package/dist/task-manager.d.ts +81 -0
- package/dist/task-manager.d.ts.map +1 -0
- package/dist/task-manager.js +337 -0
- package/dist/task-manager.js.map +1 -0
- package/dist/tool-registry.d.ts +88 -0
- package/dist/tool-registry.d.ts.map +1 -0
- package/dist/tool-registry.js +353 -0
- package/dist/tool-registry.js.map +1 -0
- package/dist/transport/http.d.ts +71 -0
- package/dist/transport/http.d.ts.map +1 -0
- package/dist/transport/http.js +567 -0
- package/dist/transport/http.js.map +1 -0
- package/dist/transport/index.d.ts +50 -0
- package/dist/transport/index.d.ts.map +1 -0
- package/dist/transport/index.js +181 -0
- package/dist/transport/index.js.map +1 -0
- package/dist/transport/stdio.d.ts +43 -0
- package/dist/transport/stdio.d.ts.map +1 -0
- package/dist/transport/stdio.js +194 -0
- package/dist/transport/stdio.js.map +1 -0
- package/dist/transport/websocket.d.ts +87 -0
- package/dist/transport/websocket.d.ts.map +1 -0
- package/dist/transport/websocket.js +408 -0
- package/dist/transport/websocket.js.map +1 -0
- package/dist/types.d.ts +473 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +40 -0
- package/dist/types.js.map +1 -0
- package/package.json +45 -0
|
@@ -0,0 +1,567 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @monoes/mcp - HTTP Transport
|
|
3
|
+
*
|
|
4
|
+
* HTTP/REST transport with WebSocket support
|
|
5
|
+
*/
|
|
6
|
+
import { EventEmitter } from 'events';
|
|
7
|
+
import express from 'express';
|
|
8
|
+
import { createServer } from 'http';
|
|
9
|
+
import { WebSocketServer, WebSocket } from 'ws';
|
|
10
|
+
import cors from 'cors';
|
|
11
|
+
import helmet from 'helmet';
|
|
12
|
+
export class HttpTransport extends EventEmitter {
|
|
13
|
+
logger;
|
|
14
|
+
config;
|
|
15
|
+
type = 'http';
|
|
16
|
+
requestHandler;
|
|
17
|
+
notificationHandler;
|
|
18
|
+
app;
|
|
19
|
+
server;
|
|
20
|
+
wss;
|
|
21
|
+
running = false;
|
|
22
|
+
activeConnections = new Set();
|
|
23
|
+
messagesReceived = 0;
|
|
24
|
+
messagesSent = 0;
|
|
25
|
+
errors = 0;
|
|
26
|
+
httpRequests = 0;
|
|
27
|
+
wsMessages = 0;
|
|
28
|
+
constructor(logger, config) {
|
|
29
|
+
super();
|
|
30
|
+
this.logger = logger;
|
|
31
|
+
this.config = config;
|
|
32
|
+
this.app = express();
|
|
33
|
+
this.setupMiddleware();
|
|
34
|
+
this.setupRoutes();
|
|
35
|
+
}
|
|
36
|
+
async start() {
|
|
37
|
+
if (this.running) {
|
|
38
|
+
throw new Error('HTTP transport already running');
|
|
39
|
+
}
|
|
40
|
+
const bindHost = this.resolveBindHost();
|
|
41
|
+
this.logger.info('Starting HTTP transport', {
|
|
42
|
+
host: bindHost,
|
|
43
|
+
port: this.config.port,
|
|
44
|
+
});
|
|
45
|
+
this.server = createServer(this.app);
|
|
46
|
+
this.wss = new WebSocketServer({
|
|
47
|
+
server: this.server,
|
|
48
|
+
path: '/ws',
|
|
49
|
+
// SECURITY: mirror websocket.ts's standalone server — without an
|
|
50
|
+
// explicit maxPayload, `ws` defaults to 100MiB, which is 10x larger
|
|
51
|
+
// than the HTTP side's maxRequestSize and lets a WS client force
|
|
52
|
+
// memory allocations the HTTP body-size limit was meant to prevent.
|
|
53
|
+
maxPayload: this.parseMaxRequestSizeBytes(),
|
|
54
|
+
});
|
|
55
|
+
this.setupWebSocketHandlers();
|
|
56
|
+
await new Promise((resolve, reject) => {
|
|
57
|
+
this.server.listen(this.config.port, bindHost, () => {
|
|
58
|
+
resolve();
|
|
59
|
+
});
|
|
60
|
+
this.server.on('error', reject);
|
|
61
|
+
});
|
|
62
|
+
this.running = true;
|
|
63
|
+
this.logger.info('HTTP transport started', {
|
|
64
|
+
url: `http://${bindHost}:${this.config.port}`,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* SECURITY: Refuse to bind unauthenticated servers to a non-loopback
|
|
69
|
+
* interface. Without `auth` configured, `handleHttpRequest` processes
|
|
70
|
+
* every request without validating credentials — that is only acceptable
|
|
71
|
+
* on loopback. If the operator asked for a non-loopback host with no auth,
|
|
72
|
+
* fall back to 127.0.0.1 unless they explicitly opt in via
|
|
73
|
+
* MONOMIND_MCP_ALLOW_REMOTE=1 (matching the CLI's own remote-bind gate).
|
|
74
|
+
*/
|
|
75
|
+
resolveBindHost() {
|
|
76
|
+
const configuredHost = this.config.host;
|
|
77
|
+
if (this.config.auth) {
|
|
78
|
+
// Auth is explicitly configured — respect the requested host. Binding
|
|
79
|
+
// safety in this case is the operator's informed decision.
|
|
80
|
+
return configuredHost;
|
|
81
|
+
}
|
|
82
|
+
const isLoopback = configuredHost === 'localhost' ||
|
|
83
|
+
configuredHost === '127.0.0.1' ||
|
|
84
|
+
configuredHost === '::1' ||
|
|
85
|
+
configuredHost === '::ffff:127.0.0.1';
|
|
86
|
+
if (isLoopback) {
|
|
87
|
+
return configuredHost;
|
|
88
|
+
}
|
|
89
|
+
if (process.env.MONOMIND_MCP_ALLOW_REMOTE === '1') {
|
|
90
|
+
this.logger.warn(`SECURITY WARNING: HTTP transport is binding to non-loopback host "${configuredHost}" ` +
|
|
91
|
+
'with NO authentication configured. MONOMIND_MCP_ALLOW_REMOTE=1 opt-in detected — ' +
|
|
92
|
+
'every request will be processed unauthenticated. This exposes every registered tool ' +
|
|
93
|
+
'to anyone who can reach this host/port.');
|
|
94
|
+
return configuredHost;
|
|
95
|
+
}
|
|
96
|
+
this.logger.warn(`SECURITY: refusing to bind HTTP transport to non-loopback host "${configuredHost}" with ` +
|
|
97
|
+
'no "auth" configured. Falling back to 127.0.0.1. Set MONOMIND_MCP_ALLOW_REMOTE=1 to ' +
|
|
98
|
+
'override (unsafe) or configure "auth" with tokens.');
|
|
99
|
+
return '127.0.0.1';
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* SECURITY: Parses the same `maxRequestSize` string used for the HTTP
|
|
103
|
+
* body-size limit (e.g. "10mb") into a byte count for the embedded
|
|
104
|
+
* WebSocketServer's `maxPayload` option, so both sides of this transport
|
|
105
|
+
* enforce the same ceiling.
|
|
106
|
+
*/
|
|
107
|
+
parseMaxRequestSizeBytes() {
|
|
108
|
+
const raw = this.config.maxRequestSize || '10mb';
|
|
109
|
+
if (typeof raw === 'number') {
|
|
110
|
+
return raw;
|
|
111
|
+
}
|
|
112
|
+
const match = /^(\d+(?:\.\d+)?)\s*(b|kb|mb|gb)?$/i.exec(raw.trim());
|
|
113
|
+
if (!match) {
|
|
114
|
+
return 10 * 1024 * 1024;
|
|
115
|
+
}
|
|
116
|
+
const value = parseFloat(match[1]);
|
|
117
|
+
const unit = (match[2] || 'b').toLowerCase();
|
|
118
|
+
const multipliers = {
|
|
119
|
+
b: 1,
|
|
120
|
+
kb: 1024,
|
|
121
|
+
mb: 1024 * 1024,
|
|
122
|
+
gb: 1024 * 1024 * 1024,
|
|
123
|
+
};
|
|
124
|
+
return Math.round(value * (multipliers[unit] ?? 1));
|
|
125
|
+
}
|
|
126
|
+
async stop() {
|
|
127
|
+
if (!this.running) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
this.logger.info('Stopping HTTP transport');
|
|
131
|
+
this.running = false;
|
|
132
|
+
for (const ws of this.activeConnections) {
|
|
133
|
+
try {
|
|
134
|
+
ws.close(1000, 'Server shutting down');
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
// Ignore errors
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
this.activeConnections.clear();
|
|
141
|
+
if (this.wss) {
|
|
142
|
+
this.wss.close();
|
|
143
|
+
this.wss = undefined;
|
|
144
|
+
}
|
|
145
|
+
if (this.server) {
|
|
146
|
+
await new Promise((resolve) => {
|
|
147
|
+
this.server.close(() => resolve());
|
|
148
|
+
});
|
|
149
|
+
this.server = undefined;
|
|
150
|
+
}
|
|
151
|
+
this.logger.info('HTTP transport stopped');
|
|
152
|
+
}
|
|
153
|
+
onRequest(handler) {
|
|
154
|
+
this.requestHandler = handler;
|
|
155
|
+
}
|
|
156
|
+
onNotification(handler) {
|
|
157
|
+
this.notificationHandler = handler;
|
|
158
|
+
}
|
|
159
|
+
async getHealthStatus() {
|
|
160
|
+
return {
|
|
161
|
+
healthy: this.running,
|
|
162
|
+
metrics: {
|
|
163
|
+
messagesReceived: this.messagesReceived,
|
|
164
|
+
messagesSent: this.messagesSent,
|
|
165
|
+
errors: this.errors,
|
|
166
|
+
httpRequests: this.httpRequests,
|
|
167
|
+
wsMessages: this.wsMessages,
|
|
168
|
+
activeConnections: this.activeConnections.size,
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
async sendNotification(notification) {
|
|
173
|
+
const message = JSON.stringify(notification);
|
|
174
|
+
for (const ws of this.activeConnections) {
|
|
175
|
+
try {
|
|
176
|
+
if (ws.readyState === WebSocket.OPEN) {
|
|
177
|
+
ws.send(message);
|
|
178
|
+
this.messagesSent++;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
this.logger.error('Failed to send notification', { error });
|
|
183
|
+
this.errors++;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
setupMiddleware() {
|
|
188
|
+
this.app.use(helmet({
|
|
189
|
+
contentSecurityPolicy: false,
|
|
190
|
+
}));
|
|
191
|
+
if (this.config.corsEnabled !== false) {
|
|
192
|
+
const allowedOrigins = this.config.corsOrigins;
|
|
193
|
+
if (!allowedOrigins || allowedOrigins.length === 0) {
|
|
194
|
+
this.logger.warn('CORS: No origins configured, restricting to same-origin only');
|
|
195
|
+
}
|
|
196
|
+
this.app.use(cors({
|
|
197
|
+
origin: (origin, callback) => {
|
|
198
|
+
if (!origin) {
|
|
199
|
+
callback(null, true);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
if (allowedOrigins && allowedOrigins.length > 0) {
|
|
203
|
+
if (allowedOrigins.includes(origin) || allowedOrigins.includes('*')) {
|
|
204
|
+
callback(null, true);
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
callback(new Error(`CORS: Origin '${origin}' not allowed`));
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
callback(new Error('CORS: Cross-origin requests not allowed'));
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
credentials: true,
|
|
215
|
+
maxAge: 86400,
|
|
216
|
+
methods: ['GET', 'POST', 'OPTIONS'],
|
|
217
|
+
allowedHeaders: ['Content-Type', 'Authorization', 'X-Request-ID'],
|
|
218
|
+
}));
|
|
219
|
+
}
|
|
220
|
+
this.app.use(express.json({
|
|
221
|
+
limit: this.config.maxRequestSize || '10mb',
|
|
222
|
+
}));
|
|
223
|
+
if (this.config.requestTimeout) {
|
|
224
|
+
this.app.use((req, res, next) => {
|
|
225
|
+
res.setTimeout(this.config.requestTimeout, () => {
|
|
226
|
+
res.status(408).json({
|
|
227
|
+
jsonrpc: '2.0',
|
|
228
|
+
id: null,
|
|
229
|
+
error: { code: -32000, message: 'Request timeout' },
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
next();
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
this.app.use((req, res, next) => {
|
|
236
|
+
const startTime = performance.now();
|
|
237
|
+
res.on('finish', () => {
|
|
238
|
+
const duration = performance.now() - startTime;
|
|
239
|
+
this.logger.debug('HTTP request', {
|
|
240
|
+
method: req.method,
|
|
241
|
+
path: req.path,
|
|
242
|
+
status: res.statusCode,
|
|
243
|
+
duration: `${duration.toFixed(2)}ms`,
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
next();
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
setupRoutes() {
|
|
250
|
+
this.app.get('/health', (req, res) => {
|
|
251
|
+
res.json({
|
|
252
|
+
status: 'ok',
|
|
253
|
+
timestamp: new Date().toISOString(),
|
|
254
|
+
connections: this.activeConnections.size,
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
this.app.post('/rpc', async (req, res) => {
|
|
258
|
+
await this.handleHttpRequest(req, res);
|
|
259
|
+
});
|
|
260
|
+
this.app.post('/mcp', async (req, res) => {
|
|
261
|
+
await this.handleHttpRequest(req, res);
|
|
262
|
+
});
|
|
263
|
+
this.app.get('/info', (req, res) => {
|
|
264
|
+
res.json({
|
|
265
|
+
name: 'Monomind MCP Server V1',
|
|
266
|
+
version: '3.0.0',
|
|
267
|
+
transport: 'http',
|
|
268
|
+
capabilities: {
|
|
269
|
+
jsonrpc: true,
|
|
270
|
+
websocket: true,
|
|
271
|
+
},
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
this.app.use((req, res) => {
|
|
275
|
+
res.status(404).json({
|
|
276
|
+
error: 'Not found',
|
|
277
|
+
path: req.path,
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
this.app.use((err, req, res, next) => {
|
|
281
|
+
this.logger.error('Express error', { error: err });
|
|
282
|
+
this.errors++;
|
|
283
|
+
res.status(500).json({
|
|
284
|
+
jsonrpc: '2.0',
|
|
285
|
+
id: null,
|
|
286
|
+
error: { code: -32603, message: 'Internal error' },
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
setupWebSocketHandlers() {
|
|
291
|
+
if (!this.wss)
|
|
292
|
+
return;
|
|
293
|
+
// SECURITY: Handle WebSocket authentication via upgrade request
|
|
294
|
+
this.wss.on('connection', (ws, req) => {
|
|
295
|
+
// Validate authentication if enabled
|
|
296
|
+
if (this.config.auth?.enabled) {
|
|
297
|
+
// SECURITY: prefer the Authorization header sent during the WS
|
|
298
|
+
// upgrade handshake over a query-string credential — URLs land in
|
|
299
|
+
// access logs and intermediate proxy logs. Only fall back to the
|
|
300
|
+
// query param for clients that cannot set upgrade headers.
|
|
301
|
+
const authHeader = req.headers.authorization;
|
|
302
|
+
const fromHeader = authHeader ? authHeader.replace(/^Bearer\s+/i, '') : undefined;
|
|
303
|
+
const url = new URL(req.url || '', `http://${req.headers.host}`);
|
|
304
|
+
const fromQuery = url.searchParams.get('token');
|
|
305
|
+
const credential = fromHeader || fromQuery || undefined;
|
|
306
|
+
if (!credential) {
|
|
307
|
+
this.logger.warn('WebSocket connection rejected: no authentication token');
|
|
308
|
+
ws.close(4001, 'Authentication required');
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
// SECURITY: Timing-safe token validation
|
|
312
|
+
let valid = false;
|
|
313
|
+
if (this.config.auth.tokens?.length) {
|
|
314
|
+
for (const validToken of this.config.auth.tokens) {
|
|
315
|
+
if (this.timingSafeCompare(credential, validToken)) {
|
|
316
|
+
valid = true;
|
|
317
|
+
break;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
if (!valid) {
|
|
322
|
+
this.logger.warn('WebSocket connection rejected: invalid token');
|
|
323
|
+
ws.close(4003, 'Invalid token');
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
this.activeConnections.add(ws);
|
|
328
|
+
this.logger.info('WebSocket client connected', {
|
|
329
|
+
total: this.activeConnections.size,
|
|
330
|
+
authenticated: !!this.config.auth?.enabled,
|
|
331
|
+
});
|
|
332
|
+
ws.on('message', async (data) => {
|
|
333
|
+
await this.handleWebSocketMessage(ws, data.toString());
|
|
334
|
+
});
|
|
335
|
+
ws.on('close', () => {
|
|
336
|
+
this.activeConnections.delete(ws);
|
|
337
|
+
this.logger.info('WebSocket client disconnected', {
|
|
338
|
+
total: this.activeConnections.size,
|
|
339
|
+
});
|
|
340
|
+
});
|
|
341
|
+
ws.on('error', (error) => {
|
|
342
|
+
this.logger.error('WebSocket error', { error });
|
|
343
|
+
this.errors++;
|
|
344
|
+
this.activeConnections.delete(ws);
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
async handleHttpRequest(req, res) {
|
|
349
|
+
this.httpRequests++;
|
|
350
|
+
this.messagesReceived++;
|
|
351
|
+
const requiresAuth = this.config.auth?.enabled !== false;
|
|
352
|
+
if (requiresAuth && this.config.auth) {
|
|
353
|
+
const authResult = this.validateAuth(req);
|
|
354
|
+
if (!authResult.valid) {
|
|
355
|
+
this.logger.warn('Authentication failed', {
|
|
356
|
+
ip: req.ip,
|
|
357
|
+
path: req.path,
|
|
358
|
+
error: authResult.error,
|
|
359
|
+
});
|
|
360
|
+
res.status(401).json({
|
|
361
|
+
jsonrpc: '2.0',
|
|
362
|
+
id: null,
|
|
363
|
+
error: { code: -32001, message: 'Unauthorized' },
|
|
364
|
+
});
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
else if (requiresAuth && !this.config.auth) {
|
|
369
|
+
// SECURITY: loud warning on every request, not an info-level note —
|
|
370
|
+
// credentials are not being validated on this transport at all.
|
|
371
|
+
// resolveBindHost() keeps this safe by default (loopback bind only).
|
|
372
|
+
this.logger.warn('SECURITY WARNING: MCP HTTP transport has no auth policy configured; ' +
|
|
373
|
+
'this request is being processed without checking any credentials. ' +
|
|
374
|
+
'Set an auth policy with tokens to require authentication.');
|
|
375
|
+
}
|
|
376
|
+
try {
|
|
377
|
+
const message = req.body;
|
|
378
|
+
// SECURITY: express.json() only populates req.body when the request's
|
|
379
|
+
// Content-Type matches its configured type (application/json). Any
|
|
380
|
+
// other content type (or a missing body) leaves req.body undefined,
|
|
381
|
+
// which previously crashed this handler on `message.jsonrpc` — an
|
|
382
|
+
// uncaught TypeError inside an async Express route that Express 4
|
|
383
|
+
// does not catch, producing an unhandled rejection that can bring
|
|
384
|
+
// down the whole process. Guard explicitly before touching it.
|
|
385
|
+
if (!message || typeof message !== 'object') {
|
|
386
|
+
res.status(400).json({
|
|
387
|
+
jsonrpc: '2.0',
|
|
388
|
+
id: null,
|
|
389
|
+
error: {
|
|
390
|
+
code: -32600,
|
|
391
|
+
message: 'Invalid request: expected a JSON object body with Content-Type: application/json',
|
|
392
|
+
},
|
|
393
|
+
});
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
if (message.jsonrpc !== '2.0') {
|
|
397
|
+
res.status(400).json({
|
|
398
|
+
jsonrpc: '2.0',
|
|
399
|
+
id: message.id || null,
|
|
400
|
+
error: { code: -32600, message: 'Invalid JSON-RPC version' },
|
|
401
|
+
});
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
if (!message.method) {
|
|
405
|
+
res.status(400).json({
|
|
406
|
+
jsonrpc: '2.0',
|
|
407
|
+
id: message.id || null,
|
|
408
|
+
error: { code: -32600, message: 'Missing method' },
|
|
409
|
+
});
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
if (message.id === undefined) {
|
|
413
|
+
if (this.notificationHandler) {
|
|
414
|
+
await this.notificationHandler(message);
|
|
415
|
+
}
|
|
416
|
+
res.status(204).end();
|
|
417
|
+
}
|
|
418
|
+
else {
|
|
419
|
+
if (!this.requestHandler) {
|
|
420
|
+
res.status(500).json({
|
|
421
|
+
jsonrpc: '2.0',
|
|
422
|
+
id: message.id,
|
|
423
|
+
error: { code: -32603, message: 'No request handler' },
|
|
424
|
+
});
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
try {
|
|
428
|
+
const response = await this.requestHandler(message);
|
|
429
|
+
res.json(response);
|
|
430
|
+
this.messagesSent++;
|
|
431
|
+
}
|
|
432
|
+
catch (error) {
|
|
433
|
+
this.errors++;
|
|
434
|
+
res.status(500).json({
|
|
435
|
+
jsonrpc: '2.0',
|
|
436
|
+
id: message.id,
|
|
437
|
+
error: {
|
|
438
|
+
code: -32603,
|
|
439
|
+
message: error instanceof Error ? error.message : 'Internal error',
|
|
440
|
+
},
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
catch (error) {
|
|
446
|
+
// SECURITY: catch-all so ANY unexpected exception in this handler
|
|
447
|
+
// (malformed body, unexpected shape, etc.) produces a JSON-RPC error
|
|
448
|
+
// response instead of an unhandled promise rejection that can crash
|
|
449
|
+
// the process under Node's default --unhandled-rejections=throw.
|
|
450
|
+
this.errors++;
|
|
451
|
+
this.logger.error('Unexpected error handling HTTP request', { error });
|
|
452
|
+
if (!res.headersSent) {
|
|
453
|
+
res.status(500).json({
|
|
454
|
+
jsonrpc: '2.0',
|
|
455
|
+
id: null,
|
|
456
|
+
error: {
|
|
457
|
+
code: -32603,
|
|
458
|
+
message: error instanceof Error ? error.message : 'Internal error',
|
|
459
|
+
},
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
async handleWebSocketMessage(ws, data) {
|
|
465
|
+
this.wsMessages++;
|
|
466
|
+
this.messagesReceived++;
|
|
467
|
+
try {
|
|
468
|
+
const message = JSON.parse(data);
|
|
469
|
+
if (message.jsonrpc !== '2.0') {
|
|
470
|
+
ws.send(JSON.stringify({
|
|
471
|
+
jsonrpc: '2.0',
|
|
472
|
+
id: message.id || null,
|
|
473
|
+
error: { code: -32600, message: 'Invalid JSON-RPC version' },
|
|
474
|
+
}));
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
if (message.id === undefined) {
|
|
478
|
+
if (this.notificationHandler) {
|
|
479
|
+
await this.notificationHandler(message);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
else {
|
|
483
|
+
if (!this.requestHandler) {
|
|
484
|
+
ws.send(JSON.stringify({
|
|
485
|
+
jsonrpc: '2.0',
|
|
486
|
+
id: message.id,
|
|
487
|
+
error: { code: -32603, message: 'No request handler' },
|
|
488
|
+
}));
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
const response = await this.requestHandler(message);
|
|
492
|
+
ws.send(JSON.stringify(response));
|
|
493
|
+
this.messagesSent++;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
catch (error) {
|
|
497
|
+
this.errors++;
|
|
498
|
+
this.logger.error('WebSocket message error', { error });
|
|
499
|
+
try {
|
|
500
|
+
const parsed = JSON.parse(data);
|
|
501
|
+
ws.send(JSON.stringify({
|
|
502
|
+
jsonrpc: '2.0',
|
|
503
|
+
id: parsed.id || null,
|
|
504
|
+
error: { code: -32700, message: 'Parse error' },
|
|
505
|
+
}));
|
|
506
|
+
}
|
|
507
|
+
catch {
|
|
508
|
+
ws.send(JSON.stringify({
|
|
509
|
+
jsonrpc: '2.0',
|
|
510
|
+
id: null,
|
|
511
|
+
error: { code: -32700, message: 'Parse error' },
|
|
512
|
+
}));
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* SECURITY: Timing-safe token comparison to prevent timing attacks
|
|
518
|
+
*/
|
|
519
|
+
timingSafeCompare(a, b) {
|
|
520
|
+
const crypto = require('crypto');
|
|
521
|
+
// Ensure both strings are the same length for timing-safe comparison
|
|
522
|
+
const bufA = Buffer.from(a, 'utf-8');
|
|
523
|
+
const bufB = Buffer.from(b, 'utf-8');
|
|
524
|
+
// If lengths differ, still do a comparison to prevent length-based timing
|
|
525
|
+
if (bufA.length !== bufB.length) {
|
|
526
|
+
// Compare against itself to maintain constant time
|
|
527
|
+
crypto.timingSafeEqual(bufA, bufA);
|
|
528
|
+
return false;
|
|
529
|
+
}
|
|
530
|
+
return crypto.timingSafeEqual(bufA, bufB);
|
|
531
|
+
}
|
|
532
|
+
validateAuth(req) {
|
|
533
|
+
const auth = req.headers.authorization;
|
|
534
|
+
if (!auth) {
|
|
535
|
+
return { valid: false, error: 'Authorization header required' };
|
|
536
|
+
}
|
|
537
|
+
const tokenMatch = auth.match(/^Bearer\s+(.+)$/i);
|
|
538
|
+
if (!tokenMatch) {
|
|
539
|
+
return { valid: false, error: 'Invalid authorization format' };
|
|
540
|
+
}
|
|
541
|
+
const token = tokenMatch[1];
|
|
542
|
+
// SECURITY: an empty/missing token list with auth.enabled=true must
|
|
543
|
+
// reject every request (reject-all). The previous `if (tokens?.length)`
|
|
544
|
+
// guard skipped validation entirely when the list was empty, which
|
|
545
|
+
// accepted ANY bearer value as valid (accept-all).
|
|
546
|
+
const configuredTokens = this.config.auth?.tokens;
|
|
547
|
+
if (!configuredTokens || configuredTokens.length === 0) {
|
|
548
|
+
return { valid: false, error: 'No tokens configured for authentication' };
|
|
549
|
+
}
|
|
550
|
+
let valid = false;
|
|
551
|
+
for (const validToken of configuredTokens) {
|
|
552
|
+
// SECURITY: Use timing-safe comparison to prevent timing attacks
|
|
553
|
+
if (this.timingSafeCompare(token, validToken)) {
|
|
554
|
+
valid = true;
|
|
555
|
+
break;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
if (!valid) {
|
|
559
|
+
return { valid: false, error: 'Invalid token' };
|
|
560
|
+
}
|
|
561
|
+
return { valid: true };
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
export function createHttpTransport(logger, config) {
|
|
565
|
+
return new HttpTransport(logger, config);
|
|
566
|
+
}
|
|
567
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/transport/http.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,OAAqD,MAAM,SAAS,CAAC;AAC5E,OAAO,EAAE,YAAY,EAAU,MAAM,MAAM,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAChD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,MAAM,MAAM,QAAQ,CAAC;AA2B5B,MAAM,OAAO,aAAc,SAAQ,YAAY;IAkB1B,MAAM;IACN,MAAM;IAlBT,IAAI,GAAkB,MAAM,CAAC;IAErC,cAAc,CAAkB;IAChC,mBAAmB,CAAuB;IAC1C,GAAG,CAAU;IACb,MAAM,CAAU;IAChB,GAAG,CAAmB;IACtB,OAAO,GAAG,KAAK,CAAC;IAChB,iBAAiB,GAAG,IAAI,GAAG,EAAa,CAAC;IAEzC,gBAAgB,GAAG,CAAC,CAAC;IACrB,YAAY,GAAG,CAAC,CAAC;IACjB,MAAM,GAAG,CAAC,CAAC;IACX,YAAY,GAAG,CAAC,CAAC;IACjB,UAAU,GAAG,CAAC,CAAC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CAAC,CAAC;QAClD,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,8BAA8B,EAAE,CAAC;QACjE,CAAC;QAED,MAAM,KAAK,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;QAE5B,oEAAoE;QACpE,wEAAwE;QACxE,mEAAmE;QACnE,mDAAmD;QACnD,MAAM,gBAAgB,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC;QAClD,IAAI,CAAC,gBAAgB,IAAI,gBAAgB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,yCAAyC,EAAE,CAAC;QAC5E,CAAC;QAED,IAAI,KAAK,GAAG,KAAK,CAAC;QAClB,KAAK,MAAM,UAAU,IAAI,gBAAgB,EAAE,CAAC;YAC1C,iEAAiE;YACjE,IAAI,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,EAAE,CAAC;gBAC9C,KAAK,GAAG,IAAI,CAAC;gBACb,MAAM;YACR,CAAC;QACH,CAAC;QACD,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,eAAe,EAAE,CAAC;QAClD,CAAC;QAED,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IACzB,CAAC;CACF;AAED,MAAM,UAAU,mBAAmB,CACjC,MAAe,EACf,MAA2B;IAE3B,OAAO,IAAI,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @monoes/mcp - Transport Factory
|
|
3
|
+
*
|
|
4
|
+
* Central factory for creating transport instances
|
|
5
|
+
*/
|
|
6
|
+
import type { ITransport, TransportType, ILogger } from '../types.js';
|
|
7
|
+
import { StdioTransportConfig } from './stdio.js';
|
|
8
|
+
import { HttpTransportConfig } from './http.js';
|
|
9
|
+
import { WebSocketTransportConfig } from './websocket.js';
|
|
10
|
+
export { StdioTransport } from './stdio.js';
|
|
11
|
+
export { HttpTransport } from './http.js';
|
|
12
|
+
export { WebSocketTransport } from './websocket.js';
|
|
13
|
+
export type { StdioTransportConfig } from './stdio.js';
|
|
14
|
+
export type { HttpTransportConfig } from './http.js';
|
|
15
|
+
export type { WebSocketTransportConfig } from './websocket.js';
|
|
16
|
+
export type TransportConfig = ({
|
|
17
|
+
type: 'stdio';
|
|
18
|
+
} & StdioTransportConfig) | ({
|
|
19
|
+
type: 'http';
|
|
20
|
+
} & HttpTransportConfig) | ({
|
|
21
|
+
type: 'websocket';
|
|
22
|
+
} & WebSocketTransportConfig) | {
|
|
23
|
+
type: 'in-process';
|
|
24
|
+
};
|
|
25
|
+
export declare function createTransport(type: TransportType, logger: ILogger, config?: Partial<TransportConfig>): ITransport;
|
|
26
|
+
export declare function createInProcessTransport(logger: ILogger): ITransport;
|
|
27
|
+
export declare class TransportManager {
|
|
28
|
+
private readonly logger;
|
|
29
|
+
private transports;
|
|
30
|
+
private running;
|
|
31
|
+
constructor(logger: ILogger);
|
|
32
|
+
addTransport(name: string, transport: ITransport): void;
|
|
33
|
+
removeTransport(name: string): Promise<boolean>;
|
|
34
|
+
getTransport(name: string): ITransport | undefined;
|
|
35
|
+
getTransportNames(): string[];
|
|
36
|
+
startAll(): Promise<void>;
|
|
37
|
+
stopAll(): Promise<void>;
|
|
38
|
+
getHealthStatus(): Promise<Record<string, {
|
|
39
|
+
healthy: boolean;
|
|
40
|
+
error?: string;
|
|
41
|
+
}>>;
|
|
42
|
+
isRunning(): boolean;
|
|
43
|
+
}
|
|
44
|
+
export declare function createTransportManager(logger: ILogger): TransportManager;
|
|
45
|
+
export declare const DEFAULT_TRANSPORT_CONFIGS: {
|
|
46
|
+
readonly stdio: StdioTransportConfig;
|
|
47
|
+
readonly http: HttpTransportConfig;
|
|
48
|
+
readonly websocket: WebSocketTransportConfig;
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/transport/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,aAAa,EAEb,OAAO,EACR,MAAM,aAAa,CAAC;AACrB,OAAO,EAAkB,oBAAoB,EAAwB,MAAM,YAAY,CAAC;AACxF,OAAO,EAAiB,mBAAmB,EAAuB,MAAM,WAAW,CAAC;AACpF,OAAO,EAAsB,wBAAwB,EAA4B,MAAM,gBAAgB,CAAC;AAExG,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD,YAAY,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AACvD,YAAY,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACrD,YAAY,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAE/D,MAAM,MAAM,eAAe,GACzB,CAAE;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,GAAG,oBAAoB,KACxC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,mBAAmB,KACtC;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,GAAG,wBAAwB,IAChD;IAAE,IAAI,EAAE,YAAY,CAAA;CAAE,CAAC;AAE3B,wBAAgB,eAAe,CAC7B,IAAI,EAAE,aAAa,EACnB,MAAM,EAAE,OAAO,EACf,MAAM,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,GAChC,UAAU,CA+BZ;AAkCD,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,OAAO,GAAG,UAAU,CAEpE;AAED,qBAAa,gBAAgB;IAIf,OAA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