A Model Context Protocol (MCP) server that provides AI assistants like Claude with secure, structured access to SQL Server databases through natural language queries.
Model Context Protocol (MCP) is an open protocol that standardizes how AI applications connect to data sources. Instead of building custom integrations for each AI assistant, you build one MCP server that works with any MCP-compatible client.
Key Benefits:
- Natural Language Interface: Query databases using plain English instead of writing SQL
- AI Orchestration: AI can call multiple tools and synthesize results intelligently
- Standardized Protocol: One server works with Claude, future AI tools, and custom applications
- Controlled Access: Expose only specific, pre-defined operations rather than raw database access
┌─────────────────┐
│ Claude Desktop │ (MCP Client)
└────────┬────────┘
│ JSON-RPC over stdio
│
┌────────▼────────┐
│ MCP Server │ (This Project)
│ (C# .NET 9) │
└────────┬────────┘
│ Entity Framework Core
│
┌────────▼────────────┐
│ SQL Server │
│ (AdventureWorks2025)│
└─────────────────────┘
- .NET 9: Modern C# runtime
- Entity Framework Core: Database ORM with code-first approach
- Model Context Protocol: JSON-RPC 2.0 over stdio transport
- SQL Server Express: Local database engine
- Dependency Injection: Clean architecture with interface-based services
- get_customers: Retrieve top N customers from the database
- search_products: Search products by name, price range, or category
- get_top_selling_products: Get best-selling products by quantity sold
User: "What are our top 5 best-selling products?"
Claude: [Calls get_top_selling_products tool]
Result: Detailed product list with sales metrics
User: "Show me bikes under $1000"
Claude: [Calls search_products with filters]
Result: Filtered product list
User: "What's the average price of our top 10 sellers?"
Claude: [Calls get_top_selling_products, then analyzes]
Result: Calculated insights with context
- .NET 9 SDK
- SQL Server Express (or any SQL Server instance)
- Claude Desktop app
- AdventureWorks2025 sample database
Download the backup file from Microsoft SQL Server Samples and restore it:
RESTORE DATABASE AdventureWorks2025
FROM DISK = 'path\to\AdventureWorksLT2025.bak'git clone <your-repo-url>
cd SqlServerMcpServerCopy the example configuration and update with your connection string:
copy appsettings.example.json appsettings.jsonEdit appsettings.json:
{
"ConnectionStrings": {
"AdventureWorks": "Server=YOUR_SERVER\\SQLEXPRESS;Database=AdventureWorks2025;Trusted_Connection=True;TrustServerCertificate=True;"
}
}dotnet restore
dotnet build
dotnet publish -c Release -o publishEdit Claude Desktop's configuration file:
- Windows:
%APPDATA%\Claude\claude_desktop_config.json
Add your MCP server:
{
"mcpServers": {
"sql-server": {
"command": "dotnet",
"args": ["<full-path-to-project>\\publish\\SqlServerMcpServer.dll"],
"cwd": "<full-path-to-project>\\publish"
}
}
}Close and reopen Claude Desktop. You should see a hammer icon (🔨) in the input box indicating MCP tools are available.
- Database queries execute with full user credentials
- Query results are sent to Anthropic's cloud for AI processing
- NOT suitable for production use with sensitive data
For production use with real data, implement:
-
Read-Only Database Access
- Create SQL user with SELECT-only permissions
- Restrict access to specific tables/views
- Use row-level security if available
-
Data Masking/Anonymization
- Filter PII before returning results
- Hash sensitive identifiers
- Implement field-level encryption for sensitive data
-
Self-Hosted AI Models
- Deploy open-source LLMs (Llama, Mistral) on-premise
- Build custom MCP client that doesn't send data to external APIs
- Keep all data processing within your network
-
Audit Logging
- Log all MCP tool invocations
- Track which users accessed what data
- Implement compliance reporting
-
Rate Limiting & Throttling
- Prevent excessive database queries
- Implement query complexity limits
- Add authentication/authorization layers
When using Claude Desktop with this MCP server:
- Your queries and database results are sent to Anthropic's API for processing
- Anthropic's data usage policies apply
- Only use with non-sensitive, non-PII data
- For sensitive data, consider enterprise contracts with DPA agreements
npm install -g @modelcontextprotocol/inspector
cd SqlServerMcpServer\publish
mcp-inspector dotnet SqlServerMcpServer.dllThis opens a web UI where you can test individual tools before connecting to Claude.
Run the server directly and send JSON-RPC requests:
dotnet runThen input:
{"jsonrpc":"2.0","method":"tools/list","params":{},"id":1}This is a learning project demonstrating MCP concepts. Feel free to:
- Fork and experiment
- Add new tools (sales analytics, customer insights, etc.)
- Improve error handling
- Add unit tests
MIT License - feel free to use this as a learning resource or starting point for your own MCP servers.
Built as a learning project to explore AI integration patterns and the Model Context Protocol.
Note: This project demonstrates MCP concepts using Microsoft's AdventureWorks sample database. Always review security implications before adapting for production use with real data.