Skip to main content

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.

  1. Copy the .env file 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
  1. 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 .env file (not committed to version control)

Output Files

The tools generate various output files:

  • Jupyter Notebooks: .ipynb files with analysis code
  • Visualizations: .html files with interactive charts
  • Power BI Data: .csv and .json files for Power BI import

Troubleshooting

Connection Issues

  1. Verify your server address format (use tcp: prefix for Azure SQL)
  2. Check firewall rules allow connections from your IP
  3. Ensure SQL Server authentication is enabled
  4. Verify credentials in .env file

Permission Errors

  • Check ALLOW_*_OPERATIONS settings 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:

  1. All database tools are implemented in mssql.py
  2. MCP server interface is in main.py
  3. Add new tools by:
    • Creating a method in MSSQLTools class
    • Adding tool definition in list_tools()
    • Adding handler in call_tool()

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)

Source distribution for mcp-mssql-server 0.1.0
File Size Uploaded Provenance
mcp_mssql_server-0.1.0.tar.gz 12.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for mcp-mssql-server 0.1.0
File Interpreter ABI Platform
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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page