A Model Context Protocol server for Microsoft SQL Server with data analysis and visualization capabilities
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mcp_mssql_server-0.1.0.tar.gz.
File metadata
- Download URL: mcp_mssql_server-0.1.0.tar.gz
- Upload date:
- Size: 12.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b5c8779ebe762dff522e0d2cd95ec456a346a16f623ec9e74ff6ede1db8cb4d
|
|
| MD5 |
0a9a3e6feaabe14e7332403d6ca71f4b
|
|
| BLAKE2b-256 |
3535da3f560166b1b6d9d69aae55198d9d287f6814775d14906507a4292aa173
|
File details
Details for the file mcp_mssql_server-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mcp_mssql_server-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dee26ea8b82d8dc5f6c5420a9284dca9a514d66290dc510cfb2649794bce2591
|
|
| MD5 |
271968555082642121798801b9aec44f
|
|
| BLAKE2b-256 |
835bd181dce0c0da68ae899f98ef659e98171370ce114ad2de688906db3711a6
|