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
<PackageReference Include="EducationHub.McpSQLServerTools.Sql" Version="1.0.3" />
<PackageVersion Include="EducationHub.McpSQLServerTools.Sql" Version="1.0.3" />
<PackageReference Include="EducationHub.McpSQLServerTools.Sql" />
paket add EducationHub.McpSQLServerTools.Sql --version 1.0.3
#r "nuget: EducationHub.McpSQLServerTools.Sql, 1.0.3"
#:package EducationHub.McpSQLServerTools.Sql@1.0.3
#addin nuget:?package=EducationHub.McpSQLServerTools.Sql&version=1.0.3
#tool nuget:?package=EducationHub.McpSQLServerTools.Sql&version=1.0.3
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
- 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
- Open GitHub Copilot Chat in VS Code or GitHub.com.
- Ensure MCP support is enabled (Copilot Labs β MCP settings).
- Point Copilot to your
mcp.json
. - Ask Copilot something like:
"Use the
sql-server-tools
MCP server to query theEmployees
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 | 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.