From bc48bd9d486a3f71f2dedae77fa367b30a33a3e9 Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Fri, 20 Jun 2025 09:42:10 -0700 Subject: [PATCH] Capture to pcap file in a temp directory Without this I was getting permission errors: ``` Called capture_packets Parameters: { "interface": "en0", "duration": 120 } Result: Error: Command failed: /opt/homebrew/bin/tshark -i en0 -w temp_capture.pcap -a duration:120 Capturing on 'Wi-Fi: en0' tshark: The file to which the capture would be saved ("temp_capture.pcap") could not be opened: Read-only file system. 0 packets captured ``` --- index.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index c8ece68..524ec8f 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,8 @@ const { exec } = require('child_process'); const { promisify } = require('util'); const which = require('which'); const fs = require('fs').promises; +const path = require('path'); +const os = require('os'); const execAsync = promisify(exec); const { McpServer } = require('@modelcontextprotocol/sdk/server/mcp.js'); const { StdioServerTransport } = require('@modelcontextprotocol/sdk/server/stdio.js'); @@ -56,7 +58,7 @@ server.tool( try { const tsharkPath = await findTshark(); const { interface, duration } = args; - const tempPcap = 'temp_capture.pcap'; + const tempPcap = path.join(os.tmpdir(), `wiremcp_capture_${Date.now()}.pcap`); console.error(`Capturing packets on ${interface} for ${duration}s`); await execAsync( @@ -108,7 +110,7 @@ server.tool( try { const tsharkPath = await findTshark(); const { interface, duration } = args; - const tempPcap = 'temp_capture.pcap'; + const tempPcap = path.join(os.tmpdir(), `wiremcp_summary_${Date.now()}.pcap`); console.error(`Capturing summary stats on ${interface} for ${duration}s`); await execAsync( @@ -149,7 +151,7 @@ server.tool( try { const tsharkPath = await findTshark(); const { interface, duration } = args; - const tempPcap = 'temp_capture.pcap'; + const tempPcap = path.join(os.tmpdir(), `wiremcp_conversations_${Date.now()}.pcap`); console.error(`Capturing conversations on ${interface} for ${duration}s`); await execAsync( @@ -190,7 +192,7 @@ server.tool( try { const tsharkPath = await findTshark(); const { interface, duration } = args; - const tempPcap = 'temp_capture.pcap'; + const tempPcap = path.join(os.tmpdir(), `wiremcp_threats_${Date.now()}.pcap`); console.error(`Capturing traffic on ${interface} for ${duration}s to check threats`); await execAsync(