Mass ruff auto-fix:
- ruff check --fix: 109 issues fixed (F401 unused imports,
I001 unsorted imports, UP037 quoted annotations, SIM105
suppressible exception, RUF100 unused-noqa)
- ruff check --fix --unsafe-fixes: 22 additional issues
- ruff format: 70 files reformatted
- Manual pass: fix 16 misplaced import httpx lines
- Manual pass: fix remaining E402 (import-after-docstring)
Result: 283 errors -> 30 errors.
The remaining 30 are real issues that need manual review:
5 F401 unused-import (likely auto-generated stubs)
5 F821 undefined-name (real bugs in code that references
redis/pydantic/LLMRegistry without imports)
3 BLE001 (the compliance LLM fallback is intentional; the
other two are real)
3 RUF012 mutable-class-default
3 SIM105, 3 SIM117, 2 E722, 2 E741
1 B007, 1 B025, 1 E402, 1 RUF200 (pyproject.toml issue)
Tests: 436/437 pass (1 pre-existing SSE sandbox failure).
format check + import sort: now clean.
make ci: still gated on the 30 remaining real issues.
Follow-up: triage the 30 issues file-by-file.
131 lines
4.9 KiB
Python
131 lines
4.9 KiB
Python
"""Pry MCP Server — expose scrape, crawl, automate as MCP tools.
|
|
Enables any MCP-compatible AI agent (Claude, Hermes, Cursor) to use Pry."""
|
|
|
|
# SPDX-License-Identifier: MIT
|
|
# Copyright (c) 2026 Rug Munch Media LLC
|
|
#
|
|
# Part of Pry — https://git.rugmunch.io/RugMunchMedia/pryscraper
|
|
# Licensed under MIT. See LICENSE.
|
|
|
|
import httpx
|
|
|
|
|
|
class PryMCPServer:
|
|
"""MCP server exposing Pry as tools for AI agents.
|
|
|
|
Implements the Model Context Protocol (MCP) for tool discovery.
|
|
"""
|
|
|
|
def __init__(self, base_url: str = "http://localhost:8002"):
|
|
self.base_url = base_url
|
|
self._client = httpx.Client(timeout=60)
|
|
|
|
def list_tools(self) -> list[dict]:
|
|
"""MCP tool discovery — returns available tools."""
|
|
return [
|
|
{
|
|
"name": "pry_scrape",
|
|
"description": "Scrape a URL to clean markdown. Bypasses Cloudflare automatically.",
|
|
"inputSchema": {
|
|
"type": "object",
|
|
"properties": {
|
|
"url": {"type": "string", "description": "URL to scrape"},
|
|
"timeout": {
|
|
"type": "integer",
|
|
"description": "Timeout in seconds",
|
|
"default": 30,
|
|
},
|
|
},
|
|
"required": ["url"],
|
|
},
|
|
},
|
|
{
|
|
"name": "pry_crawl",
|
|
"description": "Crawl multiple pages from a starting URL.",
|
|
"inputSchema": {
|
|
"type": "object",
|
|
"properties": {
|
|
"url": {"type": "string", "description": "Starting URL"},
|
|
"maxPages": {"type": "integer", "description": "Max pages", "default": 10},
|
|
},
|
|
"required": ["url"],
|
|
},
|
|
},
|
|
{
|
|
"name": "pry_map",
|
|
"description": "Discover all URLs on a website.",
|
|
"inputSchema": {
|
|
"type": "object",
|
|
"properties": {
|
|
"url": {"type": "string", "description": "Site URL"},
|
|
"limit": {"type": "integer", "description": "Max links", "default": 50},
|
|
},
|
|
"required": ["url"],
|
|
},
|
|
},
|
|
{
|
|
"name": "pry_parse",
|
|
"description": "Parse a document (PDF, DOCX, image) to text.",
|
|
"inputSchema": {
|
|
"type": "object",
|
|
"properties": {
|
|
"url": {"type": "string", "description": "Document URL"},
|
|
},
|
|
"required": ["url"],
|
|
},
|
|
},
|
|
{
|
|
"name": "pry_screenshot",
|
|
"description": "Take a screenshot of a URL.",
|
|
"inputSchema": {
|
|
"type": "object",
|
|
"properties": {
|
|
"url": {"type": "string", "description": "URL to screenshot"},
|
|
},
|
|
"required": ["url"],
|
|
},
|
|
},
|
|
{
|
|
"name": "pry_automate",
|
|
"description": "Execute browser automation steps (navigate, click, type, extract). Login automation, form filling.",
|
|
"inputSchema": {
|
|
"type": "object",
|
|
"properties": {
|
|
"steps": {
|
|
"type": "array",
|
|
"items": {"type": "object"},
|
|
"description": "List of automation steps. Each step: {action, selector?, value?, url?}",
|
|
}
|
|
},
|
|
"required": ["steps"],
|
|
},
|
|
},
|
|
]
|
|
|
|
async def call_tool(self, name: str, arguments: dict) -> dict:
|
|
"""Execute an MCP tool call."""
|
|
tool_map = {
|
|
"pry_scrape": (
|
|
"/v1/scrape",
|
|
{"url": arguments["url"], "timeout": arguments.get("timeout", 30)},
|
|
),
|
|
"pry_crawl": (
|
|
"/v1/crawl",
|
|
{"url": arguments["url"], "maxPages": arguments.get("maxPages", 10)},
|
|
),
|
|
"pry_map": (
|
|
"/v1/map",
|
|
{"url": arguments["url"], "limit": arguments.get("limit", 50)},
|
|
),
|
|
"pry_parse": ("/v1/parse", {"url": arguments["url"]}),
|
|
"pry_screenshot": ("/v1/screenshot", {"url": arguments["url"]}),
|
|
"pry_automate": ("/v1/automate", {"steps": arguments["steps"]}),
|
|
}
|
|
|
|
if name not in tool_map:
|
|
return {"error": f"Unknown tool: {name}"}
|
|
|
|
path, payload = tool_map[name]
|
|
async with httpx.AsyncClient(timeout=120) as client:
|
|
resp = await client.post(f"{self.base_url}{path}", json=payload)
|
|
return resp.json()
|