This MCP server allows you to connect to Microsoft SQL Server databases and execute SQL queries through a standardized Model Context Protocol interface. It provides a convenient way to integrate SQL Server database operations into your workflows.
The easiest way to install the MSSQL MCP Server for Claude Desktop is via Smithery:
npx -y @smithery/cli install @c0h1b4/mssql-mcp-server --client claude
Alternatively, you can install the package directly using npm:
npm install mssql-mcp-server
To use the server, add it to your MCP settings configuration file:
{
"mcpServers": {
"mssql": {
"command": "mssql-mcp-server",
"env": {
"MSSQL_CONNECTION_STRING": "Server=localhost;Database=master;User Id=sa;Password=yourpassword;"
}
}
}
}
You can also configure the connection using individual parameters instead of a connection string:
{
"mcpServers": {
"mssql": {
"command": "mssql-mcp-server",
"env": {
"MSSQL_HOST": "localhost",
"MSSQL_PORT": "1433",
"MSSQL_DATABASE": "master",
"MSSQL_USER": "sa",
"MSSQL_PASSWORD": "yourpassword",
"MSSQL_ENCRYPT": "false",
"MSSQL_TRUST_SERVER_CERTIFICATE": "true"
}
}
}
}
The main functionality is provided through the query
tool, which allows you to execute SQL queries against your database.
connectionString
(string, optional): Full connection stringhost
(string, optional): Database server hostnameport
(number, optional): Database server port (default: 1433)database
(string, optional): Database name (default: master)username
(string, optional): Database usernamepassword
(string, optional): Database passwordquery
(string, required): SQL query to executeencrypt
(boolean, optional): Enable encryption (default: false)trustServerCertificate
(boolean, optional): Trust server certificate (default: true)Note: You must provide either connectionString
OR the combination of host
, username
, and password
.
Here's how to execute a simple query:
const result = await use_mcp_tool({
server_name: 'mssql',
tool_name: 'query',
arguments: {
host: 'localhost',
username: 'sa',
password: 'yourpassword',
query: 'SELECT * FROM Users',
},
});
The server implements several security measures:
Always use appropriate authentication and limit database user permissions to reduce potential security risks.
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "mssql" '{"command":"mssql-mcp-server","env":{"MSSQL_CONNECTION_STRING":"Server=localhost;Database=master;User Id=sa;Password=yourpassword;"}}'
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": "mssql-mcp-server",
"env": {
"MSSQL_CONNECTION_STRING": "Server=localhost;Database=master;User Id=sa;Password=yourpassword;"
}
}
}
}
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.json
2. Add this to your configuration file:
{
"mcpServers": {
"mssql": {
"command": "mssql-mcp-server",
"env": {
"MSSQL_CONNECTION_STRING": "Server=localhost;Database=master;User Id=sa;Password=yourpassword;"
}
}
}
}
3. Restart Claude Desktop for the changes to take effect