mcp-db-connect
1.0.4
dotnet tool install --global mcp-db-connect --version 1.0.4
dotnet new tool-manifest
dotnet tool install --local mcp-db-connect --version 1.0.4
#tool dotnet:?package=mcp-db-connect&version=1.0.4
nuke :add-package mcp-db-connect --version 1.0.4
mcp-db-connect
.NET global tool to expose SQL databases as a professional MCP server.
Installation
dotnet tool install --global mcp-db-connect
Quick Start (as global tool)
mcp-db-connect --sqlserver --host <HOST> --database <DB> --user <USER> --password <PASS> [options]
You can use the same arguments for MySQL, PostgreSQL, or SQLite.
Usage examples with different database engines
SQL Server
mcp-db-connect --sqlserver --host localhost --database testdb --user sa --password password --port 1433 --trustServerCertificate true
MySQL
mcp-db-connect --mysql --host localhost --database testdb --user user --password password --port 3306
PostgreSQL
mcp-db-connect --postgresql --host localhost --database testdb --user user --password password --port 5432
SQLite
mcp-db-connect --sqlite --database C:/path/to/your/file.db
Local development execution
You can build and run the server directly from the source code, useful for development and debugging:
dotnet build
dotnet run --project MCP_db -- --sqlserver --host <HOST> --database <DB> --user <USER> --password <PASS> [options]
Examples:
# SQL Server
dotnet run --project MCP_db -- --sqlserver --host localhost --database testdb --user sa --password password --port 1433 --trustServerCertificate true
# MySQL
dotnet run --project MCP_db -- --mysql --host localhost --database testdb --user user --password password --port 3306
# PostgreSQL
dotnet run --project MCP_db -- --postgresql --host localhost --database testdb --user user --password password --port 5432
# SQLite
dotnet run --project MCP_db -- --sqlite --database C:/path/to/your/file.db
Integration with editors and MCP clients
Configure your editor (VS Code, Cursor, etc.) to use the global or local command. Here are examples for each engine:
SQL Server
{
"sqlserverCSharpMCP": {
"command": "mcp-db-connect",
"args": [
"--sqlserver",
"--host", "SERVER",
"--instance", "INSTANCE",
"--database", "db_name",
"--port", "1433",
"--user", "user",
"--password", "password",
"--trustServerCertificate", "true"
]
}
}
MySQL
{
"mysqlCSharpMCP": {
"command": "mcp-db-connect",
"args": [
"--mysql",
"--host", "mysql_host",
"--database", "db_name",
"--port", "3306",
"--user", "user",
"--password", "password"
]
}
}
PostgreSQL
{
"postgresCSharpMCP": {
"command": "mcp-db-connect",
"args": [
"--postgresql",
"--host", "postgres_host",
"--database", "db_name",
"--port", "5432",
"--user", "user",
"--password", "password"
]
}
}
SQLite
{
"sqliteCSharpMCP": {
"command": "mcp-db-connect",
"args": [
"--sqlite",
"--database", "C:/path/to/your/file.db"
]
}
}
Or, for local development:
{
"sqlserverCSharpMCP": {
"command": "dotnet",
"args": [
"run", "--project", "MCP_db", "--", "--sqlserver", "--host", "SERVER", "--database", "db_name", "--user", "user", "--password", "password"
]
}
}
⚠️ Do not include real credentials in shared configuration files or repositories. Use environment variables or local files ignored by git for sensitive data.
Functional example: interaction with an AI agent and MCP tools
Suppose you have an AI agent (e.g., in VS Code, Cursor, or an LLM) connected to the MCP server:
User:
Show me the tables in the database
AI Agent:
- Detects the intent and automatically calls the MCP tool
list_tables. - The server executes the query and responds with the list of tables.
Agent's response:
The tables in the database are:
clientes,ordenes,productos.
Another example:
User:
How many records are in the
clientestable?
AI Agent:
- Calls the MCP tool
read_querywith the querySELECT COUNT(*) FROM clientes. - The server executes the query and responds with the result.
Agent's response:
The
clientestable has 1245 records.
Export example:
User:
Export the data from the
productostable in CSV format
AI Agent:
- Calls the MCP tool
export_querywith the querySELECT * FROM productosand formatcsv. - The server generates the CSV and delivers it to the user.
Agent's response:
Here is the CSV file with the data from the
productostable.
Example: search and show a stored procedure
User:
Find the stored procedure
usp_ObtenerClientesand show me its content
AI Agent:
- Calls the MCP tool
find_stored_procedurewith the nameusp_ObtenerClientes. - The server searches for the procedure and retrieves its SQL definition.
Agent's response:
The stored procedure
usp_ObtenerClienteshas the following content:CREATE PROCEDURE usp_ObtenerClientes AS SELECT * FROM clientes
These flows work the same for SQL Server, MySQL, PostgreSQL, or SQLite, and can be used from any compatible MCP client.
What is MCP and what is it for?
- MCP is an open protocol that allows applications and editors to interact with tools and structured data in a standard, secure, and extensible way.
- This MCP server exposes database operations (queries, administration, insights) as MCP tools, which can be consumed by compatible clients (VS Code, Cursor, LLMs, etc.).
Troubleshooting and best practices
- Do not write logs to stdout: Only the MCP protocol (JSON) should go to stdout. Use the .NET logger or
Console.Errorfor logs. - Extensibility: To add new tools, create static methods in a class decorated with
[McpServerToolType]and use[McpServerTool]. - Layer separation: Keep business logic in Application, technical implementations in Infrastructure, and configuration in the main project.
- Validation: Always validate input parameters and the connection string.
- If the MCP client shows JSON errors, make sure there are no logs in stdout.
- If tools do not appear, check that they are correctly decorated and that the assembly is registered with
.WithToolsFromAssembly. - Use stderr logs for advanced debugging.
Credits and License
- Based on the official Model Context Protocol SDK.
- Architecture inspired by Clean Architecture.
- MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. 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. |
This package has no dependencies.