@mcp-shark/mcp-shark 1.5.5 → 1.5.7
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/core/services/ServerManagementService.js +9 -17
- package/package.json +1 -1
- package/ui/server/controllers/ServerManagementController.js +23 -2
- package/ui/server/routes/composite/index.js +4 -1
- package/ui/server/setup.js +2 -4
- package/ui/server/swagger/paths/serverManagement.js +36 -0
- package/ui/server/websocket/handler.js +8 -5
|
@@ -36,13 +36,10 @@ export class ServerManagementService {
|
|
|
36
36
|
|
|
37
37
|
// If filePath is provided, restore original config if already patched
|
|
38
38
|
// This ensures processSetup reads the original config, not the patched one
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
restoreWarning = restoreResult.warning;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
39
|
+
const restoreWarning =
|
|
40
|
+
filePath && !fileContent
|
|
41
|
+
? this.configPatchingService.restoreIfPatched(filePath).warning || null
|
|
42
|
+
: null;
|
|
46
43
|
|
|
47
44
|
// Process setup
|
|
48
45
|
const setupResult = this.configService.processSetup(filePath, fileContent, selectedServices);
|
|
@@ -80,16 +77,11 @@ export class ServerManagementService {
|
|
|
80
77
|
});
|
|
81
78
|
|
|
82
79
|
// Patch the original config file if it exists
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
);
|
|
89
|
-
if (patchResult.warning) {
|
|
90
|
-
patchWarning = patchResult.warning;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
80
|
+
const patchWarning =
|
|
81
|
+
fileData.resolvedFilePath && this.configService.fileExists(fileData.resolvedFilePath)
|
|
82
|
+
? this.configPatchingService.patchConfigFile(fileData.resolvedFilePath, updatedConfig)
|
|
83
|
+
.warning || null
|
|
84
|
+
: null;
|
|
93
85
|
|
|
94
86
|
return {
|
|
95
87
|
success: true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcp-shark/mcp-shark",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.7",
|
|
4
4
|
"description": "Aggregate multiple Model Context Protocol (MCP) servers into a single unified interface with a powerful monitoring UI. Prov deep visibility into every request and response.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./bin/mcp-shark.js",
|
|
@@ -5,10 +5,11 @@ import { handleError, handleValidationError } from '../utils/errorHandler.js';
|
|
|
5
5
|
* Controller for server management HTTP endpoints
|
|
6
6
|
*/
|
|
7
7
|
export class ServerManagementController {
|
|
8
|
-
constructor(serverManagementService, logService, logger) {
|
|
8
|
+
constructor(serverManagementService, logService, logger, configService = null) {
|
|
9
9
|
this.serverManagementService = serverManagementService;
|
|
10
10
|
this.logService = logService;
|
|
11
11
|
this.logger = logger;
|
|
12
|
+
this.configService = configService;
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
/**
|
|
@@ -76,7 +77,7 @@ export class ServerManagementController {
|
|
|
76
77
|
stop = async (_req, res) => {
|
|
77
78
|
try {
|
|
78
79
|
const stopped = await this.serverManagementService.stopServer();
|
|
79
|
-
const restored = this.configService.restoreOriginalConfig();
|
|
80
|
+
const restored = this.configService ? this.configService.restoreOriginalConfig() : false;
|
|
80
81
|
|
|
81
82
|
if (stopped) {
|
|
82
83
|
if (restored) {
|
|
@@ -109,6 +110,26 @@ export class ServerManagementController {
|
|
|
109
110
|
}
|
|
110
111
|
};
|
|
111
112
|
|
|
113
|
+
/**
|
|
114
|
+
* GET /api/mcp-server/status
|
|
115
|
+
* Check if the MCP server (gateway) is running
|
|
116
|
+
* This endpoint specifically indicates whether the MCP gateway server is active
|
|
117
|
+
* so users can know if they should focus on the traffic page
|
|
118
|
+
*/
|
|
119
|
+
getMcpServerStatus = (_req, res) => {
|
|
120
|
+
try {
|
|
121
|
+
const status = this.serverManagementService.getServerStatus();
|
|
122
|
+
res.json({
|
|
123
|
+
running: status.running,
|
|
124
|
+
message: status.running
|
|
125
|
+
? 'MCP server (gateway) is running and ready to receive traffic'
|
|
126
|
+
: 'MCP server (gateway) is not running. Start the server to begin capturing traffic.',
|
|
127
|
+
});
|
|
128
|
+
} catch (error) {
|
|
129
|
+
handleError(error, res, this.logger, 'Error getting MCP server status');
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
|
|
112
133
|
shutdown = async (_req, res) => {
|
|
113
134
|
try {
|
|
114
135
|
if (!this.cleanup) {
|
|
@@ -37,6 +37,7 @@ export function createCompositeRoutes(
|
|
|
37
37
|
const serverManagementService = container.getService('serverManagement');
|
|
38
38
|
const logService = container.getService('log');
|
|
39
39
|
const logger = container.getLibrary('logger');
|
|
40
|
+
const configService = container.getService('config');
|
|
40
41
|
|
|
41
42
|
// Initialize log service with the log array
|
|
42
43
|
logService.initialize(mcpSharkLogs);
|
|
@@ -56,7 +57,8 @@ export function createCompositeRoutes(
|
|
|
56
57
|
const serverManagementController = new ServerManagementController(
|
|
57
58
|
serverManagementService,
|
|
58
59
|
logService,
|
|
59
|
-
logger
|
|
60
|
+
logger,
|
|
61
|
+
configService
|
|
60
62
|
);
|
|
61
63
|
|
|
62
64
|
// Set cleanup function for shutdown endpoint
|
|
@@ -69,6 +71,7 @@ export function createCompositeRoutes(
|
|
|
69
71
|
router.setup = serverManagementController.setup;
|
|
70
72
|
router.stop = serverManagementController.stop;
|
|
71
73
|
router.getStatus = serverManagementController.getStatus;
|
|
74
|
+
router.getMcpServerStatus = serverManagementController.getMcpServerStatus;
|
|
72
75
|
router.shutdown = serverManagementController.shutdown;
|
|
73
76
|
router.getServers = getServers(container);
|
|
74
77
|
|
package/ui/server/setup.js
CHANGED
|
@@ -24,7 +24,6 @@ import { createSmartScanRoutes } from './routes/smartscan.js';
|
|
|
24
24
|
import { createStatisticsRoutes } from './routes/statistics.js';
|
|
25
25
|
import { swaggerSpec } from './swagger/swagger.js';
|
|
26
26
|
import { performCleanup } from './utils/cleanup.js';
|
|
27
|
-
import { restoreConfig } from './utils/config.js';
|
|
28
27
|
import { getMcpSharkProcess, setMcpSharkProcess } from './utils/processState.js';
|
|
29
28
|
import { broadcastLogUpdate, notifyClients } from './websocket/broadcast.js';
|
|
30
29
|
import { handleWebSocketConnection } from './websocket/handler.js';
|
|
@@ -110,10 +109,9 @@ export function createUIServer() {
|
|
|
110
109
|
app.post('/api/config/backup/delete', backupRoutes.deleteBackup);
|
|
111
110
|
|
|
112
111
|
app.post('/api/composite/setup', compositeRoutes.setup);
|
|
113
|
-
app.post('/api/composite/stop',
|
|
114
|
-
compositeRoutes.stop(req, res, () => restoreConfig(container));
|
|
115
|
-
});
|
|
112
|
+
app.post('/api/composite/stop', compositeRoutes.stop);
|
|
116
113
|
app.get('/api/composite/status', compositeRoutes.getStatus);
|
|
114
|
+
app.get('/api/mcp-server/status', compositeRoutes.getMcpServerStatus);
|
|
117
115
|
app.post('/api/composite/shutdown', compositeRoutes.shutdown);
|
|
118
116
|
app.get('/api/composite/servers', compositeRoutes.getServers);
|
|
119
117
|
|
|
@@ -112,6 +112,42 @@ export const serverManagementPaths = {
|
|
|
112
112
|
},
|
|
113
113
|
},
|
|
114
114
|
},
|
|
115
|
+
'/api/mcp-server/status': {
|
|
116
|
+
get: {
|
|
117
|
+
tags: ['Server Management'],
|
|
118
|
+
summary: 'Check MCP server (gateway) status',
|
|
119
|
+
description:
|
|
120
|
+
'Check if the MCP server (gateway) is running. This endpoint specifically indicates whether the MCP gateway server is active, so users can know if they should focus on the traffic page.',
|
|
121
|
+
responses: {
|
|
122
|
+
200: {
|
|
123
|
+
description: 'MCP server status',
|
|
124
|
+
content: {
|
|
125
|
+
'application/json': {
|
|
126
|
+
schema: {
|
|
127
|
+
type: 'object',
|
|
128
|
+
properties: {
|
|
129
|
+
running: {
|
|
130
|
+
type: 'boolean',
|
|
131
|
+
description: 'Whether the MCP server (gateway) is running',
|
|
132
|
+
example: true,
|
|
133
|
+
},
|
|
134
|
+
message: {
|
|
135
|
+
type: 'string',
|
|
136
|
+
description: 'Human-readable status message',
|
|
137
|
+
example: 'MCP server (gateway) is running and ready to receive traffic',
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
required: ['running', 'message'],
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
500: {
|
|
146
|
+
description: 'Internal server error',
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
},
|
|
115
151
|
'/api/composite/shutdown': {
|
|
116
152
|
post: {
|
|
117
153
|
tags: ['Server Management'],
|
|
@@ -9,8 +9,11 @@ import { Server as ServerConstants } from '#core/constants/Server.js';
|
|
|
9
9
|
export function handleWebSocketConnection(clients, ws, logger) {
|
|
10
10
|
clients.add(ws);
|
|
11
11
|
|
|
12
|
+
// Use object to hold timeout ID (allows reassignment while keeping const)
|
|
13
|
+
const timeoutState = { id: null };
|
|
14
|
+
|
|
12
15
|
// Set up timeout to close stale connections
|
|
13
|
-
|
|
16
|
+
timeoutState.id = setTimeout(() => {
|
|
14
17
|
if (ws.readyState === 1) {
|
|
15
18
|
logger?.warn('WebSocket connection timeout, closing');
|
|
16
19
|
ws.close();
|
|
@@ -28,8 +31,8 @@ export function handleWebSocketConnection(clients, ws, logger) {
|
|
|
28
31
|
|
|
29
32
|
ws.on('pong', () => {
|
|
30
33
|
// Reset timeout on pong
|
|
31
|
-
clearTimeout(
|
|
32
|
-
|
|
34
|
+
clearTimeout(timeoutState.id);
|
|
35
|
+
timeoutState.id = setTimeout(() => {
|
|
33
36
|
if (ws.readyState === 1) {
|
|
34
37
|
logger?.warn('WebSocket connection timeout, closing');
|
|
35
38
|
ws.close();
|
|
@@ -38,14 +41,14 @@ export function handleWebSocketConnection(clients, ws, logger) {
|
|
|
38
41
|
});
|
|
39
42
|
|
|
40
43
|
ws.on('close', () => {
|
|
41
|
-
clearTimeout(
|
|
44
|
+
clearTimeout(timeoutState.id);
|
|
42
45
|
clearInterval(heartbeatInterval);
|
|
43
46
|
clients.delete(ws);
|
|
44
47
|
});
|
|
45
48
|
|
|
46
49
|
ws.on('error', (error) => {
|
|
47
50
|
logger?.error({ error: error.message }, 'WebSocket error');
|
|
48
|
-
clearTimeout(
|
|
51
|
+
clearTimeout(timeoutState.id);
|
|
49
52
|
clearInterval(heartbeatInterval);
|
|
50
53
|
clients.delete(ws);
|
|
51
54
|
});
|