EducationHub.McpSQLServerTools.Sql
1.0.1
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
<PackageReference Include="EducationHub.McpSQLServerTools.Sql" Version="1.0.1" />
<PackageVersion Include="EducationHub.McpSQLServerTools.Sql" Version="1.0.1" />
<PackageReference Include="EducationHub.McpSQLServerTools.Sql" />
paket add EducationHub.McpSQLServerTools.Sql --version 1.0.1
#r "nuget: EducationHub.McpSQLServerTools.Sql, 1.0.1"
#:package EducationHub.McpSQLServerTools.Sql@1.0.1
#addin nuget:?package=EducationHub.McpSQLServerTools.Sql&version=1.0.1
#tool nuget:?package=EducationHub.McpSQLServerTools.Sql&version=1.0.1
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
- 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 | Versions 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. |
-
net9.0
- Microsoft.Data.SqlClient (>= 6.1.1)
- ModelContextProtocol (>= 0.3.0-preview.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.