EducationHub.McpSQLServerTools.Sql 1.0.3

dotnet add package EducationHub.McpSQLServerTools.Sql --version 1.0.3
                    
NuGet\Install-Package EducationHub.McpSQLServerTools.Sql -Version 1.0.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EducationHub.McpSQLServerTools.Sql" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EducationHub.McpSQLServerTools.Sql" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="EducationHub.McpSQLServerTools.Sql" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add EducationHub.McpSQLServerTools.Sql --version 1.0.3
                    
#r "nuget: EducationHub.McpSQLServerTools.Sql, 1.0.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package EducationHub.McpSQLServerTools.Sql@1.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=EducationHub.McpSQLServerTools.Sql&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=EducationHub.McpSQLServerTools.Sql&version=1.0.3
                    
Install as a Cake Tool

EducationHub.McpSQLServerTools.Sql

This is AI MCP Server Tools to Connect AI Agents with Your SQL Server Database

EducationHub.McpSQLServerTools.Sql is a Model Context Protocol (MCP) server tool that enables querying SQL Server databases through MCP.
It provides a simple way to expose SQL query functionality as MCP tools that can be consumed by AI agents or applications.


πŸš€ Installation

Add the NuGet package to your project:

dotnet add package Microsoft.Extensions.Hosting
dotnet add package EducationHub.McpSQLServerTools.Sql

βš™οΈ Setup

  1. In your .NET project, register the MCP server and load the tools:
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using ModelContextProtocol.Server;
using EducationHub.McpSQLServerTools.Sql;

var builder = Host.CreateApplicationBuilder(args);

// Enable logging
builder.Logging.AddConsole(consoleLogOptions =>
{
    consoleLogOptions.LogToStandardErrorThreshold = LogLevel.Trace;
});

// Register MCP server with SQL Tools
builder.Services
    .AddMcpServer()
    .WithStdioServerTransport()
    .WithToolsFromAssembly(typeof(SqlQueryTools).Assembly); // load tools

await builder.Build().RunAsync();

πŸ”‘ Configure SQL Server Connection

Before running, set your SQL Server connection string in an environment variable:

$env:SQL_SERVER_CONNECTION_STRING="Server=localhost;Database=MyDb;User Id=sa;Password=Your_password123;"

Or in Linux/macOS:

export SQL_SERVER_CONNECTION_STRING="Server=localhost;Database=MyDb;User Id=sa;Password=Your_password123;"

πŸ› οΈ Usage

This package provides the tool:

query_table

  • Description: Query all rows from a given SQL Server table.
  • Input:
    {
      "tableName": "Employees"
    }
    
  • Output:
    A list of rows, each represented as a dictionary of column/value pairs.

πŸ“– Example

1. Request

Send this request to the MCP server:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "query_table",
    "arguments": {
      "tableName": "Employees"
    }
  }
}

2. Response

The MCP server will return:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "data": [
      {
        "Id": 1,
        "Name": "John Doe",
        "Department": "HR"
      },
      {
        "Id": 2,
        "Name": "Jane Smith",
        "Department": "IT"
      }
    ]
  }
}

πŸ—οΈ Example Project

Here’s how to run a test project:

dotnet new console -n McpSqlTest
cd McpSqlTest
dotnet add package EducationHub.McpSQLServerTools.Sql

Replace Program.cs with the setup code above, then run:

dotnet run

⚑ Create mcp.json

To use this MCP server with GitHub Copilot, create a file named mcp.json in your project root folder.
Update the absolute project path inside --project.

Example if your project is located at:
C:\Users\YourName\source\repos\McpSqlTest.csproj

{
  "servers": {
    "sql-server-tools": {
      "command": "dotnet",
      "args": [
        "run",
        "--project",
        "C:/Users/YourName/source/repos/McpSqlTest.csproj"
      ],
      "env": {
        "SQL_SERVER_CONNECTION_STRING": "Server=localhost;Database=MyDb;User Id=sa;Password=Your_password123;"
      }
    }
  }
}

πŸ€– Testing with GitHub Copilot

  1. Open GitHub Copilot Chat in VS Code or GitHub.com.
  2. Ensure MCP support is enabled (Copilot Labs β†’ MCP settings).
  3. Point Copilot to your mcp.json.
  4. Ask Copilot something like:

"Use the sql-server-tools MCP server to query the Employees table."

Copilot will call the query_table tool from your MCP server and return rows directly in chat.


πŸ“Œ Notes

  • Ensure your SQL Server is running and accessible.
  • The current implementation supports simple SELECT * FROM <table> queries.
  • Future versions will support parameterized queries and filtering.

πŸ“¦ Publishing

This package is maintained under the EducationHub namespace.
If you want to contribute, fork the repo and submit a PR.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.