benbjohnson / benbjohnson/litestream

refactor(mcp): call Litestream in-process instead of exec-ing a PATH binary

Open
#1,367 0 comments 0 reactions 1 assignee Claimed by @corylanou View on GitHub
enhancement
Dominant language
Go
Stars
14.4k
Forks
417
Avg merge
7d 1h
Merged PRs (30d)
21

Description

## Problem

Most MCP tools run `exec.CommandContext(ctx, "litestream", …)` (`cmd/litestream/mcp.go:96,116,167,235,287,313,339`). Consequences: they depend on a `litestream` on `$PATH` that may differ from the running build, pay process-spawn cost per call, lose typed errors, and couple correctness to CLI text output. The server may target **local paths or remote replica URLs** (`s3://`, `gs://`) or a remote Litestream instance (e.g. Fly.io) — the implementation must keep supporting all of these.

> Note: `litestream_version` is **out of scope** here — its exec removal and version semantics are owned by #1365. This issue converts the remaining tools and must not reintroduce any PATH-binary behavior.

## Fix

Replace the shell-outs with in-process calls to Litestream's library / daemon-IPC API, reusing existing surface:

- restore → `litestream.NewReplicaFromConfig` + `Replica.Restore` / `Replica.CalcRestoreTarget` (`replica.go`)
- ltx → `ReplicaClient.LTXFiles` (`replica_client.go`)
- status → `NewDBFromConfig` + `DB.SyncStatus` / `DB.MaxLTX` (`db.go`)
- databases → `ReadConfigFile` + `NewDBFromConfig`
- reset → `DB.ResetLocalState`
- daemon-backed tools (see #1372) → the existing Unix-socket IPC client

Explicitly handle both local paths and remote replica URLs. This same in-process/IPC path is what later lets tools talk to a **connected** (possibly remote) daemon instead of exec — including the remote-version behavior noted in #1365. Can be done tool-by-tool.

## Acceptance

- No MCP tool spawns a `litestream` subprocess (the `version` tool is already converted by #1365).
- Tools work against local databases and remote replica URLs.
- No tool reintroduces PATH-binary drift.

## Cross-refs

Complements #1365 (which owns the `litestream_version` / #1353 fix and the embedded-vs-remote version semantics). Touches every remaining handler, same code as #1368 — recommend landing **before** #1368, or combining in one PR at the maintainer's discretion. #1367 + #1370 enable the remote "connected-daemon version" behavior described in #1365.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.