EducationHub.McpSQLServerTools.Sql 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package EducationHub.McpSQLServerTools.Sql --version 1.0.1
                    
NuGet\Install-Package EducationHub.McpSQLServerTools.Sql -Version 1.0.1
                    
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.1" />
                    
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.1" />
                    
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.1
                    
#r "nuget: EducationHub.McpSQLServerTools.Sql, 1.0.1"
                    
#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.1
                    
#: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.1
                    
Install as a Cake Addin
#tool nuget:?package=EducationHub.McpSQLServerTools.Sql&version=1.0.1
                    
Install as a Cake Tool

EducationHub.McpSQLServerTools.Sql

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 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();

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

πŸ“Œ 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.