Metadata-Version: 2.4
Name: playwright-mcp-fetch
Version: 0.1.5
Summary: A MCP server with playwright fetch tools
Author-email: Dewei Yen <k@funmula.com>
License: MIT
License-File: LICENSE
Requires-Python: >=3.10
Requires-Dist: aiohttp>=3.9.0
Requires-Dist: beautifulsoup4>=4.12.0
Requires-Dist: fastapi>=0.104.0
Requires-Dist: html2text>=2024.2.26
Requires-Dist: mcp>=1.4.1
Requires-Dist: playwright>=1.40.0
Requires-Dist: pydantic>=2.0.0
Requires-Dist: python-dotenv>=1.0.0
Requires-Dist: sse-starlette>=1.6.5
Requires-Dist: uvicorn>=0.24.0
Description-Content-Type: text/markdown

# playwright-mcp-fetch

**Current version: 0.1.5**

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

## Requirements

- Python 3.10 or higher

## 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

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

### Install Dependencies

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

## Usage

### Run as stdio MCP Server

```bash
playwright-mcp-fetch
```

### Run as SSE MCP Server

```bash
# 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:

### SSE Transport

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

### stdio Transport

```json
{
  "mcpServers": {
    "fetch-tools": {
      "enabled": true,
      "transport": "stdio",
      "command": "uvx",
      "args": ["playwright-mcp-fetch"]
    }
  }
}
```

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

## API Examples

### List Tools

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

### Call a Tool

```bash
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

```python
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

```bash
# Install in development mode
pip install -e .

# Run tests
pytest
```

## Docker Support

Build and run with Docker:

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

Or use Docker Compose:

```bash
docker-compose up -d
```

## License

MIT
