MSSQL MCP Server
Enables interaction with Microsoft SQL Server databases through a virtual filesystem interface, comprehensive stored procedure management with draft-test-deploy workflows, safe write operations with transaction control, and performance analysis capabilities.
README
MSSQL MCP Server
A production-ready Model Context Protocol (MCP) server for Microsoft SQL Server with comprehensive stored procedure management, virtual filesystem protocol, and safe write operations.
Features
- Virtual Filesystem: Browse database objects (stored procedures, views, functions) as files
- Discovery Tools: Search stored procedures, inspect table schemas, analyze dependencies
- Safe Write Operations: SQL validation, transaction management, audit logging
- SP Management: Draft → Test → Deploy → Rollback workflow with version control
- Performance Analysis: Query execution statistics from plan cache
- Security: SQL injection prevention, blocked keywords, row limits
Installation
npm install
npm run build
Configuration
Copy .env.example to .env and configure:
cp .env.example .env
Key configuration options:
- DB_SERVER: SQL Server hostname
- DB_DATABASE: Database name
- DB_USER/DB_PASSWORD: Credentials
- DB_ENCRYPT: Enable encryption (default: true)
- DB_TRUST_SERVER_CERTIFICATE: Trust server certificate for dev environments (default: false)
- ENABLE_WRITE_OPERATIONS: Enable INSERT/UPDATE/DELETE (default: true)
- ENABLE_SP_MODIFICATIONS: Enable stored procedure management (default: true)
- REQUIRE_TRANSACTIONS: Require explicit transactions for modifications (default: true)
- MAX_ROWS_AFFECTED: Maximum rows that can be modified in one operation (default: 10000)
- DRAFT_SCHEMA: Schema for testing SPs before deployment (default: dbo_draft)
- AUTO_BACKUP_BEFORE_DEPLOY: Auto-backup SPs before deploying (default: true)
See .env.example for all options.
Usage with Claude Code
Add to your MCP configuration file (.claude.json or ~/.claude.json):
{
"mcpServers": {
"mssql": {
"command": "node",
"args": ["/absolute/path/to/sql-server-mcp/dist/index.js"],
"env": {
"DB_SERVER": "localhost",
"DB_DATABASE": "MyDatabase",
"DB_USER": "sa",
"DB_PASSWORD": "YourPassword",
"ENABLE_WRITE_OPERATIONS": "true",
"ENABLE_SP_MODIFICATIONS": "true"
}
}
}
}
Available Tools
Discovery & Schema
- list_stored_procedures: List stored procedures with pagination
- search_stored_procedures: Search SPs by name or content
- get_table_schema: Get table structure with columns, indexes, foreign keys
- get_dependencies: Analyze object dependencies (callers and references)
- analyze_sp_performance: View execution statistics from plan cache
Execution
- execute_query_write: Execute INSERT/UPDATE/DELETE with validation
Transactions
- begin_transaction: Start a new transaction
- commit_transaction: Commit changes
- rollback_transaction: Undo changes
Stored Procedure Management
- create_sp_draft: Create a draft SP in separate schema
- test_sp_draft: Test draft with parameters
- deploy_sp: Deploy to production (auto-backs up current version)
- rollback_sp: Restore previous version
- list_sp_versions: View version history
Example Workflows
Searching for Stored Procedures
search for stored procedures that modify the Orders table
Viewing Database Objects as Files
show me /database/stored_procedures/dbo/GetCustomerOrders.sql
Modifying a Stored Procedure
I need to update GetCustomerOrders to include email.
Create a draft, test it with CustomerId=123, then deploy.
Safe Data Modifications
Start a transaction, update Customer set Status='Active' where Id=123,
show me the result, then commit.
Performance Analysis
Analyze performance of GetDailySalesReport and show execution stats
Architecture
Phase 1: Read-Only Foundation
- Virtual filesystem for database objects
- Connection pooling (read-only pool)
- Query execution with error handling
- Discovery and schema inspection tools
Phase 2: Safe Writes
- SQL validation and injection prevention
- Transaction manager with timeout protection
- Audit logging for compliance
- Write operation tools
Phase 3: SP Management
- Version control with SPVersionHistory table
- Draft schema for safe testing
- Deploy/rollback workflow
- Automatic backups before deployment
Phase 4: Advanced Features
- Dependency analysis
- Performance monitoring from DMVs
- Reference finding
Security Features
- SQL Validation: Blocks dangerous keywords and patterns
- Parameterized Queries: Prevents SQL injection
- Row Limits: Prevents accidental mass updates
- Transaction Timeouts: Auto-rollback after 5 minutes
- Audit Trail: Logs all operations to file
- Separate Credentials: Optional read-only and read-write connections
Testing
A complete test environment is included in the test/ directory:
cd test
./setup.sh init
This sets up a Docker container with SQL Server 2022 and a test database (MCPTestDB) pre-populated with:
- Sample tables (Customers, Products, Orders, etc.)
- 13 test stored procedures
- Views and functions
- Sample data for testing all MCP features
Connection string for testing:
Server=localhost,1433;Database=MCPTestDB;User Id=sa;Password=McpTest123!;TrustServerCertificate=true
Running Tests
After setting up the test database:
# Run all tests
npm run test:all
# Or run specific tests
npm run test:connection # Basic connectivity test
npm run test:db # Database object verification
npm run test:scenarios # Comprehensive functionality tests
See test/README.md for detailed testing scenarios and management commands.
Development
# Development mode with auto-reload
npm run dev
# Build
npm run build
# Run production build
npm start
# Lint
npm run lint
# Format
npm run format
Project Structure
sql-server-mcp/
├── src/
│ ├── index.ts # Entry point
│ ├── server.ts # MCP server setup
│ ├── types/ # TypeScript interfaces
│ ├── config/ # Configuration and logging
│ ├── database/ # Connection, query execution, transactions
│ ├── filesystem/ # Virtual filesystem protocol
│ ├── tools/ # MCP tool implementations
│ │ ├── discovery/ # Search and discovery
│ │ ├── schema/ # Schema inspection
│ │ ├── execution/ # Query execution
│ │ ├── sp-management/ # SP lifecycle
│ │ └── transactions/ # Transaction control
│ ├── security/ # Validation, audit logging
│ └── utils/ # Version manager, helpers
├── test/ # Test environment (Docker + SQL Server)
│ ├── docker-compose.yml # SQL Server 2022 container
│ ├── setup.sh # Management script
│ ├── init-scripts/ # Database initialization
│ └── backups/ # Database backups
├── .env.example # Configuration template
└── package.json
License
MIT
Contributing
Contributions are welcome! Please ensure all tools follow security best practices.
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。