@mcp-shark/mcp-shark 1.4.2 → 1.5.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 +84 -645
- package/bin/mcp-shark.js +30 -36
- package/mcp-server/index.js +115 -0
- package/mcp-server/lib/auditor/audit.js +22 -38
- package/mcp-server/lib/common/error.js +1 -1
- package/mcp-server/lib/server/external/all.js +5 -6
- package/mcp-server/lib/server/external/config.js +1 -3
- package/mcp-server/lib/server/external/kv.js +4 -12
- package/mcp-server/lib/server/external/single/request.js +3 -6
- package/mcp-server/lib/server/external/single/run.js +8 -19
- package/mcp-server/lib/server/internal/handlers/prompts-get.js +3 -13
- package/mcp-server/lib/server/internal/handlers/prompts-list.js +2 -6
- package/mcp-server/lib/server/internal/handlers/resources-list.js +2 -6
- package/mcp-server/lib/server/internal/handlers/resources-read.js +3 -12
- package/mcp-server/lib/server/internal/handlers/tools-call.js +3 -9
- package/mcp-server/lib/server/internal/handlers/tools-list.js +2 -2
- package/mcp-server/lib/server/internal/run.js +4 -16
- package/mcp-server/lib/server/internal/server.js +6 -7
- package/mcp-server/lib/server/internal/session.js +2 -15
- package/mcp-server/mcp-shark.js +16 -66
- package/package.json +23 -38
- package/ui/dist/assets/index-Cc-IUa83.css +1 -0
- package/ui/dist/assets/index-srLDlk97.js +35 -0
- package/ui/dist/index.html +17 -0
- package/ui/dist/og-image.png +0 -0
- package/ui/server/routes/backups/deleteBackup.js +54 -0
- package/ui/server/routes/backups/index.js +15 -0
- package/ui/server/routes/backups/listBackups.js +75 -0
- package/ui/server/routes/backups/restoreBackup.js +83 -0
- package/ui/server/routes/backups/viewBackup.js +47 -0
- package/ui/server/routes/composite/index.js +46 -0
- package/ui/server/routes/composite/servers.js +18 -0
- package/ui/server/routes/composite/setup.js +129 -0
- package/ui/server/routes/composite/status.js +7 -0
- package/ui/server/routes/composite/stop.js +39 -0
- package/ui/server/routes/composite/utils.js +45 -0
- package/ui/server/routes/config.js +34 -30
- package/ui/server/routes/conversations.js +3 -3
- package/ui/server/routes/help.js +2 -2
- package/ui/server/routes/logs.js +5 -5
- package/ui/server/routes/playground.js +45 -47
- package/ui/server/routes/requests.js +112 -108
- package/ui/server/routes/sessions.js +4 -4
- package/ui/server/routes/settings.js +199 -0
- package/ui/server/routes/smartscan/discover.js +7 -6
- package/ui/server/routes/smartscan/scans/clearCache.js +3 -2
- package/ui/server/routes/smartscan/scans/createBatchScans.js +4 -3
- package/ui/server/routes/smartscan/scans/createScan.js +2 -1
- package/ui/server/routes/smartscan/scans/getCachedResults.js +2 -1
- package/ui/server/routes/smartscan/scans/getScan.js +2 -1
- package/ui/server/routes/smartscan/scans/listScans.js +5 -4
- package/ui/server/routes/smartscan/scans.js +3 -3
- package/ui/server/routes/smartscan/token.js +4 -3
- package/ui/server/routes/smartscan/transport.js +1 -1
- package/ui/server/routes/smartscan.js +1 -1
- package/ui/server/routes/statistics.js +13 -10
- package/ui/server/utils/config-update.js +7 -6
- package/ui/server/utils/config.js +4 -4
- package/ui/server/utils/logger.js +2 -0
- package/ui/server/utils/paths.js +210 -2
- package/ui/server/utils/port.js +2 -2
- package/ui/server/utils/process.js +0 -67
- package/ui/server/utils/scan-cache/all-results.js +76 -59
- package/ui/server/utils/scan-cache/directory.js +1 -1
- package/ui/server/utils/scan-cache/file-operations.js +19 -16
- package/ui/server/utils/scan-cache/server-operations.js +14 -9
- package/ui/server/utils/serialization.js +9 -3
- package/ui/server/utils/smartscan-token.js +4 -3
- package/ui/server.js +86 -41
- package/ui/src/App.jsx +5 -5
- package/ui/src/CompositeLogs.jsx +20 -20
- package/ui/src/CompositeSetup.jsx +9 -9
- package/ui/src/HelpGuide/HelpGuideFooter.jsx +1 -0
- package/ui/src/HelpGuide/HelpGuideHeader.jsx +2 -1
- package/ui/src/HelpGuide.jsx +17 -4
- package/ui/src/IntroTour.jsx +19 -5
- package/ui/src/LogDetail.jsx +1 -0
- package/ui/src/LogTable.jsx +24 -6
- package/ui/src/PacketDetail.jsx +21 -16
- package/ui/src/PacketFilters.jsx +29 -14
- package/ui/src/PacketList.jsx +4 -5
- package/ui/src/SmartScan.jsx +5 -5
- package/ui/src/TabNavigation.jsx +5 -5
- package/ui/src/components/App/HelpButton.jsx +4 -0
- package/ui/src/components/App/TrafficTab.jsx +4 -4
- package/ui/src/components/App/useAppState.js +118 -24
- package/ui/src/components/BackupList.jsx +6 -2
- package/ui/src/components/CollapsibleSection.jsx +16 -2
- package/ui/src/components/ConfigViewerModal.jsx +17 -3
- package/ui/src/components/ConfirmationModal.jsx +20 -3
- package/ui/src/components/DetailsTab/BodySection.jsx +3 -1
- package/ui/src/components/DetailsTab/CollapsibleRequestResponse.jsx +14 -3
- package/ui/src/components/DetailsTab/InfoSection.jsx +4 -2
- package/ui/src/components/DetailsTab/RequestDetailsSection.jsx +7 -5
- package/ui/src/components/DetailsTab/ResponseDetailsSection.jsx +7 -5
- package/ui/src/components/DetectedPathsList.jsx +5 -2
- package/ui/src/components/FileInput.jsx +3 -1
- package/ui/src/components/GroupHeader.jsx +14 -0
- package/ui/src/components/GroupedByMcpView.jsx +3 -4
- package/ui/src/components/GroupedByServerView.jsx +1 -1
- package/ui/src/components/GroupedBySessionView.jsx +1 -1
- package/ui/src/components/HexTab.jsx +17 -4
- package/ui/src/components/LogsToolbar.jsx +3 -1
- package/ui/src/components/McpPlayground/LoadingModal.jsx +7 -3
- package/ui/src/components/McpPlayground/PromptsSection/PromptCallPanel.jsx +5 -0
- package/ui/src/components/McpPlayground/PromptsSection/PromptItem.jsx +6 -2
- package/ui/src/components/McpPlayground/PromptsSection/PromptsList.jsx +4 -4
- package/ui/src/components/McpPlayground/PromptsSection.jsx +2 -1
- package/ui/src/components/McpPlayground/ResourcesSection/ResourceCallPanel.jsx +3 -0
- package/ui/src/components/McpPlayground/ResourcesSection/ResourceItem.jsx +6 -2
- package/ui/src/components/McpPlayground/ResourcesSection/ResourcesList.jsx +4 -4
- package/ui/src/components/McpPlayground/ResourcesSection.jsx +2 -1
- package/ui/src/components/McpPlayground/ToolsSection/ToolCallPanel.jsx +5 -0
- package/ui/src/components/McpPlayground/ToolsSection/ToolItem.jsx +6 -2
- package/ui/src/components/McpPlayground/ToolsSection/ToolsList.jsx +4 -4
- package/ui/src/components/McpPlayground/ToolsSection.jsx +2 -1
- package/ui/src/components/McpPlayground/hooks/useMcpDataLoader.js +9 -9
- package/ui/src/components/McpPlayground/hooks/useMcpRequest.js +10 -5
- package/ui/src/components/McpPlayground/hooks/useMcpServerStatus.js +43 -23
- package/ui/src/components/McpPlayground/useMcpPlayground.js +72 -44
- package/ui/src/components/McpPlayground.jsx +5 -2
- package/ui/src/components/PacketDetailHeader.jsx +8 -3
- package/ui/src/components/PacketFilters/ExportControls.jsx +2 -1
- package/ui/src/components/PacketFilters/FilterInput.jsx +1 -1
- package/ui/src/components/RawTab.jsx +15 -2
- package/ui/src/components/RequestRow/OrphanedResponseRow.jsx +10 -2
- package/ui/src/components/RequestRow/RequestRowMain.jsx +12 -3
- package/ui/src/components/RequestRow/ResponseRow.jsx +11 -3
- package/ui/src/components/RequestRow.jsx +17 -9
- package/ui/src/components/ServerControl.jsx +3 -1
- package/ui/src/components/ServiceSelector.jsx +2 -0
- package/ui/src/components/SmartScan/AnalysisResult.jsx +2 -2
- package/ui/src/components/SmartScan/BatchResultsDisplay/BatchResultItem.jsx +2 -1
- package/ui/src/components/SmartScan/BatchResultsDisplay/BatchResultsHeader.jsx +1 -1
- package/ui/src/components/SmartScan/BatchResultsDisplay.jsx +9 -3
- package/ui/src/components/SmartScan/EmptyState.jsx +3 -0
- package/ui/src/components/SmartScan/ErrorDisplay.jsx +4 -2
- package/ui/src/components/SmartScan/ExpandableSection.jsx +4 -0
- package/ui/src/components/SmartScan/FindingsTable.jsx +46 -42
- package/ui/src/components/SmartScan/ListViewContent.jsx +2 -2
- package/ui/src/components/SmartScan/NotablePatternsSection.jsx +13 -8
- package/ui/src/components/SmartScan/OverallSummarySection.jsx +36 -29
- package/ui/src/components/SmartScan/RecommendationsSection.jsx +10 -8
- package/ui/src/components/SmartScan/ScanDetailHeader.jsx +2 -1
- package/ui/src/components/SmartScan/ScanDetailView.jsx +4 -4
- package/ui/src/components/SmartScan/ScanListView/ScanListHeader.jsx +2 -1
- package/ui/src/components/SmartScan/ScanListView/ScanListItem.jsx +15 -1
- package/ui/src/components/SmartScan/ScanOverviewSection.jsx +3 -1
- package/ui/src/components/SmartScan/ScanResultsDisplay.jsx +1 -1
- package/ui/src/components/SmartScan/ScanViewContent.jsx +2 -2
- package/ui/src/components/SmartScan/ScanningProgress.jsx +4 -2
- package/ui/src/components/SmartScan/ServerInfoSection.jsx +3 -1
- package/ui/src/components/SmartScan/ServerSelectionRow.jsx +4 -2
- package/ui/src/components/SmartScan/SingleResultDisplay.jsx +5 -3
- package/ui/src/components/SmartScan/SmartScanControls.jsx +11 -7
- package/ui/src/components/SmartScan/SmartScanHeader.jsx +1 -1
- package/ui/src/components/SmartScan/ViewModeTabs.jsx +2 -0
- package/ui/src/components/SmartScan/hooks/useCacheManagement.js +1 -2
- package/ui/src/components/SmartScan/hooks/useMcpDiscovery.js +22 -26
- package/ui/src/components/SmartScan/hooks/useScanList.js +10 -9
- package/ui/src/components/SmartScan/hooks/useScanOperations.js +23 -14
- package/ui/src/components/SmartScan/hooks/useServerStatus.js +2 -2
- package/ui/src/components/SmartScan/hooks/useTokenManagement.js +2 -2
- package/ui/src/components/SmartScan/scanDataUtils.js +22 -17
- package/ui/src/components/SmartScan/useSmartScan.js +4 -4
- package/ui/src/components/SmartScan/utils.js +3 -1
- package/ui/src/components/SmartScanIcons.jsx +6 -3
- package/ui/src/components/TabNavigation/DesktopTabs.jsx +8 -3
- package/ui/src/components/TabNavigation/MobileDropdown.jsx +3 -1
- package/ui/src/components/TabNavigation.jsx +8 -3
- package/ui/src/components/TabNavigationIcons.jsx +4 -4
- package/ui/src/components/TourOverlay.jsx +1 -1
- package/ui/src/components/TourTooltip/TourTooltipButtons.jsx +3 -0
- package/ui/src/components/TourTooltip/TourTooltipHeader.jsx +1 -0
- package/ui/src/components/TourTooltip/TourTooltipIcons.jsx +9 -0
- package/ui/src/components/TourTooltip/useTooltipPosition.js +63 -36
- package/ui/src/components/TourTooltip.jsx +11 -3
- package/ui/src/components/ViewModeTabs.jsx +3 -1
- package/ui/src/config/tourSteps.jsx +0 -2
- package/ui/src/hooks/useAnimation.js +15 -12
- package/ui/src/hooks/useConfigManagement.js +8 -8
- package/ui/src/hooks/useServiceExtraction.js +1 -1
- package/ui/src/index.css +3 -8
- package/ui/src/theme.js +3 -3
- package/ui/src/utils/hexUtils.js +11 -5
- package/ui/src/utils/mcpGroupingUtils.js +18 -10
- package/ui/src/utils/requestPairing.js +89 -0
- package/ui/src/utils/requestUtils.js +32 -101
- package/ui/vite.config.js +1 -1
- package/mcp-server/.editorconfig +0 -15
- package/mcp-server/.prettierignore +0 -11
- package/mcp-server/.prettierrc +0 -12
- package/mcp-server/README.md +0 -280
- package/mcp-server/commitlint.config.cjs +0 -42
- package/mcp-server/eslint.config.js +0 -131
- package/mcp-server/package-lock.json +0 -4784
- package/mcp-server/package.json +0 -30
- package/ui/README.md +0 -212
- package/ui/package-lock.json +0 -3574
- package/ui/package.json +0 -12
- package/ui/paths.js +0 -282
- package/ui/server/routes/backups.js +0 -251
- package/ui/server/routes/composite.js +0 -260
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
import * as path from 'node:path';
|
|
2
|
-
import * as fs from 'node:fs';
|
|
3
|
-
import { homedir } from 'node:os';
|
|
4
|
-
import { checkPortReady } from '../utils/port.js';
|
|
5
|
-
import { findMcpServerPath } from '../utils/paths.js';
|
|
6
|
-
import { convertMcpServersToServers, clearOriginalConfig } from '../utils/config.js';
|
|
7
|
-
import { getMcpConfigPath } from 'mcp-shark-common/configs/index.js';
|
|
8
|
-
import {
|
|
9
|
-
createLogEntry,
|
|
10
|
-
spawnMcpSharkServer,
|
|
11
|
-
setupProcessHandlers,
|
|
12
|
-
getMcpSharkJsPath,
|
|
13
|
-
} from '../utils/process.js';
|
|
14
|
-
import { updateConfigFile, getSelectedServiceNames } from '../utils/config-update.js';
|
|
15
|
-
|
|
16
|
-
const MAX_LOG_LINES = 10000;
|
|
17
|
-
|
|
18
|
-
export function createCompositeRoutes(
|
|
19
|
-
getMcpSharkProcess,
|
|
20
|
-
setMcpSharkProcess,
|
|
21
|
-
mcpSharkLogs,
|
|
22
|
-
broadcastLogUpdate
|
|
23
|
-
) {
|
|
24
|
-
const router = {};
|
|
25
|
-
|
|
26
|
-
router.setup = async (req, res) => {
|
|
27
|
-
mcpSharkLogs.length = 0;
|
|
28
|
-
const logEntry = createLogEntry(mcpSharkLogs, broadcastLogUpdate);
|
|
29
|
-
|
|
30
|
-
try {
|
|
31
|
-
const { filePath, fileContent, selectedServices } = req.body;
|
|
32
|
-
|
|
33
|
-
if (!filePath && !fileContent) {
|
|
34
|
-
return res.status(400).json({ error: 'Either filePath or fileContent is required' });
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const fileData = (() => {
|
|
38
|
-
if (fileContent) {
|
|
39
|
-
const resolvedFilePath = filePath
|
|
40
|
-
? filePath.startsWith('~')
|
|
41
|
-
? path.join(homedir(), filePath.slice(1))
|
|
42
|
-
: filePath
|
|
43
|
-
: null;
|
|
44
|
-
return { content: fileContent, resolvedFilePath };
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const resolvedFilePath = filePath.startsWith('~')
|
|
48
|
-
? path.join(homedir(), filePath.slice(1))
|
|
49
|
-
: filePath;
|
|
50
|
-
|
|
51
|
-
if (!fs.existsSync(resolvedFilePath)) {
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
content: fs.readFileSync(resolvedFilePath, 'utf-8'),
|
|
57
|
-
resolvedFilePath,
|
|
58
|
-
};
|
|
59
|
-
})();
|
|
60
|
-
|
|
61
|
-
if (!fileData) {
|
|
62
|
-
const resolvedFilePath = filePath.startsWith('~')
|
|
63
|
-
? path.join(homedir(), filePath.slice(1))
|
|
64
|
-
: filePath;
|
|
65
|
-
return res.status(404).json({ error: 'File not found', path: resolvedFilePath });
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const parseResult = (() => {
|
|
69
|
-
try {
|
|
70
|
-
return { config: JSON.parse(fileData.content), error: null };
|
|
71
|
-
} catch (e) {
|
|
72
|
-
return { config: null, error: e };
|
|
73
|
-
}
|
|
74
|
-
})();
|
|
75
|
-
|
|
76
|
-
if (!parseResult.config) {
|
|
77
|
-
return res.status(400).json({
|
|
78
|
-
error: 'Invalid JSON file',
|
|
79
|
-
details: parseResult.error ? parseResult.error.message : 'Failed to parse JSON',
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const originalConfig = parseResult.config;
|
|
84
|
-
let convertedConfig = convertMcpServersToServers(originalConfig);
|
|
85
|
-
|
|
86
|
-
if (selectedServices && Array.isArray(selectedServices) && selectedServices.length > 0) {
|
|
87
|
-
const filteredServers = {};
|
|
88
|
-
selectedServices.forEach((serviceName) => {
|
|
89
|
-
if (convertedConfig.servers[serviceName]) {
|
|
90
|
-
filteredServers[serviceName] = convertedConfig.servers[serviceName];
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
convertedConfig = { servers: filteredServers };
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (Object.keys(convertedConfig.servers).length === 0) {
|
|
97
|
-
return res.status(400).json({ error: 'No servers found in config' });
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const mcpServerPath = findMcpServerPath();
|
|
101
|
-
const mcpsJsonPath = getMcpConfigPath();
|
|
102
|
-
fs.writeFileSync(mcpsJsonPath, JSON.stringify(convertedConfig, null, 2));
|
|
103
|
-
console.log(`Wrote converted config to: ${mcpsJsonPath}`);
|
|
104
|
-
|
|
105
|
-
const currentProcess = getMcpSharkProcess();
|
|
106
|
-
if (currentProcess) {
|
|
107
|
-
currentProcess.kill();
|
|
108
|
-
setMcpSharkProcess(null);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const mcpSharkJsPath = getMcpSharkJsPath();
|
|
112
|
-
if (!fs.existsSync(mcpSharkJsPath)) {
|
|
113
|
-
return res.status(500).json({
|
|
114
|
-
error: 'MCP Shark server not found',
|
|
115
|
-
details: `Could not find mcp-shark.js at ${mcpSharkJsPath}`,
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const processHandle = spawnMcpSharkServer(mcpSharkJsPath, mcpsJsonPath, logEntry);
|
|
120
|
-
setMcpSharkProcess(processHandle);
|
|
121
|
-
|
|
122
|
-
setupProcessHandlers(
|
|
123
|
-
processHandle,
|
|
124
|
-
logEntry,
|
|
125
|
-
(err) => {
|
|
126
|
-
setMcpSharkProcess(null);
|
|
127
|
-
return res.status(500).json({
|
|
128
|
-
error: 'Failed to start mcp-shark server',
|
|
129
|
-
details: err.message,
|
|
130
|
-
});
|
|
131
|
-
},
|
|
132
|
-
() => {
|
|
133
|
-
setMcpSharkProcess(null);
|
|
134
|
-
}
|
|
135
|
-
);
|
|
136
|
-
|
|
137
|
-
try {
|
|
138
|
-
console.log('Waiting for mcp-shark server to start on port 9851...');
|
|
139
|
-
await checkPortReady(9851, 'localhost', 15000);
|
|
140
|
-
console.log('MCP Shark server is ready!');
|
|
141
|
-
|
|
142
|
-
const selectedServiceNames = getSelectedServiceNames(originalConfig, selectedServices);
|
|
143
|
-
const { updatedConfig, backupPath: createdBackupPath } = updateConfigFile(
|
|
144
|
-
originalConfig,
|
|
145
|
-
selectedServiceNames,
|
|
146
|
-
fileData.resolvedFilePath,
|
|
147
|
-
fileData.content,
|
|
148
|
-
mcpSharkLogs,
|
|
149
|
-
broadcastLogUpdate
|
|
150
|
-
);
|
|
151
|
-
|
|
152
|
-
if (!fileData.resolvedFilePath) {
|
|
153
|
-
clearOriginalConfig();
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
res.json({
|
|
157
|
-
success: true,
|
|
158
|
-
message: 'MCP Shark server started successfully and config file updated',
|
|
159
|
-
convertedConfig,
|
|
160
|
-
updatedConfig,
|
|
161
|
-
filePath: fileData.resolvedFilePath || null,
|
|
162
|
-
backupPath: createdBackupPath || null,
|
|
163
|
-
});
|
|
164
|
-
} catch (waitError) {
|
|
165
|
-
console.error('MCP Shark server did not start in time:', waitError);
|
|
166
|
-
if (processHandle) {
|
|
167
|
-
processHandle.kill();
|
|
168
|
-
setMcpSharkProcess(null);
|
|
169
|
-
}
|
|
170
|
-
const timestamp = new Date().toISOString();
|
|
171
|
-
const errorLog = {
|
|
172
|
-
timestamp,
|
|
173
|
-
type: 'error',
|
|
174
|
-
line: `[ERROR] MCP Shark server failed to start: ${waitError.message}`,
|
|
175
|
-
};
|
|
176
|
-
mcpSharkLogs.push(errorLog);
|
|
177
|
-
if (mcpSharkLogs.length > MAX_LOG_LINES) {
|
|
178
|
-
mcpSharkLogs.shift();
|
|
179
|
-
}
|
|
180
|
-
broadcastLogUpdate(errorLog);
|
|
181
|
-
return res.status(500).json({
|
|
182
|
-
error: 'MCP Shark server failed to start',
|
|
183
|
-
details: waitError.message,
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
} catch (error) {
|
|
187
|
-
console.error('Error setting up mcp-shark server:', error);
|
|
188
|
-
const timestamp = new Date().toISOString();
|
|
189
|
-
const errorLog = {
|
|
190
|
-
timestamp,
|
|
191
|
-
type: 'error',
|
|
192
|
-
line: `[ERROR] Failed to setup mcp-shark server: ${error.message}`,
|
|
193
|
-
};
|
|
194
|
-
mcpSharkLogs.push(errorLog);
|
|
195
|
-
if (mcpSharkLogs.length > MAX_LOG_LINES) {
|
|
196
|
-
mcpSharkLogs.shift();
|
|
197
|
-
}
|
|
198
|
-
broadcastLogUpdate(errorLog);
|
|
199
|
-
res.status(500).json({ error: 'Failed to setup mcp-shark server', details: error.message });
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
router.stop = (req, res, restoreOriginalConfig) => {
|
|
204
|
-
try {
|
|
205
|
-
const currentProcess = getMcpSharkProcess();
|
|
206
|
-
if (currentProcess) {
|
|
207
|
-
currentProcess.kill();
|
|
208
|
-
setMcpSharkProcess(null);
|
|
209
|
-
|
|
210
|
-
const restored = restoreOriginalConfig();
|
|
211
|
-
|
|
212
|
-
if (restored) {
|
|
213
|
-
const timestamp = new Date().toISOString();
|
|
214
|
-
const restoreLog = {
|
|
215
|
-
timestamp,
|
|
216
|
-
type: 'stdout',
|
|
217
|
-
line: `[RESTORE] Restored original config`,
|
|
218
|
-
};
|
|
219
|
-
mcpSharkLogs.push(restoreLog);
|
|
220
|
-
if (mcpSharkLogs.length > MAX_LOG_LINES) {
|
|
221
|
-
mcpSharkLogs.shift();
|
|
222
|
-
}
|
|
223
|
-
broadcastLogUpdate(restoreLog);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
res.json({ success: true, message: 'MCP Shark server stopped and config restored' });
|
|
227
|
-
} else {
|
|
228
|
-
res.json({ success: true, message: 'MCP Shark server was not running' });
|
|
229
|
-
}
|
|
230
|
-
} catch (error) {
|
|
231
|
-
res.status(500).json({ error: 'Failed to stop mcp-shark server', details: error.message });
|
|
232
|
-
}
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
router.getStatus = (req, res) => {
|
|
236
|
-
const currentProcess = getMcpSharkProcess();
|
|
237
|
-
res.json({
|
|
238
|
-
running: currentProcess !== null,
|
|
239
|
-
pid: currentProcess?.pid || null,
|
|
240
|
-
});
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
router.getServers = (req, res) => {
|
|
244
|
-
try {
|
|
245
|
-
const mcpsJsonPath = getMcpConfigPath();
|
|
246
|
-
if (!fs.existsSync(mcpsJsonPath)) {
|
|
247
|
-
return res.json({ servers: [] });
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
const configContent = fs.readFileSync(mcpsJsonPath, 'utf-8');
|
|
251
|
-
const config = JSON.parse(configContent);
|
|
252
|
-
const servers = config.servers ? Object.keys(config.servers) : [];
|
|
253
|
-
res.json({ servers });
|
|
254
|
-
} catch (error) {
|
|
255
|
-
res.status(500).json({ error: 'Failed to get servers', details: error.message });
|
|
256
|
-
}
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
return router;
|
|
260
|
-
}
|