hs-sql-agent
Provides governed SQL access to MySQL databases, enabling secure query execution, DML with human approval, and table-level access control.
Provides governed SQL access to PostgreSQL databases, enabling secure query execution, DML with human approval, and table-level access control.
Provides governed SQL access to SQLite databases, enabling secure query execution, DML with human approval, and table-level access control.
hs-sql-agent
A high-performance MCP server for secure SQL access and enterprise governance.
hs-sql-agent connects MCP clients to SQLite, PostgreSQL, MySQL, SQL Server, Oracle, and Firebird through an HTTP MCP endpoint and a built-in Admin Panel.
Why hs-sql-agent?
Instead of executing unrestricted LLM-generated SQL, the server parses supported SQL into structured definitions, validates it, and rebuilds the final statement through a provider-specific SQL compiler.
Six database providers — SQLite, PostgreSQL, MySQL, SQL Server, Oracle, and Firebird.
Governed access — Per-key database binding, table whitelisting, CORS, rate limits, and execution policies.
Safe DML — Transactional dry-run followed by MCP Elicitation for explicit human approval.
Admin Panel — Manage databases, keys, roles, custom tools, audit records, and runtime policies.
Enterprise ready — OIDC SSO, TOTP MFA, audit retention, Prometheus metrics, OTLP, and webhook/SIEM delivery.
Semantic metadata — Table and column synonyms, relationships, and scoped metric metadata for schema discovery.
SQL support is intentionally bounded: unsupported syntax is rejected instead of silently changing its meaning. See the MCP Tools Reference for the supported SQL contract.
Related MCP server: safedb-mcp
Quick Start
cp .env.example .env
# Set HMAC_KEY and JWT_KEY to unique secrets of at least 32 bytes.
docker compose up -dOpen the Admin Panel at http://localhost:8080. Configuration options and production deployment guidance are documented in the Wiki.
Use with an MCP client
Create an MCP key in the Admin Panel. The key dialog displays the plaintext secret once and generates configuration for Claude Desktop, Cursor, and generic Streamable HTTP clients.
Set MCP_PUBLIC_ENDPOINT to the externally reachable MCP URL, including /mcp. For client compatibility, onboarding, and DML Elicitation requirements, see MCP client onboarding.
NuGet for existing .NET APIs
Embed the MCP SQL Agent and optional Admin UI in an ASP.NET Core application:
dotnet add package HsSqlAgent.Serverbuilder.Services.AddHsSqlAgent(options => { ... });
app.UseHsSqlAgent(); // API only
// app.UseHsSqlAgent().ServeAdminUi(); // API and Admin UISee the NuGet Package guide for configuration and deployment details.
How SQL execution works
Authenticate the MCP key and apply its database, table, and policy scope.
Parse supported SQL into a structured definition.
Validate the definition and compile it for the configured database provider.
Execute queries within configured limits.
For DML, dry-run in a transaction and require human approval through MCP Elicitation before commit.
Custom SQL tools pass through the same parser, validation, access policy, and execution limits as built-in tools. Lifecycle, parameter, and publishing rules are documented in the Admin Panel guide.
Documentation
Topic | Documentation |
Getting started | |
Configuration | |
Admin Panel | |
MCP tools and SQL support | |
Security, OIDC, and MFA | |
Deployment and observability | |
API | |
Troubleshooting | |
Development |
SQL Execution Flow
%%{init: { 'theme': 'neutral' }}%%
flowchart TD
LLM(["Client :: LLM / MCP Client"])
MCP["Server :: HsSqlAgent"]
AUTH["Middleware :: Authentication<br/>Access Key | DB Binding | Whitelist"]
ROUTE{"Gateway :: Router"}
LLM -->|Call tool with SQL| MCP
MCP --> AUTH
AUTH --> ROUTE
subgraph Query_Flow [" 🔍 Query Pipeline (SELECT) "]
QPARSE["Parse Query SQL<br/>SqlDefinitionParser.ParseQuery"]
QDEF["QueryDefinition<br/>AST Structure Data"]
QVALID["DefinitionValidator<br/>Rule Verification"]
QBUILD["SQL Strategy Compiler<br/>Compile Strategy"]
QEXEC["Execution Engine<br/>Execute SELECT"]
QRESULT(["Result :: Rows / JSON"])
QPARSE --> QDEF
QDEF --> QVALID
QVALID --> QBUILD
QBUILD --> QEXEC
QEXEC --> QRESULT
end
subgraph DML_Flow [" ✏️ Mutation Pipeline (DML) "]
DPARSE["Parse Mutation SQL<br/>SqlDefinitionParser.ParseDml"]
DDEF["DmlDefinition<br/>AST Structure Data"]
DVALID["DefinitionValidator<br/>Rule Verification"]
DRYRUN["Transaction Dry-run<br/>Uncommitted State"]
ELICIT["MCP Elicitation<br/>User Approval Prompt"]
DECIDE{" Action :: Decision"}
DEXEC["Transaction :: Commit<br/>Apply Changes"]
DROLLBACK["Transaction :: Rollback<br/>Discard Changes"]
DPARSE --> DDEF
DDEF --> DVALID
DVALID --> DRYRUN
DRYRUN --> ELICIT
ELICIT --> DECIDE
DECIDE -->|Allowed| DEXEC
DECIDE -->|Denied| DROLLBACK
end
ROUTE -->|execute_query_sql| QPARSE
ROUTE -->|execute_dml_sql| DPARSE
AUDIT[("Storage :: Async Audit Log")]
QRESULT --> AUDIT
DEXEC --> AUDIT
DROLLBACK --> AUDIT
classDef client fill:#f3f4f6,stroke:#374151,stroke-width:1px,color:#111827;
classDef server fill:#e5e7eb,stroke:#4b5563,stroke-width:1px,color:#1f2937;
classDef auth fill:#f9fafb,stroke:#9ca3af,stroke-width:1px,color:#4b5563;
classDef cond fill:#ffffff,stroke:#111827,stroke-width:1.5px,color:#111827;
classDef danger fill:#fee2e2,stroke:#ef4444,stroke-width:1px,color:#991b1b;
classDef success fill:#dcfce7,stroke:#22c55e,stroke-width:1px,color:#166534;
class LLM client;
class MCP,AUDIT server;
class AUTH auth;
class ROUTE,DECIDE cond;
class QRESULT,DEXEC success;
class DROLLBACK danger;DML Approval Prompt
This is what the human-in-the-loop approval step looks like during execute_dml_sql:
Contributing
See CONTRIBUTING.md and the Development guide.
License
This server cannot be installed
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- Alicense-qualityDmaintenanceA Model Context Protocol (MCP) server that enables AI agents to interact with Microsoft SQL Server databases through secure, intelligent database operations. This server provides comprehensive CRUD capabilities, schema introspection, stored procedure execution, transaction management, and bulk opera31637MIT
- AlicenseAqualityAmaintenanceSecure MCP server for safe, read-only DB access by AI agents, with SQL guardrails, table allowlists, PII masking, and audit logs6437MIT
- AlicenseAqualityAmaintenanceSecure and token-efficient MySQL MCP server built specifically for AI agents. Prevents hallucinations, optimizes context windows and blocks dangerous queries.5106MIT
- Flicense-qualityBmaintenanceA read-only MCP server for MS SQL Server, written in Python. Lets AI agents query your database safely — no writes, no stored procedures, no shell access.1
Related MCP Connectors
Analytical memory for AI agents: a real Postgres queried in plain English over MCP. One command.
GibsonAI MCP server: manage your databases with natural language
Security firewall for AI agents — scans MCP calls for injection, secrets, and risks.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/tse-wei-chen/hs-sql-agent'
If you have feedback or need assistance with the MCP directory API, please join our Discord server