A lightweight logging system that captures frontend console logs and makes them accessible via MCP (Model Context Protocol). Perfect for development and debugging environments with AI assistants.
The Browser Logging System consists of three main components:
- Frontend Logger (
mcp-logger.js) - Captures console logs and sends to backend - Backend Server (
logger-server.js) - Receives and stores logs from frontend - MCP Server (
mcp-server.js) - Provides MCP access to stored logs
graph TB
subgraph "Your Applications"
app1["Web App"]
app2["Mobile App"]
app3["Backend API"]
end
subgraph "Browser Logger System"
logger["Logging System"]
end
dev["Developer"]
ai["AI Assistant"]
%% Your apps send logs to the system
app1 -->|"logs"| logger
app2 -->|"logs"| logger
app3 -->|"logs"| logger
%% You interact with AI to get insights
dev -->|"asks about issues"| ai
ai -->|"fetches logs"| logger
ai -->|"provides insights"| dev
classDef yourApp fill:#e8f5e8,stroke:#2e7d32
classDef logger fill:#e1f5fe,stroke:#01579b
classDef person fill:#fff3e0,stroke:#f57c00
class app1,app2,app3 yourApp
class logger logger
class dev,ai person
How it works:
- Your applications send logs to the centralized logging system
- You ask your AI assistant about issues or problems
- AI retrieves and analyzes logs from any of your applications
- You get actionable insights back from your AI assistant
cd mcp-logger
npm install# Copy the example configuration file
cp .env.example .env
# Edit .env to customize settings (optional):
# PORT=3000
# HOST=0.0.0.0
# MAX_LOG_ENTRIES=500# Terminal 1
node logger-server.js
# Expected: ๐ Browser Logger Server running on http://localhost:22345The MCP server uses STDIO transport and is launched automatically by your LLM client:
# Show quick setup with Claude Code CLI
node mcp-server.js mcp-helpWith default app my-app (AI client will use MCP FE-logs only for app my-app):
claude mcp add FE-logs node $(pwd)/mcp-server.js \
--scope local --env FILTER_APP=my-appOr use base setup (requires app parameter in get_logs calls):
claude mcp add FE-logs node $(pwd)/mcp-server.jsTest with MCP inspector:
npx @modelcontextprotocol/inspector --cli node $(pwd)/mcp-server.js \
-e FILTER_APP=my-app --method tools/call --tool-name 'get_logs'Add this single script to your HTML file - it handles both online and offline scenarios automatically:
<script>
window.MCP_LOGGING_ENABLED = true;
window.MCP_LOGGING_APP_NAME = 'my-app'; // REQUIRED: Set your app name
window.MCP_LOGGING_BACKEND_URL = 'http://localhost:22345';
(function() {
// Try to load from server first, fallback to local file
var script = document.createElement('script');
script.src = window.MCP_LOGGING_BACKEND_URL + '/mcp-logger.js';
script.onerror = function() {
// Server is down, create a simple fallback logger
console.log('MCP Logger server offline, using local fallback');
window.logger = {
log: function(namespace, data) {
console.debug('[' + namespace + ']', data);
}
};
};
document.head.appendChild(script);
})();
</script>Use the get_logs() tool in your MCP client to retrieve logs from your frontend application.
Without FILTER_APP (requires app parameter):
get_logs(app="my-app")
get_logs(app="my-app", filter="error", lines=50)With FILTER_APP set (app parameter optional):
get_logs() // Uses default app
get_logs(filter="error", lines=50) // Uses default app
get_logs(app="other-app") // Override default appCreate a .env file from .env.example to customize your setup:
# Copy the example configuration
cp .env.example .envBackend Server Configuration:
PORT=22345 # Server port
HOST=localhost # Server host (use 0.0.0.0 for external access)
MAX_LOG_ENTRIES=500 # Max log entries per namespaceMCP Server Configuration:
BACKEND_HOST=localhost # Host where MCP server can reach backend
BACKEND_PORT=22345 # Port where MCP server can reach backend
FILTER_APP=my-app # Default app name for get_logs toolDifferent Port:
# .env file
PORT=3000
HOST=localhost
# Frontend script
window.MCP_LOGGING_BACKEND_URL = 'http://localhost:3000';External Access:
# .env file
PORT=22345
HOST=0.0.0.0
BACKEND_HOST=192.168.1.100
# Frontend script
window.MCP_LOGGING_BACKEND_URL = 'http://192.168.1.100:22345';Complete Remote Setup:
# .env file
PORT=3000
HOST=0.0.0.0
BACKEND_HOST=192.168.1.100
BACKEND_PORT=3000
FILTER_APP=dashboardMain Endpoints:
POST /api/logs/submit- Submit logs from frontendGET /api/logs/status- Get all apps, hosts, and namespacesGET /api/health- Health checkGET /- Web log viewer interfaceGET /mcp-logger.js- Frontend logger script
// All console methods are automatically captured
console.log('Application started');
console.info('User logged in');
console.warn('Deprecated API used');
console.error('Network request failed');// User interaction logging
logger.log('user-actions', {
action: 'click',
target: 'submit-button',
page: '/checkout',
timestamp: Date.now()
});
// API call logging
logger.log('api-calls', {
method: 'POST',
url: '/api/users',
status: 200,
duration: 150
});
// Error logging
logger.log('errors', {
type: 'validation',
message: 'Invalid email format',
field: 'email'
});# First argument is app name, rest is command
./shell-log.sh my-app npm run build
./shell-log.sh api-test curl -s http://api.example.com/health
./shell-log.sh markdown-ticket bash start.sh
# View logs in web interface at http://localhost:22345
# App: my-app, Namespace: npm (auto-generated from command)// Basic log retrieval
// auto-selects single host
// use app=unknown-app or defined in app=${FILTER_APP} env variable
get_logs()
// Retrieve with filtering
get_logs(filter="error", lines=10)
// Specific host and namespace
get_logs(frontend_host="localhost:3000", namespace="user-actions")Access the web interface at http://localhost:22345 when the backend server is running.
Features:
- Real-time log streaming
- Filter by text, log level, or source
- Dark/light themes
- Export logs to clipboard
- Pause/resume streaming
# Start backend and open viewer
npm run start-backend
open http://localhost:22345# Test backend health
curl http://localhost:22345/api/healthThe comprehensive Postman collection provides complete API testing coverage:
# Import the collection
1. Open Postman โ Import โ File โ sandbox/MCP-Logger-API.postman_collection.json
2. Run individual requests or use Collection Runner for bulk testing
3. View detailed guide: sandbox/POSTMAN_API_GUIDE.mdTest Coverage:
- โ System health and status endpoints
- โ Log submission (browser, application, shell formats)
- โ Log retrieval with filtering and pagination
- โ Real-time SSE streaming
- โ Frontend asset serving
- โ Load testing and concurrent requests
- โ Error handling and edge cases
Open test/test-frontend.html in your browser to test logging functionality.
// Set before loading mcp-logger.js
window.MCP_LOGGING_ENABLED = true; // Enable/disable logging
window.MCP_LOGGING_APP_NAME = 'my-app'; // REQUIRED: Your app name
window.MCP_LOGGING_BACKEND_URL = 'http://localhost:22345'; // Backend URL
window.MCP_LOGGING_BUFFER_SIZE = 100; // Log buffer sizeNote: Backend configuration is handled through the .env file (see Configuration section above).
Backend server won't start:
# Check if port is in use
lsof -i :22345
# Check .env file configuration
cat .env
# Use different port if needed
PORT=3001 node logger-server.js
# Or use environment variables directly
HOST=0.0.0.0 PORT=3001 node logger-server.jsFrontend can't connect:
# Check backend health
curl http://localhost:22345/api/healthLogs not appearing in MCP:
- Check browser console for errors
- Verify network requests are being sent to
/api/logs/submit - Ensure backend server is running
MCP tool not available:
- Verify AI Client configuration path is correct
- Check that args array contains absolute path to
mcp-server.js
This system is designed for development environments only. It uses HTTP communication and assumes trusted local networks. For production use, implement proper authentication and use HTTPS.
mcp-logger/
โโโ mcp-logger.js # Frontend logger
โโโ inject-logger.js # Auto-loading script
โโโ logger-server.js # Backend HTTP server
โโโ mcp-server.js # MCP server (STDIO transport)
โโโ shell-log.sh # Bash wrapper for shell command logging
โโโ .env.example # Example configuration
โโโ .env # Your configuration (create from .env.example)
โโโ package.json # Dependencies and scripts
โโโ openapi.yaml # OpenAPI 3.1 specification
โโโ CLAUDE.md # Claude Code project instructions
โโโ assets/ # Web viewer assets
โ โโโ log-viewer.css # Web viewer styles
โ โโโ log-viewer.js # Web viewer functionality
โโโ templates/ # HTML templates
โ โโโ log-viewer.html # Web log viewer template
โโโ docs/ # Documentation
โ โโโ SHELL_LOGGING.md # Comprehensive shell logging guide
โ โโโ CRs/ # Change requests (gitignored)
โ โโโ MCL-001-*.md # Shell logging feature
โ โโโ MCL-002-*.md # Web UI feature
โโโ sandbox/ # Non-tracked files (gitignored)
โ โโโ MCP-Logger-API.postman_collection.json # Postman API testing collection
โ โโโ POSTMAN_API_GUIDE.md # Postman collection usage guide
โ โโโ SSE_MONITORING.md # SSE monitoring guide
โ โโโ *.sh, *.html # Various test scripts and files
โโโ test/ # Test files
โ โโโ test-frontend.html # Full integration test
โ โโโ test-frontend-simulation.js # Backend test simulation
โ โโโ test-spam-protection.js # Rate limiting test
โโโ test-log-viewer.html # Standalone log viewer test
โโโ README.md # This file
Capture shell command output in real-time using nohup with process substitution.
# Usage: ./shell-log.sh app-name command [args...]
./shell-log.sh my-app npm run build
./shell-log.sh api-test curl -s http://api.example.com/health
./shell-log.sh markdown-ticket bash start.sh
# With verbose output
MCP_LOGGING_VERBOSE=true ./shell-log.sh test-app your-commandKey Features:
- First argument is the app name
- Namespace is auto-generated from command (truncated to 30 chars)
- Background process capture using nohup + process substitution
- Memory-only logging (no disk files)
- Real-time streaming to web interface
- Stdout/stderr separation with LOG/ERROR levels
Environment Variables:
MCP_LOGGING_BACKEND_URL- Backend URL (default: http://localhost:22345)MCP_LOGGING_VERBOSE- Enable debug outputHOSTNAME- Host identifier (default: system hostname)
๐ Detailed Guide: See docs/SHELL_LOGGING.md for comprehensive shell logging documentation.
This logger can be simply used from any backend system as well, just use http://localhost:22345/api/logs/submit endpoint with
POST /api/logs/submit
Content-Type: application/json
{
"app": "my-backend-app",
"host": "localhost:3000",
"logs": {
"{your namespace}": [ ]
}
}For technical support:
- Check the troubleshooting section above
- See CLAUDE.md for project setup guidance
- Create an issue with detailed information
- ๐ OpenAPI Specification: openapi.yaml - Complete OpenAPI 3.1 specification
- ๐ฎ Postman Collection: sandbox/MCP-Logger-API.postman_collection.json - Complete API testing collection
- ๐ฎ Postman Guide: sandbox/POSTMAN_API_GUIDE.md - Comprehensive Postman usage guide
- ๐ SSE Monitoring: sandbox/SSE_MONITORING.md - SSE monitoring guide
- ๐ค Claude Code Setup: CLAUDE.md - Project instructions and development guidance
- ๐ Frontend Integration: test/test-frontend.html - Full integration test
- โก Backend Simulation: test/test-frontend-simulation.js - Test backend API directly
- ๐ก๏ธ Rate Limiting: test/test-spam-protection.js - Test rate limiting functionality