Crawl4AI MCP Wrapper

Crawl4AI MCP Wrapper

Enables web scraping, crawling, and content extraction through Crawl4AI Docker API. Supports markdown extraction, screenshots, PDFs, JavaScript execution, and multi-URL crawling with reliable stdio transport.

Category
访问服务器

README

Crawl4AI MCP Wrapper

Custom Model Context Protocol (MCP) server that wraps the Crawl4AI Docker API with reliable stdio transport for Claude Code integration.

Overview

This MCP wrapper provides 7 tools for web scraping, crawling, and content extraction:

  1. scrape_markdown - Extract clean markdown from webpages
  2. extract_html - Get preprocessed HTML structures
  3. capture_screenshot - Take full-page PNG screenshots
  4. generate_pdf - Create PDF documents from webpages
  5. execute_javascript - Run JavaScript in browser context
  6. crawl_urls - Crawl multiple URLs with configuration options
  7. ask_crawl4ai - Query Crawl4AI documentation and examples

Prerequisites

  • Python 3.8 or higher
  • Crawl4AI Docker container running on port 11235
  • Claude Code installed

Installation

1. Start Crawl4AI Docker Container

docker run -d -p 11235:11235 --name crawl4ai --shm-size=2g unclecode/crawl4ai:latest

Verify it's running:

curl http://localhost:11235/health

2. Set Up Virtual Environment

cd /Volumes/4TB/Users/josephmcmyne/myProjects/mcp/crawl4ai-wrapper
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

3. Test the Wrapper

python test_wrapper.py

You should see all tests pass:

✅ All tests passed! MCP wrapper is ready to use.

Configuration

For Claude Code (Project-Level)

Add to /Volumes/4TB/Users/josephmcmyne/general/.mcp.json:

{
  "mcpServers": {
    "iterm-mcp": {
      "args": ["-y", "iterm-mcp"],
      "command": "npx"
    },
    "crawl4ai-custom": {
      "command": "/Volumes/4TB/Users/josephmcmyne/myProjects/mcp/crawl4ai-wrapper/venv/bin/python",
      "args": ["/Volumes/4TB/Users/josephmcmyne/myProjects/mcp/crawl4ai-wrapper/crawl4ai_mcp.py"],
      "env": {
        "CRAWL4AI_BASE_URL": "http://localhost:11235"
      }
    }
  }
}

For Claude Code (Global)

Add to ~/.claude/claude_desktop_config.json (if this file exists):

{
  "mcpServers": {
    "crawl4ai-custom": {
      "command": "/Volumes/4TB/Users/josephmcmyne/myProjects/mcp/crawl4ai-wrapper/venv/bin/python",
      "args": ["/Volumes/4TB/Users/josephmcmyne/myProjects/mcp/crawl4ai-wrapper/crawl4ai_mcp.py"],
      "env": {
        "CRAWL4AI_BASE_URL": "http://localhost:11235"
      }
    }
  }
}

Usage

Restart Claude Code

After configuration, restart Claude Code to load the new MCP server.

Verify Connection

claude mcp list

You should see:

crawl4ai-custom: ... - ✓ Connected

Use in Claude Code

Example prompts:

Scrape the content from https://example.com and summarize it.
Take a screenshot of https://github.com
Crawl these URLs and extract their main content: https://example.com, https://example.org

Tool Reference

scrape_markdown

Extract clean markdown from a webpage.

Parameters:

  • url (required): URL to scrape
  • filter_type (optional): 'fit', 'raw', 'bm25', or 'llm' (default: 'fit')
  • query (optional): Query string for BM25/LLM filters
  • cache_bust (optional): Cache-bust counter (default: '0')

Example:

result = await scrape_markdown("https://example.com")

extract_html

Get preprocessed HTML from a webpage.

Parameters:

  • url (required): URL to extract HTML from

capture_screenshot

Capture a full-page PNG screenshot.

Parameters:

  • url (required): URL to screenshot
  • screenshot_wait_for (optional): Seconds to wait before capture (default: 2.0)
  • output_path (optional): Path to save the screenshot file

generate_pdf

Generate a PDF document from a webpage.

Parameters:

  • url (required): URL to convert to PDF
  • output_path (optional): Path to save the PDF file

execute_javascript

Run JavaScript code on a webpage.

Parameters:

  • url (required): URL to execute scripts on
  • scripts (required): List of JavaScript snippets to execute

crawl_urls

Crawl multiple URLs with configuration.

Parameters:

  • urls (required): List of 1-100 URLs to crawl
  • browser_config (optional): Browser configuration overrides
  • crawler_config (optional): Crawler configuration overrides
  • hooks (optional): Custom hook functions

ask_crawl4ai

Query Crawl4AI documentation.

Parameters:

  • query (required): Search query
  • context_type (optional): 'code', 'doc', or 'all' (default: 'all')
  • score_ratio (optional): Minimum score threshold (default: 0.5)
  • max_results (optional): Maximum results (default: 20)

Troubleshooting

Container Not Running

If tests fail with connection errors:

docker ps | grep crawl4ai

If not running, start it:

docker start crawl4ai

MCP Server Not Connecting

Check Claude Code logs:

tail -f ~/Library/Logs/Claude/mcp*.log

Verify the Python path in your .mcp.json is correct:

which python
# Should match the venv path in your config

Port Conflicts

If port 11235 is in use:

  1. Stop the Crawl4AI container: docker stop crawl4ai
  2. Find the conflicting process: lsof -i :11235
  3. Either stop that process or change the port in both Docker and this wrapper

Development

Adding New Tools

To add a new tool:

  1. Add an async function decorated with @mcp.tool() in crawl4ai_mcp.py
  2. Make an HTTP request to the appropriate Crawl4AI endpoint
  3. Add error handling
  4. Add a test in test_wrapper.py
  5. Update this README

Running in Debug Mode

# Enable debug logging
export CRAWL4AI_MCP_LOG=DEBUG

# Run the server
python crawl4ai_mcp.py

Architecture

┌─────────────────┐
│  Claude Code    │
└────────┬────────┘
         │ stdio (MCP protocol)
         ▼
┌─────────────────┐
│  FastMCP Server │ (this wrapper)
│  crawl4ai_mcp.py│
└────────┬────────┘
         │ HTTP/REST API
         ▼
┌─────────────────┐
│ Crawl4AI Docker │
│   Container     │
│  (port 11235)   │
└─────────────────┘

Benefits Over Official SSE Server

  • Reliable stdio transport: No SSE connection issues
  • Full control: Easy to extend and customize
  • Better error handling: Graceful degradation
  • Simple debugging: Standard Python stack traces
  • No protocol mismatches: Direct HTTP to Crawl4AI API

License

MIT License - feel free to modify and distribute.

Credits

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选