Skip to content

Commit 0581d68

Browse files
make sure logs are available for the mcp
1 parent 00b96ee commit 0581d68

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

lib/Echidna/UI.hs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,21 @@ ui vm dict initialCorpus cliSelectedContract = do
104104
Interactive -> do
105105
-- Channel to push events to update UI
106106
uiChannel <- liftIO $ newBChan 1000
107-
let forwardEvent = void . writeBChanNonBlocking uiChannel . EventReceived
107+
logBuffer <- newIORef []
108+
109+
let forwardEvent ev = do
110+
msg <- runReaderT (ppLogLine vm ev) env
111+
liftIO $ atomicModifyIORef' logBuffer (\logs -> (pack msg : logs, ()))
112+
void $ writeBChanNonBlocking uiChannel $ EventReceived ev
113+
108114
uiEventsForwarderStopVar <- spawnListener forwardEvent
109115

116+
case conf.campaignConf.serverPort of
117+
Just port -> do
118+
liftIO $ pushCampaignEvent env (ServerLog ("MCP Server running at http://127.0.0.1:" ++ show port ++ "/mcp"))
119+
void $ liftIO $ forkIO $ runMCPServer env (fromIntegral port) logBuffer
120+
Nothing -> pure ()
121+
110122
ticker <- liftIO . forkIO . forever $ do
111123
threadDelay 200_000 -- 200 ms
112124

@@ -197,8 +209,10 @@ ui vm dict initialCorpus cliSelectedContract = do
197209
states <- liftIO $ workerStates workers
198210
time <- timePrefix <$> getTimestamp
199211
line <- statusLine env states lastUpdateRef
200-
putStrLn $ time <> "[status] " <> line
212+
let statusMsg = time <> "[status] " <> line
213+
putStrLn statusMsg
201214
hFlush stdout
215+
liftIO $ atomicModifyIORef' logBuffer (\logs -> (pack statusMsg : logs, ()))
202216

203217
case conf.campaignConf.serverPort of
204218
Just port -> do

0 commit comments

Comments
 (0)