# MSSQL MCP Server A Model Context Protocol (MCP) server for read-only Microsoft SQL Server interactions. This server provides safe, read-only access to MSSQL databases through the MCP protocol. ## Features - **Read-only operations**: Only SELECT, DECLARE, and SET (for local variables) queries are allowed - **Schema exploration**: Browse databases, tables, columns, and indexes - **Safe querying**: SQL injection protection and query validation - **Connection management**: Secure connection handling with proper cleanup ## Installation 1. Clone this repository: ```bash git clone cd mssql-mcp ``` 2. Install dependencies: ```bash pip install -e . ``` 3. Set up environment variables: ```bash cp .env.example .env # Edit .env with your database connection details ``` **Important:** The server automatically loads environment variables from a `.env` file in the current directory. Make sure to create this file with your database connection details. ## Configuration Create a `.env` file with your MSSQL connection details: ```env MSSQL_SERVER=localhost MSSQL_DATABASE=your_database MSSQL_USERNAME=your_username MSSQL_PASSWORD=your_password MSSQL_PORT=1433 MSSQL_TIMEOUT=30 MSSQL_CHARSET=UTF-8 MSSQL_AUTOCOMMIT=true ``` ## Usage ### Development Mode ```bash mcp dev src/mssql_mcp/server.py ``` ### Claude Desktop Integration ```bash mcp install src/mssql_mcp/server.py --name "MSSQL Server" ``` ### Direct Execution ```bash python -m mssql_mcp.server ``` ## Available Resources - `db://schemas` - List all schemas in the current database - `db://tables/{database}` - List all tables in the current database - `db://schema_tables/{schema_name}` - List tables in a specific schema - `db://columns/{schema_name}/{table_name}` - Get column information for a table - `db://indexes/{database}/{schema_name}/{table_name}` - Get index information for a table ## Available Tools - `list_databases` - List all accessible databases - `list_tables` - List tables in the current database ## Security This server implements several security measures: - Only SELECT, DECLARE, and SET (for local variables) statements are allowed - SQL parsing and validation - Parameterized queries where possible - Connection string security - No DDL or DML operations permitted ## Requirements - Python 3.9+ - Access to a Microsoft SQL Server instance - pymssql library (automatically installed with dependencies) ## License MIT License