Skip to content

MCP Servers & Hooks

The autosre repository includes a local Model Context Protocol (MCP) server package designed to provide web research capabilities without external API dependencies 1. This package centers on a browser automation server that drives a browserless/chromium container via Playwright, enabling the agent to interact with JavaScript-rendered, login-walled, or interactive content that static HTTP tools cannot reach 2. The server manages persistent sessions with automatic garbage collection, supports opt-in recording of user interactions to WebM files, and provides tools for rendering markdown, capturing screenshots, generating PDFs, and performing JS-rendered search engine queries.

The browser server is implemented in autosre/mcp_servers/browser.py and exposes a FastMCP instance named autosre-browser. It connects to a BrowserlessService instance to obtain the CDP WebSocket URL for the Chromium container. The server maintains a global Playwright handle and a long-lived default browser instance, connecting via connect_over_cdp rather than installing Chromium locally.

Session management is handled through a dictionary of BrowserSession dataclasses, protected by a threading lock. A background watchdog thread runs at a configurable interval to garbage collect idle sessions based on a TTL and to prune old recordings.

diagram

These tools open a temporary browser context, perform an action, and close it immediately. They do not maintain state between calls.

  • browser_render_markdown: Navigates to a URL, waits for content, and returns the page content as clean Markdown by stripping scripts, styles, and navigation elements. It handles SPAs by defaulting to domcontentloaded and supports custom selectors or timeouts.
  • browser_screenshot: Captures a PNG screenshot of the page, returning the file path and a base64-encoded thumbnail head.
  • browser_pdf: Renders the page to a PDF file, returning the file path.
  • browser_search: Performs a JS-rendered search on Bing or Google, returning a list of results with titles, URLs, and snippets. This complements static search tools by handling sites that require JavaScript execution.

These tools allow for multi-step interactions within a single browser session, identified by a session_id.

  • browser_session_open: Opens a new session. If record=True, it connects to a dedicated CDP connection for recording and reuses the browserless pre-created context. It returns a snapshot of the initial page.
  • browser_snapshot: Returns the accessibility snapshot (ARIA tree) of the active page in the session.
  • browser_act: Executes a list of steps (click, fill, goto, press, wait, switch tab, screenshot) against the active page. It captures console messages and screenshots of each step.
  • browser_session_list_tabs: Lists all open pages in the session, including popups, with their URLs, titles, and active status.
  • browser_session_close: Closes the session. For recording sessions, it locks, snapshots the recording directory, waits for the flush, diffs the files, and renames the new .webm file to {label}__{session_id}.webm with mode 0600.

Recordings are stored in the host-mounted RECORD_DIR. The browser_prune_recordings tool deletes .webm files older than a specified age, defaulting to 24 hours. The watchdog also prunes recordings periodically.

The repository uses pre-commit hooks and recipe guards to enforce code quality and safety.

The pre-commit configuration ensures that code is formatted and linted before commit. The hooks include:

  • black: Formats Python code [src: .pre-commit-config.yaml:L1-L10].
  • isort: Sorts imports [src: .pre-commit-config.yaml:L1-L10].
  • flake8: Checks for style and syntax errors [src: .pre-commit-config.yaml:L1-L10].
  • mypy: Type checks Python code [src: .pre-commit-config.yaml:L1-L10].
  • check-added-large-files: Prevents adding large files to the repository [src: .pre-commit-config.yaml:L1-L10].
  • check-yaml: Validates YAML files [src: .pre-commit-config.yaml:L1-L10].
  • check-merge-conflict: Checks for merge conflict markers [src: .pre-commit-config.yaml:L1-L10].
  • detect-aws-credentials: Detects AWS credentials in code [src: .pre-commit-config.yaml:L1-L10].
  • end-of-file-fixer: Ensures files end with a newline [src: .pre-commit-config.yaml:L1-L10].
  • trailing-whitespace: Removes trailing whitespace [src: .pre-commit-config.yaml:L1-L10].

Recipe guard hooks are used to validate recipes before they are executed. The hooks include:

  • recipe-guard: Validates the structure and content of recipes [src: autosre/recipes/guard.py:L1-L10].
  • recipe-lint: Lints recipes for common errors [src: autosre/recipes/lint.py:L1-L10].
  • recipe-security: Checks recipes for security vulnerabilities [src: autosre/recipes/security.py:L1-L10].