ThomasB98/MCPDataBaseServer
If you are the rightful owner of MCPDataBaseServer and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
The MCPDataBaseMSSQLServer is a .NET 8 console application that hosts a Model-Context-Protocol (MCP) server capable of interacting with various relational databases.
MCPDataBaseMSSQLServer
A small, self-contained .NET 8 console application that hosts a Model-Context-Protocol (MCP) server able to talk to a relational database.
Although the project name references MSSQL, the code has been abstracted so you can easily switch between several popular database engines (SQLite, SQL Server, PostgreSQL and MySQL) just by changing the configuration file β no code changes required.
What the project does
- Bootstraps an MCP server β The
Program.cs
entry point wires the MCP services and exposes them over STDIO so the executable can be embedded in other host processes (e.g. editors). - Initialises a database connection β At start-up the application reads
appsettings.json
to decide which ADO.NET provider to use and opens the connection (SqliteConnection
,SqlConnection
,NpgsqlConnection
orMySqlConnection
). - Provides basic logging & validation β Logging is enabled via
Microsoft.Extensions.Logging
and optional query-validation rules are read from configuration. - Offers a playground for experimenting with Dapper & MCP β Because it is framework-agnostic you can point the same binary at different database back-ends to test behaviour and performance.
Quick start
Prerequisites
- .NET 8 SDK (download from https://dotnet.microsoft.com)
- One of the supported databases running locally (or reachable via network)
Build & run
# Restore packages & compile
$ dotnet build
# Run with default settings (SQLite / sample.db)
$ dotnet run --project MCPDataBaseMSSQLServer.csproj
When the application starts you should see logging similar to:
info: Program[0]
Initializing SQLITE database connection
info: Program[0]
Database connection established successfully
Changing the database provider
All runtime behaviour is driven by appsettings.json
(or the environment-specific variant such as appsettings.Development.json
).
"DatabaseSettings": {
"Provider": "SQLite", // <-- Change to SQLServer | PostgreSQL | MySQL
"CommandTimeout": 30,
"MaxRetryAttempts": 3
},
"ConnectionStrings": {
"DefaultConnection": "Data Source=sample.db",
"SqlServerConnection": "Server=localhost;Database=TestDB;Trusted_Connection=true;TrustServerCertificate=true;",
"PostgreSqlConnection": "Host=localhost;Database=testdb;Username=postgres;Password=password;",
"MySqlConnection": "Server=localhost;Database=testdb;Uid=root;Pwd=password;"
}
Steps:
- Set
DatabaseSettings:Provider
to the desired engine. - Update the matching connection string.
- Re-run the application.
NOTE: The application opens the connection at start-up. If the string is invalid or the server cannot be reached it will throw immediately.
Security & query validation
The Security
section allows you to restrict what the MCP server may execute:
"Security": {
"AllowedCommands": [ "SELECT", "INSERT", "UPDATE", "DELETE" ],
"RestrictedTables": [ "sys_users", "admin_settings" ],
"EnableQueryValidation": true
}
- AllowedCommands β Whitelist of SQL verbs permitted.
- RestrictedTables β Blacklist of tables that must never be referenced.
- EnableQueryValidation β Toggle validation on/off.
Adjust these lists to fit the policies of your environment.
Typical changes you may need to make
- Connection strings β Point to your own databases.
- Provider selection β Change from the default SQLite to your chosen engine.
- Timeouts & retry logic β Tune
CommandTimeout
andMaxRetryAttempts
based on workload. - Logging level β Set
Logging.LogLevel.*
to control verbosity. - Security rules β Expand or tighten the
Security
section. - Packaging β If you want a single-file executable run:
dotnet publish -c Release -r win-x64 --self-contained true /p:PublishSingleFile=true
Project structure
β Program.cs # Bootstrap & composition root
β appsettings.json # Main configuration file
β MCPDataBaseMSSQLServer.csproj
ββββREADME.md # You are here
Contributing
Pull requests are welcome! If you have feature requests or run into problems, please open an issue.
License
This project is released under the MIT License.