mssql-mcp 1.0.3 ā 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +98 -76
- package/dist/index.js +16 -20
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,38 +1,18 @@
|
|
|
1
|
-
# MS SQL Server MCP Server
|
|
1
|
+
# MS SQL Server MCP Server v2.0.3
|
|
2
2
|
|
|
3
|
-
Model Context Protocol (MCP) server for Microsoft SQL Server
|
|
3
|
+
š **Smart Trust-Based Model Context Protocol (MCP) server** for Microsoft SQL Server with intelligent auto-connection and AI-friendly design.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## š Quick Start
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
- ā
**Input Validation**: Strict validation for table names, schema names, and query parameters
|
|
9
|
-
- ā
**Updated Dependencies**: Latest @modelcontextprotocol/sdk (v1.17.1)
|
|
10
|
-
- ā
**Better Error Handling**: Comprehensive logging and graceful error recovery
|
|
11
|
-
- ā
**Performance Monitoring**: Query execution time tracking
|
|
12
|
-
- ā
**Connection Security**: Enhanced SSL/TLS settings and connection pooling
|
|
7
|
+
### 1. Install
|
|
13
8
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
- š **SQL Query Execution**: Parameterized queries and DDL/DML operations with injection protection
|
|
18
|
-
- šļø **Schema Management**: Tables, views, stored procedures
|
|
19
|
-
- š **Table Operations**: Structure inspection, data viewing, pagination
|
|
20
|
-
- āļø **Stored Procedures**: Execute with parameters
|
|
21
|
-
- š¢ **Database Listing**: All databases in the instance
|
|
22
|
-
- š **Security**: SQL injection protection, input validation
|
|
23
|
-
|
|
24
|
-
## IDE Configuration
|
|
25
|
-
|
|
26
|
-
This MCP server can be used in IDEs like Claude Desktop, Cursor, Windsurf, and VS Code.
|
|
27
|
-
|
|
28
|
-
### Configuration Files
|
|
29
|
-
|
|
30
|
-
**For Claude Desktop**: `%APPDATA%\Claude\claude_desktop_config.json` (Windows) or `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS)
|
|
31
|
-
|
|
32
|
-
**For VS Code-based IDEs**: `.vscode/mcp.json`
|
|
9
|
+
```bash
|
|
10
|
+
npm install -g mssql-mcp
|
|
11
|
+
```
|
|
33
12
|
|
|
34
|
-
###
|
|
13
|
+
### 2. Configure IDE
|
|
35
14
|
|
|
15
|
+
**Claude Desktop** (`claude_desktop_config.json`):
|
|
36
16
|
```json
|
|
37
17
|
{
|
|
38
18
|
"mcpServers": {
|
|
@@ -41,10 +21,9 @@ This MCP server can be used in IDEs like Claude Desktop, Cursor, Windsurf, and V
|
|
|
41
21
|
"args": ["-y", "mssql-mcp@latest"],
|
|
42
22
|
"env": {
|
|
43
23
|
"DB_SERVER": "your-server.com",
|
|
44
|
-
"DB_DATABASE": "your-database",
|
|
24
|
+
"DB_DATABASE": "your-database",
|
|
45
25
|
"DB_USER": "your-username",
|
|
46
26
|
"DB_PASSWORD": "your-password",
|
|
47
|
-
"DB_PORT": "1433",
|
|
48
27
|
"DB_TRUST_SERVER_CERTIFICATE": "true"
|
|
49
28
|
}
|
|
50
29
|
}
|
|
@@ -52,63 +31,106 @@ This MCP server can be used in IDEs like Claude Desktop, Cursor, Windsurf, and V
|
|
|
52
31
|
}
|
|
53
32
|
```
|
|
54
33
|
|
|
55
|
-
|
|
34
|
+
**Cursor/Windsurf/VS Code** (`.vscode/mcp.json`):
|
|
35
|
+
```json
|
|
36
|
+
{
|
|
37
|
+
"servers": {
|
|
38
|
+
"mssql": {
|
|
39
|
+
"command": "npx",
|
|
40
|
+
"args": ["-y", "mssql-mcp@latest"],
|
|
41
|
+
"env": {
|
|
42
|
+
"DB_SERVER": "your-server.com",
|
|
43
|
+
"DB_DATABASE": "your-database",
|
|
44
|
+
"DB_USER": "your-username",
|
|
45
|
+
"DB_PASSWORD": "your-password",
|
|
46
|
+
"DB_TRUST_SERVER_CERTIFICATE": "true"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
> Replace with your actual database credentials. Server auto-connects using these.
|
|
54
|
+
|
|
55
|
+
## š ļø Available Tools
|
|
56
56
|
|
|
57
|
-
|
|
57
|
+
| Tool | Description |
|
|
58
|
+
|------|-------------|
|
|
59
|
+
| `execute_query` | Execute any SQL query with parameters |
|
|
60
|
+
| `get_schema` | List database objects (tables, views, procedures) |
|
|
61
|
+
| `describe_table` | Get detailed table structure |
|
|
62
|
+
| `get_table_data` | Retrieve data with pagination |
|
|
63
|
+
| `execute_procedure` | Execute stored procedures |
|
|
64
|
+
| `list_databases` | List all databases |
|
|
65
|
+
| `connection_status` | Check connection state |
|
|
66
|
+
| `connect_database` | Manual connection (rarely needed) |
|
|
67
|
+
| `disconnect_database` | Close connection |
|
|
68
|
+
| `clear_cache` | Clear query cache |
|
|
58
69
|
|
|
59
|
-
|
|
60
|
-
- **Windows**: Use `"command": "cmd"` and `"args": ["/c", "npx", "-y", "mssql-mcp@latest"]`
|
|
61
|
-
- **WSL**: Use `"command": "wsl"` and `"args": ["npx", "-y", "mssql-mcp@latest"]`
|
|
70
|
+
All tools auto-connect using environment variables.
|
|
62
71
|
|
|
63
|
-
## Environment Variables
|
|
72
|
+
## š§ Environment Variables
|
|
64
73
|
|
|
65
|
-
|
|
74
|
+
| Variable | Required | Default |
|
|
75
|
+
|----------|----------|---------|
|
|
76
|
+
| `DB_SERVER` | ā
| - |
|
|
77
|
+
| `DB_DATABASE` | ā
| - |
|
|
78
|
+
| `DB_USER` | ā
| - |
|
|
79
|
+
| `DB_PASSWORD` | ā
| - |
|
|
80
|
+
| `DB_PORT` | ā | 1433 |
|
|
81
|
+
| `DB_TRUST_SERVER_CERTIFICATE` | ā | true |
|
|
82
|
+
| `DB_CONNECTION_TIMEOUT` | ā | 30000 |
|
|
83
|
+
| `DB_REQUEST_TIMEOUT` | ā | 30000 |
|
|
66
84
|
|
|
67
|
-
|
|
68
|
-
- `DB_DATABASE`: Database name
|
|
69
|
-
- `DB_USER`: Username (leave empty for Windows Authentication)
|
|
70
|
-
- `DB_PASSWORD`: Password
|
|
71
|
-
- `DB_PORT`: Port number (default: 1433)
|
|
72
|
-
- `DB_TRUST_SERVER_CERTIFICATE`: SSL certificate trust (true/false)
|
|
73
|
-
- `DB_CONNECTION_TIMEOUT`: Connection timeout in milliseconds (default: 30000)
|
|
74
|
-
- `DB_REQUEST_TIMEOUT`: Request timeout in milliseconds (default: 30000)
|
|
85
|
+
## š”ļø Security
|
|
75
86
|
|
|
76
|
-
|
|
87
|
+
**ā
Supported:** All database operations (SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, DROP)
|
|
77
88
|
|
|
78
|
-
|
|
89
|
+
**šØ Blocked:** Server-level operations only (SHUTDOWN, XP_CMDSHELL, RECONFIGURE)
|
|
79
90
|
|
|
80
|
-
|
|
81
|
-
|----------|-------------|
|
|
82
|
-
| `connect_database` | Establishes connection to SQL Server |
|
|
83
|
-
| `connection_status` | Checks connection status |
|
|
84
|
-
| `disconnect_database` | Closes the connection |
|
|
85
|
-
| `execute_query` | Executes SQL queries (SELECT, INSERT, UPDATE, DELETE) |
|
|
86
|
-
| `execute_procedure` | Executes stored procedures |
|
|
87
|
-
| `get_schema` | Lists database schema (tables, views, procedures) |
|
|
88
|
-
| `describe_table` | Shows detailed table structure |
|
|
89
|
-
| `list_databases` | Lists all databases |
|
|
90
|
-
| `get_table_data` | Retrieves table data with pagination |
|
|
91
|
+
## š Features
|
|
91
92
|
|
|
92
|
-
|
|
93
|
+
- ā
**Auto-Connection**: Environment-based, no manual steps
|
|
94
|
+
- ā
**Complete SQL Support**: All database operations
|
|
95
|
+
- ā
**No Rate Limiting**: Natural workflow
|
|
96
|
+
- ā
**Query Caching**: 5-minute TTL for SELECT queries
|
|
97
|
+
- ā
**Performance Monitoring**: Execution time tracking
|
|
98
|
+
- ā
**Latest MCP SDK**: v1.20.2 with 2025 protocol
|
|
99
|
+
- ā
**Clean Logging**: Minimal console output, MCP protocol compatible
|
|
93
100
|
|
|
94
|
-
|
|
95
|
-
- **Input Validation**: All user inputs are validated and sanitized
|
|
96
|
-
- **SSL/TLS**: Enable encryption for production environments
|
|
97
|
-
- **Connection Pooling**: Automatic connection management with timeout settings
|
|
98
|
-
- **Error Handling**: Comprehensive error logging without exposing sensitive information
|
|
99
|
-
- **Parameterized Queries**: Always use parameters for user input to prevent SQL injection
|
|
101
|
+
## š Troubleshooting
|
|
100
102
|
|
|
101
|
-
|
|
103
|
+
**ā Auto-connection failed**
|
|
104
|
+
- Set all required environment variables
|
|
105
|
+
- Verify server accessibility and credentials
|
|
106
|
+
- Check network connectivity
|
|
102
107
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
4. **Monitor logs for security warnings**
|
|
107
|
-
5. **Regularly update the package for security fixes**
|
|
108
|
+
**ā SQL Security Alert**
|
|
109
|
+
- Only server operations are blocked
|
|
110
|
+
- Database operations should work normally
|
|
108
111
|
|
|
109
|
-
##
|
|
112
|
+
## š Version History
|
|
110
113
|
|
|
111
|
-
|
|
114
|
+
### v2.0.3 - Latest
|
|
115
|
+
- ā
Updated documentation with modern styling
|
|
116
|
+
- ā
Improved troubleshooting section
|
|
117
|
+
- ā
Enhanced feature descriptions
|
|
118
|
+
|
|
119
|
+
### v2.0.2 - Performance & Compatibility
|
|
120
|
+
- ā
Simplified logging for MCP protocol compatibility
|
|
121
|
+
- ā
All console output moved to stderr
|
|
122
|
+
- ā
Clean, professional log messages
|
|
123
|
+
- ā
Version bump to 2.0.2
|
|
124
|
+
|
|
125
|
+
## š License
|
|
126
|
+
|
|
127
|
+
MIT License
|
|
128
|
+
|
|
129
|
+
## š Support
|
|
130
|
+
|
|
131
|
+
- **Issues**: [GitHub Issues](https://github.com/BYMCS/mssql-mcp/issues)
|
|
112
132
|
- **Repository**: [BYMCS/mssql-mcp](https://github.com/BYMCS/mssql-mcp)
|
|
113
|
-
|
|
114
|
-
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
**š v2.0.3: Enhanced documentation and user experience**
|
package/dist/index.js
CHANGED
|
@@ -24,7 +24,7 @@ class MSSQLMCPServer {
|
|
|
24
24
|
constructor() {
|
|
25
25
|
this.server = new McpServer({
|
|
26
26
|
name: "mssql-mcp-server",
|
|
27
|
-
version: "
|
|
27
|
+
version: "2.0.3",
|
|
28
28
|
});
|
|
29
29
|
this.setupTools();
|
|
30
30
|
this.setupResources();
|
|
@@ -511,10 +511,10 @@ class MSSQLMCPServer {
|
|
|
511
511
|
try {
|
|
512
512
|
// Close existing connection if any
|
|
513
513
|
if (this.pool) {
|
|
514
|
-
console.
|
|
514
|
+
console.error("Closing existing connection...");
|
|
515
515
|
await this.pool.close();
|
|
516
516
|
}
|
|
517
|
-
console.
|
|
517
|
+
console.error(`Connecting to ${config.server}:${config.port}`);
|
|
518
518
|
// Create new connection pool with enhanced security settings
|
|
519
519
|
this.pool = new sql.ConnectionPool({
|
|
520
520
|
server: config.server,
|
|
@@ -538,17 +538,17 @@ class MSSQLMCPServer {
|
|
|
538
538
|
});
|
|
539
539
|
// Set up event handlers for better monitoring
|
|
540
540
|
this.pool.on('connect', () => {
|
|
541
|
-
console.
|
|
541
|
+
console.error('Database connected');
|
|
542
542
|
});
|
|
543
543
|
this.pool.on('error', (err) => {
|
|
544
|
-
console.error('
|
|
544
|
+
console.error('Database error:', err);
|
|
545
545
|
});
|
|
546
546
|
await this.pool.connect();
|
|
547
547
|
this.config = config;
|
|
548
|
-
console.
|
|
548
|
+
console.error(`Connected to ${config.server}${config.database ? `/${config.database}` : ''}`);
|
|
549
549
|
}
|
|
550
550
|
catch (error) {
|
|
551
|
-
console.error("
|
|
551
|
+
console.error("Connection failed:", error);
|
|
552
552
|
if (this.pool) {
|
|
553
553
|
try {
|
|
554
554
|
await this.pool.close();
|
|
@@ -566,18 +566,18 @@ class MSSQLMCPServer {
|
|
|
566
566
|
const transport = new StdioServerTransport();
|
|
567
567
|
// Enhanced graceful shutdown handling
|
|
568
568
|
const shutdown = async (signal) => {
|
|
569
|
-
console.
|
|
569
|
+
console.error(`\nShutting down (${signal})...`);
|
|
570
570
|
try {
|
|
571
571
|
if (this.pool) {
|
|
572
|
-
console.
|
|
572
|
+
console.error("Closing database connection...");
|
|
573
573
|
await this.pool.close();
|
|
574
|
-
console.
|
|
574
|
+
console.error("Database connection closed");
|
|
575
575
|
}
|
|
576
576
|
}
|
|
577
577
|
catch (error) {
|
|
578
|
-
console.error("
|
|
578
|
+
console.error("Shutdown error:", error);
|
|
579
579
|
}
|
|
580
|
-
console.
|
|
580
|
+
console.error("Server stopped");
|
|
581
581
|
process.exit(0);
|
|
582
582
|
};
|
|
583
583
|
// Handle various shutdown signals
|
|
@@ -586,20 +586,16 @@ class MSSQLMCPServer {
|
|
|
586
586
|
process.on('SIGUSR2', () => shutdown('SIGUSR2')); // For nodemon
|
|
587
587
|
// Handle uncaught exceptions
|
|
588
588
|
process.on('uncaughtException', (error) => {
|
|
589
|
-
console.error('
|
|
589
|
+
console.error('Uncaught Exception:', error);
|
|
590
590
|
shutdown('uncaughtException');
|
|
591
591
|
});
|
|
592
592
|
process.on('unhandledRejection', (reason, promise) => {
|
|
593
|
-
console.error('
|
|
593
|
+
console.error('Unhandled Rejection:', reason);
|
|
594
594
|
shutdown('unhandledRejection');
|
|
595
595
|
});
|
|
596
|
-
console.
|
|
597
|
-
console.log("š Security features enabled:");
|
|
598
|
-
console.log(" - SQL injection protection: Enabled");
|
|
599
|
-
console.log(" - Input validation: Enhanced");
|
|
600
|
-
console.log(" - Parameterized queries: Enforced");
|
|
596
|
+
console.error("MSSQL MCP Server v2.0.3 starting...");
|
|
601
597
|
await this.server.connect(transport);
|
|
602
|
-
console.
|
|
598
|
+
console.error("Server ready");
|
|
603
599
|
}
|
|
604
600
|
}
|
|
605
601
|
// Start the server
|