Skip to content

MCP Server

PAM Crawl exposes its tools over the Model Context Protocol, so any MCP client (desktop assistants, IDE agents, command-line agents) can read pages as Markdown, follow links, extract structured data and discover URLs. You can run it locally over stdio, where the client starts the server as a child process, or share one server over HTTP.

Start the server on stdin and stdout:

Terminal window
pam crawl mcp # inside a PAM project (pam.json) or with the global CLI
pam vendor/bin/crawl mcp # in any project that requires pushinbr/pam-crawl

Then register it with your client. Most clients read an mcpServers block like this:

mcp.json
{
"mcpServers": {
"crawl": { "command": "pam", "args": ["crawl", "mcp"] }
}
}

Use absolute paths when the client does not start in your project directory. The env block is optional; it configures the LLM used by the ask tool.

The server reads one JSON-RPC message per line, so you can drive it from a file:

session.jsonl
{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"cli","version":"1.0"}}}
{"jsonrpc":"2.0","method":"notifications/initialized"}
{"jsonrpc":"2.0","id":2,"method":"tools/list"}
{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"md","arguments":{"url":"https://example.com"}}}
Terminal window
pam vendor/bin/crawl mcp < session.jsonl

You get one JSON-RPC response per line: the server info, the tool list and the Markdown of the page. The package ships a ready-made session in vendor/pushinbr/pam-crawl/examples/mcp/.

Tool Arguments Result
md url, f (fit, raw, bm25, pruning, llm; default fit), q Clean Markdown
html url Cleaned, schema-ready HTML
crawl urls (1 to 100), output (fit, markdown, json), max_pages, depth, only, options Markdown per page; max_pages turns on a same-site deep crawl
links url, internal_only Internal and external links
extract url, schema JSON from a Crawl4AI CSS/XPath schema
seed domain, limit (default 200), pattern URLs from sitemaps and Common Crawl, without crawling them
ask url, question An answer from the configured LLM
screenshot url, screenshot_wait_for (seconds, default 2), wait_for_images PNG image content
pdf url Embedded PDF resource
execute_js url, scripts (1 to 50) Script results plus the page Markdown

screenshot, pdf and execute_js need the browser plugin. Without it they stay listed and return an error result with the install hint, so the assistant can tell you what is missing. The options argument of crawl accepts the same keys as pam crawl options and Crawl4AI crawler_config names.

Start the HTTP API and point clients at one of its MCP transports:

Transport Endpoint Notes
Streamable HTTP POST /mcp JSON responses; Mcp-Session-Id is returned on initialize
HTTP+SSE (legacy, Crawl4AI’s) GET /mcp/sse, then POST /mcp/messages/?session_id=... The stream first sends an endpoint event, then every response as a message event; POSTs answer 202
WebSocket GET /mcp/ws Not available (501)
mcp.json
{
"mcpServers": {
"crawl-http": { "type": "http", "url": "http://127.0.0.1:11235/mcp" },
"crawl-sse": { "type": "sse", "url": "http://127.0.0.1:11235/mcp/sse" }
}
}

If the server runs with --token or CRAWL_API_TOKEN, add "headers": {"Authorization": "Bearer <token>"} to each entry. You can call a tool with curl to check the setup:

Terminal window
curl -s -X POST http://127.0.0.1:11235/mcp \
-H 'content-type: application/json' -H 'accept: application/json, text/event-stream' \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"md","arguments":{"url":"https://example.com"}}}'

SSE sessions are file-backed queues in CRAWL_STATE_DIR/mcp, so a POST may land on any PAM worker. They are bounded by these variables:

Variable Default Meaning
CRAWL_MCP_MAX_SESSIONS 64 Open SSE sessions
CRAWL_MCP_MAX_QUEUED 256 Queued messages per session
CRAWL_MCP_SSE_TTL 900 Seconds a stream may stay open

A session whose stream stops polling for 30 seconds is pruned. The stream waits with Pam\Async\delay, so a single PAM worker serves the stream and the POST requests concurrently. On plain PHP, use PHP-FPM or PHP_CLI_SERVER_WORKERS=2 (or more) with php -S.

Set CRAWL_MCP=0 to disable every MCP endpoint on the HTTP server.

The PAM runtime supports RFC 6455 WebSockets, but it upgrades connections only on its own /ws route and frames every message in its event envelope. MCP’s WebSocket transport sends raw JSON-RPC frames on a path of its choosing. Until the runtime can hand raw frames to PHP, the streamable HTTP and SSE transports cover every MCP client.


This product includes software developed by UncleCode (https://x.com/unclecode) as part of the Crawl4AI project (https://github.com/unclecode/crawl4ai).