SnapRef

SnapRef

Policy-gated MCP server for local-first browser automation, enabling agents to drive isolated Chromium sessions via snapshots, revision-bound refs, typed actuation, scripts, and telemetry receipts.

Category
访问服务器

README

SnapRef

ci

SnapRef is a dependency-light, local-first browser automation core for agents: isolated sessions, interactive snapshots with revision-bound executable refs, typed actuation/assertion, scripts, policy-gated MCP, telemetry receipts, and cross-platform lifecycle gates.

go install github.com/nstranquist/snapref/cmd/snapref@v0.2.0-rc.1
snapref runtime install --runtime chrome-for-testing --channel stable
snapref runtime install --runtime headless-shell --channel stable
snapref self-test
snapref demo mcp-policy
snapref demo ref-integrity

self-test checks delayed hydration, open shadow roots, and same-origin iframes, then clicks all three. demo mcp-policy does not launch Chrome. demo ref-integrity needs a managed runtime.

GitHub Actions go does not launch Chrome. The Ubuntu self-test job installs Chrome for Testing and runs snapref self-test plus snapref demo ref-integrity. demo mcp-policy is covered by go test.

In a source checkout, make init runs the same two runtime installs.

Status: 0.2.0-rc.1 at https://github.com/nstranquist/snapref. Windows support is not advertised until a physical Windows+Chrome gate passes.

Packages

  • browser: sessions, CDP, snapshots/refs, actionability, evidence, skills;
  • contract: typed operation/permission/result registry;
  • script: YAML/JSON/Starlark repeatable workflow engine;
  • mcp: policy-gated MCP stdio server;
  • cmd/snapref: standalone CLI and live self-test.

The standalone skill and job-posting commands emit generic typed extraction only. Host-specific product handoffs are outside this module.

Proofs

These two receipts are the public wedge. They are not example.com YAML.

snapref demo mcp-policy
snapref demo ref-integrity

See examples/mcp-policy/ and examples/ref-integrity/. Talk about SnapRef as the kernel under the host adapter, not as a second browser-automation brand.

Golden path

snapref runtime install --runtime chrome-for-testing --channel stable
snapref runtime install --runtime headless-shell --channel stable
snapref runtime verify --all
snapref open demo
snapref exec demo navigate http://localhost:3000
snapref exec demo snapshot --wait-for-selector '[data-test="app-ready"]' --settle 1s
snapref exec demo click 'sr-…:e1'
snapref close demo --purge-profile

Headless is the default. auto uses only verified managed runtimes (or an explicit SNAPREF_CHROME external override); it never searches or launches the operator's personal browser installation. Headful and unpacked-extension work routes to Chrome for Testing. Ordinary headless work uses Headless Shell only after an exact-version local acceptance benchmark passes; otherwise it uses managed Chrome for Testing. Runtime installation is explicit and is the only browser command that downloads.

Named CLI sessions have a crash-safe 10-minute idle lease; every browser operation renews it. Use --idle-timeout (or SNAPREF_BROWSER_IDLE_TIMEOUT) for a longer bounded workflow and --keep-alive only when persistence is intentional. Idle expiry retains the named profile for cookie/state reuse; snapref gc previews stale dead sessions and profiles, and snapref gc --apply reclaims them. Snapshot before acting. Use the newest ref. MCP drive, host-read, host-write, and origin grants are separate SNAPREF_MCP_* authorities.

Screenshots are full-page by default. YAML/JSON playbooks can declare screenshot_mode: full-page for archival evidence or screenshot_mode: viewport for exact fold/focus evidence; an individual step can override the plan. Full-page capture measures the rendered document but does not trigger application-specific lazy loading or scroll reveals. Each script receipt records the effective mode and measured PNG width/height.

Verify

make verify
make verify-release

make verify runs tests, the race detector, vet, native compilation, Windows cross-compilation, and release-contract checks.

make verify-release also builds the release artifacts twice. It requires that every artifact is byte-identical across both builds.

The artifact builder uses only the local module cache. It disables dependency downloads, workspace overrides, user Go settings, and automatic toolchain downloads.

The live snapref self-test verifies hydrated snapshot readiness. It also verifies ref actuation across open shadow roots and same-origin frames. That command is a machine receipt (--json). GitHub Actions runs it on Ubuntu after snapref runtime install --runtime chrome-for-testing. Local make verify does not launch Chrome.

snapref demo mcp-policy is the drive/origin grant receipt. snapref demo ref-integrity is the stale-ref receipt: snapshot, click sr-…, snapshot again, old ref fails closed.

