Skip to main content

Microsoft SQL Server MCP Server (Ishaan's Version)

PyPI License: MIT Python

A Model Context Protocol (MCP) server for secure SQL Server database access through Claude Desktop.

🚀 Quick Start

Prerequisites

  • Python 3.11 or higher (Python 3.12 recommended)
  • FreeTDS (for SQL Server connectivity)

Install FreeTDS

# macOS
brew install freetds

# Ubuntu/Debian
sudo apt-get install freetds-dev

# RHEL/CentOS
sudo yum install freetds-devel

Install the Package

pip install mssql-mcp-server-ishaan

Configure Claude Desktop

Add to your claude_desktop_config.json:

{
  "mcpServers": {
    "mssql": {
      "command": "python",
      "args": ["-m", "mssql_mcp_server_ishaan"],
      "env": {
        "MSSQL_CONNECTION_STRING": "server=your-server;database=your-db;uid=your-user;pwd=your-password;encrypt=true;trustServerCertificate=true"
      }
    }
  }
}

📋 Features

  • Secure SQL Server connectivity with encrypted connections
  • Read-only operations for safety (SELECT queries only)
  • Table schema inspection and metadata retrieval
  • SQL injection protection with parameterized queries
  • Connection validation and error handling
  • Comprehensive logging for debugging

🔧 Configuration Options

Environment Variables

# Basic connection (choose one method)
MSSQL_CONNECTION_STRING="server=localhost;database=mydb;uid=user;pwd=pass"
# OR individual components:
MSSQL_SERVER=localhost
MSSQL_DATABASE=mydb
MSSQL_USERNAME=your_user
MSSQL_PASSWORD=your_password

# Optional settings
MSSQL_PORT=1433                 # Custom port (default: 1433)
MSSQL_ENCRYPT=true              # Enable encryption (true/false)

🛠️ Available Tools

1. execute_query

Execute SELECT queries on the database.

Parameters:

  • query (string): SQL SELECT statement
  • parameters (array, optional): Query parameters for safe parameterization

Example:

SELECT TOP 10 * FROM Users WHERE Department = ?

2. list_tables

List all tables in the database with their schemas.

3. describe_table

Get detailed schema information for a specific table.

Parameters:

  • table_name (string): Name of the table to describe

4. get_table_sample

Retrieve a sample of data from a table.

Parameters:

  • table_name (string): Name of the table
  • limit (integer, optional): Number of rows to return (default: 10)

🔒 Security Features

  • Read-only access: Only SELECT operations are allowed
  • SQL injection protection: All queries use parameterized statements
  • Input validation: Table names and queries are validated
  • Connection encryption: Supports encrypted connections
  • Error sanitization: Database errors are sanitized before returning

📦 Installation Methods

pip install mssql-mcp-server-ishaan

Method 2: From Source

git clone https://github.com/ishaan119/mssql_mcp_server.git
cd mssql_mcp_server
pip install -e .

🧪 Testing the Installation

# Test import
python -c "import mssql_mcp_server_ishaan; print('✅ Package imported successfully!')"

# Run the server (requires connection string)
python -m mssql_mcp_server_ishaan

# Or use the command-line script
mssql_mcp_server_ishaan

🐛 Troubleshooting

Common Issues

  1. Python Version Error

    ERROR: Requires-Python >=3.11
    

    Solution: Upgrade to Python 3.11 or higher

    brew install python@3.12  # macOS
    
  2. FreeTDS Not Found

    error: Microsoft SQL Server Native Client
    

    Solution: Install FreeTDS

    brew install freetds  # macOS
    
  3. Connection Issues

    • Verify your connection string format
    • Check firewall settings
    • Ensure SQL Server allows remote connections
    • Try adding trustServerCertificate=true for self-signed certificates

Debug Mode

Enable detailed logging by setting the log level:

export PYTHONPATH=.
python -c "
import logging
logging.basicConfig(level=logging.DEBUG)
import mssql_mcp_server_ishaan
"

📚 Example Usage

Basic Query

{
  "tool": "execute_query",
  "arguments": {
    "query": "SELECT TOP 5 CustomerID, CompanyName FROM Customers"
  }
}

Parameterized Query

{
  "tool": "execute_query",
  "arguments": {
    "query": "SELECT * FROM Orders WHERE CustomerID = ? AND OrderDate > ?",
    "parameters": ["ALFKI", "2023-01-01"]
  }
}

Table Information

{
  "tool": "describe_table",
  "arguments": {
    "table_name": "Customers"
  }
}

🤝 Contributing

This is a fork of the original mssql_mcp_server by Richard Han.

Development Setup

git clone https://github.com/ishaan119/mssql_mcp_server.git
cd mssql_mcp_server
pip install -e ".[dev]"

Running Tests

pytest

📄 License

MIT License - see LICENSE file for details.

📈 Version History

  • v0.1.3: Current stable version with Python 3.11+ support
  • v0.1.2: Attempted Python 3.10+ support
  • v0.1.1: Attempted Python 3.9+ support
  • v0.1.0: Initial release with Python 3.11+ requirement

Note: This package requires Python 3.11+ due to the Model Context Protocol (MCP) library dependency. For the best experience, use Python 3.12.

Metadata

Release files for mssql-mcp-server-ishaan 0.1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mssql-mcp-server-ishaan 0.1.7
File Size Uploaded Provenance
mssql_mcp_server_ishaan-0.1.7.tar.gz 39.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for mssql-mcp-server-ishaan 0.1.7
File Interpreter ABI Platform
mssql_mcp_server_ishaan-0.1.7-py3-none-any.whl Python 3 none any Details

Total release size: 48.4 kB

Release files / mssql_mcp_server_ishaan-0.1.7.tar.gz

Download URL mssql_mcp_server_ishaan-0.1.7.tar.gz
Size 39.9 kB
Tags Source
SHA-256 checksum
How to use checksums
7b9b60aa5ad685c8ba5794cc637855ccfab3f6b6c0013325b5e987e178094ec8
BLAKE2b-256 checksum
How to use checksums
5d3c631dad0a04cdc42be91c0357b294aa6384d5c3169b1a714b40f6fc18da9b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.6

Release files / mssql_mcp_server_ishaan-0.1.7-py3-none-any.whl

Download URL mssql_mcp_server_ishaan-0.1.7-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
368fa4de7365db5b817802ce7e568b336799b4f5d9b6360c8ea6f1757c025893
BLAKE2b-256 checksum
How to use checksums
f35de8ae71dda90501f9470e9d045572489ba84a53253560f658b973c3679376
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.6

Security for mssql-mcp-server-ishaan 0.1.7

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.

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