MCP-Tools
README.md
# š MCP-Tools: Advanced Browser Automation & Web Analysis
> **Enterprise-grade browser automation platform with W3C WebDriver BiDi, network interception, and comprehensive web analysis**
A powerful collection of Model Context Protocol (MCP) tools for advanced browser automation, web analysis, and development workflows. Built with Node.js, Docker, and cutting-edge web technologies including the latest W3C standards.
## ⨠Features
### š **Advanced Screenshot Capabilities**
- **HTTPS Support**: Handle self-signed certificates automatically
- **Full Page Rendering**: Capture complete web pages with dynamic content
- **Custom Viewports**: Support for desktop, mobile, and tablet resolutions
- **Direct URL Access**: No browser navigation required
- **Multi-Format Support**: PNG, JPEG, WebP, and PDF output
### š **Lighthouse Integration**
- **Performance Audits**: Detailed performance metrics and optimization suggestions
- **Accessibility Testing**: WCAG compliance and accessibility analysis
- **SEO Analysis**: Meta tags, structured data, and SEO optimization
- **Best Practices**: Security, performance, and coding standards
- **Core Web Vitals**: FCP, LCP, FID, CLS, and TTI metrics
### š§ **Development Tools**
- **Console Monitoring**: Real-time console logs and error tracking
- **Network Analysis**: Request/response monitoring and debugging
- **Enhanced Element Interactions**: Advanced locator-based interactions with automatic waiting
- **Advanced Selectors**: Text, ARIA, and Shadow DOM selectors
- **Form Automation**: Multi-field form filling with validation
- **Keyboard & Mouse Control**: Precise input and click interactions
- **JavaScript Execution**: Execute JavaScript in page context with full DOM access
- **Element Script Execution**: Run scripts on specific elements or element collections
- **Script Injection**: Inject and execute custom scripts with page context access
- **Network Interception**: Intercept, block, modify, and mock network requests
- **Request/Response Monitoring**: Real-time network traffic analysis
- **WebDriver BiDi**: W3C-standard bidirectional browser automation protocol
- **Real-time Events**: Live browsing context and script events
- **Responsive Testing**: Cross-device compatibility validation
### š³ **Docker Integration**
- **Containerized Environment**: Consistent deployment across platforms
- **HTTPS Support**: Built-in SSL certificate generation
- **Easy Setup**: One-command deployment with Docker Compose
- **Resource Management**: Configurable memory and CPU limits
- **Health Monitoring**: Built-in health checks and monitoring
## šļø Project Structure
```
MCP-Tools/
āāā src/ # Source code
ā āāā mcp-server/ # MCP server implementation
ā ā āāā mcp-server.ts # Main MCP server
ā ā āāā package.json # MCP server dependencies
ā ā āāā dist/ # Compiled JavaScript
ā āāā http-server/ # HTTP API server
ā ā āāā browser-connector-extended.js
ā ā āāā package.json # HTTP server dependencies
ā ā āāā secure-server.ts # HTTPS support
ā āāā services/ # Core services
ā ā āāā chromium-screenshot-service.js
ā ā āāā lighthouse-service.js
ā ā āāā enhanced-interaction-service.js
ā ā āāā javascript-execution-service.js
ā ā āāā network-interception-service.js
ā ā āāā webdriver-bidi-service.js
ā āāā utils/ # Utilities
āāā docs/ # Comprehensive documentation
āāā tests/ # Test files and examples
āāā scripts/ # Build and utility scripts
āāā docker/ # Docker configuration
āāā examples/ # Usage examples
āāā config/ # Configuration files
```
## š Quick Start
### Prerequisites
- Docker and Docker Compose
- Node.js 18+ (for local development)
- Git
### Installation
1. **Clone the repository**
```bash
git clone https://github.com/zachshallbetter/MCP-Tools.git
cd MCP-Tools
```
2. **Install dependencies and build**
```bash
npm install
npm run build
```
3. **Start with Docker**
```bash
npm run start
# or
cd docker && docker-compose up -d
```
4. **Verify installation**
```bash
curl http://localhost:3025/.identity
```
### MCP Configuration
Add to your MCP configuration (e.g., `~/.cursor/mcp.json`):
```json
{
"mcpServers": {
"browser-tools": {
"command": "node",
"args": [
"/path/to/MCP-Tools/src/mcp-server/dist/mcp-server.js"
],
"env": {}
}
}
}
```
## š Usage Examples
### Screenshots
```bash
# Take a screenshot of any website
curl -X POST http://localhost:3025/capture-screenshot \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com", "fullPage": true}'
# Mobile viewport screenshot
curl -X POST http://localhost:3025/capture-screenshot \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com", "viewport": {"width": 375, "height": 667}}'
```
### Lighthouse Audits
```bash
# Run comprehensive Lighthouse audit
curl -X POST http://localhost:3025/lighthouse-audit \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com", "categories": ["performance", "accessibility"]}'
# Mobile performance analysis
curl -X POST http://localhost:3025/analyze-performance \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com", "device": "mobile"}'
```
### Enhanced Element Interactions
```bash
# Click element with automatic waiting
curl -X POST http://localhost:3025/interact/click \
-H "Content-Type: application/json" \
-d '{"selector": "button[type=\"submit\"]", "url": "https://example.com"}'
# Fill form with multiple fields
curl -X POST http://localhost:3025/interact/fill-form \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com", "formData": {"input[name=\"email\"]": "user@example.com", "input[name=\"password\"]": "password123"}}'
# Find element by text content
curl -X POST http://localhost:3025/interact/text-selector \
-H "Content-Type: application/json" \
-d '{"text": "Submit Form", "url": "https://example.com"}'
```
### JavaScript Execution
```bash
# Execute JavaScript in page context
curl -X POST http://localhost:3025/js/evaluate \
-H "Content-Type: application/json" \
-d '{"script": "return document.title;", "url": "https://example.com"}'
# Execute function with arguments
curl -X POST http://localhost:3025/js/execute-function \
-H "Content-Type: application/json" \
-d '{"functionBody": "return arg0 + arg1;", "args": [5, 10]}'
# Execute script on specific element
curl -X POST http://localhost:3025/js/execute-on-element \
-H "Content-Type: application/json" \
-d '{"selector": "input[name=\"email\"]", "script": "return this.value;"}'
```
### Network Interception
```bash
# Enable network interception
curl -X POST http://localhost:3025/network/enable-interception \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com"}'
# Block image and analytics requests
curl -X POST http://localhost:3025/network/block-requests \
-H "Content-Type: application/json" \
-d '{"patterns": [".png", ".jpg", "analytics"], "reason": "performance optimization"}'
# Mock API response
curl -X POST http://localhost:3025/network/mock-response \
-H "Content-Type: application/json" \
-d '{"urlPattern": "/api/users", "mockData": {"status": 200, "body": {"users": [{"id": 1, "name": "John"}]}}}'
```
### WebDriver BiDi (W3C Standard)
```bash
# Connect to WebDriver BiDi
curl -X POST http://localhost:3025/bidi/connect \
-H "Content-Type: application/json"
# Create browsing context
curl -X POST http://localhost:3025/bidi/create-context \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com"}'
# Navigate via BiDi
curl -X POST http://localhost:3025/bidi/navigate \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com"}'
# Take screenshot via BiDi
curl -X POST http://localhost:3025/bidi/screenshot \
-H "Content-Type: application/json"
# Evaluate script via BiDi
curl -X POST http://localhost:3025/bidi/evaluate \
-H "Content-Type: application/json" \
-d '{"script": "return document.title;", "awaitPromise": true}'
```
## š§ Development
### Available Scripts
```bash
# Build all components
npm run build
# Build specific components
npm run build:mcp # Build MCP server
npm run build:http # Build HTTP server
# Start services
npm run start # Start with Docker
npm run stop # Stop Docker services
# Development mode
npm run dev # Build and start
# Testing
npm run test # Run all tests
npm run test:api # Test API endpoints
npm run test:mcp # Test MCP tools
# Docker management
npm run docker:build # Build Docker image
npm run docker:up # Start Docker services
npm run docker:down # Stop Docker services
npm run docker:logs # View Docker logs
# Cleanup
npm run clean # Remove build artifacts
```
### Local Development
```bash
# Install dependencies
npm install
# Build MCP server
cd src/mcp-server && npm run build
# Start HTTP server
cd src/http-server && npm start
```
### Docker Development
```bash
# Build and start
cd docker && docker-compose up --build
# View logs
cd docker && docker-compose logs -f
# Access container
docker exec -it browser-tools-mcp-dev bash
```
## š Documentation
### **Getting Started**
- **[š Getting Started Guide](docs/getting-started.md)** - Complete setup and configuration
- **[š³ Docker Guide](docs/docker-guide.md)** - Containerization and deployment
- **[š§ Troubleshooting](docs/troubleshooting.md)** - Common issues and solutions
### **Reference Documentation**
- **[š API Reference](docs/api-reference.md)** - Complete API documentation
- **[⨠Features Guide](docs/features.md)** - Detailed feature overview
### **Project Overview**
- **[š Main README](README.md)** - Project overview and quick start
- **[š¦ Repository](https://github.com/zachshallbetter/MCP-Tools)** - Source code and issues
## š Advanced Features
### **Enhanced Element Interactions (Inspired by [Puppeteer](https://pptr.dev/guides/page-interactions))**
- **Automatic Waiting**: Elements are automatically waited for with proper state validation
- **Stability Checks**: Bounding box stability over animation frames
- **Viewport Positioning**: Automatic scrolling to bring elements into view
- **State Validation**: Ensures elements are visible, enabled, and ready for interaction
### **JavaScript Execution (Inspired by [Puppeteer JavaScript Execution](https://pptr.dev/guides/javascript-execution))**
- **Page Context Execution**: Execute JavaScript directly in the page context with full DOM access
- **Handle Management**: Work with JSHandle and ElementHandle for complex object manipulation
- **Function Execution**: Execute custom functions with argument passing and return value handling
- **Element-Specific Scripts**: Run scripts on specific elements or element collections
- **Promise Support**: Handle asynchronous operations and promises with automatic awaiting
- **Script Injection**: Inject and execute custom scripts with full page context access
### **Network Interception (Inspired by [Puppeteer Network Interception](https://pptr.dev/guides/network-interception))**
- **Request Interception**: Intercept and control every network request before it's made
- **Cooperative Intercept Mode**: Multiple handlers working together with priority-based resolution
- **Request Blocking**: Block requests by URL patterns, resource types, or custom criteria
- **Header Modification**: Modify request headers for authentication, testing, or debugging
- **Response Mocking**: Mock API responses for testing and development
- **Request Throttling**: Simulate slow network conditions and test performance
### **WebDriver BiDi (W3C Standard - [Specification](https://w3c.github.io/webdriver-bidi/))**
- **Bidirectional Communication**: Real-time two-way communication with the browser
- **W3C Standard**: Industry-standard protocol for browser automation
- **Browsing Context Management**: Create, navigate, and manage browser contexts
- **Real-time Events**: Live subscription to browsing context and script events
- **Script Execution**: Execute scripts in sandboxed realms with full context access
- **Node Location**: Locate DOM nodes using CSS selectors with BiDi protocol
- **Preload Scripts**: Inject scripts that run before page load
- **Session Management**: Full session lifecycle management with proper cleanup
## š Security & HTTPS
### HTTPS Support
```bash
# Enable HTTPS
export ENABLE_HTTPS=true
npm run start
# Generate certificates
cd src/http-server
node generate-certs.js
# Test HTTPS endpoint
curl -k https://localhost:3026/.identity
```
### Security Features
- **Self-signed Certificate Generation**: Automatic SSL certificate creation
- **TLS 1.2+ Support**: Modern encryption standards
- **Request Validation**: Input sanitization and validation
- **Rate Limiting**: Configurable request rate limiting
- **Access Control**: IP whitelisting and authentication support
## š Monitoring & Performance
### Health Checks
```bash
# Service health
curl http://localhost:3025/.identity
# Container status
cd docker && docker-compose ps
# Resource usage
docker stats browser-tools-mcp-dev
```
### Performance Optimization
- **Headless Browser**: Resource-efficient operation
- **Connection Pooling**: HTTP connection reuse
- **Memory Management**: Efficient memory usage and cleanup
- **Request Batching**: Multiple operations in single requests
## š§ Configuration
### Environment Variables
```bash
# Server configuration
PORT=3025
ENABLE_HTTPS=true
CERT_DIR=/app/certs
CHROMIUM_PATH=/usr/bin/chromium
# Development mode
NODE_ENV=development
DEBUG=browser-tools:*
LOG_LEVEL=debug
```
### Docker Configuration
```yaml
# docker/docker-compose.yml
version: '3.8'
services:
browser-tools-mcp-dev:
build:
context: ..
dockerfile: docker/Dockerfile
ports:
- "3025:3025" # HTTP
- "3026:3026" # HTTPS
environment:
- ENABLE_HTTPS=true
- PORT=3025
volumes:
- ../src:/app/src
- ../certs:/app/certs
```
## š¤ Contributing
1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request
### Development Guidelines
- **Code Style**: Follow existing code patterns and ESLint rules
- **Testing**: Include tests for new features
- **Documentation**: Update relevant documentation
- **TypeScript**: Use TypeScript for new features when possible
## š License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## š Acknowledgments
- **Model Context Protocol**: For the MCP framework
- **Puppeteer**: For browser automation capabilities and advanced interaction patterns
- **Lighthouse**: For web analysis and auditing
- **W3C WebDriver BiDi**: For the bidirectional protocol specification
- **Docker**: For containerization and deployment
## š Support
- **Issues**: [GitHub Issues](https://github.com/zachshallbetter/MCP-Tools/issues)
- **Documentation**: [Wiki](https://github.com/zachshallbetter/MCP-Tools/wiki)
- **Discussions**: [GitHub Discussions](https://github.com/zachshallbetter/MCP-Tools/discussions)
- **Community**: [MCP Community](https://modelcontextprotocol.io/)
## š Roadmap
### **Upcoming Features**
- **Multi-Browser Support**: Firefox, Safari, and Edge automation
- **Cloud Deployment**: AWS, Azure, and Google Cloud integration
- **CI/CD Integration**: GitHub Actions, Jenkins, and GitLab CI
- **Advanced Analytics**: Performance metrics and trend analysis
- **Plugin System**: Extensible architecture for custom tools
### **Performance Improvements**
- **Parallel Processing**: Concurrent browser automation
- **Resource Optimization**: Memory and CPU usage optimization
- **Caching System**: Intelligent response caching
- **Load Balancing**: Horizontal scaling and distribution
---
**MCP-Tools: The most comprehensive browser automation platform for professional web development and testing workflows! š**
*Built with ā¤ļø for the MCP community*
This server cannot be deployed
Maintenance
ActivityInactive
ResponsivenessNo recent community issues