- MS SQL Server MCP Server
MS SQL Server MCP Server
MCP Server for MS SQL Integration - Provides ModelContextProtocol support for Microsoft SQL Server
Content
MS SQL Server MCP Server
This project provides an MCP server for interacting with MS SQL Server databases via AI assistants using the Model Context Protocol (MCP).
It uses a secure profile management system leveraging the system's native credential store (via the keyring library) to avoid sending passwords over MCP.
Prerequisites
For Direct Python Execution:
- Python 3.10+
- Pip (Python package installer)
- ODBC Driver for SQL Server installed on the machine running the server.
keyringlibrary dependencies might require system packages (e.g.,dbus-launch,gnome-keyringorkwalleton Linux, seekeyringdocumentation for details).
For Docker Execution:
- Docker installed and running.
- The Dockerfile is configured to use the
keyrings.cryptfilebackend for secure password storage within the container's filesystem. This requires mounting a volume for persistence.
Installation
Option 1: Direct Python Execution
- Clone the repository (if applicable):
git clone <repository_url> cd mcp-server-mssql - Create and activate a Python virtual environment:
python -m venv venv # Activate (Windows PowerShell): .\venv\Scripts\Activate.ps1 # Activate (macOS/Linux): source venv/bin/activate - Install dependencies:
pip install -r requirements.txt
Option 2: Docker Execution
- Clone the repository (if applicable).
- Build the Docker image:
(Note: The Dockerfile includes ODBC driver installation and configures thedocker build -t mcp-mssql-server .keyrings.cryptfilebackend.)
Configuration: Profile Management
This server uses connection profiles to manage database credentials securely.
- Profiles File (
profiles.json): Stores non-sensitive details (driver, server, database, username) locally in the server's directory. This file is created automatically if it doesn't exist. Ensure this file is added to your.gitignore. - System Keyring: Passwords are stored securely in your operating system's credential manager (like Windows Credential Manager, macOS Keychain) using the
keyringlibrary under the service namemcp-mssql-server. - Adding Profiles: Use the
add_connection_profiletool. When first adding a profile, you will be prompted in the terminal where the server is running to securely enter the password. This password is never sent via MCP. - Managing Profiles: Use
list_connection_profilesandremove_connection_profiletools.
Usage
Option 1: Direct Python Execution (Stdio)
- Activate the virtual environment.
- Configure in MCP Client Settings (e.g.,
mcp_settings.json):
Adjust paths accordingly.{ "mcpServers": { // ... other servers ... "mssql": { "command": "python", // Or full path to venv python "args": ["D:/path/to/your/mcp-server-mssql/server.py"], "cwd": "D:/path/to/your/mcp-server-mssql", "alwaysAllow": [ "add_connection_profile", "list_connection_profiles", "remove_connection_profile", "read_table_rows", "create_table_records", "update_table_records", "delete_table_records", "get_table_schema", "list_tables" ] } // ... other servers ... } } - Restart your MCP Client/IDE Extension. Add profiles using the
add_connection_profiletool (requires console interaction for password).
Option 2: Docker Execution (Stdio)
- Ensure the Docker image
mcp-mssql-serveris built. - Configure in MCP Client Settings:
{ "mcpServers": { // ... other servers ... "mssql-docker": { "command": "docker", "args": [ "run", "-i", "--rm", "--env-file", "./mcp-server-mssql/.env_docker", // Example: Store KEYRING_CRYPTFILE_PASSWORD here "-v", "mssql_keyring_data:/keyring_data", // Mount volume for keyring data "mcp-mssql-server" ], "alwaysAllow": [ "add_connection_profile", // Note: Password prompt will appear in container logs "list_connection_profiles", "remove_connection_profile", "read_table_rows", "create_table_records", "update_table_records", "delete_table_records", "get_table_schema", "list_tables" ] } // ... other servers ... } } - Restart your MCP Client/IDE Extension.
- Important:
- The Dockerfile is configured to use the
keyrings.cryptfilebackend. You MUST provide a strong password for encrypting the keyring file via theKEYRING_CRYPTFILE_PASSWORDenvironment variable when running the container. It is highly recommended to use a.envfile (like the example.env_dockerin theargs) or Docker secrets, rather than passing the password directly on the command line. - A Docker volume (e.g.,
mssql_keyring_datain the example) MUST be mounted to/keyring_datainside the container to persist the encrypted keyring file (keyring_pass.cfg) and theprofiles.jsonfile across container restarts. - The
add_connection_profilepassword prompt will still appear in the container's logs/terminal.
- The Dockerfile is configured to use the
Available Tools
Profile Management:
add_connection_profile(profile_name: str, driver: str, server: str, database: str, username: str)list_connection_profiles()remove_connection_profile(profile_name: str)
Database Operations (Requires profile_name):
read_table_rows(profile_name: str, table_name: str, ...)create_table_records(profile_name: str, table_name: str, records: List[Dict])update_table_records(profile_name: str, table_name: str, updates: Dict, filters: Dict)delete_table_records(profile_name: str, table_name: str, filters: Dict)get_table_schema(profile_name: str, table_name: str)list_tables(profile_name: str, schema: Optional[str] = None)
Refer to the docstrings within server.py for detailed argument descriptions.
Example Tool Usage (Conceptual)
- Add a profile (requires console interaction on server):
"Using the
mssqlserver, calladd_connection_profilewith nameSalesDB_UK, driver{ODBC Driver 17 for SQL Server}, servermyserver.example.com, databaseSalesDB, usernamereport_user." (Then enter password in server console). - Use the profile:
"Using the
mssqlserver, callread_table_rowsusing profileSalesDB_UKfor the tableCustomers. Filter whereCountryis 'UK'."
The AI assistant would construct the second call like:
// Conceptual MCP Tool Call
{
"tool_name": "read_table_rows",
"arguments": {
"profile_name": "SalesDB_UK",
"table_name": "Customers",
"filters": {
"Country": "UK"
}
}
}
Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
ChatWiseThe second fastest AI chatbot™
Playwright McpPlaywright MCP server
Tavily Mcp
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题;
Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
WindsurfThe new purpose-built IDE to harness magic
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
Serper MCP ServerA Serper MCP Server
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
CursorThe AI Code Editor
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
DeepChatYour AI Partner on Desktop
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
Amap Maps高德地图官方 MCP Server