Skip to main content

A MCP server with playwright fetch tools

Project description

playwright-mcp-fetch

Current version: 0.1.0

This tool provides a Model Context Protocol (MCP) server for fetching content from websites and converting it to different formats using Playwright.

Features

  • fetch_html: Fetch the raw HTML content from a website
  • fetch_markdown: Fetch content from a website and convert it to Markdown format
  • fetch_txt: Fetch and return plain text content from a website (HTML tags removed)
  • fetch_json: Fetch and parse JSON content

Installation

From Source

git clone https://github.com/kevinwatt/playwright-mcp-fetch.git
cd playwright-mcp-fetch
pip install -e .

Install Dependencies

pip install -r requirements.txt
# Install Playwright browsers
playwright install

Usage

Run as stdio MCP Server

playwright-mcp-fetch

Run as SSE MCP Server

# Run with the SSE transport
playwright-mcp-fetch-sse

This will start an HTTP server providing the following endpoints:

  • GET /: Server status page
  • GET /sse: SSE connection endpoint
  • POST /api/list-tools: List available tools
  • POST /api/call-tool: Call a tool

Environment Variables

  • PORT: HTTP server port (default: 3000)
  • TRANSPORT_TYPE: Transport type, either stdio or sse (default: stdio)
  • fetch_html: Whether to enable the fetch_html tool, either Enable or Disable (default: Disable)

MCP Client Configuration

To use this server in an MCP client, use the following configuration:

{
  "mcpServers": {
    "fetch-tools": {
      "enabled": true,
      "transport": "sse",
      "url": "http://localhost:3000/sse"
    }
  }
}

You can replace fetch-tools with any name you prefer, and adjust the URL according to your deployment environment.

API Examples

List Tools

curl -X POST http://localhost:3000/api/list-tools

Call a Tool

curl -X POST http://localhost:3000/api/call-tool \
  -H "Content-Type: application/json" \
  -d '{"name": "fetch_markdown", "arguments": {"url": "https://example.com"}}'

SSE Client Example

import json
import aiohttp
import asyncio

async def sse_client():
    async with aiohttp.ClientSession() as session:
        async with session.get("http://localhost:3000/sse") as response:
            async for line in response.content:
                if line.startswith(b"data: "):
                    data = json.loads(line[6:].decode("utf-8"))
                    print(f"Received event: {data}")

asyncio.run(sse_client())

Development

# Install in development mode
pip install -e .

# Run tests
pytest

Docker Support

Build and run with Docker:

docker build -t playwright-mcp-fetch .
docker run -p 3000:3000 -e TRANSPORT_TYPE=sse playwright-mcp-fetch

Or use Docker Compose:

docker-compose up -d

License

MIT

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

playwright_mcp_fetch-0.1.0.tar.gz (28.1 kB view details)

Uploaded Source

Built Distribution

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

playwright_mcp_fetch-0.1.0-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: playwright_mcp_fetch-0.1.0.tar.gz
  • Upload date:
  • Size: 28.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for playwright_mcp_fetch-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d4247d75d7375659f013f34541399644a9b32043c7a589b8447e8a37d51c9eb6
MD5 334603aead6062a6bc99f9e34c51d6f4
BLAKE2b-256 9462005b947ac775f56c93d7b571718bccbd5d8c5187423a939872a087e2dc0b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for playwright_mcp_fetch-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 901abd28ca3fef561e0f9cd52096396ce6fa0fb83fa70fb8f5119edec3922110
MD5 0d37de6a0294829bd5d1838226520719
BLAKE2b-256 8ce30a44f0458ec6107392d0395817a5175dbf15afbcb4642e4ff0cd25ff0675

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