@@ -288,160 +288,63 @@ Best for local development with AI assistants:
288288}
289289```
290290
291- In stdio mode:
292- - MCP communication happens over ** stdio** (no HTTP MCP endpoint)
293- - An ** HTTP ingest server** runs on a local port (127.0.0.1) for browsers to POST logs
294- - The actual URL is written to ` .browser-echo-mcp.json ` in your project root
295- - Console output (stderr): ` MCP (stdio) listening on stdio (ingest HTTP active) `
296-
297- ### HTTP Mode
298-
299- For web-based AI tools or when you need HTTP MCP access:
300-
301- ``` json
302- // .cursor/mcp.json
303- {
304- "mcpServers" : {
305- "browser-echo" : {
306- "command" : " node" ,
307- "args" : [" packages/mcp/bin/cli.mjs" , " --http" ]
308- }
309- }
310- }
311- ```
312-
313- In HTTP mode:
314- - Full ** Streamable HTTP** MCP endpoint and HTTP ingest endpoint run on the specified host/port
315- - Console output: ` MCP (Streamable HTTP) listening → http://127.0.0.1:<port>/mcp `
316-
317- ### Custom Configuration
318-
319- ``` bash
320- # Custom ingest port in stdio mode (override ephemeral)
321- BROWSER_ECHO_INGEST_PORT=8081 node packages/mcp/bin/cli.mjs
322-
323- # Custom HTTP server
324- node packages/mcp/bin/cli.mjs --http --host 0.0.0.0 --port 5179
325- ```
291+ - Vite/Next/Nuxt send ` X-Browser-Echo-Project-Name ` so logs are project-tagged.
292+ - No ` .browser-echo-mcp.json ` discovery files are used anymore.
326293
327294---
328295
329- ## How Logs Reach the Server
330-
331- ### Browser → Ingest (Recommended)
332-
333- Your framework packages automatically send logs to the ingest endpoint:
296+ ## Available Tools
334297
335- ``` typescript
336- // Browser automatically POSTs to ingest endpoint
337- POST http :// 127.0.0.1:5179/__client-logs
338- {
339- " sessionId" : " tab-123" ,
340- " entries" : [
341- {
342- " level" : " error" ,
343- " text" : " Failed to fetch user" ,
344- " time" : 1724200000000 ,
345- " source" : " api.ts:42" ,
346- " stack" : " Error: ..."
347- }
348- ]
349- }
350- ```
298+ ### ` get_logs ` — Fetch Frontend Browser Logs
351299
352- ### Framework Forwarding
300+ Key params (selection):
301+ - ` project?: string ` — filter by project name
302+ - ` level?: string[] ` , ` sinceMs?: number ` , ` contains?: string `
303+ - ` session?: string ` , ` includeStack?: boolean ` , ` limit?: number `
304+ - ` autoBaseline?: boolean ` (default true)
305+ - ` stackedMode?: boolean ` (default false) — disables auto-baseline
353306
354- Framework packages (Next.js, Nuxt, etc.) can forward logs to the MCP server:
307+ Adaptive output:
308+ - If multiple projects are active and no ` project ` specified, returns grouped previews per project with counts and a tip to filter.
355309
356- ``` bash
357- # Set this in your app's environment
358- export BROWSER_ECHO_MCP_URL=http://127.0.0.1:5179/mcp
359- ```
310+ ### ` clear_logs ` — Clear Frontend Browser Logs
360311
361- When set, framework handlers automatically forward browser logs to the MCP ingest endpoint.
312+ - Supports ` project?: string ` to clear only that project’s logs.
313+ - ` scope: 'soft' | 'hard' ` for baselining vs deletion.
362314
363315---
364316
365317## Programmatic API
366318
367- Start the MCP server programmatically in your Node.js application:
368-
369- ``` typescript
319+ ``` ts
370320import { startMcpServer , publishLogEntry } from ' @browser-echo/mcp' ;
371321
372- // Start HTTP MCP server in-process
373- await startMcpServer ({
374- name: ' My App Logs' ,
375- version: ' 1.0.0' ,
376- bufferSize: 2000 ,
377- host: ' 127.0.0.1' ,
378- port: 5179 ,
379- endpoint: ' /mcp' ,
380- logsRoute: ' /__client-logs'
381- });
322+ await startMcpServer ({ host: ' 127.0.0.1' , port: 5179 , endpoint: ' /mcp' , logsRoute: ' /__client-logs' });
382323
383- // Publish log entries programmatically
384324publishLogEntry ({
385325 sessionId: ' user-123' ,
386326 level: ' error' ,
387327 text: ' Failed to fetch user data' ,
388328 time: Date .now (),
389- source: ' api.ts:42' ,
390- stack: ' Error: Failed to fetch...' ,
391- tag: ' [api]'
329+ tag: ' [api]' ,
330+ project: ' my-app'
392331});
393332```
394333
395- > ** Note:** If ` BROWSER_ECHO_MCP_URL ` is set, ` startMcpServer() ` becomes a no-op to avoid duplicate servers.
396-
397334---
398335
399336## Environment Variables
400337
401- Configure the MCP server behavior with these environment variables:
402-
403- - ` BROWSER_ECHO_MCP_URL=http://127.0.0.1:5179/mcp ` — MCP server URL for framework forwarding (if set, frameworks bypass auto-discovery)
404- - ` BROWSER_ECHO_BUFFER_SIZE=1000 ` — Max entries kept in memory (default: ` 1000 ` )
405- - ` BROWSER_ECHO_INGEST_PORT=5179 ` — Force a fixed ingest port in stdio mode (default: 5179)
406- - ` BROWSER_ECHO_SUPPRESS_TERMINAL=1 ` — Force suppress terminal output when MCP is forwarding logs
407- - ` BROWSER_ECHO_SUPPRESS_TERMINAL=0 ` — Force show terminal output even when MCP is active
408-
409- ---
410-
411- ## Common Workflows
412-
413- ### Debug Hydration Errors
414- ```
415- 1. User: "Clear logs and let me reproduce the hydration error"
416- → clear_logs({ scope: 'soft' })
417- 2. User reproduces the issue in browser
418- 3. User: "Check for hydration errors"
419- → get_logs({ level: ['error', 'warn'], contains: 'hydration' })
420- ```
421-
422- ### Monitor Specific Browser Tab
423- ```
424- 1. User: "Show me all active sessions"
425- → get_logs() // Look for unique session IDs
426- 2. User: "Focus on session starting with 'a1b2'"
427- → get_logs({ session: 'a1b2' })
428- ```
429-
430- ### Fresh Error Capture
431- ```
432- 1. clear_logs({ scope: 'soft' }) // Set baseline
433- 2. Run tests or reproduce issue
434- 3. get_logs({ level: ['error', 'warn'] }) // Only new errors
435- ```
338+ - ` BROWSER_ECHO_MCP_URL=http://127.0.0.1:5179/mcp ` — Frameworks forward logs here
339+ - ` BROWSER_ECHO_PROJECT_NAME ` — Label logs by project
340+ - ` BROWSER_ECHO_BUFFER_SIZE=1000 ` — Ring buffer size
436341
437342---
438343
439344## Security
440345
441- ** Local Development Defaults:**
442- - CORS headers are permissive (` Access-Control-Allow-Origin: * ` )
443- - Binds to ` 127.0.0.1 ` by default for local-only access
444- - When exposing over network, add authentication/proxy as needed
346+ - Binds to ` 127.0.0.1 ` by default
347+ - CORS permissive for local dev; add auth/proxy if exposing
445348
446349---
447350
0 commit comments