SQL Server MCP
The SQL Server MCP server enables AI assistants like Claude to interact with Microsoft SQL Server databases through natural language and a standardized protocol.
Connection Management: Connect to and disconnect from databases, list active connections, list available databases (including system databases), and switch between database contexts.
Data Querying & Reading: Execute read-only SQL SELECT queries with automatic row limits, read rows by primary key, multiple IDs, or custom filters, validate query safety, and select specific or all columns from tables.
CRUD Operations: Insert new rows with automatic identity column handling, update existing rows by primary key, delete rows by primary key, and use schema-qualified table names.
Schema Exploration: List tables and views with optional schema and pattern filtering, examine columns, data types, nullability, primary/foreign key relationships, and indexes.
Stored Procedure Management: List available stored procedures with filtering, describe parameters (name, type, direction), execute procedures with input parameters, and retrieve multiple result sets.
Data Export: Export query results to JSON or CSV files with custom delimiters, and get file metadata including path, row count, and file size.
Transaction Control: Begin, commit, and roll back database transactions.
Safety & Security Features: Read-only mode, command blocking for dangerous SQL operations (DROP, TRUNCATE, etc.), maximum row limits, query validation with warnings and suggestions, schema restrictions, database blocklists, and parameterized queries to prevent SQL injection.
AI Integration Features: Knowledge persistence to save and retrieve learned information about the database, search saved knowledge for context-aware interactions, natural language query support, and automatic connection recovery with watchdog functionality.
Deployment Options: Run locally with Claude Desktop, as HTTP server, or with OAuth for Claude.ai integration.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@SQL Server MCP show me the top 5 customers by total purchases"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
pymssql-mcp
An MCP (Model Context Protocol) server for Microsoft SQL Server databases. Enables AI assistants like Claude to interact with SQL Server through a standardized protocol.
Features
Natural Language Queries: Ask Claude about your data in plain English
Schema Discovery: Explore tables, views, columns, and relationships
CRUD Operations: Read, insert, update, and delete rows safely
Stored Procedures: Execute stored procedures with parameters
Multi-Database Support: List and switch between databases
Data Export: Export query results to JSON or CSV files
Transaction Support: Begin, commit, and rollback transactions
Knowledge Persistence: Claude remembers what it learns about your database
Safety Controls: Read-only mode, command blocking, row limits, schema restrictions
Connection Watchdog: Automatic recovery from hung connections
OAuth Integration: Deploy as a Claude.ai Custom Connector with SSO
Related MCP server: MSSQL MCP Server
Documentation
Guide | Description |
Understanding MCP and pymssql-mcp | |
Complete installation guide | |
Get running in 10 minutes | |
All configuration options | |
Detailed tool documentation | |
Common usage patterns | |
Claude.ai integration with SSO |
Quick Start
1. Install
pip install pymssql-mcp2. Configure Claude Desktop
Edit your Claude Desktop config file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"mssql": {
"command": "pymssql-mcp",
"env": {
"MSSQL_HOST": "your-server.example.com",
"MSSQL_USER": "your-username",
"MSSQL_PASSWORD": "your-password",
"MSSQL_DATABASE": "your-database",
"MSSQL_READ_ONLY": "true"
}
}
}
}3. Restart Claude Desktop
Quit and reopen Claude Desktop. You'll see a hammer icon indicating tools are available.
4. Start Chatting
Ask Claude about your database:
"What tables are available?"
"Describe the Customers table"
"Show me the top 10 orders by total amount"
"How many customers do we have in each state?"
Available Tools
Connection & Database
Tool | Description |
| Connect to the database |
| Close all connections |
| List available databases |
| Switch database context |
Queries & Schema
Tool | Description |
| Run a SELECT query |
| Check if a query is safe |
| List tables and views |
| Get column information |
CRUD Operations
Tool | Description |
| Read rows by ID or filter |
| Insert a new row |
| Update an existing row |
| Delete a row |
Stored Procedures
Tool | Description |
| List available procedures |
| Get procedure parameters |
| Execute a procedure |
Export & Transactions
Tool | Description |
| Export results to JSON |
| Export results to CSV |
| Start a transaction |
| Commit changes |
| Rollback changes |
Knowledge Persistence
Tool | Description |
| Save learned information |
| Retrieve all knowledge |
| Search saved knowledge |
Configuration
Required Variables
Variable | Description |
| SQL Server hostname |
| Database username |
| Database password |
| Database name |
Safety Settings
Variable | Default | Description |
|
| Block all write operations |
|
| Maximum rows per query |
|
| Commands to block |
| (all) | Restrict to specific schemas |
| (none) | Hide specific databases |
See Configuration Reference for all options.
Deployment Modes
Local (Default)
Run as a local process with Claude Desktop:
pymssql-mcpHTTP/SSE Server
Run as a shared HTTP server for multiple users:
pymssql-mcp --http --host 0.0.0.0 --port 8080Streamable HTTP (Claude.ai Integration)
Run with OAuth authentication for Claude.ai:
pymssql-mcp --streamable-http --host 0.0.0.0 --port 8080See OAuth Setup for complete integration instructions.
Development
# Clone repository
git clone https://github.com/bpamiri/pymssql-mcp.git
cd pymssql-mcp
# Install with dev dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Lint and format
ruff check .
ruff format .
# Type check
mypy src/Security
pymssql-mcp includes multiple safety features:
Read-only mode: Prevent all write operations
Command blocking: Block dangerous SQL commands (DROP, TRUNCATE, etc.)
Schema restrictions: Limit access to specific schemas
Database blocklist: Hide sensitive databases
Row limits: Cap query results to prevent memory issues
Query validation: Analyze queries before execution
Parameterized queries: Prevent SQL injection
See SECURITY.md for security policy and best practices.
Contributing
Contributions are welcome! See CONTRIBUTING.md for guidelines.
License
Apache-2.0. See LICENSE for details.
Links
Available Tools
18 toolscall_stored_procB
Execute a stored procedure.
Args:
procedure: Procedure name, optionally with schema (e.g., 'dbo.sp_GetUser' or 'sp_GetUser')
params: Input parameter values as dictionary (parameter names without @)
Returns:
Dictionary with:
- procedure: Full procedure name
- result_sets: List of result sets (each is a list of row dictionaries)
- status: 'success' or error
Inputs: procedure (required), params. Returns: object
connectA
Establish connection to the SQL Server database.
Uses configuration from environment variables:
- MSSQL_HOST: Server hostname or IP
- MSSQL_USER: Username
- MSSQL_PASSWORD: Password
- MSSQL_DATABASE: Database name
- MSSQL_PORT: Port (default: 1433)
Returns:
Connection status and details including host, database, and timestamp.
Inputs: no named parameters. Returns: object
delete_rowA
Delete a row by primary key.
Args:
table: Table name (can include schema: 'dbo.Users' or 'Users')
id: Primary key value of the row to delete
Returns:
Dictionary with:
- status: 'deleted' or error
- table: Full table name
- id: The deleted row's ID
- rows_affected: Number of rows deleted (should be 1)
Inputs: table (required), id (required). Returns: object
describe_stored_procB
Get parameter information for a stored procedure.
Args:
procedure: Procedure name, optionally with schema (e.g., 'dbo.sp_GetUser' or 'sp_GetUser')
Returns:
Dictionary with:
- procedure: Full procedure name (schema.name)
- parameters: List of parameter info (name, type, direction, etc.)
Inputs: procedure (required). Returns: object
describe_tableA
Get detailed column information for a table.
Retrieves column definitions, primary keys, foreign keys, and indexes.
Args:
table: Table name, optionally with schema (e.g., 'dbo.Users' or 'Users').
Defaults to 'dbo' schema if not specified.
Returns:
Dictionary with:
- table: Full table name (schema.table)
- columns: List of column info (name, type, nullable, etc.)
- primary_key: List of primary key column names
- foreign_keys: List of foreign key relationships
- indexes: List of index info
Inputs: table (required). Returns: object
disconnectA
Close all connections to the SQL Server database.
Returns:
Disconnection status and count of closed connections.
Inputs: no named parameters. Returns: object
execute_queryA
Execute a read-only SQL query and return results.
Only SELECT statements are allowed. The query will have a row limit applied
automatically if not specified.
Args:
query: SQL SELECT statement to execute
max_rows: Maximum rows to return (overrides default, capped by MSSQL_MAX_ROWS)
Returns:
Dictionary with:
- query: The original query
- executed_query: The query that was actually executed (may include TOP)
- columns: List of column names
- rows: List of row dictionaries
- row_count: Number of rows returned
- max_rows: The effective row limit applied
Inputs: query (required), max_rows. Returns: object
export_to_csvA
Export query results to a CSV file.
Args:
query: SQL SELECT query to execute
filename: Output filename (relative or absolute path)
delimiter: Field delimiter (default: comma)
Returns:
Dictionary with:
- status: 'success' or error
- path: Absolute path to created file
- row_count: Number of rows exported
- file_size: Size of created file in bytes
Inputs: query (required), filename (required), delimiter. Returns: object
export_to_jsonA
Export query results to a JSON file.
Args:
query: SQL SELECT query to execute
filename: Output filename (relative or absolute path)
Returns:
Dictionary with:
- status: 'success' or error
- path: Absolute path to created file
- row_count: Number of rows exported
- file_size: Size of created file in bytes
Inputs: query (required), filename (required). Returns: object
insert_rowB
Insert a new row into a table.
Args:
table: Table name (can include schema: 'dbo.Users' or 'Users')
data: Dictionary of column names and values to insert
Returns:
Dictionary with:
- status: 'success' or error
- table: Full table name
- inserted: The inserted row (including generated identity columns)
Inputs: table (required), data (required). Returns: object
list_connectionsB
List all active database connections.
Returns:
List of active connections with their details (name, host, database,
connection time, and active status).
Inputs: no named parameters. Returns: object
list_databasesA
List all available databases on the SQL Server.
Queries sys.databases to discover accessible databases. System databases
(master, tempdb, model, msdb) are excluded by default. Databases in the
blocklist (MSSQL_BLOCKED_DATABASES) are always excluded.
Args:
include_system: If True, include system databases in the list
Returns:
Dictionary with:
- databases: List of available database names
- current_database: The currently active database
- count: Number of databases returned
- blocked_count: Number of databases hidden due to blocklist
Inputs: include_system. Returns: object
list_stored_procsA
List available stored procedures in the database.
Args:
schema: Filter by schema name (e.g., 'dbo')
pattern: Filter by name pattern using SQL LIKE syntax (e.g., 'sp_%', '%User%')
Returns:
Dictionary with:
- procedures: List of procedure info (schema, name, created, modified)
- count: Number of procedures found
Inputs: schema, pattern. Returns: object
list_tablesA
List all tables and views in the database.
Args:
schema: Filter by schema name (e.g., 'dbo'). If not specified, returns all schemas.
include_views: Include views in results (default: True)
pattern: Filter by name pattern using SQL LIKE syntax (e.g., 'Cust%', '%Order%')
Returns:
Dictionary with:
- tables: List of table/view info (schema, name, type)
- count: Number of results
Inputs: schema, include_views, pattern. Returns: object
read_rowsA
Read rows from a table by primary key or filter.
Provide one of: id (single row), ids (multiple rows), or filter (WHERE clause).
Args:
table: Table name (can include schema: 'dbo.Users' or 'Users')
id: Single primary key value (for composite keys, use filter)
ids: List of primary key values
filter: WHERE clause without 'WHERE' keyword (e.g., "status = 'active'")
columns: List of columns to return (default: all columns)
max_rows: Maximum rows to return
Returns:
Dictionary with:
- table: Full table name
- rows: List of row dictionaries
- count: Number of rows returned
Inputs: table (required), id, ids, filter, +2 more. Returns: object
switch_databaseA
Switch the active database context.
Changes the current database using the USE statement. The database must
exist, be online, and not be in the blocklist (MSSQL_BLOCKED_DATABASES).
Args:
database_name: Name of the database to switch to
Returns:
Dictionary with:
- status: "switched" on success, "error" on failure
- database: The new active database name
- previous_database: The previously active database
- error: Error message if switch failed
Inputs: database_name (required). Returns: object
update_rowA
Update an existing row by primary key.
Args:
table: Table name (can include schema: 'dbo.Users' or 'Users')
id: Primary key value of the row to update
data: Dictionary of column names and new values
Returns:
Dictionary with:
- status: 'success' or error
- table: Full table name
- updated: The updated row
Inputs: table (required), id (required), data (required). Returns: object
validate_queryA
Check if a query is safe to execute without running it.
Validates the query against:
- Statement type (SELECT, INSERT, UPDATE, DELETE, DDL, EXEC)
- Blocked commands list
- Read-only mode compliance
- Potential issues (missing WHERE clause, unbounded SELECT)
Args:
query: SQL statement to validate
Returns:
Dictionary with:
- query: The original query
- valid: Whether the query is valid
- statement_type: Type of SQL statement
- warnings: List of warning messages
- suggestions: List of suggested improvements
- error: Error message if invalid
Inputs: query (required). Returns: object
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 18 tools
Every tool has a clearly distinct purpose with no ambiguity. For example, call_stored_proc is for executing procedures while describe_stored_proc is for inspecting them, and read_rows is for reading data while execute_query is for running SELECT queries. The tools cover different aspects of SQL Server interaction without overlap.
All tools follow a consistent verb_noun naming pattern throughout. Examples include describe_table, list_tables, insert_row, update_row, and export_to_csv. The naming is predictable and follows the same convention across all 18 tools.
With 18 tools, the count is slightly high but reasonable for a comprehensive SQL Server interface. The tools cover connection management, CRUD operations, stored procedures, metadata inspection, and data export, which justifies the number. It's well-scoped but could potentially be streamlined.
The tool surface provides complete coverage for SQL Server interaction. It includes connection management (connect, disconnect, list_connections), database operations (list_databases, switch_database), table operations (full CRUD with insert_row, read_rows, update_row, delete_row), stored procedure handling, metadata inspection, query execution, validation, and data export. No obvious gaps exist for the domain.
Maintenance
Related MCP Connectors
Work with your database from AI tools: ask, export, approved changes, and scheduled jobs.
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
Query Postgres, MySQL, SQL Server, Oracle, BigQuery, ClickHouse and Redshift from your AI client.
Hosted SQL Server MCP server for Claude, ChatGPT and Cursor, with each action switched per account.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to securely interact with Microsoft SQL Server databases to query data, inspect schemas, and retrieve metadata with read-only operations by default and optional write capabilities.1MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to interact with Microsoft SQL Server databases through a standardized interface. Supports executing SQL queries, browsing database schemas, and viewing table data with flexible authentication options for both local and Azure SQL databases.5MIT
- AlicenseAqualityDmaintenanceEnables AI models to interact with MS SQL Server databases through a standardized interface. Supports executing SQL queries with parameters, listing tables, and describing table schemas.3MIT
- AlicenseNot gradedqualityBmaintenanceEnables AI assistants to interact with Microsoft SQL Server databases via introspection and query tools. Supports single or multiple databases with read-only mode by default and an optional write capability.442 npm5MIT