The Microsoft SQL Server MCP server provides a comprehensive interface for AI assistants and language models to interact with MSSQL databases, enabling schema inspection, query execution, and management of database objects through a standardized protocol.
CRITICAL: Limit to ONE database per MCP server instance
IMPORTANT: File operations not supported within chat context
Clone or create the project directory:
mkdir mcp-sqlserver && cd mcp-sqlserver
Run the installation script:
chmod +x install.sh
./install.sh
Configure your database connection:
cp env.example .env
# Edit .env with your database details
Create virtual environment:
python3 -m venv venv
source venv/bin/activate
Install dependencies:
pip install -r requirements.txt
Install ODBC Driver (macOS):
brew tap microsoft/mssql-release
brew install msodbcsql17 mssql-tools
Create a .env file with your database configuration:
MSSQL_DRIVER={ODBC Driver 17 for SQL Server}
MSSQL_SERVER=your-server-address
MSSQL_DATABASE=your-database-name
MSSQL_USER=your-username
MSSQL_PASSWORD=your-password
MSSQL_PORT=1433
TrustServerCertificate=yes
MSSQL_SERVER: Server hostname or IP address (required)MSSQL_DATABASE: Database name to connect to (required)MSSQL_USER: Username for authenticationMSSQL_PASSWORD: Password for authenticationMSSQL_PORT: Port number (default: 1433)MSSQL_DRIVER: ODBC driver name (default: {ODBC Driver 17 for SQL Server})TrustServerCertificate: Trust server certificate (default: yes)Trusted_Connection: Use Windows authentication (default: no)For AI Assistant Integration:
python3 src/server.py
The server will start and wait for MCP protocol messages on stdin. This is how AI assistants like Claude Desktop or other MCP clients will communicate with it.
For Testing and Development:
Test database connection:
python3 test_connection.py
Check server status:
./status.sh
read_query - Execute SELECT queries to read datawrite_query - Execute INSERT, UPDATE, DELETE, and DDL querieslist_tables - List all tables in the databasedescribe_table - Get schema information for a specific tablecreate_table - Create new tablescreate_procedure - Create new stored proceduresmodify_procedure - Modify existing stored proceduresdelete_procedure - Delete stored procedureslist_procedures - List all stored procedures with metadatadescribe_procedure - Get complete procedure definitionsexecute_procedure - Execute procedures with parametersget_procedure_parameters - Get detailed parameter informationcreate_view - Create new viewsmodify_view - Modify existing viewsdelete_view - Delete viewslist_views - List all views in the databasedescribe_view - Get view definitions and schemacreate_index - Create new indexesdelete_index - Delete indexeslist_indexes - List all indexes (optionally by table)describe_index - Get detailed index informationlist_schemas - List all schemas in the databaselist_all_objects - List all database objects organized by schemaBoth tables and views are exposed as MCP resources with URIs like:
mssql://table_name/data - Access table data in CSV formatmssql://view_name/data - Access view data in CSV format# Start with schemas
list_schemas
# Get all objects in a specific schema
list_all_objects(schema_name: "dbo")
# Or get all objects across all schemas
list_all_objects()
# List all tables
list_tables
# Get detailed table information
describe_table(table_name: "YourTableName")
# Access table data as MCP resource
# URI: mssql://YourTableName/data
# List all views
list_views
# Get view definition
describe_view(view_name: "YourViewName")
# Create a new view
create_view(view_script: "CREATE VIEW MyView AS SELECT * FROM MyTable WHERE Active = 1")
# Access view data as MCP resource
# URI: mssql://YourViewName/data
# List all procedures
list_procedures
# Get complete procedure definition
describe_procedure(procedure_name: "YourProcedureName")
# Get parameter details
get_procedure_parameters(procedure_name: "YourProcedureName")
# Execute procedure
execute_procedure(procedure_name: "YourProcedureName", parameters: ["param1", "param2"])
# List all indexes
list_indexes()
# List indexes for specific table
list_indexes(table_name: "YourTableName")
# Get index details
describe_index(index_name: "IX_YourIndex", table_name: "YourTableName")
# Create new index
create_index(index_script: "CREATE INDEX IX_NewIndex ON MyTable (Column1, Column2)")
CREATE PROCEDURE GetEmployeeCount
AS
BEGIN
SELECT COUNT(*) AS TotalEmployees FROM Employees
END
CREATE PROCEDURE GetEmployeesByDepartment
@DepartmentId INT,
@MinSalary DECIMAL(10,2) = 0
AS
BEGIN
SELECT
EmployeeId,
FirstName,
LastName,
Salary,
DepartmentId
FROM Employees
WHERE DepartmentId = @DepartmentId
AND Salary >= @MinSalary
ORDER BY LastName, FirstName
END
CREATE PROCEDURE GetDepartmentStats
@DepartmentId INT,
@EmployeeCount INT OUTPUT,
@AverageSalary DECIMAL(10,2) OUTPUT
AS
BEGIN
SELECT
@EmployeeCount = COUNT(*),
@AverageSalary = AVG(Salary)
FROM Employees
WHERE DepartmentId = @DepartmentId
END
ALTER PROCEDURE GetEmployeesByDepartment
@DepartmentId INT,
@MinSalary DECIMAL(10,2) = 0,
@MaxSalary DECIMAL(10,2) = 999999.99
AS
BEGIN
SELECT
EmployeeId,
FirstName,
LastName,
Salary,
DepartmentId,
HireDate
FROM Employees
WHERE DepartmentId = @DepartmentId
AND Salary BETWEEN @MinSalary AND @MaxSalary
ORDER BY Salary DESC, LastName, FirstName
END
The server efficiently handles large database objects like stored procedures:
# Describe a large procedure (gets complete definition)
describe_procedure(procedure_name: "wmPostPurchase")
# Works with procedures of any size (tested with 1400+ line procedures)
While large procedures can be retrieved and displayed in chat, saving them to files via MCP tools is not reliable due to inference token limits. For bulk data extraction:
Add this server to your Claude Desktop configuration:
{
"mcpServers": {
"mssql": {
"command": "python3",
"args": ["/path/to/mcp-sqlserver/src/server.py"],
"cwd": "/path/to/mcp-sqlserver",
"env": {
"MSSQL_SERVER": "your-server",
"MSSQL_DATABASE": "your-database",
"MSSQL_USER": "your-username",
"MSSQL_PASSWORD": "your-password"
}
}
}
}
If you encounter issues with large content:
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "mssql" '{"command":"python3","args":["/path/to/mcp-sqlserver/src/server.py"],"cwd":"/path/to/mcp-sqlserver","env":{"MSSQL_SERVER":"your-server","MSSQL_DATABASE":"your-database","MSSQL_USER":"your-username","MSSQL_PASSWORD":"your-password"}}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:
{
"mcpServers": {
"mssql": {
"command": "python3",
"args": [
"/path/to/mcp-sqlserver/src/server.py"
],
"cwd": "/path/to/mcp-sqlserver",
"env": {
"MSSQL_SERVER": "your-server",
"MSSQL_DATABASE": "your-database",
"MSSQL_USER": "your-username",
"MSSQL_PASSWORD": "your-password"
}
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json%APPDATA%\Claude\claude_desktop_config.json~/.config/Claude/claude_desktop_config.json2. Add this to your configuration file:
{
"mcpServers": {
"mssql": {
"command": "python3",
"args": [
"/path/to/mcp-sqlserver/src/server.py"
],
"cwd": "/path/to/mcp-sqlserver",
"env": {
"MSSQL_SERVER": "your-server",
"MSSQL_DATABASE": "your-database",
"MSSQL_USER": "your-username",
"MSSQL_PASSWORD": "your-password"
}
}
}
}
3. Restart Claude Desktop for the changes to take effect