Peekdb MCP
MCP server de solo lectura para anΓ‘lisis de SQL Server
Ask AI about Peekdb MCP
Powered by Claude Β· Grounded in docs
I know everything about Peekdb MCP. Ask me about installation, configuration, usage, or troubleshooting.
0/500
Reviews
Documentation
peekdb-mcp π
A read-only MCP (Model Context Protocol) server for SQL Server. Enables AI clients like Claude Desktop, Cursor, or any MCP-compatible client to analyze schemas, dependencies, stored procedures, and missing indexes β without risking any data changes.
β‘ Features
- 9 ready-to-use analysis tools
- Read-only β no DDL or DML execution, only system view queries
- Parameterized queries β SQL injection protection
- stdio communication β JSON-RPC 2.0 via stdin/stdout
- Secure logging β Serilog writes to files only, never to stdout
π οΈ Available Tools
| Tool | Description |
|---|---|
list_tables | Lists all tables with approximate row counts and space |
analyze_table_schema | Columns, types, PKs, FKs, and indexes of a table |
get_sp_definition | Source code of a stored procedure |
list_stored_procedures | Catalog of all stored procedures |
get_function_definition | Source code of a function |
find_object_dependencies | What objects reference and who references it |
search_in_code | Search text in all objects' code |
get_missing_indexes | Missing indexes suggested by the engine (DMVs) |
get_table_relationships | Foreign key map |
π Requirements
- .NET 8 SDK or higher
- Access to a SQL Server instance
- A SQL user with read-only permissions (recommended:
db_datareader+VIEW DEFINITION)
π Installation
Option A: Download binary (recommended)
Download the executable for your platform from Releases:
peekdb-mcp-win-x64.zipβ Windowspeekdb-mcp-linux-x64.tar.gzβ Linuxpeekdb-mcp-osx-x64.tar.gzβ macOS
These are self-contained β no .NET installation required.
Option B: Build from source
git clone https://github.com/EmilianoRojas/peekdb-mcp.git
cd peekdb-mcp/PeekDbMcp
dotnet publish -c Release -o ./publish
Option C: Docker
docker build -t peekdb-mcp .
Verify
# Linux/macOS
./publish/PeekDbMcp
# Windows
.\publish\PeekDbMcp.exe
The process will wait for input on stdin. If it stays waiting, it's working correctly. Exit with
Ctrl+C.
βοΈ Configuration
SQL Server connection is configured via the SQLSERVER_CONNECTION_STRING environment variable.
Connection String Format
Server=your-server;Database=your-db;User Id=your-user;Password=your-password;TrustServerCertificate=True;
For Windows Authentication:
Server=your-server;Database=your-db;Integrated Security=True;TrustServerCertificate=True;
π MCP Client Integration
Claude Desktop
Edit your config file (claude_desktop_config.json):
Windows: %APPDATA%\Claude\claude_desktop_config.json
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"peekdb": {
"command": "dotnet",
"args": ["run", "--project", "C:/path/to/peekdb-mcp/PeekDbMcp"],
"env": {
"SQLSERVER_CONNECTION_STRING": "Server=localhost;Database=MyDb;User Id=reader;Password=secret;TrustServerCertificate=True;"
}
}
}
}
Or using the published executable:
{
"mcpServers": {
"peekdb": {
"command": "C:/path/to/peekdb-mcp/PeekDbMcp/publish/PeekDbMcp.exe",
"env": {
"SQLSERVER_CONNECTION_STRING": "Server=localhost;Database=MyDb;User Id=reader;Password=secret;TrustServerCertificate=True;"
}
}
}
}
Cursor
In Cursor's settings, add the MCP server with the same command, args, and env parameters.
Docker
{
"mcpServers": {
"peekdb": {
"command": "docker",
"args": [
"run", "-i", "--rm",
"-e", "SQLSERVER_CONNECTION_STRING=Server=host.docker.internal;Database=MyDb;User Id=reader;Password=secret;TrustServerCertificate=True;",
"peekdb-mcp"
]
}
}
}
Note: Use
host.docker.internalto connect to the host's SQL Server.
π‘ Usage Examples
Once configured, you can ask Claude things like:
- "What tables are in this database?"
- "Show me the schema of the Users table"
- "Give me the code for the usp_GetOrderDetails SP"
- "What objects depend on the Products table?"
- "Search for all references to 'CustomerID' in the code"
- "Are there missing indexes I should create?"
- "Show me the relationship map for the Orders table"
π Security
Recommended Permissions
Create a dedicated SQL user with minimal permissions:
CREATE LOGIN McpReader WITH PASSWORD = 'your-secure-password';
USE YourDatabase;
CREATE USER McpReader FOR LOGIN McpReader;
ALTER ROLE db_datareader ADD MEMBER McpReader;
GRANT VIEW DEFINITION TO McpReader;
Security Principles
- Read-only by design: No code path executes
INSERT,UPDATE,DELETE, or DDL - Parameterized queries: All LLM input goes through ADO.NET/Dapper SQL parameters
- No secrets in stdout: Logs go exclusively to files in
Logs/
π Project Structure
PeekDbMcp/
βββ Program.cs # Entry point, Serilog config
βββ Core/
β βββ McpDispatcher.cs # JSON-RPC stdin/stdout loop
β βββ JsonRpcModels.cs # Serialization models
β βββ ToolRegistry.cs # Tool catalog + JSON Schemas
βββ Services/
β βββ DatabaseAnalyzer.cs # T-SQL queries with Dapper
βββ Tools/
β βββ ToolHandler.cs # Tool router
βββ Configuration/
β βββ AppSettings.cs # Environment variable reading
βββ Logs/ # Generated at runtime
For architecture details, see ARCHITECTURE.md.
π Logs
Logs are written to PeekDbMcp/Logs/ (or next to the published executable). Daily rotation, 7-day retention.
# Watch logs in real-time
tail -f PeekDbMcp/Logs/mcp-20260405.log
π€ Contributing
- Fork the repo
- Create your branch (
git checkout -b feature/new-tool) - Commit (
git commit -m 'feat: add tool X') - Push (
git push origin feature/new-tool) - Open a Pull Request
π License
MIT
