hs-sql-agent
C# SQL Agent MCP server featuring raw SQL input, strict AST validation, and an embedded Admin UI. Eliminates LLM hallucinations and security risks across 6 major databases.
README
hs-sql-agent
A high-performance MCP server for secure SQL access and enterprise governance.
<img width="1000" height="500" alt="coverImage" src="https://github.com/user-attachments/assets/e317cee2-7bf3-4b11-94b9-4fdeedb29689" />
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.
Quick Start
cp .env.example .env
# Set HMAC_KEY and JWT_KEY to unique secrets of at least 32 bytes.
docker compose up -d
Open 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.Server
builder.Services.AddHsSqlAgent(options => { ... });
app.UseHsSqlAgent(); // API only
// app.UseHsSqlAgent().ServeAdminUi(); // API and Admin UI
See 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 | Getting Started |
| Configuration | Configuration |
| Admin Panel | Admin Panel |
| MCP tools and SQL support | MCP Tools Reference |
| Security, OIDC, and MFA | Security Governance |
| Deployment and observability | Deployment · Distributed Deployment |
| API | API Reference |
| Troubleshooting | Troubleshooting |
| Development | Development |
SQL Execution Flow
<img width="970" height="1850" alt="image" src="https://github.com/user-attachments/assets/2c3306fb-5962-4ba6-88fc-db192d57e684" />
DML Approval Prompt
This is what the human-in-the-loop approval step looks like during execute_dml_sql:
<img width="1199" height="890" alt="dml-approval-prompt" src="https://github.com/user-attachments/assets/ebd40519-e0b3-43d6-9e83-24238f3c00d6" />
Contributing
See CONTRIBUTING.md and the Development guide.
License
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。