MCP MS SQL Server
A Model Context Protocol (MCP) server for Microsoft SQL Server that provides tools for database operations, data analysis, and visualization generation.
Installation
pip install mcp-mssql-server
## Features
This MCP server provides 8 powerful tools:
1. **sql_query** - Execute SQL queries with permission controls
2. **get_database_info** - Get server and database information
3. **show_tables** - List all tables in the database
4. **describe_table** - Get detailed table structure information
5. **show_indexes** - Display table indexes
6. **generate_analysis_notebook** - Create Jupyter notebooks for data analysis
7. **generate_visualization** - Create interactive visualizations (bar, scatter, pie, line, heatmap, table)
8. **generate_powerbi_visualization** - Generate Power BI compatible data exports
## Installation
1. Clone this repository
2. Install dependencies using uv:
```bash
cd mcp-mssql-server
uv pip install -e .
Configuration
use uv pip install -r requirements.txt to install all the requirements.
- Copy the
.envfile and update with your database credentials:
# Database Type (mssql)
DB_TYPE=mssql
# SQL Server Configuration
MSSQL_SERVER=tcp:your-server.database.windows.net
MSSQL_PORT=1433
MSSQL_USER=your-username
MSSQL_PASSWORD=your-password
MSSQL_DATABASE=your-database
MSSQL_ENCRYPT=true
MSSQL_TRUST_SERVER_CERTIFICATE=true
# Security Settings
ALLOW_WRITE_OPERATIONS=false
ALLOW_INSERT_OPERATION=false
ALLOW_UPDATE_OPERATION=false
ALLOW_DELETE_OPERATION=false
# Performance Settings
CONNECTION_POOL_MIN=1
CONNECTION_POOL_MAX=10
QUERY_TIMEOUT=30000
- Update the password field with your actual password.
Usage
Running the MCP Server
uv run python main.py
Or with logging:
uv run python main.py --log
uv run python mssql.py --log
Using with Claude Desktop
Add the following to your Claude Desktop configuration:
{
"mcp-mssql-server": {
"command": "uv",
"args": ["run", "python", "/path/to/mcp-mssql-server/mssql.py"]
}
}
Tools Documentation
1. sql_query
Execute any SQL query on the database.
{
"query": "SELECT TOP 10 * FROM users"
}
2. get_database_info
Get information about the SQL Server instance and available databases.
3. show_tables
List all tables in the current database.
{
"schema": "dbo" // optional
}
4. describe_table
Get detailed information about a table's columns and structure.
{
"table_name": "users",
"schema": "dbo"
}
5. show_indexes
Display indexes for a specific table or all tables.
{
"table_name": "users", // optional
"schema": "dbo"
}
6. generate_analysis_notebook
Create a Jupyter notebook with automated data analysis code.
{
"query": "SELECT * FROM sales_data",
"output_file": "sales_analysis.ipynb" // optional
}
7. generate_visualization
Create interactive visualizations from query results.
{
"query": "SELECT category, SUM(amount) as total FROM sales GROUP BY category",
"viz_type": "bar", // auto, bar, scatter, pie, line, heatmap, table
"title": "Sales by Category"
}
8. generate_powerbi_visualization
Export data in Power BI compatible format.
{
"query": "SELECT * FROM sales_data",
"viz_type": "auto"
}
Security
- All write operations (INSERT, UPDATE, DELETE) are disabled by default
- Enable specific operations by setting the corresponding environment variables to
true - Connection uses encryption by default
- Credentials are stored in
.envfile (not committed to version control)
Output Files
The tools generate various output files:
- Jupyter Notebooks:
.ipynbfiles with analysis code - Visualizations:
.htmlfiles with interactive charts - Power BI Data:
.csvand.jsonfiles for Power BI import
Troubleshooting
Connection Issues
- Verify your server address format (use
tcp:prefix for Azure SQL) - Check firewall rules allow connections from your IP
- Ensure SQL Server authentication is enabled
- Verify credentials in
.envfile
Permission Errors
- Check
ALLOW_*_OPERATIONSsettings in.env - Ensure database user has appropriate permissions
Visualization Errors
- Ensure query returns data suitable for the visualization type
- Check that numeric columns exist for scatter/line charts
- Verify categorical columns exist for bar/pie charts
Development
To modify or extend the server:
- All database tools are implemented in
mssql.py - MCP server interface is in
main.py - Add new tools by:
- Creating a method in
MSSQLToolsclass - Adding tool definition in
list_tools() - Adding handler in
call_tool()
- Creating a method in
License
MIT
Metadata
Release files for mcp-mssql-server 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| mcp_mssql_server-0.1.0.tar.gz | 12.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mcp_mssql_server-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 23.9 kB
Release files / mcp_mssql_server-0.1.0.tar.gz
| Download URL | mcp_mssql_server-0.1.0.tar.gz |
|---|---|
| Size | 12.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8b5c8779ebe762dff522e0d2cd95ec456a346a16f623ec9e74ff6ede1db8cb4d
|
|
BLAKE2b-256 checksum How to use checksums |
3535da3f560166b1b6d9d69aae55198d9d287f6814775d14906507a4292aa173
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.0
|
Release files / mcp_mssql_server-0.1.0-py3-none-any.whl
| Download URL | mcp_mssql_server-0.1.0-py3-none-any.whl |
|---|---|
| Size | 11.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dee26ea8b82d8dc5f6c5420a9284dca9a514d66290dc510cfb2649794bce2591
|
|
BLAKE2b-256 checksum How to use checksums |
835bd181dce0c0da68ae899f98ef659e98171370ce114ad2de688906db3711a6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.0
|
Security for mcp-mssql-server 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.