MSSQL MCP Server
Connect to and interact with Microsoft SQL Server databases.
MSSQL MCP Server
A Model Context Protocol (MCP) server for connecting to Microsoft SQL Server databases. This server provides tools for executing SQL queries and managing database connections.
Version Notice: This project has been upgraded to use Model Context Protocol SDK 1.9.0. See UPGRADE.md for details.
Installation
Installing via Smithery
To install MSSQL MCP Server for Claude Desktop automatically via Smithery:
npx -y @smithery/cli install @c0h1b4/mssql-mcp-server --client claude
Manual Installation
npm install mssql-mcp-server
Usage
Add the server 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;",
// Or individual connection parameters:
"MSSQL_HOST": "localhost",
"MSSQL_PORT": "1433",
"MSSQL_DATABASE": "master",
"MSSQL_USER": "sa",
"MSSQL_PASSWORD": "yourpassword",
"MSSQL_ENCRYPT": "false",
"MSSQL_TRUST_SERVER_CERTIFICATE": "true"
}
}
}
}
Tools
query
Execute a SQL query on a MSSQL database.
Parameters
connectionString(string, optional): Full connection string (alternative to individual parameters)host(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)
Either connectionString OR (host + username + password) must be provided.
Example
const result = await use_mcp_tool({
server_name: 'mssql',
tool_name: 'query',
arguments: {
host: 'localhost',
username: 'sa',
password: 'yourpassword',
query: 'SELECT * FROM Users',
},
});
Running the Server
Local Development
# Install dependencies
npm install
# Run in development mode
npm run dev
# Build
npm run build
# Run the built server
npm start
Using Docker
# Build and start services (SQL Server + MCP server)
docker-compose up
# Or just build the Docker image
docker build -t mssql-mcp-server .
Testing
# Run tests
npm test
# Run tests with coverage
npm run test:coverage
Running evals
The evals package loads an mcp client that then runs the index.ts file, so there is no need to rebuild between tests. You can load environment variables by prefixing the npx command. Full documentation can be found here.
OPENAI_API_KEY=your-key npx mcp-eval src/evals/evals.ts examples/simple-server.ts
Security
The server includes safeguards against dangerous SQL operations:
- Blocks potentially harmful commands like DROP, TRUNCATE, ALTER, CREATE, EXEC, etc.
- Validates all input parameters and database names
- Sets reasonable limits on query length and timeout
- Uses connection pooling for better performance and security
License
MIT
Related Servers
Solana MCP Server
Provides comprehensive access to Solana blockchain data using 21 essential RPC methods.
Instructure DAP
Query Canvas and other Instructure data using the Instructure Data Access Platform (DAP) API.
Iceberg MCP Server (via Impala)
Provides read-only access to Apache Iceberg tables via Apache Impala, allowing LLMs to inspect schemas and execute queries.
Highrise by CData
A read-only MCP server for Highrise, enabling LLMs to query live data using the CData JDBC Driver.
Tabular MCP Server
An MCP server for local Tabular Models like PowerBI. It allows LLM clients to debug, analyze, and compose DAX queries by connecting to a local Tabular model instance.
KnowledgeGraph MCP Server
Enables persistent knowledge storage for Claude using a knowledge graph with multiple database backends like PostgreSQL and SQLite.
Trino MCP Server
A Go implementation of a Model Context Protocol (MCP) server for Trino, enabling LLM models to query distributed SQL databases through standardized tools.
MySQL MCP Server
A MySQL database server for AI assistants, enabling full CRUD operations, transaction management, and intelligent rollback.
ChromaDB MCP
An MCP server for vector storage and retrieval using ChromaDB.
PostgreSQL Multi-Schema
Provides read-only access to PostgreSQL databases with multi-schema support, allowing LLMs to inspect schemas and execute queries across different namespaces.