Fire in da houseTop Tip:Most people pay up to $340 per month for Perplexity, MidJourney, Runway, ChatGPT, and more - but you can get them all your AI tools for $15 with Galaxy. It's free to test!Fire in da houseCheck it out

mssql_mcp_server

MCP.Pizza Chef: RichardHan

The mssql_mcp_server is a Model Context Protocol (MCP) server designed to facilitate secure and structured interactions with Microsoft SQL Server databases. It enables AI assistants to safely list database tables, read table contents, and execute SQL queries through a controlled interface. The server emphasizes security by using environment variables for database credentials and includes comprehensive logging and error handling. It also automates the installation of necessary system dependencies like FreeTDS, simplifying setup. This MCP server is ideal for integrating SQL Server data access into AI workflows, ensuring safe, auditable, and efficient database operations.

Use This MCP server To

List Microsoft SQL Server tables securely Read data from SQL Server tables Execute SQL queries with error handling Integrate SQL Server data into AI workflows Log database interactions for auditing Automate dependency installation for SQL access

README

Microsoft SQL Server MCP Server

A Model Context Protocol (MCP) server that enables secure interaction with Microsoft SQL Server databases. This server allows AI assistants to list tables, read data, and execute SQL queries through a controlled interface, making database exploration and analysis safer and more structured.

Features

  • List available SQL Server tables as resources
  • Read table contents
  • Execute SQL queries with proper error handling
  • Secure database access through environment variables
  • Comprehensive logging
  • Automatic system dependency installation

Installation

The package will automatically install required system dependencies (like FreeTDS) when installed through MCP:

pip install mssql-mcp-server

Configuration

Set the following environment variables:

MSSQL_SERVER=localhost
MSSQL_USER=your_username
MSSQL_PASSWORD=your_password
MSSQL_DATABASE=your_database

Usage

With Claude Desktop

Add this to your claude_desktop_config.json:

{
  "mcpServers": {
    "mssql": {
      "command": "uv",
      "args": [
        "--directory", 
        "path/to/mssql_mcp_server",
        "run",
        "mssql_mcp_server"
      ],
      "env": {
        "MSSQL_SERVER": "localhost",
        "MSSQL_USER": "your_username",
        "MSSQL_PASSWORD": "your_password",
        "MSSQL_DATABASE": "your_database"
      }
    }
  }
}

As a standalone server

# Install dependencies
pip install -r requirements.txt

# Run the server
python -m mssql_mcp_server

Development

# Clone the repository
git clone https://github.com/RichardHan/mssql_mcp_server.git
cd mssql_mcp_server

# Create virtual environment
python -m venv venv
source venv/bin/activate  # or `venv\Scripts\activate` on Windows

# Install development dependencies
pip install -r requirements-dev.txt

# Run tests
pytest

Security Considerations

  • Never commit environment variables or credentials
  • Use a database user with minimal required permissions
  • Consider implementing query whitelisting for production use
  • Monitor and log all database operations

Security Best Practices

This MCP server requires database access to function. For security:

  1. Create a dedicated SQL Server login with minimal permissions
  2. Never use sa credentials or administrative accounts
  3. Restrict database access to only necessary operations
  4. Enable logging for audit purposes
  5. Regular security reviews of database access

See SQL Server Security Configuration Guide for detailed instructions on:

  • Creating a restricted SQL Server login
  • Setting appropriate permissions
  • Monitoring database access
  • Security best practices

⚠️ IMPORTANT: Always follow the principle of least privilege when configuring database access.

License

MIT License - see LICENSE file for details.

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

mssql_mcp_server FAQ

How do I configure database credentials for mssql_mcp_server?
Set environment variables MSSQL_SERVER, MSSQL_USER, MSSQL_PASSWORD, and MSSQL_DATABASE with your SQL Server details before running the server.
Does mssql_mcp_server handle SQL query errors?
Yes, it includes proper error handling to safely manage and report SQL query issues during execution.
Are system dependencies installed automatically?
Yes, required dependencies like FreeTDS are automatically installed when you install the mssql_mcp_server package via pip.
How does mssql_mcp_server ensure secure database access?
It uses environment variables for credentials and restricts operations through a controlled MCP interface to prevent unauthorized access.
Can I use mssql_mcp_server with different AI platforms?
Yes, it is designed to work with any MCP-compatible AI host, including platforms like Claude Desktop, GPT-4, and Gemini.
Is logging available for database operations?
Yes, the server provides comprehensive logging to track all interactions for security and auditing purposes.
What SQL Server versions are supported?
The server supports Microsoft SQL Server versions compatible with FreeTDS and standard SQL protocols.
How do I install mssql_mcp_server?
Install it easily using pip with the command 'pip install mssql-mcp-server'.