make release-dist reproducibly builds CGO-free macOS arm64, Linux amd64, and Windows amd64 archives with legal/security files and a SHA256SUMS manifest. It does not publish them.

The release command builds all files in a sibling staging directory. It changes only the named archives and SHA256SUMS in an existing output directory.

Unrelated output files remain unchanged. The command rejects filesystem roots, the source tree, source-tree ancestors, symbolic-link outputs, and non-regular managed artifacts.

If restoration fails after a publication error, the command prints and keeps the recovery staging directory. Do not delete that directory until you restore or copy the retained artifacts.

Use an operator-controlled output directory. The release transaction does not protect against an untrusted process that changes the directory concurrently.

EXTRACTION.json pins a digest of every shared source path, canonical regular file mode, and file byte. Windows checkout permissions are normalized to the repository's required 0644 mode; other platforms fail on permission drift. A digest mismatch means the checked-out tree drifted from the reviewed source lock and must be resynchronized before a release.

The versioned public artifact contracts live in schemas/telemetry-v2.schema.json and schemas/script-run-v2.schema.json. Each release archive includes both schemas and docs/VERSIONING.md.

Architecture

SnapRef is a local engine, not a hosted browser fleet.

  • browser owns isolated Chromium sessions, CDP, snapshots, revision-bound refs, actionability, recordings, and managed runtimes.
  • contract is the typed operation and permission registry.
  • script runs YAML/JSON/Starlark plans against an open session.
  • mcp is a policy-gated stdio server. Drive, host-read, host-write, and origin grants are separate authorities.
  • cmd/snapref is the standalone CLI. Host adapters live outside this module.
  • processtree is a vendored MIT copy used only for bounded subprocess cancellation in release and benchmark tools.

See docs/ARCHITECTURE.md.

Usage

snapref open demo
snapref exec demo navigate https://example.com
snapref exec demo snapshot --wait-for-selector body --settle 1s
snapref exec demo click 'sr-…:e1'
snapref close demo --purge-profile
snapref mcp

snapshot is the discovery default. Act on the newest revision-bound ref. eval is an escape hatch, not the discovery path. MCP drive, host-read, host-write, and origin grants are separate explicit authorities.

Configuration

Variable Purpose
SNAPREF_HOME Session, profile, recording, and telemetry root (default ~/.snapref/browser)
SNAPREF_SKILLS Skill directory (default ~/.snapref/skills)
SNAPREF_CHROME Explicit external Chromium path; never a personal-browser search
SNAPREF_BROWSER_IDLE_TIMEOUT Named-session idle lease (default 10m)
SNAPREF_JSONL_MAX_BYTES Hot telemetry rotate threshold (default 64KiB; 0 disables)
NDEV_JSONL_MAX_BYTES Compatibility alias for SNAPREF_JSONL_MAX_BYTES (host adapters)
SNAPREF_MCP_ALLOW_DRIVE MCP actuation
SNAPREF_MCP_ALLOW_HOST_READ MCP caller-selected playbook reads
SNAPREF_MCP_ALLOW_HOST_WRITE MCP caller-selected screenshot/pack paths
SNAPREF_MCP_ALLOW_ORIGINS MCP navigate/fetch allowlist
SNAPREF_DEBUG Chrome stderr

Runtime install is the only command that downloads. Recording packs that encode video or GIF require ffmpeg on PATH; still-shot packs do not.

Troubleshooting

  • no Chromium-class browser found: run snapref runtime install --runtime chrome-for-testing --channel stable.
  • Session missing after idle: named sessions expire after 10 minutes; the profile remains until close --purge-profile or gc --apply.
  • Stale executable ref: take a new snapshot and use the newest sr-… ref.
  • MCP actuation refused: set SNAPREF_MCP_ALLOW_DRIVE=1 (or --allow-drive) and an origin allowlist if you restrict hosts.
  • already recording after a crash: the next in-process start reclaims abandoned in-process state. A detached start that failed before a PID was stamped must be removed: delete $SNAPREF_HOME/recordings/<name> (default ~/.snapref/browser/recordings/<name>). If a detached PID is still alive, stop that process first.
  • Video encode fails: install ffmpeg; still packs do not need it. The CLI prints a bounded ffmpeg stderr on failure.

Apache-2.0. See SECURITY.md, docs/VERSIONING.md, NOTICE, THIRD_PARTY_NOTICES.md, and the bundled third_party/licenses/ texts before redistribution.

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选