Skip to main content

A Model Context Protocol (MCP) server that provides comprehensive website snapshot capabilities using Playwright for LLM integration

Project description

MCP Web Snapshot

A Model Context Protocol (MCP) server that provides comprehensive website snapshot capabilities using Playwright. This server enables LLMs to capture and analyze web pages through structured accessibility snapshots, network monitoring, and console message collection.

Key Features

  • ๐Ÿš€ Fast and lightweight: Uses Playwright's accessibility tree for efficient snapshots
  • ๐ŸŽฏ LLM-optimized: Structured data output designed specifically for AI consumption
  • ๐Ÿ“Š Comprehensive monitoring: Captures network requests, responses, and console messages
  • ๐Ÿ” Element references: Adds unique identifiers to interactive elements for precise targeting
  • ๐Ÿ›ก๏ธ Production-ready: Built-in error handling, resource limits, and timeout management
  • โœ… Well-tested: Comprehensive test suite with code coverage

Requirements

  • Python 3.11 or newer
  • VS Code, Cursor, Windsurf, Claude Desktop or any other MCP client

Getting Started

First, install the MCP Web Snapshot server with your client. A typical configuration looks like this:

{
  "mcpServers": {
    "mcp-web-snapshot": {
      "command": "uv",
      "args": [
        "--directory",
        "/path/to/mcp-web-snapshot",
        "run",
        "python",
        "src/server.py"
      ]
    }
  }
}

Install in VS Code

You can install the MCP Web Snapshot server using the VS Code CLI:

# For VS Code
code --add-mcp '{"name":"mcp-web-snapshot","command":"uv","args":["--directory","/path/to/mcp-web-snapshot","run","python","src/server.py"]}'

After installation, the MCP Web Snapshot server will be available for use with your GitHub Copilot agent in VS Code.

Install in Cursor

Go to Cursor Settings โ†’ MCP โ†’ Add new MCP Server. Name to your liking, use command type with the command uv and args ["--directory", "/path/to/mcp-web-snapshot", "run", "python", "src/server.py"].

{
  "mcpServers": {
    "mcp-web-snapshot": {
      "command": "uv",
      "args": [
        "--directory",
        "/path/to/mcp-web-snapshot",
        "run",
        "python",
        "src/server.py"
      ]
    }
  }
}

Development Setup

Local Installation

  1. Clone this repository:
git clone https://github.com/your-username/mcp-web-snapshot.git
cd mcp-web-snapshot
  1. Install dependencies using uv:
uv sync
  1. Install Playwright browsers:
uv run playwright install
  1. Run the server:
uv run python src/server.py

Project Structure

โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ server.py               # Main MCP server entry point
โ”‚   โ”œโ”€โ”€ registry.py             # Tool registration logic
โ”‚   โ””โ”€โ”€ tools/
โ”‚       โ”œโ”€โ”€ __init__.py
โ”‚       โ””โ”€โ”€ snapshot_url.py     # Web snapshot implementation
โ”œโ”€โ”€ tests/                      # Test suite
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ test_snapshot_url.py    # Unit tests for website_snapshot
โ”‚   โ””โ”€โ”€ README.md               # Test documentation
โ”œโ”€โ”€ pyproject.toml              # Project configuration
โ”œโ”€โ”€ pytest.ini                  # Pytest configuration
โ”œโ”€โ”€ uv.lock                     # Lock file for dependencies
โ””โ”€โ”€ README.md                   # This file

Testing

The project includes a comprehensive test suite using pytest:

# Run all tests
uv run pytest

# Run with verbose output
uv run pytest -v

# Run with coverage report
PYTHONPATH=. uv run pytest --cov=src.tools.snapshot_url --cov-report=term-missing

Test coverage currently stands at 92%, covering:

  • Successful snapshot capture and formatting
  • Network request and console message monitoring
  • URL validation
  • Error handling and recovery

Available Tools

Website Snapshot

Tool: website_snapshot

Description: Take comprehensive snapshots of web pages with monitoring capabilities

Parameters:

  • target_url (string): The URL to capture (must be a valid URL with protocol)

Features:

  • ๐ŸŽญ Accessibility Snapshot: Captures the complete accessibility tree structure
  • ๐ŸŒ Network Monitoring: Records all network requests and responses during page load
  • ๐Ÿ–ฅ๏ธ Console Messages: Captures client-side console output (logs, warnings, errors)
  • ๐ŸŽฏ Element References: Adds unique reference IDs to interactive elements
  • ๐Ÿ“Š Performance Metrics: Provides summary of captured elements and network activity

