PT

popplywop/tsql-mcp-server

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

7 stars 5 forks 质量 68 趋势 15MIT

SQL Server MCP Server - Provides SQL Server database access via Model Context Protocol

概览

A Model Context Protocol (MCP) server that provides tools for interacting with SQL Server databases. This server allows Large Language Models (LLMs) to query and inspect SQL Server databases through a standardized protocol. - : Execute SQL queries and retrieve results - : List tables, views, stored procedures, and examine table schemas - : Built-in validation to prevent SQL injection attacks - : Metadata caching for improved performance - .NET 10.0 SDK or later (or Docker) - SQL Server instance (local or remote) Run the server using Docker without installing .NET: - The -i flag is required for stdio transport - Use host.docker.internal to connect to SQL Server on your host machine - For WSL2 users: if host.docker.internal doesn't resolve, use --network host and localhost instead To use this server with Claude or other LLMs that support the Model Context Protocol, you'll need to configure it in your MCP configuration file. Replace the connection string with your actual values.

README

以下为原文 README 节选,完整内容请查看原文。

SQL Server MCP Server

A Model Context Protocol (MCP) server that provides tools for interacting with SQL Server databases. This server allows Large Language Models (LLMs) to query and inspect SQL Server databases through a standardized protocol.

Features

  • Database Querying: Execute SQL queries and retrieve results
  • Schema Inspection: List tables, views, stored procedures, and examine table schemas
  • SQL Injection Prevention: Built-in validation to prevent SQL injection attacks
  • Resource Caching: Metadata caching for improved performance

Getting Started

Prerequisites

  • .NET 10.0 SDK or later (or Docker)
  • SQL Server instance (local or remote)

Installation

Run the server using Docker without installing .NET:

# Build the image
docker build -t tsql-mcp-server .

# Run with connection string
docker run -i tsql-mcp-server --dsn "Server=host.docker.internal;Database=mydb;User Id=sa;Password=mypassword;TrustServerCertificate=True;"

# Run in read-only mode
docker run -i tsql-mcp-server --dsn "..." --read-only

# Run with environment variable
docker run -i -e SQL_CONNECTION="Server=..." tsql-mcp-server --env-var SQL_CONNECTION

Notes:

  • The -i flag is required for stdio transport
  • Use host.docker.internal to connect to SQL Server on your host machine
  • For WSL2 users: if host.docker.internal doesn’t resolve, use --network host and localhost instead

Option 2: Install as a .NET Tool

Install globally as a .NET tool:

dotnet tool install --global tsql-mcp-server

To update to the latest version:

dotnet tool update --global tsql-mcp-server

Option 2: Build from Source

# Clone the repository
git clone https://github.com/Popplywop/tsql-mcp-server
cd tsql-mcp-server

# Build the project
dotnet build

Running the Server

Using the .NET Tool

If installed as a .NET global tool:

# Using a direct connection string
tsql-mcp-server --dsn "Server=your-server;Database=your-database;User Id=your-username;Password=your-password;TrustServerCertificate=True;"

# Using an environment variable
tsql-mcp-server --env-var "SQL_CONNECTION_STRING"

Using Source Code

If building from source:

# Using a direct connection string
dotnet run --dsn "Server=your-server;Database=your-database;User Id=your-username;Password=your-password;TrustServerCertificate=True;"

# Using an environment variable
dotnet run --env-var "SQL_CONNECTION_STRING"

MCP Server Configuration

To use this server with Claude or other LLMs that support the Model Context Protocol, you’ll need to configure it in your MCP configuration file.

If Installed as a .NET Tool

{
  "servers": [
    {
      "name": "SqlServerMcp",
      "command": "tsql-mcp-server",
      "args": [
        "--dsn",
在 GitHub 查看完整 README

安装

docker run -i --rm tsql-mcp-server --dsn Server=host.docker.internal;Database=your-database;User Id=your-username;Password=your-password;TrustServerCertificate=True;
新手?先看 mcpskill.org 教程 →

配置

{ "mcpServers": { "sqlserver": { "command": "docker", "args": [ "run", "-i", "--rm", "tsql-mcp-server", "--dsn", "Server=host.docker.internal;Database=your-database;User Id=your-username;Password=your-password;TrustServerCertificate=True;" ] } } }