A Model Context Protocol (MCP) server that provides safe, read-only database access to Large Language Models (LLMs). This enables LLMs like Claude to explore database schemas, sample data, and execute SELECT queries through a standardized interface.
⚠️ Early Development Notice: This project is in early development. While functional, it lacks comprehensive testing and production-ready features. Use at your own risk in production environments.
- Schema Exploration: Discover database structure, tables, and columns
- Data Sampling: Preview table contents with configurable row limits
- Safe Querying: Execute read-only SELECT queries with built-in safety measures
- Multi-Database Support: PostgreSQL, MySQL, and SQLite
- MCP Protocol: Seamless integration with Claude Desktop and other MCP-compatible clients
- Go 1.24.4 or higher
- Docker (for development database)
- One of the supported databases:
- PostgreSQL
- MySQL
- SQLite
- Clone the repository:
git clone https://github.com/melkeydev/mcp-database
cd mcp-database- Start the development database (PostgreSQL):
docker-compose up -d- Configure your database connection in
config.yaml:
database:
type: "postgres" # Options: postgres, mysql, sqlite
connection_string: "postgres://postgres:postgres@localhost:5432/mcp_db?sslmode=disable"
file: "database.db" # For SQLite only- Build and run:
go build -o mcp-database
./mcp-database -config config.yamlAdd the server to your Claude Desktop configuration:
{
"mcpServers": {
"database": {
"command": "/path/to/mcp-database",
"args": ["-config", "/path/to/config.yaml"]
}
}
}The server exposes three MCP tools:
Discovers the database schema including all tables, columns, and their types.
// No parameters requiredReturns a sample of rows from a specified table.
{
"table_name": "users", // Required
"limit": 10 // Optional, default: 10
}Executes a read-only SELECT query.
{
"query": "SELECT name, email FROM users WHERE created_at > '2024-01-01'"
}The config.yaml file supports the following database configurations:
database:
type: "postgres"
connection_string: "postgres://user:password@host:port/dbname?sslmode=disable"database:
type: "mysql"
connection_string: "user:password@tcp(host:port)/dbname"database:
type: "sqlite"
file: "path/to/database.db"mcp-database/
├── main.go # Entry point
├── config/ # Configuration management
├── databases/ # Database connectors
│ ├── connector.go # Common interface
│ ├── postgres/ # PostgreSQL implementation
│ ├── mysql/ # MySQL implementation
│ └── sqlite/ # SQLite implementation
├── handlers/ # Request handlers
├── mcp/ # MCP protocol implementation
└── types/ # Shared type definitions
- Read-only operations: All database operations are executed within read-only transactions
- Query validation: Only SELECT statements are allowed
- Resource limits: Configurable row limits for data sampling
- Error handling: Comprehensive error handling and reporting
# Install dependencies
go mod download
# Build
go build -o mcp-database
# Run tests (coming soon)
go test ./...- Create a new package under
databases/ - Implement the
DatabaseConnectorinterface - Update
GetConnector()indatabases/connector.go - Add configuration support in
config/
- Comprehensive test suite
- Connection pooling
- Query result caching
- Support for more databases (Oracle, SQL Server)
- Query timeout configuration
- Result size limits
- Schema caching for better performance
- Support for custom SQL functions
- Docker image for easier deployment
Contributions are welcome! Please feel free to submit a Pull Request. Since this is an early-stage project, please open an issue first to discuss major changes.
- Writing comprehensive tests
- Adding support for more databases
- Improving error messages and debugging
- Documentation improvements
- Performance optimizations
This project is in early development and not yet production-ready. While it implements safety measures for read-only access, please use caution when connecting to production databases. Always use appropriate credentials with minimal required permissions.
Built on the Model Context Protocol by Anthropic.