# SQL Server MCP Testing Guide
## Overview
This guide provides comprehensive testing procedures for the SQL Server MCP server, covering **automated**,
**manual**, and **protocol-level** testing approaches. The MCP server has been **fully validated**
through 610+ tests across all testing layers.
**β
Production Status**: This MCP server has been **comprehensively tested and validated** with 100% success rates across all security phases.
## Purpose
- **Verify Core Functionality**: Ensure all database operations work as expected
- **Validate Security**: Confirm the three-tier safety system is properly enforced
- **Identify Issues**: Detect any connectivity, configuration, or functionality problems
- **Production Readiness**: Assess production deployment readiness
- **Multiple Test Approaches**: Automated, manual, and protocol-level validation
## Testing Approaches
### π **Quick Testing (Automated)**
```bash
# Run all automated tests (unit + integration)
npm test
# Run with coverage
npm run test:coverage
```
### π§ **Comprehensive Testing (Manual)**
```bash
# Test all three security phases (40 tests)
npm run test:integration:manual
# Note: Individual phase tests are run sequentially within test:integration:manual
# Phase 1: 20 tests - Read-only security
# Phase 2: 10 tests - DML operations
# Phase 3: 10 tests - DDL operations
```
### π‘ **Protocol Testing (MCP Client-Server Communication)**
```bash
# Test MCP protocol communication (20 tests)
npm run test:integration:protocol
```
## Prerequisites
### **For Automated Tests**
- β
**No special setup required** - Uses mocked databases
- β
**Runs in CI/CD** - No external dependencies
### **For Manual & Protocol Tests**
1. **SQL Server Instance**: Running and accessible
2. **Test Database**: `WarpMcpTest` with sample data (created automatically if missing)
3. **Environment Configuration**: Valid `.env` file or environment variables
4. **SSL Configuration**: Proper certificate trust settings if encryption enabled
## Comprehensive Test Coverage
### π **Test Suite Overview**
| Test Type | Count | Purpose | Database | Automation |
| ------------------------------ | -------- | ------------------------------ | --------- | ------------ |
| **Unit Tests** | 535+ | Code logic validation | Mocked | β
Automated |
| **Integration Tests (Auto)** | 15 | Component integration | Mocked | β
Automated |
| **Integration Tests (Manual)** | 40 | Security phase validation | Live DB | β Manual |
| **Protocol Tests** | 20 | MCP communication validation | Live DB | β Manual |
| **TOTAL** | **610+** | **Complete system validation** | **Mixed** | **Mixed** |
### β
**Production Validation Results**
- **β
Phase 1 (Read-Only)**: 20/20 tests passed - Maximum security validated
- **β
Phase 2 (DML Operations)**: 10/10 tests passed - Selective permissions validated
- **β
Phase 3 (DDL Operations)**: 10/10 tests passed - Full development mode validated
- **β
Protocol Communication**: 20/20 tests passed - MCP client-server validated
#### Total: 100% success rate across all manual validation tests
## Manual Testing Categories (For Reference)
### 1. Basic Connectivity and Database Operations
**Objective**: Verify basic connection and database enumeration capabilities.
**Tests**:
- `list_databases` - Should return user databases (excluding system DBs)
- `list_tables` - Should list tables in a specified database
**Expected Results**:
- β
Connection established successfully
- β
Database list returned with proper formatting
- β
Table list shows correct schema and table information
**Sample Commands**:
```json
// List all databases
{"name": "list_databases", "input": {}}
// List tables in specific database
{"name": "list_tables", "input": {"database": "WarpMcpTest"}}
```
### 2. Core Database Schema Operations
**Objective**: Test schema inspection and relationship discovery capabilities.
**Tests**:
- `describe_table` - Get detailed table schema information
- `list_foreign_keys` - Discover foreign key relationships
**Expected Results**:
- β
Complete column information (types, nullability, defaults, constraints)
- β
Primary key identification
- β
Foreign key relationships properly mapped
**Sample Commands**:
```json
// Describe table structure
{"name": "describe_table", "input": {"database": "WarpMcpTest", "table_name": "Products"}}
// List foreign key relationships
{"name": "list_foreign_keys", "input": {"database": "WarpMcpTest"}}
```
### 3. Data Retrieval Operations
**Objective**: Verify data access and export functionality.
**Tests**:
- `get_table_data` - Retrieve sample data with optional filtering
- `export_table_csv` - Export data in CSV format
**Expected Results**:
- β
Properly formatted tabular data returned
- β
CSV export with correct headers and formatting
- β
Filtering and limiting work correctly
**Sample Commands**:
```json
// Get sample data
{"name": "get_table_data", "input": {"database": "WarpMcpTest", "table_name": "Categories", "limit": 5}}
// Export as CSV
{"name": "export_table_csv", "input": {"database": "WarpMcpTest", "table_name": "Products", "limit": 3}}
```
### 4. Query Execution and Analysis
**Objective**: Test SQL query execution capabilities.
**Tests**:
- `execute_query` - Execute arbitrary SQL queries
- `explain_query` - Generate execution plans
**Expected Results**:
- β
SELECT queries execute successfully
- β
Complex JOINs and aggregations work
- β
`explain_query` now works with proper batch handling
**Sample Commands**:
```json
// Execute complex query
{
"name": "execute_query",
"input": {
"database": "WarpMcpTest",
"query": "SELECT TOP 3 p.ProductName, c.CategoryName, p.Price FROM Products p JOIN Categories c ON p.CategoryID = c.CategoryID ORDER BY p.Price DESC"
}
}
// Explain query execution plan
{
"name": "explain_query",
"input": {
"database": "WarpMcpTest",
"query": "SELECT COUNT(*) FROM Products WHERE CategoryID = 1"
}
}
```
### 5. Performance Monitoring Tools
**Objective**: Test performance monitoring and health check capabilities.
**Tests**:
- `get_performance_stats` - Overall performance statistics
- `get_query_performance` - Query performance breakdown
- `get_connection_health` - Connection pool health
**Expected Results**:
- β
Performance statistics returned in proper JSON format
- β
Query performance breakdown available
- β
Connection health metrics accessible
**Sample Commands**:
```json
// Get performance statistics
{"name": "get_performance_stats", "input": {"timeframe": "all"}}
// Get query performance
{"name": "get_query_performance", "input": {}}
// Check connection health
{"name": "get_connection_health", "input": {}}
```
### 6. Query Optimization Tools
**Objective**: Test advanced query optimization and analysis features.
**Tests**:
- `get_index_recommendations` - Index optimization suggestions
- `analyze_query_performance` - Deep query analysis
- `detect_query_bottlenecks` - Bottleneck detection
- `get_optimization_insights` - Comprehensive optimization analysis
**Expected Results**:
- β
Index recommendations returned in structured format
- β
Query performance analysis available
- β
Bottleneck detection working
- β
Optimization insights accessible
**Sample Commands**:
```json
// Get index recommendations
{"name": "get_index_recommendations", "input": {"database": "WarpMcpTest"}}
// Analyze query performance
{
"name": "analyze_query_performance",
"input": {
"database": "WarpMcpTest",
"query": "SELECT * FROM Products WHERE CategoryID = 1"
}
}
// Detect bottlenecks
{"name": "detect_query_bottlenecks", "input": {"database": "WarpMcpTest"}}
// Get optimization insights
{"name": "get_optimization_insights", "input": {"database": "WarpMcpTest"}}
```
### 7. Security and Safety Boundaries
**Objective**: Verify the three-tier safety system is properly enforced.
**Tests**:
- Test INSERT operations (should be blocked in read-only mode)
- Test UPDATE operations (should be blocked in read-only mode)
- Test DELETE operations (should be blocked in read-only mode)
- Test DDL operations (should be blocked in read-only mode)
- Verify SELECT operations work normally
**Expected Results**:
- π All modification operations blocked with clear error messages
- β
SELECT queries continue to work normally
- β
Security policy violations properly reported
**Sample Commands**:
```json
// These should be BLOCKED in read-only mode
{"name": "execute_query", "input": {"database": "WarpMcpTest", "query": "INSERT INTO Categories (CategoryName, Description) VALUES ('Test', 'Test')"}}
{"name": "execute_query", "input": {"database": "WarpMcpTest", "query": "UPDATE Products SET Price = 50.00 WHERE ProductID = 1"}}
{"name": "execute_query", "input": {"database": "WarpMcpTest", "query": "DELETE FROM Products WHERE ProductID = 99"}}
{"name": "execute_query", "input": {"database": "WarpMcpTest", "query": "CREATE TABLE TestTable (ID int PRIMARY KEY, Name nvarchar(100))"}}
// This should WORK
{"name": "execute_query", "input": {"database": "WarpMcpTest", "query": "SELECT COUNT(*) as ProductCount FROM Products"}}
```
## Automated Test Execution
### π **Recommended Testing Workflow**
#### **1. Development Testing**
````bash
# Quick validation during development
npm test # Run all automated tests
```bash
npm run test:coverage # Check code coverage
````
#### **Manual Testing (Live Database)**
````bash
npm run test:integration:manual # All 3 security phases (40 tests)
npm run test:integration:protocol # MCP protocol validation (20 tests)
```bash
# End of previous section
````
#### **2. Pre-Production Validation**
```bash
# Comprehensive manual testing before deployment
npm run test:integration:manual # All 3 security phases (40 tests)
npm run test:integration:protocol # MCP protocol validation (20 tests)
```
#### **3. Production Readiness Check**
````bash
# Complete validation suite
npm run ci # Full CI pipeline with security audit
```bash
npm run test:integration:manual # Manual integration validation
npm run test:integration:protocol # Protocol communication validation
```bash
# Complete validation suite
npm run ci # Full CI pipeline with security audit
```
### π **Comprehensive Testing Guides**
- **[Manual Integration Tests β](../test/integration/manual/README.md)** - Complete guide for manual security phase testing
- **[Protocol Tests β](../test/protocol/README.md)** - MCP client-server communication testing
- **[Unit Tests β](../test/README.md)** - Comprehensive unit test documentation
### β
**Quick Validation Checklist**
#### **Automated Tests (Always Run)**
- [ ] **Unit Tests** - `npm test` (535+ tests)
- [ ] **Coverage** - `npm run test:coverage` (60%+ coverage)
- [ ] **Code Quality** - `npm run ci` (linting, formatting, security)
#### **Manual Tests (Pre-Production)**
- [ ] **Phase 1-3** - `npm run test:integration:manual` (All security phases)
- [ ] **Protocol** - `npm run test:integration:protocol` (MCP communication)
### π― **Using Warp AI Terminal**
With Warp MCP integration, you can validate functionality by:
1. **Ask Warp to list databases**: "List all databases on the SQL Server"
2. **Test table operations**: "Show me the structure of the Products table"
3. **Execute queries**: "Get the top 5 products by price"
4. **Export data**: "Export the Categories table as CSV"
5. **Test security**: Try INSERT/UPDATE operations (should be blocked in read-only mode)
## Expected Results Summary
### β
**Complete Production Validation Results**
#### **All 16 MCP Tools (100% Validated)**
| Category | Tool | Status | Validation |
| ---------------- | --------------------------- | --------------------------- | ------------------ | --------------- |
| **Database** | `list_databases` | β
Validated | All test phases |
| **Database** | `list_tables` | β
Validated | All test phases |
| **Schema** | `describe_table` | β
Validated | All test phases |
| **Schema** | `list_foreign_keys` | β
Validated | All test phases |
| **Data** | `get_table_data` | β
Validated | All test phases |
| **Data** | `export_table_csv` | β
Validated | All test phases |
| **Query** | `execute_query` | β
Validated | All security modes |
| **Query** | `explain_query` | β
Validated | All test phases |
| **Performance** | `get_performance_stats` | β
Validated | All test phases |
| **Performance** | `get_query_performance` | β
Validated | All test phases |
| **Performance** | `get_connection_health` | β
Validated | All test phases |
| **Optimization** | `get_index_recommendations` | β
Validated | All test phases |
| **Optimization** | `analyze_query_performance` | β
Validated | All test phases |
| **Optimization** | `detect_query_bottlenecks` | β
Validated | All test phases |
| | **Optimization** | `get_optimization_insights` | β
Validated | All test phases |
| | **Diagnostics** | `get_server_info` | β
Validated | All test phases |
#### **Security System (100% Validated)**
| Security Level | Configuration | Validation | Status |
| -------------- | ----------------- | ----------- | ----------- |
| **Phase 1** | Read-Only Mode | 20/20 tests | β
**100%** |
| **Phase 2** | DML Operations | 10/10 tests | β
**100%** |
| **Phase 3** | DDL Operations | 10/10 tests | β
**100%** |
| **Protocol** | MCP Communication | 20/20 tests | β
**100%** |
### π― **Test Execution Results**
| Test Suite | Tests | Passed | Failed | Success Rate |
| ------------------------ | -------- | -------- | ------ | ------------ |
| **Unit Tests** | 535+ | 535+ | 0 | **100%** |
| **Integration (Auto)** | 15 | 15 | 0 | **100%** |
| **Integration (Manual)** | 40 | 40 | 0 | **100%** |
| **Protocol Tests** | 20 | 20 | 0 | **100%** |
| **TOTAL** | **610+** | **610+** | **0** | **100%** |
### β
**All Historical Issues Resolved**
| Previous Issue | Status | Resolution |
| --------------------------------------- | -------- | ------------------------------------------------ |
| Performance tool serialization errors | β
Fixed | Response format corrected for MCP protocol |
| Query optimization serialization errors | β
Fixed | Response format corrected for MCP protocol |
| `explain_query` batch limitations | β
Fixed | Separate batch execution implemented |
| MCP response format compatibility | β
Fixed | All tools now return proper MCP responses |
| SSL certificate handling | β
Fixed | Self-signed certificate trust implemented |
| Configuration loading | β
Fixed | Environment variable override system implemented |
| Test isolation | β
Fixed | Manual tests properly excluded from CI/CD |
## Troubleshooting
### Common Issues and Solutions
#### Previous Serialization Issues (RESOLVED)
**Previous Error**: `"data did not match any variant of untagged enum Response"`
**Resolution**: β
**FIXED** - All performance and optimization tools now return properly formatted MCP responses.
**What was changed**:
- Fixed nested `content` structure in performance monitoring methods
- Corrected response format in query optimization tools
- All tools now conform to MCP protocol requirements
#### Connection Issues
**Error**: Connection timeout or authentication failures
**Solution**:
- Verify MCP server configuration
- Check database connectivity
- Validate authentication credentials
- Review SSL/encryption settings
#### Security Policy Violations
**Error**: `"Query blocked by safety policy"`
**Expected Behavior**: This is correct in read-only mode
**Solution**:
- For testing modifications, set `SQL_SERVER_READ_ONLY=false`
- For production, keep security restrictions active
## Validation Criteria
### Pass Criteria
- β
All database operations (16 tools) work correctly
- β
Security system properly enforces read-only restrictions
- β
Data retrieval and export functions correctly
- β
Query execution and analysis works reliably
- β
Performance monitoring and optimization tools accessible
### Acceptance Criteria
- **100% Core Functionality**: β
All database operations work
- **100% Security**: β
Safety system properly enforced
- **100% Data Integrity**: β
All data operations return accurate results
- **100% Error Handling**: β
Clear error messages for policy violations
- **100% MCP Compatibility**: β
All tools return proper MCP responses
### Production Readiness Assessment
#### β
FULLY PRODUCTION READY - COMPREHENSIVELY VALIDATED
- **β
All 16 MCP Tools**: 100% functional across all security phases
- **β
Three-Tier Security**: 100% validated across 40 integration tests
- **β
MCP Protocol**: 100% compliant through 20 protocol tests
- **β
Enterprise Ready**: SSL/TLS, configuration management, error handling
- **β
Performance Monitoring**: Comprehensive tracking and optimization
- **β
Code Quality**: 535+ unit tests with extensive coverage
**TOTAL VALIDATION**: 610+ tests with 100% success rate
## Testing Architecture Improvements β
### Completed in v1.7.0+
1. β
**Comprehensive Testing Suite**: 610+ tests across all system layers
2. β
**Manual Integration Testing**: 40 tests validating all 3 security phases
3. β
**Protocol Testing**: 20 tests validating MCP client-server communication
4. β
**CI/CD Integration**: Automated tests run on every commit
5. β
**Production Validation**: 100% success rate across all test phases
6. β
**Test Organization**: Clear separation of automated vs manual testing
7. β
**Documentation**: Comprehensive guides for all testing approaches
### Testing Infrastructure
1. β
**Unit Tests**: Mock-based testing for rapid development feedback
2. β
**Integration Tests**: Live database validation for production readiness
3. β
**Protocol Tests**: End-to-end MCP communication validation
4. β
**Security Testing**: All three security phases comprehensively validated
5. β
**Performance Testing**: Query execution and optimization validation
## Conclusion
The SQL Server MCP server has been **comprehensively validated** through extensive testing across all system layers:
### π― **Validation Summary**
- **β
610+ Total Tests**: Complete system validation
- **β
100% Success Rate**: All tests passing across all phases
- **β
Production Validated**: Live database testing with real-world scenarios
- **β
Security Proven**: Three-tier safety system comprehensively tested
- **β
Protocol Compliant**: Full MCP client-server communication validated
- **β
Enterprise Ready**: SSL/TLS, performance monitoring, error handling
### π **Deployment Confidence**
With **100% test success rates** across:
- **535+ Unit Tests** - Code logic validation
- **15 Integration Tests** - Component integration
- **40 Manual Tests** - Security phase validation
- **20 Protocol Tests** - MCP communication validation
**Overall Assessment**: β
**COMPREHENSIVELY VALIDATED - ENTERPRISE PRODUCTION READY**
This MCP server demonstrates enterprise-grade software development practices with rigorous testing, robust security, and production-ready reliability.
---
_This document should be updated as issues are resolved and new features are added._
```
````