LogCarverGuard MCP server
Commit Nov 5, 2026Provides a secure proxy for AI agents to interact with SQL Server using statement blocking, read-only modes, and audit logging.
Also known as caiderek/LogCarverGuard
- Stars
- 1
- Tools
- —
- Downloads, 30 days
- —
- Latest version
- 0.1.0
- Last commit
- Nov 5, 2026
- License
- MIT
What is LogCarverGuard MCP?
LogCarverGuard provides a secure proxy for AI agents to interact with SQL Server using statement blocking, read-only modes, and audit logging.
Summary generated from the project's README
About LogCarverGuard MCP server
LogCarverGuard acts as a secure intermediary between AI coding agents and production SQL Server environments. It provides a single execute_sql tool that allows agents to perform reads and writes without ever seeing actual database credentials. The proxy uses a real T-SQL parser to identify and block dangerous commands like DROP TABLE or permission changes before they reach the database. It also manages transactions by rolling back entire batches if any single statement fails.
Developers can choose between a local mode for individual use or a central service for team environments. Local mode runs via stdio on your machine using environment variables for configuration. The central service runs in Docker or natively on Linux and uses API keys to map users to their specific SQL logins. This ensures that the existing GRANT and DENY permissions of the caller are strictly respected. Every action is recorded in a local SQLite audit log, capturing the user, timestamp, and the specific SQL executed.
What you can do with it
- 1Prevent accidental database destructionAn AI agent can be given access to a database while the proxy automatically blocks commands like DROP TABLE or RESTORE DATABASE.
- 2Audit all AI-generated queriesA developer can review a SQLite file to see exactly which SQL statements were executed and by whom.
- 3Maintain user-level permissionsThe proxy impersonates the caller's specific SQL login so that their individual database permissions are enforced.
Written from the project's README. Every use case is checked against a quote from it.
Configuration
LOGCARVERGUARD_CONNECTION_STRINGRequiredSecretSQL Server connection string the statements run as. Example: Server=localhost;Database=MyDb;Integrated Security=true;TrustServerCertificate=true
LOGCARVERGUARD_ALTER_DROP_COLUMN_ALLOWLISTComma-separated schema.table entries where ALTER TABLE ... DROP COLUMN is allowed. Empty means it is blocked.
LOGCARVERGUARD_AUDIT_DB_PATHPath of the audit log SQLite file. Defaults to LogCarverGuard/audit.db under the local application data folder.
LOGCARVERGUARD_EXEC_WHITELISTComma-separated schema.procedure entries that may be run with EXEC. Empty means all EXEC is blocked.
LOGCARVERGUARD_READ_ONLYSet to true to allow queries only (SELECT without INTO; remote sources such as OPENQUERY are blocked). Leave unset for the default guard rules.
LOGCARVERGUARD_TRUNCATE_ALLOWLISTComma-separated schema.table entries where TRUNCATE TABLE is allowed. Empty means all TRUNCATE is blocked.
| Name | Description | |
|---|---|---|
| LOGCARVERGUARD_CONNECTION_STRING | SQL Server connection string the statements run as. Example: Server=localhost;Database=MyDb;Integrated Security=true;TrustServerCertificate=true | RequiredSecret |
| LOGCARVERGUARD_ALTER_DROP_COLUMN_ALLOWLIST | Comma-separated schema.table entries where ALTER TABLE ... DROP COLUMN is allowed. Empty means it is blocked. | |
| LOGCARVERGUARD_AUDIT_DB_PATH | Path of the audit log SQLite file. Defaults to LogCarverGuard/audit.db under the local application data folder. | |
| LOGCARVERGUARD_EXEC_WHITELIST | Comma-separated schema.procedure entries that may be run with EXEC. Empty means all EXEC is blocked. | |
| LOGCARVERGUARD_READ_ONLY | Set to true to allow queries only (SELECT without INTO; remote sources such as OPENQUERY are blocked). Leave unset for the default guard rules. | |
| LOGCARVERGUARD_TRUNCATE_ALLOWLIST | Comma-separated schema.table entries where TRUNCATE TABLE is allowed. Empty means all TRUNCATE is blocked. |
Automated checks
Ran Nov 13, 2026Full report →Not verified yet. A server needs a score of 80, no serious finding, and enough data for us to check. How checks work · What to fix for more points
- Source repository linked and reachablecaiderek/logcarverguard is public and reachablegithub.com/caiderek/logcarverguard ↗Pass
- Package names this repository as its sourceNot checked
- Build provenance (Sigstore attestation)Not checked
- Open source license (OSI)MITspdx.org/licenses/MIT.html ↗Pass
- Commit or release in the last yearLast commit or release 2026-11-05github.com/caiderek/logcarverguard ↗Pass
- OpenSSF ScorecardNot checked
- Package name not close to a popular packageNot checked
- No critical advisory in the package or its dependenciesNot checked
- No hidden instructions to the model0 tool descriptions and the README read; no override phrases, credential paths or hidden charactersPass
- Destructive tools are labelledNot checked
- Remote endpoint answers the MCP handshakeNot checked
README
View on GitHubLogCarverGuard
English | 繁體中文
An MCP proxy that lets an AI coding agent (Claude Code, Cursor, …) read and write a production SQL Server without handing it the real credentials or a free hand. Every statement runs under the caller's own SQL login and grants, dangerous statements are blocked before they reach the database, and everything is written to an audit log.
Status: early (v0.1).
What it does
AI agent --(MCP, API key)--> LogCarverGuard proxy --(EXECUTE AS the caller's own login)--> SQL Server
- One tool,
execute_sql. Reads and writes go through it. ASELECTreturns its rows (first 100 shown, with a count of the rest). A write is executed and audited. - A real T-SQL parser decides what is allowed, not keyword matching, so a fake keyword inside a comment or string does nothing.
- The AI never sees the database password. The proxy holds one service login. Each person gets an API key that maps to their own SQL login, and the proxy impersonates it, so their existing
GRANT/DENYstill decide what they can do. - The service login does not need sysadmin. It needs
IMPERSONATEon each user's login, and a database user in the target database so it can connect. The host tests run SELECT, UPDATE and a permission-denied DELETE through a service account that is not sysadmin. - Data changes run in a transaction the proxy controls. A batch containing
INSERT/UPDATE/DELETEis rolled back as a whole if any statement fails. DDL (ALTER TABLE…),TRUNCATEandEXECrun as they are and are not rolled back as part of a batch.BEGIN TRAN/COMMIT/ROLLBACKfrom the caller is blocked. - Audit log in a local SQLite file: who, when, which SQL, and whether it was blocked or executed. Executed statements are recorded after they commit. A statement that SQL Server rejects (for example permission denied) or a request with a bad key is not recorded.
Always blocked
DROP TABLE, DROP DATABASE, RESTORE DATABASE / RESTORE LOG, ALTER DATABASE … SET, sp_executesql, xp_cmdshell, dynamic EXEC of a variable or string, identity switching (REVERT, EXECUTE AS, SETUSER), permission changes (GRANT, DENY, REVOKE), and caller-managed transactions (BEGIN TRAN, COMMIT, ROLLBACK, SAVE TRANSACTION).
Blocked unless the admin allow-lists it
TRUNCATE TABLE, ALTER TABLE … DROP COLUMN, and EXEC of a named stored procedure (including INSERT … EXEC). Allow-list entries are written as schema.name; a statement that names a database or a server (OtherDb.dbo.T, [srv].db.dbo.P) is never matched against them.
This list is deliberately narrow. It is not "everything an AI could break": DROP INDEX, sp_rename, BACKUP DATABASE, or a Linked Server OPENQUERY are not specially handled and run if the real login may run them. The real security boundary is the SQL login's own grants, so issue each API key against an account with the least privilege you can accept, never sysadmin or db_owner.
Local mode
Runs on your own machine, started by your AI tool over stdio. No server, no Docker, no API keys. Settings come only from environment variables (not from appsettings.json or the command line). Tested on Windows with integrated authentication.
dotnet tool install -g LogCarverGuard.Local
claude mcp add logcarverguard --env LOGCARVERGUARD_CONNECTION_STRING="Server=localhost;Database=MyDb;Integrated Security=true;TrustServerCertificate=true" -- logcarverguard
Or run it without installing, through dnx (end the command with -- dotnet dnx LogCarverGuard.Local --yes).
| Variable | Purpose | Default |
|---|---|---|
LOGCARVERGUARD_CONNECTION_STRING (or _FILE) |
The login the statements run as | required |
LOGCARVERGUARD_READ_ONLY |
true allows queries only |
false |
LOGCARVERGUARD_AUDIT_DB_PATH |
Audit log SQLite file | LogCarverGuard/audit.db under your local application data folder |
LOGCARVERGUARD_TRUNCATE_ALLOWLIST, LOGCARVERGUARD_EXEC_WHITELIST, LOGCARVERGUARD_ALTER_DROP_COLUMN_ALLOWLIST |
Same allow-lists as the central service | empty (all blocked) |
Read-only mode lets SELECT (without INTO) through, plus SET, DECLARE and PRINT. Everything else is blocked with a reason, including EXEC even when it is allow-listed, NEXT VALUE FOR, and the remote or file sources OPENQUERY, OPENROWSET and OPENDATASOURCE (they can run a write on another server). What read-only mode does not cover: a SELECT that calls a CLR or extended-procedure function with side effects, long-running or expensive queries, and locks. Also give the login only the permissions it needs; the guard is a second layer, not the first.
What local mode is, and is not. It is a guardrail against an agent doing something destructive by accident. It is not a security boundary:
- The connection string, and so the credentials, live on your machine and in your AI tool's configuration. An agent that can run shell commands or read that configuration can connect to SQL Server directly and skip this proxy.
- Every statement runs as the one login in the connection string. There is no per-person identity; the audit log records the operating-system user name and is a local file.
- For a real boundary use the central service below: SQL Server only accepts connections from the proxy, and each person has their own login.
Install the central service
Needs a Linux host with Docker (or the .NET 10 SDK for the native install below), and a SQL Server with TCP/IP enabled and mixed-mode authentication.
-
Create the service login and let it impersonate each user's own login:
CREATE LOGIN logcarverguard_svc WITH PASSWORD = '…'; GRANT IMPERSONATE ON LOGIN::[alice_sql_login] TO logcarverguard_svc;In the target database, create a database user for the service login and one for each person's login, then give each person the permissions they normally have; the proxy never widens them:
CREATE USER logcarverguard_svc FOR LOGIN logcarverguard_svc; CREATE USER alice_sql_login FOR LOGIN alice_sql_login; GRANT SELECT, UPDATE ON dbo.Orders TO alice_sql_login; -
Clone and configure
git clone https://github.com/caiderek/LogCarverGuard cd LogCarverGuardEdit
docker-compose.ymland setLOGCARVERGUARD_SQLSERVER_CONNECTION_STRING. For production prefer a mounted secret file andLOGCARVERGUARD_SQLSERVER_CONNECTION_STRING_FILE. -
Start
docker compose up -d --build docker compose logs -f -
Issue an API key (
--loginis the user's own SQL login, not the service login). The key is printed once:docker compose exec logcarverguard dotnet cli/LogCarverGuard.Cli.dll \ issue-key --owner alice --login alice_sql_login -
Point your MCP client at
http://<host>:8080/and send the key in the headerX-LogCarverGuard-Key.
Other key commands: list-keys (never prints the key itself) and revoke-key --id <n>.
Linux notes
- Docker is the main install path for the central service on Linux. The image is built from the official .NET 10 images (
mcr.microsoft.com/dotnet/sdk:10.0to build,aspnet:10.0to run). It does not depend on a particular distribution. I have not tested this Docker setup on a specific distribution. Native (non-Docker) steps for Rocky Linux are below. - You need Docker with the Compose plugin on the host, and the container must be able to reach SQL Server over TCP (the sample connection string uses port 1433). Rocky Linux does not ship Docker (its default is Podman); Docker and the Compose plugin come from Docker's own
docker-cerepository. - The container runs as a non-root user and listens on port 8080. The audit log and the API key store are SQLite files in the
/datavolume, so keep that volume and back it up. docker-compose.ymlpublishes the port on127.0.0.1only. To reach it from other machines, put a TLS-terminating reverse proxy in front, as described in Hardening for production. Opening port 8080 directly to the network sends the API key over plain HTTP.- If the host runs a firewall or SELinux, I have not tested how this Docker setup behaves under them (the native Rocky test below did include both).
- Local mode was tested on Windows with integrated authentication only. I have not tested it on Linux. Integrated authentication is a Windows feature, so on Linux you would need a connection string with SQL authentication.
Native install on Rocky Linux (without Docker)
The steps below follow the guide I wrote for the Pro build, which I ran on a real Rocky Linux 9 VM and a real Rocky Linux 10 VM. That was an earlier Pro build: it adds undo on top of the same request handling, and it connected to SQL Server as sa, so the non-sysadmin service login described above was not part of those runs. I have not re-run these steps from this Free repo; if one fails, please open an issue.
# 1. .NET 10 SDK (Rocky 9 shown; on Rocky 10 use rhel/10 in the URL)
sudo dnf install -y https://packages.microsoft.com/config/rhel/9/packages-microsoft-prod.rpm
sudo dnf install -y dotnet-sdk-10.0 git
# 2. Service account, build
sudo useradd --system --no-create-home --shell /usr/sbin/nologin logcarverguard
sudo git clone https://github.com/caiderek/LogCarverGuard /opt/logcarverguard/src
cd /opt/logcarverguard/src
sudo dotnet publish src/LogCarverGuard.Server/LogCarverGuard.Server.csproj -c Release -o /opt/logcarverguard/server
sudo dotnet publish src/LogCarverGuard.Cli/LogCarverGuard.Cli.csproj -c Release -o /opt/logcarverguard/cli
# 3. Data directory and the service login's connection string
sudo mkdir -p /var/lib/logcarverguard /etc/logcarverguard
sudo chown logcarverguard:logcarverguard /var/lib/logcarverguard
sudo tee /etc/logcarverguard/sql-connstring.txt > /dev/null <<'EOF'
Server=your-sql-server-host,1433;Initial Catalog=your-database;User Id=logcarverguard_svc;Password=CHANGE_ME;TrustServerCertificate=true;
EOF
sudo chown logcarverguard:logcarverguard /etc/logcarverguard/sql-connstring.txt
sudo chmod 600 /etc/logcarverguard/sql-connstring.txt
Drop TrustServerCertificate=true once SQL Server has a certificate this host trusts (see Hardening for production).
Create /etc/systemd/system/logcarverguard.service:
[Unit]
Description=LogCarverGuard MCP proxy
After=network.target
[Service]
Type=simple
User=logcarverguard
Group=logcarverguard
WorkingDirectory=/opt/logcarverguard/server
ExecStart=/usr/bin/dotnet /opt/logcarverguard/server/LogCarverGuard.Server.dll
Restart=on-failure
RestartSec=5
Environment=ASPNETCORE_URLS=http://127.0.0.1:8080
Environment=LOGCARVERGUARD_SQLSERVER_CONNECTION_STRING_FILE=/etc/logcarverguard/sql-connstring.txt
Environment=LOGCARVERGUARD_AUDIT_DB_PATH=/var/lib/logcarverguard/logcarverguard-audit.db
Environment=LOGCARVERGUARD_APIKEYS_DB_PATH=/var/lib/logcarverguard/logcarverguard-apikeys.db
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now logcarverguard
sudo systemctl status logcarverguard --no-pager
sudo journalctl -u logcarverguard -n 20 --no-pager # expect "Now listening on: http://127.0.0.1:8080"
# Issue a key. Run the CLI as the service user so the key file stays writable by the service.
sudo -u logcarverguard dotnet /opt/logcarverguard/cli/LogCarverGuard.Cli.dll \
issue-key --owner alice --login alice_sql_login \
--apikeys-db /var/lib/logcarverguard/logcarverguard-apikeys.db
ASPNETCORE_URLSabove listens on127.0.0.1only. For access from other machines, put a TLS-terminating reverse proxy in front (see Hardening for production). In my Rocky tests the service listened on all interfaces (http://+:8080) and I opened the port withfirewall-cmd --permanent --add-port=8080/tcpand--reload; that sends the API key over plain HTTP, so I do not recommend it outside a trusted network.- Point your MCP client at
http://127.0.0.1:8080/from the same host, or at your reverse proxy'shttps://URL from other machines, and send the key in theX-LogCarverGuard-Keyheader.curl -i http://127.0.0.1:8080/returning405 Method Not Allowedmeans the service is up (MCP only accepts POST). Other key commands:list-keysandrevoke-key --id <n>, run the same way. - If the reverse proxy runs on this host, every request comes from
127.0.0.1; setLOGCARVERGUARD_TRUSTED_PROXIES=127.0.0.1if you also useLOGCARVERGUARD_ALLOWED_CLIENT_IPS. Point the proxy at127.0.0.1:8080, notlocalhost, since the service does not listen on::1. - On both test VMs (Rocky 9.8 and Rocky 10) firewalld was running and SELinux was Enforcing. Port 8080 worked without any extra
semanagesetting andausearch -m avcshowed no denials. That was the Pro build, not re-checked with this repo. - The service account needs a database user and
IMPERSONATEon each mapped login, as in theGRANT IMPERSONATEstep earlier in this section. The connection string needs SQL authentication (mixed mode on the SQL Server).
To update:
cd /opt/logcarverguard/src
sudo git pull
sudo systemctl stop logcarverguard
sudo dotnet publish src/LogCarverGuard.Server/LogCarverGuard.Server.csproj -c Release -o /opt/logcarverguard/server
sudo dotnet publish src/LogCarverGuard.Cli/LogCarverGuard.Cli.csproj -c Release -o /opt/logcarverguard/cli
sudo systemctl start logcarverguard
The audit log and API keys live in /var/lib/logcarverguard, so republishing does not touch them.
Configuration
All settings are environment variables; they take priority over appsettings.json.
| Variable | Purpose | Default |
|---|---|---|
LOGCARVERGUARD_SQLSERVER_CONNECTION_STRING (or _FILE) |
The proxy's service login | required |
LOGCARVERGUARD_AUDIT_DB_PATH |
Audit log SQLite file | logcarverguard-audit.db |
LOGCARVERGUARD_APIKEYS_DB_PATH |
API key SQLite file | logcarverguard-apikeys.db |
LOGCARVERGUARD_TRUNCATE_ALLOWLIST |
Tables where TRUNCATE is allowed |
empty (all blocked) |
LOGCARVERGUARD_EXEC_WHITELIST |
Stored procedures that may be EXEC'd |
empty (all blocked) |
LOGCARVERGUARD_ALTER_DROP_COLUMN_ALLOWLIST |
Tables where DROP COLUMN is allowed |
empty (all blocked) |
LOGCARVERGUARD_ALLOWED_CLIENT_IPS |
IPs / CIDR ranges allowed to connect, checked before the key | empty (no restriction) |
LOGCARVERGUARD_TRUSTED_PROXIES |
Peers trusted to set X-Forwarded-For (only behind a reverse proxy) |
empty (header never read) |
ASPNETCORE_URLS |
Listen address | deployment dependent |
Set Initial Catalog in the connection string to the database the agent should work in.
Hardening for production
- Do not leave
TrustServerCertificate=truein production. The sample connection string uses it for convenience; it turns off validation of SQL Server's certificate, so install a trusted certificate and drop it. - Use TLS. The key travels in an HTTP header; over plain HTTP it can be sniffed and gives whoever holds it that person's whole SQL access. Put a TLS-terminating reverse proxy in front. The compose file binds to
127.0.0.1by default for that reason. - Restrict who can connect with
LOGCARVERGUARD_ALLOWED_CLIENT_IPS, in addition to the host firewall. Behind a reverse proxy also setLOGCARVERGUARD_TRUSTED_PROXIES, otherwise every request appears to come from the proxy. - Back up the
/datavolume (native install:/var/lib/logcarverguard). It holds the audit log and the key hashes. - Keep the .NET runtime and the MCP SDK updated.
Known limits
- SQL Server only. The central service runs on Linux (Docker, or natively with systemd); local mode was tested on Windows with integrated authentication.
- It only governs SQL sent through this MCP connection. If the agent has other tools (files, APIs, cloud consoles), this proxy cannot see or stop those.
- The API key is a single static secret: no mTLS, no device binding, no short-lived tokens.
- No mask-on-read: if an account can
SELECTsensitive data, the agent can read it. - SQL Server's own error text is returned to the caller as it is. It can name databases, objects and logins, and features such as
OPENROWSET/OPENQUERYare not blocked, so an agent holding a key with enough permission can use them to probe what the SQL Server can reach. - A
SELECTkeeps at most 1000 rows in memory (the first 100 are shown, the true count is reported). - The audit log is a SQLite file read directly; there is no MCP tool for browsing it.
Safety testing
Test suite. 200 test cases across five projects (Core, Server, Local, Cli and the SQL Server integration tests), all passing on 2026-11-05 (.NET SDK 10.0.302). The integration tests run against a real local SQL Server, not a mock.
Bypass attempts that are tested (in the tests/ folder: mainly GuardBypassRegressionTests.cs, SqlStatementGuardTests.cs, ReadOnlyModeTests.cs and the integration tests):
INSERT … EXECin its variants, which must follow the same allow-list as a plainEXEC.- A blocked keyword inside a comment or string literal does not cause a false block.
- Identity switching:
REVERT,EXECUTE AS,SETUSER. SET IMPLICIT_TRANSACTIONS ON, which would let the caller manage a transaction.- Database- or server-qualified names (
OtherDb.dbo.T,[srv].db.dbo.P), which must not match a local allow-list entry. - In read-only mode, SQL that does not parse is blocked.
- Read-only mode blocks writes, schema changes and
EXEC, even an allow-listedEXEC. - A key runs as its mapped SQL login, and that login's
GRANT/DENYapply (tested on a real SQL Server).
What the tests do not show.
- They show the guard's rules, not that the guard is complete. The real boundary is still the SQL login's own grants.
- The tests are written by the author. There has been no external penetration test.
- The Free edition blocks; it does not undo a statement that ran.
- DDL,
TRUNCATEand allow-listedEXECare not rolled back. - Most guard tests are parser-level unit tests. Only the integration and host tests run against a real SQL Server.
- The audit log is a local SQLite file with no tamper protection.
- A stolen API key gives that login's full access.
- Not covered:
OPENROWSET/OPENQUERYin read-write mode (read-only mode blocks them), mask-on-read, and anything the agent does outside this MCP connection (see Known limits).
Build and test
dotnet build
dotnet test
The integration tests need a local SQL Server and a Windows login that is sysadmin; they create and drop their own LogCarverGuard_* databases and logins.
Related
LogCarver (free, MIT) reads deleted rows from a SQL Server transaction log. LogCarver.Mcp exposes it to AI assistants over MCP.
License
MIT, see LICENSE.
LogCarverGuard MCP questions
How does the proxy handle security and credentials?
The AI agent never sees the database password. The proxy uses a service login and impersonates the caller's own SQL login via API keys, ensuring existing permissions are respected.
Does the proxy support a read-only mode?
Yes, read-only mode allows SELECT queries while blocking all other operations, including even allow-listed EXEC commands.
Where is the audit log stored?
The audit log is stored in a local SQLite file.