mcp-sqlserver
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@mcp-sqlservershow me the first 10 rows from the customers table"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
MCP SQL Server
A flexible and stable Model Context Protocol (MCP) server for Microsoft SQL Server. Supports queries, statements, metadata retrieval, and stored procedures with full Docker support.
Features
✅ Query Execution: Execute SELECT queries and retrieve results
✅ Statement Execution: Execute INSERT, UPDATE, DELETE, and DDL statements
✅ Stored Procedures: Execute procedures with input/output parameters
✅ Metadata Retrieval: List databases, tables, columns, and procedures
✅ Connection Pooling: Efficient connection management with configurable pool
✅ Retry Logic: Automatic reconnection with exponential backoff
✅ Error Handling: Comprehensive error handling and logging
✅ Docker Ready: Includes Dockerfile and docker-compose configuration
✅ Type Safe: Full TypeScript support with strict type checking
✅ Production Ready: Suitable for public repositories and enterprise use
Related MCP server: MSSQL MCP Server
Installation
Prerequisites
Node.js 20+ or Bun 1.0+
SQL Server 2019+ (local or remote)
Docker & Docker Compose (for containerized setup)
Local Setup
Clone the repository
git clone https://github.com/ekoeryanto/mssql-mcp.git
cd mssql-mcpInstall dependencies using Bun
bun installConfigure environment variables
cp .env.example .env
# Edit .env with your SQL Server detailsBuild the project
bun run buildStart the server
bun startDocker Setup
The easiest way to get started with Docker Compose:
# Build and start both SQL Server and MCP server
docker-compose up -d
# View logs
docker-compose logs -f mcp-server
# Stop services
docker-compose downThe server listens on http://localhost:3000/mcp (Streamable HTTP). Connect a client with, e.g.:
claude mcp add --transport http mssql-mcp http://localhost:3000/mcp -H "Authorization: Bearer YourSuperSecretToken"Configuration
Environment variables configuration:
# SQL Server Connection
SQLSERVER_SERVER=localhost
SQLSERVER_PORT=1433
SQLSERVER_DATABASE=master
SQLSERVER_USERNAME=sa
SQLSERVER_PASSWORD=YourStrong@Password
# Connection Options
SQLSERVER_ENCRYPT=false
SQLSERVER_TRUST_SERVER_CERTIFICATE=true
# Dynamic Skills feature (optional — see docs/DYNAMIC_SKILLS.md)
# SKILLS_ENABLED=true
# SKILLS_TABLE=tb_mcp_skills
# Connection Pool
SQLSERVER_CONNECTION_POOL_MIN=2
SQLSERVER_CONNECTION_POOL_MAX=10
SQLSERVER_REQUEST_TIMEOUT=30000
# Server Configuration
MCP_SERVER_NAME=mssql-mcp
LOG_LEVEL=info # debug, info, warn, errorDevelopment
For development with hot reload:
bun run devUsage
For detailed instructions on connecting this server to AI tools like Claude Desktop, Antigravity IDE, and Cursor, see our AI Client Integration Guide.
The MCP server provides the following tools:
1. Query Tool
Execute SELECT queries and retrieve results:
{
"name": "query",
"arguments": {
"query": "SELECT TOP 10 * FROM your_table WHERE id > 5"
}
}Response:
{
"success": true,
"rowCount": 10,
"columns": ["id", "name", "email"],
"data": [
{"id": 6, "name": "John", "email": "john@example.com"},
...
]
}2. Execute Statement Tool
Execute INSERT, UPDATE, DELETE, or DDL statements:
{
"name": "execute-statement",
"arguments": {
"statement": "INSERT INTO users (name, email) VALUES (@name, @email)",
"params": {
"name": "John Doe",
"email": "john@example.com"
}
}
}Response:
{
"success": true,
"rowsAffected": 1,
"message": "Statement executed successfully. Rows affected: 1"
}3. Get Metadata Tool
Retrieve database schema information:
{
"name": "get-metadata",
"arguments": {
"type": "tables"
}
}Types:
databases: List all databasestables: List all tables in current databasecolumns: List columns for a specific table (requiresfilter)procedures: List all stored procedures
Example with filter:
{
"name": "get-metadata",
"arguments": {
"type": "columns",
"filter": "users"
}
}4. Execute Procedure Tool
Execute stored procedures with parameters:
{
"name": "execute-procedure",
"arguments": {
"name": "sp_GetUserById",
"params": {
"userId": {
"value": 123,
"output": false
},
"userName": {
"value": null,
"output": true
}
}
}
}5. Get Status Tool
Check server connection status:
{
"name": "get-status",
"arguments": {}
}6. Save Skill Tool
Define a new reusable SQL "skill" that becomes callable as its own tool. Explore the
schema with get-metadata first, then describe the SQL and its input schema:
{
"name": "save-skill",
"arguments": {
"tool_name": "cek-tagihan",
"description": "Cek status tagihan pelanggan berdasarkan nomor pelanggan",
"keywords": "tagihan, billing, invoice",
"generated_prompt": "{\"type\":\"object\",\"properties\":{\"nomor\":{\"type\":\"string\",\"description\":\"Nomor pelanggan\"}},\"required\":[\"nomor\"]}",
"generated_sql": "SELECT * FROM tb_tagihan WHERE nomor = @nomor"
}
}See docs/DYNAMIC_SKILLS.md for the full walkthrough,
including how skills can also be inserted directly into tb_mcp_skills by hand.
Dynamic Skills
Beyond these 6 built-in tools, additional tools can be defined at runtime in a
tb_mcp_skills database table — either via save-skill above, or by inserting
directly into the table. See docs/DYNAMIC_SKILLS.md.
generated_sql runs as trusted, already-reviewed SQL — it is not gated by
SQLSERVER_ALLOW_MUTATIONS. Only the tool arguments a caller supplies are
untrusted, and those are always bound as SQL parameters. This means anyone who
can call save-skill can define and immediately run a skill that mutates data
even when SQLSERVER_ALLOW_MUTATIONS=false. Restrict access to save-skill
(and to tb_mcp_skills itself) accordingly.
Architecture
Project Structure
mssql-mcp/
├── src/
│ ├── index.ts # Main MCP server entry point
│ ├── config/
│ │ └── index.ts # Configuration loader
│ ├── db/
│ │ └── connection.ts # SQL Server connection manager
│ ├── logger/
│ │ └── index.ts # Logger implementation
│ ├── tools/
│ │ └── handlers.ts # Tool request handlers
│ └── types/
│ └── index.ts # TypeScript type definitions
├── docker-compose.yml # Docker Compose configuration
├── Dockerfile # Multi-stage Docker build
├── package.json # Dependencies and scripts
├── tsconfig.json # TypeScript configuration
└── .env.example # Environment variables templateConnection Management
The connection manager implements:
Connection Pooling: Configurable min/max pool size
Automatic Reconnection: Retry logic with exponential backoff
Error Handling: Graceful error handling and logging
Keep-Alive: Continuous connection monitoring
Security Considerations
AI Database Access Risk
Granting an AI access to your database is highly sensitive. Even though this MCP server supports INSERT, UPDATE, and DELETE commands, it is STRONGLY RECOMMENDED to connect using a Read-Only database user.
AI assistants can sometimes hallucinate or misinterpret requests, which could lead to accidental destructive commands (e.g., dropping tables, deleting or modifying critical data). Using a read-only account provides a fail-safe layer against accidental data loss.
Creating a Read-Only User (T-SQL)
Run the following T-SQL script in your SQL Server to create a dedicated read-only user for this MCP server:
-- 1. Switch to your target database
USE [YourDatabaseName];
GO
-- 2. Create a login (Server level)
CREATE LOGIN [mcp_readonly_user] WITH PASSWORD = 'YourStrongPassword123!';
GO
-- 3. Create a user for the login (Database level)
CREATE USER [mcp_readonly_user] FOR LOGIN [mcp_readonly_user];
GO
-- 4. Grant read-only permissions (db_datareader)
ALTER ROLE [db_datareader] ADD MEMBER [mcp_readonly_user];
GO
-- 5. (Optional) Grant view definition if the AI needs to inspect schemas/tables structure
GRANT VIEW DEFINITION TO [mcp_readonly_user];
GOBest Practices
Environment Variables: Never commit
.envfile with real credentialsParameter Binding: Always use parameterized queries to prevent SQL injection
Connection Pooling: Limits resource consumption
Timeout Settings: Prevents long-running queries from blocking
API Reference
Tool Definitions
Each tool follows the MCP specification with:
name: Unique tool identifierdescription: What the tool doesinputSchema: JSON Schema for input validation
Error Handling
All tools return a consistent error format:
{
"success": false,
"error": "Descriptive error message"
}Development
Running Tests
bun run testLinting
bun run lintBuilding for Production
bun run buildDeployment
Docker Compose
For quick deployment with SQL Server:
docker-compose up -dKubernetes
Example Kubernetes deployment coming soon.
Custom Environment
To use with an existing SQL Server instance:
Set environment variables
Run
bun startThe server will connect via stdio transport
Performance Considerations
Connection Pool Size: Adjust based on concurrent usage
Query Timeouts: Configure
SQLSERVER_REQUEST_TIMEOUTbased on query complexityDatabase Indexes: Ensure proper indexing for query performance
Logging Level: Use
warnorerrorin production to reduce overhead
Troubleshooting
Connection Failures
Check environment variables:
env | grep SQLSERVERQuery Timeouts
Increase SQLSERVER_REQUEST_TIMEOUT:
SQLSERVER_REQUEST_TIMEOUT=60000 # 60 secondsPool Exhaustion
Increase pool size:
SQLSERVER_CONNECTION_POOL_MAX=20Debug Logging
Set log level to debug:
LOG_LEVEL=debugContributing
Fork the repository
Create a feature branch
Make your changes
Submit a pull request
License
MIT License - see LICENSE file for details
Support
For issues and questions:
GitHub Issues: Create an issue
Discussions: Start a discussion
References
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
The BigQuery remote MCP server is a fully managed service that uses the Model Context Protocol to connect AI applications and LLMs to BigQuery data sources. It provides secure, standardized tools for AI agents to list datasets and tables, retrieve schemas, generate and execute SQL queries through natural language, and analyze data—enabling direct access to enterprise analytics data without requiring manual SQL coding.
Model Context Protocol server for Studex tools, notifications, and profile integrations
Governed data discovery, exact queries, decisions, simulations, and runtime utilities over MCP.
Create, manage, and query your Google Cloud SQL resources.
Related MCP Servers
- AlicenseBqualityDmaintenanceEnables execution of SQL queries and management of Microsoft SQL Server database connections through the Model Context Protocol.333,33815MIT
- AlicenseBqualityDmaintenanceA Model Context Protocol server that enables executing SQL queries and managing connections with Microsoft SQL Server databases.13,3386MIT
- AlicenseAqualityCmaintenanceEnables interaction with Microsoft SQL Server databases through a Model Context Protocol interface, supporting database connections, switching between databases, and executing secure SELECT queries.822MIT
- FlicenseNot gradedqualityDmaintenanceEnables Language Models to interact with Microsoft SQL Server databases by inspecting table schemas, executing SQL queries, and reading table data through a standardized Model Context Protocol interface.27
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/ekoeryanto/mssql-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server