Skip to main content
Glama

LogCarverGuard

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. A SELECT returns 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/DENY still decide what they can do.

  • The service login does not need sysadmin. It needs IMPERSONATE on 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 / DELETE is rolled back as a whole if any statement fails. DDL (ALTER TABLE…), TRUNCATE and EXEC run as they are and are not rolled back as part of a batch. BEGIN TRAN / COMMIT / ROLLBACK from 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.

Related MCP server: aperion-shield

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, and a SQL Server with TCP/IP enabled and mixed-mode authentication.

  1. 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;
  2. Clone and configure

    git clone https://github.com/caiderek/LogCarverGuard
    cd LogCarverGuard

    Edit docker-compose.yml and set LOGCARVERGUARD_SQLSERVER_CONNECTION_STRING. For production prefer a mounted secret file and LOGCARVERGUARD_SQLSERVER_CONNECTION_STRING_FILE.

  3. Start

    docker compose up -d --build
    docker compose logs -f
  4. Issue an API key (--login is 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
  5. Point your MCP client at http://<host>:8080/ and send the key in the header X-LogCarverGuard-Key.

Other key commands: list-keys (never prints the key itself) and revoke-key --id <n>.

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=true in 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.1 by default for that reason.

  • Restrict who can connect with LOGCARVERGUARD_ALLOWED_CLIENT_IPS, in addition to the host firewall. Behind a reverse proxy also set LOGCARVERGUARD_TRUSTED_PROXIES, otherwise every request appears to come from the proxy.

  • Back up the /data volume. 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); 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 SELECT sensitive 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 / OPENQUERY are not blocked, so an agent holding a key with enough permission can use them to probe what the SQL Server can reach.

  • A SELECT keeps 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.

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.

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.

Available Tools

1 tool
execute_sqlA

Execute a SQL statement against the guarded database, under your own identity. Ordinary INSERT/UPDATE/DELETE/ALTER TABLE run and are audited. DROP TABLE, unapproved TRUNCATE, unapproved EXEC, and your own BEGIN/COMMIT/ROLLBACK TRAN statements are blocked before they ever reach the database - if blocked, the reason is returned so you can adjust and retry. A batch containing INSERT/UPDATE/DELETE runs in one transaction that is rolled back if any statement fails; DDL, TRUNCATE and EXEC run as they are and are not rolled back as part of a batch. When the server runs in read-only mode only queries are allowed and every other statement is blocked with a reason.

ParametersJSON Schema
NameRequiredDescriptionDefault
sqlYesThe SQL statement to execute.

TDQS

A4.4/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden and does so excellently. It discloses blocked statement types (DROP TABLE, unapproved TRUNCATE, unapproved EXEC, transaction control), transaction rollback semantics for batches, and read-only mode restrictions, even noting that block reasons are returned.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with the core action and then systematically covers behavioral rules. Every sentence adds distinct, useful information; no filler or repetition is present.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a complex, security-sensitive SQL execution tool with no output schema, the description is highly complete on constraints and transaction behavior. It does not describe the return format for successful queries (e.g., rows, result sets), which is a minor but notable gap.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, and the single parameter is documented as 'The SQL statement to execute.' The description adds no further meaning about the parameter's format or syntax beyond what the schema already provides, so the baseline of 3 applies.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states a specific verb and resource: 'Execute a SQL statement against the guarded database.' It is unambiguous and distinguishes the tool from any potential generic query tool by noting the 'guarded database' and identity context.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It clearly explains when certain SQL statements will run or be blocked, and describes read-only mode behavior. However, with no sibling tools, it does not need to name alternatives, but it also does not explicitly frame usage in terms of choosing this tool over others.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 1 tool updatev0.1.0
    • First observedexecute_sql

TDQS

A4.4/5.0

Scored across 1 tool

Disambiguation5/5

With only one tool, there is no possibility of selecting the wrong tool or confusing overlapping purposes. The single entry point has an unambiguous, well-bounded role: execute SQL under guardrails.

Naming Consistency5/5

The lone name, execute_sql, follows the standard verb_noun snake_case convention cleanly. There are no other names to conflict with, so consistency is trivially satisfied.

Tool Count3/5

A single tool is thin for a server with this much behavior (read-only mode, batch transactions, blocking rules, auditing). It is defensible as a unified SQL gateway, but the rubric treats 1 tool as borderline.

Completeness4/5

execute_sql is a complete interface for running and guarding SQL, covering DML, DDL, EXEC and transaction rules. Minor gaps exist: no dedicated tool to inspect the audit log, check current mode, or preview whether a statement would be blocked.

Maintenance

ActivityMaintained
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    A
    maintenance
    Secure SQL proxy for AI agents. Translates natural language to safe SQL via Claude, validates at the AST level (SELECT-only, no DDL/DML), enforces per-agent row-level security, and audit-logs every query.
    1
    MIT
  • F
    license
    A
    quality
    A
    maintenance
    Local guardrail proxy for AI coding agents. Wraps any MCP server (stdio or HTTP/SSE) and blocks destructive tool calls before they execute, with TOFU catalog pinning against rug pulls and tool-poisoning/result-injection scanning. Single Rust binary, Apache-2.0.
    14
    11
    -
  • A
    license
    A
    quality
    D
    maintenance
    Exposes any Microsoft SQL Server database to AI agents with multi-database support, keyword lookup, free SELECT queries, and three transport modes (stdio/SSE/Streamable HTTP).
    4
    1,146 npm
    MIT
  • F
    license
    Not graded
    quality
    D
    maintenance
    Enables AI agents to inspect schemas, analyze performance, check security, and troubleshoot SQL Server 2019+ databases through a safe, controlled interface.
    -