MCP server for SQL Server database exploration and RAG capabilities (macOS with Docker SQL Server support)
npm install @tharanabopearachchi/sql-server-mcp-macosA Model Context Protocol (MCP) server for SQL Server that enables AI assistants like Claude to explore and query SQL Server databases. Designed specifically as a RAG (Retrieval-Augmented Generation) system for database knowledge, focusing on schema exploration and research queries.
1. Clone or download this repository
2. Install dependencies
``bash`
cd sql-server-mcp
npm install
3. Build the project
`bash`
npm run build
4. Configure environment (optional)
Copy .env.example to .env and customize:`bash`
cp .env.example .env
Edit .env with your settings:`env`
SQL_SERVER=localhost
SQL_DATABASE=master
SQL_PORT=1433
SQL_USE_WINDOWS_AUTH=true
QUERY_TIMEOUT=30
MAX_RESULT_ROWS=1000
Add to your Claude Desktop config file:
Windows: %APPDATA%\Claude\claude_desktop_config.json~/Library/Application Support/Claude/claude_desktop_config.json
macOS:
`json`
{
"mcpServers": {
"sql-server": {
"command": "node",
"args": ["D:\\path\\to\\sql-server-mcp\\dist\\index.js"],
"env": {
"SQL_SERVER": "localhost",
"SQL_DATABASE": "YourDatabase",
"SQL_USE_WINDOWS_AUTH": "true",
"SQL_PORT": "1433",
"QUERY_TIMEOUT": "30",
"MAX_RESULT_ROWS": "1000",
"ENABLE_SCHEMA_CACHE": "true",
"CACHE_TTL_MINUTES": "60"
}
}
}
}
`json`
{
"mcpServers": {
"sql-server": {
"command": "node",
"args": ["D:\\path\\to\\sql-server-mcp\\dist\\index.js"],
"env": {
"SQL_SERVER": "localhost",
"SQL_DATABASE": "YourDatabase",
"SQL_USE_WINDOWS_AUTH": "false",
"SQL_USERNAME": "your_username",
"SQL_PASSWORD": "your_password",
"SQL_PORT": "1433",
"QUERY_TIMEOUT": "30",
"MAX_RESULT_ROWS": "1000"
}
}
}
}
`json`
{
"mcpServers": {
"sql-server": {
"command": "node",
"args": ["D:\\path\\to\\sql-server-mcp\\dist\\index.js"],
"env": {
"SQL_SERVER": "localhost",
"SQL_DATABASE": "master",
"SQL_USE_WINDOWS_AUTH": "true",
"SQL_ALLOWED_DATABASES": "MyAppDB,MyTestDB,Analytics",
"QUERY_TIMEOUT": "30",
"MAX_RESULT_ROWS": "500"
}
}
}
}
| Variable | Description | Default | Required |
|----------|-------------|---------|----------|
| SQL_SERVER | SQL Server hostname or IP | localhost | Yes |SQL_DATABASE
| | Default database to connect to | master | Yes |SQL_PORT
| | SQL Server port | 1433 | No |SQL_USE_WINDOWS_AUTH
| | Use Windows Authentication | true | Yes |SQL_USERNAME
| | SQL Server username | - | If not using Windows Auth |SQL_PASSWORD
| | SQL Server password | - | If not using Windows Auth |SQL_ALLOWED_DATABASES
| | Comma-separated list of allowed databases | All | No |QUERY_TIMEOUT
| | Query timeout in seconds | 30 | No |MAX_RESULT_ROWS
| | Maximum rows to return | 1000 | No |ENABLE_WRITE_OPERATIONS
| | Allow INSERT/UPDATE/DELETE | false | No |ENABLE_SCHEMA_CACHE
| | Enable schema caching | true | No |CACHE_TTL_MINUTES
| | Cache expiration time | 60 | No |
Parameters:
- includeSystem (boolean, optional) - Include system databases
Example:
``
List all databases on the server
Parameters:
- database (string, required) - Database name
Example:
``
List all tables in the MyAppDB database
Parameters:
- database (string, required) - Database nametableName
- (string, required) - Table name (can include schema, e.g., "dbo.Users")
Example:
``
Describe the Users table in MyAppDB
Parameters:
- database (string, required) - Database nametableName
- (string, required) - Table name
Example:
``
Show me the relationships for the Orders table
Parameters:
- database (string, required) - Database namesearchTerm
- (string, required) - Search keyword
Example:
``
Search for "customer" in the database schema
Parameters:
- database (string, required) - Database namecolumnName
- (string, required) - Exact column name
Example:
``
Where is the CustomerID column used?
Parameters:
- database (string, required) - Database name
Parameters:
- database (string, required) - Database nameprocedureName
- (string, required) - Procedure name
Parameters:
- database (string, required) - Database name
Parameters:
- database (string, required) - Database name
Parameters:
- database (string, required) - Database namequery
- (string, required) - SQL SELECT query
Example:
``
Execute: SELECT TOP 10 * FROM Users WHERE Active = 1
Parameters:
- database (string, required) - Database nametableName
- (string, required) - Table name
1. Understanding Database Structure
``
"What databases are available on this server?"
"Show me all tables in the SalesDB database"
"What's the structure of the Customers table?"
2. Finding Implementations
``
"Where is the OrderStatus field used across the database?"
"Search for any tables or columns related to 'invoice'"
"Find all stored procedures that mention 'payment'"
3. Analyzing Relationships
``
"How are the Orders and OrderDetails tables related?"
"Show me all tables that reference the Customers table"
"What tables are connected to the Products table?"
4. Data Exploration
``
"Execute: SELECT TOP 10 ProductName, UnitPrice FROM Products ORDER BY UnitPrice DESC"
"Get a summary of the database structure"
"Show me recent orders from the Orders table"
- Read-only by default - Write operations disabled unless explicitly enabled
- SQL injection prevention - Query validation and sanitization
- Query timeouts - Prevents long-running queries from blocking
- Result limits - Automatic row limiting to prevent memory issues
- Database whitelisting - Optional restriction to specific databases
- Windows Authentication support - Secure local connections
Problem: Cannot connect to SQL Server
Solutions:
1. Verify SQL Server is running and accessible
2. Check firewall settings (port 1433)
3. Enable TCP/IP in SQL Server Configuration Manager
4. For Windows Auth, ensure the user has database access
5. For SQL Auth, verify credentials are correct
Problem: Windows Authentication not working
Solutions:
1. Set SQL_USE_WINDOWS_AUTH=true
2. Ensure the Windows user has SQL Server access
3. Check SQL Server allows Windows Authentication (not mixed mode required)
Problem: SQL Server Authentication not working
Solutions:
1. Set SQL_USE_WINDOWS_AUTH=falseSQL_USERNAME
2. Provide and SQL_PASSWORD
3. Verify SQL Server is in Mixed Mode authentication
4. Check user has appropriate permissions
Problem: Claude cannot see the MCP server tools
Solutions:
1. Restart Claude Desktop after config changes
2. Check claude_desktop_config.json syntaxdist/index.js
3. Verify the path to is correct (absolute path)npm run build
4. Build the project:
5. Check Claude Desktop logs for errors
Problem: "Only SELECT queries are allowed"
Solution: This is intentional. The server is read-only by default. To enable write operations (not recommended), set ENABLE_WRITE_OPERATIONS=true
Problem: Query timeout
Solution: Increase QUERY_TIMEOUT or optimize the query
bash
npm run build
`$3
`bash
npm run watch
`$3
`
sql-server-mcp/
├── src/
│ ├── index.ts # MCP server entry point
│ ├── database/
│ │ ├── connection.ts # SQL Server connection pool
│ │ ├── queries.ts # SQL query templates
│ │ └── cache.ts # Schema caching layer
│ ├── tools/
│ │ ├── schema.ts # Schema exploration tools
│ │ ├── relationships.ts # Relationship mapping tools
│ │ ├── search.ts # Search & discovery tools
│ │ └── query.ts # Safe query execution
│ └── types/
│ └── index.ts # TypeScript interfaces
├── package.json
├── tsconfig.json
└── README.md
``This implementation focuses on:
- Local SQL Server support with Windows Authentication
- RAG-optimized for database knowledge exploration
- Research-focused tools (not CRUD operations)
- Schema caching for faster repeated queries
- Simpler configuration for local development
- Read-only by default for safety
MIT
Contributions are welcome! Please feel free to submit issues or pull requests.
For issues or questions:
1. Check the Troubleshooting section above
2. Review SQL Server connection settings
3. Check Claude Desktop logs
4. Verify database permissions
Built using:
- Model Context Protocol SDK
- Tedious - SQL Server driver for Node.js
- Zod - Schema validation