Example Usage:

# Through MCP client
result = await website_snapshot("https://example.com")

Output Structure:

โœ… Captured snapshot with 25 elements, 12 requests, 0 console messages
๐Ÿ” Example Website - Home Page
๐Ÿ“ https://example.com

๐ŸŽญ Accessibility Snapshot:
- navigation "Main":
  - link "Home": [ref=1]
  - link "About": [ref=2]
  - button "Contact" [ref=3]
- main:
  - heading "Welcome to Example"
  - link "Get Started": [ref=4]

๐ŸŒ Network Requests:
๐ŸŒ GET https://example.com
   Status: 200
   Response: <!DOCTYPE html><html>...

๐Ÿ–ฅ๏ธ Console:
No console messages

๐ŸŽฏ Element References:
[ref=1]: link "Home"
[ref=2]: link "About"
[ref=3]: button "Contact"
[ref=4]: link "Get Started"

Configuration

The server can be configured through the CONFIG dictionary in src/tools/snapshot_url.py:

CONFIG = {
    "viewport": {"width": 1920, "height": 1080},
    "user_agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36",
    "timeout": 15000,  # 15 seconds
}

Customization Options

  • Viewport Size: Adjust browser window dimensions
  • User Agent: Customize browser identification
  • Timeout: Control maximum wait time for page operations
  • Content Filtering: Modify response body size limits and content type filters

Use Cases

LLM-Guided Testing

Capture comprehensive page state for automated test generation:

"Please take a snapshot of https://myapp.com/login and help me create Page Object Model classes based on the discovered elements and structure."

Web Content Analysis

Extract structured data for content analysis and monitoring:

"Take a snapshot of https://competitor.com/pricing and analyze any pricing changes or new features compared to what we discussed last week."

Accessibility Auditing

Leverage accessibility tree data for compliance checking:

"Please capture a snapshot of https://myapp.com and identify any accessibility issues or areas for improvement based on WCAG guidelines."

API Integration Analysis

Monitor network activity to understand application behavior:

"Take a snapshot of https://dashboard.example.com after I log in and show me what API calls are being made so I can understand the data flow."

Cross-Browser Testing Setup

Generate test scenarios based on captured interactions:

"Snapshot https://myapp.com/checkout and help me create comprehensive test cases that cover all the interactive elements and user workflows."

Error Handling

The server includes comprehensive error handling:

  • Invalid URLs: Returns helpful error messages for malformed URLs
  • Network Timeouts: Configurable timeout limits with graceful fallbacks
  • Browser Crashes: Automatic cleanup and resource management
  • Content Limits: Smart filtering of large response bodies to prevent memory issues

Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature-name
  3. Make your changes and add tests
  4. Run tests: uv run pytest
  5. Check test coverage: PYTHONPATH=. uv run pytest --cov=src.tools.snapshot_url --cov-report=term-missing
  6. Ensure code style compliance: uv run ruff check
  7. Submit a pull request

Please ensure all tests pass and maintain or improve the current test coverage.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

Related Projects

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file iflow_mcp_gustavo_meilus_mcp_web_snapshot-0.1.0.tar.gz.

File metadata

  • Download URL: iflow_mcp_gustavo_meilus_mcp_web_snapshot-0.1.0.tar.gz
  • Upload date:
  • Size: 49.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.30 {"installer":{"name":"uv","version":"0.9.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for iflow_mcp_gustavo_meilus_mcp_web_snapshot-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4e163ac02b3413d972f4eda387fdf099962fe1b57914e87153400209d56d9e92
MD5 63c17acd81021de982daac8bc4a17196
BLAKE2b-256 14271d14ced73b8a2e3c27c3cb1731fab3ff0e6067f28bf4b84f46a69640c67a

See more details on using hashes here.

File details

Details for the file iflow_mcp_gustavo_meilus_mcp_web_snapshot-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: iflow_mcp_gustavo_meilus_mcp_web_snapshot-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.30 {"installer":{"name":"uv","version":"0.9.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for iflow_mcp_gustavo_meilus_mcp_web_snapshot-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ef17c11921efede59fca82996c1e307f0c24d212dfdf2488634086ac8f8ffe5b
MD5 e0307c7d35a6572206d962a9ec21faf8
BLAKE2b-256 e24457ee4e459cbe60386c56169eeedc6d030325b892981b1fa352b63e29c3ef

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page