MSSQL-Python

MSSQL-Python

Asynchronous MCP server enabling secure access to MSSQL databases via FastAPI.

23
Stars
14
Forks
0
Releases

Overview

The MCP server is a Python-based implementation of the Model Context Protocol that provides controlled access to Microsoft SQL Server databases. It exposes MCP-compatible endpoints to list available tables, read data from a table as CSV, and execute arbitrary SQL queries via a standardized interface. Built with asyncio for asynchronous operation, it leverages environment-based configuration (python-dotenv) and a robust logging system, with connection pooling and management through pyodbc. Data validation is performed with Pydantic models, and the API is served through FastAPI, exposing resource listing, resource reading, and tool execution workflows. Resource listing returns table names with URIs like mssql://<table_name>/data and may include descriptions and MIME types; resource reading fetches the first 100 rows in CSV format with column headers. SQL execution supports both SELECT and modification queries, returning CSV results for SELECT and the affected row count for updates/inserts/deletes. Security features include environment-driven configuration, secure connection strings, input validation, and size limits on result sets. The solution is designed to work with the Claude Desktop ecosystem as well as standard MCP clients.

Details

Owner
amornpan
Language
Python
License
Updated
2025-12-07

Features

Asynchronous operation

Performs MCP server tasks asynchronously using Python's asyncio for responsiveness.

Environment-based configuration

Configures via python-dotenv to manage environment-specific settings and secrets.

Comprehensive logging

Provides extensive logging to monitor operations and diagnose issues.

Connection pooling with pyodbc

Manages MSSQL connections efficiently through pyodbc connection pooling.

Error handling and recovery

Includes robust error handling and recovery mechanisms for resilient operation.

FastAPI integration

Exposes MCP endpoints via FastAPI for resource listing, reading, and tool execution.

Pydantic data validation

Uses Pydantic models to validate inputs and data structures.

MSSQL/ODBC Driver support

Connects to MSSQL using the ODBC Driver 17 for SQL Server.

Audience

AI/ML developersBuilds MCP endpoints to query MSSQL data from LLMs for AI tasks.
Data scientistsInspect MSSQL schemas and run queries through the MCP server.
DevelopersIntegrate MCP-based MSSQL access into AI-assisted workflows from application logic.

Tags

MCPMSSQLSQL ServerFastAPIpyodbcPydanticdotenvasyncioschema inspectionAPI endpointsSecurity