@atom8n/mcp-mssql
v1.0.0
Published
An MCP server for executing queries against Microsoft SQL Server
Readme
MCP Mssql Server
An MCP server that exposes a single execute_sql tool for running parameterless SQL statements against Microsoft SQL Server using the native msnodesqlv8 driver. It is intended for MCP-compatible clients that need direct database access over stdio without exposing credentials in logs.
Features
- SQL Server Native Driver: Uses
msnodesqlv8and ensures an explicit driver prefix on every connection string. - Secure Logging: Masks password fields when echoing the effective connection string to stderr.
- Flexible Connection Sources: Pulls the connection string from
MSSQL_CONNECTION_STRINGor an override supplied with each request. - Structured Results: Returns
rowsAffectedcounts and all recordsets from the query for easy downstream parsing. - Stdio Transport: Ships as an MCP stdio server so it can be dropped into any MCP client configuration.
Installation
npm install @atom8n/mcp-mssqlMCP Configuration
Add the following configuration to your MCP client:
{
"mcp-mssql": {
"command": "npx",
"args": [
"@atom8n/mcp-mssql"
]
}
}Available Tools
execute_sql
Execute a SQL statement against Microsoft SQL Server.
Parameters:
query(required): T-SQL command text to execute.connectionString(optional): Overrides theMSSQL_CONNECTION_STRINGenvironment variable for this call.
The tool automatically injects Driver={SQL Server Native Client 11.0} when the provided connection string omits a driver segment, so both DSN-style and bare connection strings work out of the box.
Usage Examples
Run a query with the default connection string
{
"tool": "execute_sql",
"arguments": {
"query": "SELECT TOP (5) name FROM sys.databases ORDER BY name"
}
}Override the connection string per call
{
"tool": "execute_sql",
"arguments": {
"query": "EXEC dbo.RefreshMaterializedView @name = 'daily_snapshot'",
"connectionString": "Server=sql.internal;Database=Ops;Trusted_Connection=yes;"
}
}Response Format
Requests return JSON text via MCP content with the following shape:
{
"rowsAffected": [123],
"recordsets": [
[
{ "name": "master" },
{ "name": "model" }
]
]
}Development
Prerequisites
- Node.js 18+
- TypeScript 5.6+
- npm
Setup
# Clone the repository
git clone <repository-url>
cd mcp-mssql
# Install dependencies
npm install
# Build the project
npm run prepareProject Structure
├── src/
│ ├── index.mts # MCP server implementation
│ └── execute_sql.test.mts # Ad-hoc SQL runner for local verification
├── lib/
│ ├── index.mjs # Compiled JavaScript
│ ├── index.mjs.map # Source map
│ └── index.d.mts # TypeScript declarations
├── package.json # Package configuration
├── tsconfig.json # TypeScript configuration
└── eslint.config.mjs # ESLint configurationBuild Process
The project uses TypeScript with the following build configuration:
- Target: ES2015
- Module: CommonJS
- Output:
lib/directory - Source Maps: Enabled
- Declarations: Generated
Scripts
prepare: Compiles TypeScript and makes the binary executableinspect: Launches the MCP inspector against the compiled servertest:sql: Runssrc/execute_sql.test.mtswith ts-node for manual checks
Dependencies
Runtime Dependencies
@modelcontextprotocol/sdk: MCP server frameworkdotenv: Environment variable loadermsnodesqlv8: Native SQL Server driverrimraf: File system utilitiesspawn-rx: Process spawning utilities
Development Dependencies
@types/node: Node.js type definitionsshx: Shell utilities for cross-platform compatibilityts-node: TypeScript executiontypescript: TypeScript compiler
License
MIT License - see COPYING file for details.
Contributing
Please read CODE_OF_CONDUCT.md for our code of conduct and contribution guidelines.
Version
Current version: 1.0.0
Support
For issues and feature requests, please use the project's issue tracker.
