MsSqlMCP

by jdlemes

6 stars
455 downloads
Not rated
GitHub

About

MCP to query SQL Server database schema, such as tables, columns, and relationships

Details

Author
jdlemes
GitHub stars
6
Downloads
455
Categories
Database

- Read-only access: blocks all data modification statements.
- Schema discovery: tables, columns, relationships, stored procedures.
- Safe SQL execution: only SELECT queries allowed.
- Dual transport: stdio and HTTP/SSE protocols.
- Windows Service support for production deployments.
- Compatible with VS Code Copilot and Claude Desktop.

Configure the SQL Server connection string in appsettings.json, then run dotnet run for console mode. For HTTP transport, use dotnet run -- --http-only. The server supports both stdio and HTTP/SSE protocols for integration with MCP clients.

MsSqlMCP

MCP Server for SQL Server database schema inspection and read-only query execution.

Features

- Read-only access: All queries are validated to prevent data modification (INSERT, UPDATE, DELETE, DROP, EXEC, etc. are blocked)
- Schema discovery: Tables, columns, relationships, and stored procedures
- SQL execution: Safe SELECT queries only
- Dual transport: Supports both stdio and HTTP/SSE protocols
- Windows Service: Can run as a Windows Service for production deployments
- MCP Protocol: Compatible with VS Code Copilot, Claude Desktop, and other MCP clients

Prerequisites

- .NET 10 (or .NET 9 with minor adjustments)
- SQL Server

Architecture

The project follows SOLID principles with dependency injection:

MsSqlMCP/
├── Program.cs                    # Entry point with DI and dual transport
├── SchemaTool.cs                 # MCP tool definitions
├── Interfaces/
│   ├── IConnectionFactory.cs     # SQL connection abstraction
│   ├── IQueryExecutor.cs         # Query execution abstraction
│   ├── ISchemaRepository.cs      # Schema queries abstraction
│   └── ISqlQueryValidator.cs     # Query validation abstraction
├── Services/
│   ├── SqlConnectionFactory.cs   # Connection management
│   ├── SafeQueryExecutor.cs      # Validated query execution
│   ├── SchemaRepository.cs       # Schema query implementation
│   └── ReadOnlySqlQueryValidator.cs # Security validation (27 blocked keywords)
└── Tests/
    └── ReadOnlySqlQueryValidatorTests.cs # 42 security tests

Configuration

Connection String

Edit appsettings.json:

{
  "ConnectionStrings": {
    "DefaultConnection": "Data Source=(local);Initial Catalog=YourDatabase;Encrypt=False;Trusted_Connection=True;MultipleActiveResultSets=true"
  },
  "Urls": "http://localhost:5000"
}

Running

Console Mode (Development)

```bash

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.