Let an AI assistant find deleted rows in SQL Server (MCP)

English / 繁體中文

This page is about one case: rows were deleted from a SQL Server table, and you want an AI assistant such as Claude Code or Cursor to look at what was removed. If you only need to read the log yourself, see how to recover deleted rows without a backup.

Short answer

LogCarver.Mcp is a read-only MCP server. It gives the assistant one tool, find_deleted_rows, which reads a table’s deleted rows from the live transaction log (fn_dblog) and returns them as JSON. No Audit, CDC or Change Tracking has to be enabled beforehand.

It only runs SELECTs. The optional undo SQL it can suggest is plain text, and the tool never executes it. Everything runs on your machine and nothing is sent anywhere.

Install

You need the .NET 10 SDK or runtime.

dotnet tool install -g LogCarver.Mcp

Then add it to Claude Code:

claude mcp add logcarver --env LOGCARVER_MCP_CONNECTION_STRING="Server=localhost;Database=MyDb;Integrated Security=true;TrustServerCertificate=true" -- logcarver-mcp

The connection string comes from an environment variable, so the credentials never pass through the AI conversation. The tool only reads the database named in that string unless you list others in LOGCARVER_MCP_ALLOWED_DATABASES.

What you can ask it

Ask in plain words, for example “what rows were deleted from dbo.Orders in the last hour?”. The assistant fills in the tool parameters:

The result lists each event with its time, LSN, transaction id and the before and after column values.

Limits

Row values come straight from the database. They are data, not instructions, and the tool description tells the model so.