A Model Context Protocol (MCP) server for libSQL database operations, providing secure database access through Claude Desktop, Claude Code, Cursor, and other MCP-compatible clients. Runs on Node, written in TypeScript 1. Install: 2. Test locally: 3. Configure Claude Desktop with your Node.js path and database URL (see configuration examples below) ✅ Complete database management capabilities - All
Add this skill
npx mdskills install Xexr/mcp-libsqlProduction-ready libSQL MCP server with comprehensive security, excellent docs, and multi-platform support
1# MCP libSQL by xexr23A Model Context Protocol (MCP) server for libSQL database operations, providing secure database access through Claude Desktop, Claude Code, Cursor, and other MCP-compatible clients.45Runs on Node, written in TypeScript67## 🔧 **Quick Start**891. **Install:**10 ```bash11 pnpm install -g @xexr/mcp-libsql12 ```13142. **Test locally:**15 ```bash16 mcp-libsql --url file:///tmp/test.db --log-mode console17 ```18193. **Configure Claude Desktop** with your Node.js path and database URL (see configuration examples below)2021## 🚀 **Status**2223✅ **Complete database management capabilities** - All 6 core tools implemented and tested24✅ **Comprehensive security validation** - 67 security tests covering all injection vectors25✅ **Extensive test coverage** - 244 total tests (177 unit + 67 security) with 100% pass rate26✅ **Production deployment verified** - Successfully working with MCP clients27✅ **Robust error handling** - Connection retry, graceful degradation, and audit logging2829## 🛠️ **Features**3031### **Available Tools**32- **read-query**: Execute SELECT queries with comprehensive security validation33- **write-query**: INSERT/UPDATE/DELETE operations with transaction support34- **create-table**: DDL operations for table creation with security measures35- **alter-table**: Table structure modifications (ADD/RENAME/DROP operations)36- **list-tables**: Database metadata browsing with filtering options37- **describe-table**: Table schema inspection with multiple output formats3839### **Security & Reliability**40- **Multi-layer SQL injection prevention** with comprehensive security validation41- **Connection pooling** with health monitoring and automatic retry logic42- **Transaction support** with automatic rollback on errors43- **Comprehensive audit logging** for security compliance4445> 🔐 **Security details:** See [docs/SECURITY.md](docs/SECURITY.md) for comprehensive security features and testing.4647### **Developer Experience**48- **Beautiful table formatting** with proper alignment and NULL handling49- **Performance metrics** displayed for all operations50- **Clear error messages** with actionable context51- **Parameterized query support** for safe data handling52- **Development mode** with enhanced logging and hot reload5354## 📋 **Prerequisites**5556- **Node.js** 20+57- **pnpm** (or npm) package manager58- **libSQL database** (file-based or remote)59- **Claude Desktop** (for MCP integration)6061### **Platform Requirements**62- **macOS**: Native Node.js installation63- **Linux**: Native Node.js installation64- **Windows**: Native Node.js installation or WSL2 with Node.js installation6566## 🔧 **Installation**6768```bash69# Use your package manager of choice, e.g. npm, pnpm, bun etc7071# Install globally72pnpm install -g @xexr/mcp-libsql73mcp-libsql -v # check version7475# ...or build from the repository76git clone https://github.com/Xexr/mcp-libsql.git77cd mcp-libsql78pnpm install # Install dependencies79pnpm build # Build the project80node dist/index.js -v # check version81```8283## 🚀 **Usage**8485### **Local Testing**8687Global installation assumed below, replace "mcp-libsql" with "node dist/index.js" if using local build8889```bash90# Test with file database (default: file-only logging)91mcp-libsql --url file:///tmp/test.db9293# Test with HTTP database94mcp-libsql --url http://127.0.0.1:80809596# Test with Turso database (environment variable, alternatively export the env var)97LIBSQL_AUTH_TOKEN="your-token" mcp-libsql --url "libsql://your-db.turso.io"9899# Test with Turso database (CLI parameter)100mcp-libsql --url "libsql://your-db.turso.io" --auth-token "your-token"101102# Development mode with console logging103mcp-libsql --dev --log-mode console --url file:///tmp/test.db104105# Test with different logging modes106mcp-libsql --url --log-mode both file:///tmp/test.db107```108109### **Claude Desktop Integration**110111Configure the MCP server in Claude Desktop based on your operating system:112113#### **macOS Configuration**1141151. **Create configuration file** at `~/Library/Application Support/Claude/claude_desktop_config.json`:116117**Global install**118```json119120{121 "mcpServers": {122 "mcp-libsql": {123 "command": "mcp-libsql",124 "args": [125 "--url",126 "file:///Users/username/database.db"127 ]128 }129 }130}131```132133**Alternative configuration for local build installation:**134```json135{136 "mcpServers": {137 "mcp-libsql": {138 "command": "node",139 "args": [140 "/Users/username/projects/mcp-libsql/dist/index.js",141 "--url",142 "file:///Users/username/database.db"143 ],144 }145 }146}147```148149**Alternative configuration for global install using nvm lts for node**150```json151{152 "mcpServers": {153 "mcp-libsql": {154 "command": "zsh",155 "args": [156 "-c",157 "source ~/.nvm/nvm.sh && nvm use --lts > /dev/null && mcp-libsql --url file:///Users/username/database.db",158 ],159 }160 }161}162```163164**Important**: The global installation method is recommended as it handles PATH automatically.165166#### **Linux Configuration**1671681. **Create configuration file** at `~/.config/Claude/claude_desktop_config.json`:169170**Global install**171```json172{173 "mcpServers": {174 "mcp-libsql": {175 "command": "mcp-libsql",176 "args": [177 "--url",178 "file:///home/username/database.db"179 ]180 }181 }182}183```184185**Alternative configuration for local build installation:**186```json187{188 "mcpServers": {189 "mcp-libsql": {190 "command": "node",191 "args": [192 "/home/username/projects/mcp-libsql/dist/index.js",193 "--url",194 "file:///home/username/database.db"195 ],196 }197 }198}199```200201#### **Windows (WSL2) Configuration**2022031. **Create configuration file** at `%APPDATA%\Claude\claude_desktop_config.json`:204205**Global install**206```json207{208 "mcpServers": {209 "mcp-libsql": {210 "command": "wsl.exe",211 "args": [212 "-e",213 "bash",214 "-c",215 "mcp-libsql --url file:///home/username/database.db",216 ]217 }218 }219}220```221222**Alternative configuration for local build installation:**223```json224{225 "mcpServers": {226 "mcp-libsql": {227 "command": "wsl.exe",228 "args": [229 "-e",230 "bash",231 "-c",232 "/home/username/projects/mcp-libsql/dist/index.js --url file:///home/username/database.db",233 ]234 }235 }236}237```238239**Alternative configuration for global install using nvm for node**240```json241{242 "mcpServers": {243 "mcp-libsql": {244 "command": "wsl.exe",245 "args": [246 "-e",247 "bash",248 "-c",249 "source ~/.nvm/nvm.sh && mcp-libsql --url file:///home/username/database.db",250 ]251 }252 }253}254```255256**Important**: Use `wsl.exe -e` (not just `wsl.exe`) to ensure proper command handling and avoid issues with server command reception on Windows.257258### **Database Authentication**259260For Turso (and other credentialed) databases, you'll need an authentication token. There are two secure ways to provide it:261262_Global installation shown below, adjust accordingly for your setup_263264#### **Method 1: Environment Variable (Recommended)**265266**Configure Claude Desktop with environment variable** (macOS/Linux example):267```bash268export LIBSQL_AUTH_TOKEN="your-turso-auth-token-here"269```270271```json272{273 "mcpServers": {274 "mcp-libsql": {275 "command": "mcp-libsql",276 "args": [277 "--url",278 "libsql://your-database.turso.io"279 ]280 }281 }282}283```284285#### **Method 2: CLI Parameter**286287```json288{289 "mcpServers": {290 "mcp-libsql": {291 "command": "mcp-libsql",292 "args": [293 "--url",294 "libsql://your-database.turso.io",295 "--auth-token",296 "your-turso-auth-token-here"297 ]298 }299 }300}301```302303#### **Getting Your Turso Auth Token**3043051. **Install Turso CLI:**306 ```bash307 curl -sSfL https://get.tur.so/install.sh | bash308 ```3093102. **Login to Turso:**311 ```bash312 turso auth login313 ```3143153. **Create an auth token:**316 ```bash317 turso auth token create --name "mcp-libsql"318 ```3193204. **Get your database URL:**321 ```bash322 turso db show your-database-name --url323 ```324325#### **Security Best Practices**326327- **Environment variables are safer** than CLI parameters (tokens won't appear in process lists)328- **MCP config files may contain tokens** - ensure they're not committed to version control329- **Consider using external secret management** for production environments330- **Use scoped tokens** with minimal required permissions331- **Rotate tokens regularly** for enhanced security332- **Monitor token usage** through Turso dashboard333334#### **Example: Complete Turso Setup**3353361. **Create and configure database:**337 ```bash338 # Create database339 turso db create my-app-db340341 # Get database URL342 turso db show my-app-db --url343 # Output: libsql://my-app-db-username.turso.io344345 # Create auth token346 turso auth token create --name "mcp-libsql-token"347 # Output: your-long-auth-token-string348 ```3493502. **Configure Claude Desktop:**351 ```bash352 export LIBSQL_AUTH_TOKEN="your-turso-auth-token-here"353 ```354355 ```json356 {357 "mcpServers": {358 "mcp-libsql": {359 "command": "mcp-libsql",360 "args": [361 "--url",362 "libsql://my-app-db-username.turso.io"363 ]364 }365 }366 }367 ```3683693. **Test the connection:**370 ```bash371 # Test locally first372 mcp-libsql --url "libsql://my-app-db-username.turso.io" --log-mode console373 ```374375#### **Configuration Notes**376377- **File paths**: Use absolute paths to avoid path resolution issues378- **Database URLs**:379 - File databases: `file:///absolute/path/to/database.db`380 - HTTP databases: `http://hostname:port`381 - libSQL/Turso: `libsql://your-database.turso.io`382- **Node.js path**: Use `which node` to find your Node.js installation path383- **Working directory**: Set `cwd` to ensure relative paths work correctly384- **Authentication**: For Turso databases, use environment variables for secure token handling385- **Logging modes**:386 - Default `file` mode prevents JSON parsing errors in MCP protocol387 - Use `--log-mode console` for development debugging388 - Use `--log-mode both` for comprehensive logging389 - Use `--log-mode none` to disable all logging3903912. **Restart Claude Desktop** completely after updating the configuration3923933. **Test the integration** by asking Claude to run SQL queries:394 ```395 Can you run this SQL query: SELECT 1 as test396 ```397398399400## 📋 **Available Tools**401402- **read-query** - Execute SELECT queries with security validation403- **write-query** - INSERT/UPDATE/DELETE with transaction support404- **create-table** - CREATE TABLE with DDL security405- **alter-table** - Modify table structure (ADD/RENAME/DROP)406- **list-tables** - Browse database metadata and objects407- **describe-table** - Inspect table schema and structure408409> 📖 **Detailed API documentation:** See [docs/API.md](docs/API.md) for complete input/output examples and parameters.410411## 🧪 **Testing**412413```bash414# Run all tests415pnpm test416417# Run tests in watch mode418pnpm test:watch419420# Run tests with coverage421pnpm test:coverage422423# Run specific test file424pnpm test security-verification425426# Lint code427pnpm lint428429# Fix linting issues430pnpm lint:fix431432# Type check433pnpm typecheck434```435436**Test Coverage**: 403 tests covering all functionality including edge cases, error scenarios, CLI arguments, authentication, and comprehensive security validation.437438## ⚠️ **Common Issues**439440### **1. Build Failures**441```bash442# Clean and rebuild443rm -rf dist node_modules444pnpm install && pnpm build445```446447### **2. Node.js Version Issues (macOS)**448```449SyntaxError: Unexpected token '??='450```451**Problem**: Claude Desktop may default to using an older Node.js version on your system which doesn't support the required feature set.452453**Solution**: Use global installation and nvm node selection method shown above.454455### **3. Server Won't Start**456- For global installation: `pnpm install -g @xexr/mcp-libsql`457- For local installation: Ensure `pnpm build` was run and `dist/index.js` exists458- Test locally: `mcp-libsql --url file:///tmp/test.db`459- Restart Claude Desktop after config changes460461### **4. Tools Not Available**462- Verify database URL is accessible463- Check Claude Desktop logs for connection errors464- Test with simple file database: `file:///tmp/test.db`465466### **5. JSON Parsing Errors (Resolved)**467```468Expected ',' or ']' after array element in JSON469```470**Resolved**: This issue is caused by stdout console logging. The `--log-mode` option now defaults to `file` mode which prevents this issue. If you see these errors, ensure you're using the default `--log-mode file` or not specifying `--log-mode` at all. Note, the error is harmless, and the tool will still work with it if you wish to have console logging.471472### **6. Database Connection Issues**473```bash474# Test database connectivity475sqlite3 /tmp/test.db "SELECT 1"476477# Fix permissions478chmod 644 /path/to/database.db479```480481> 🔧 **Full troubleshooting guide:** See [docs/TROUBLESHOOTING.md](docs/TROUBLESHOOTING.md) for detailed solutions to all issues.482483## 🏗️ **Architecture**484485Built with TypeScript and modern Node.js patterns:486- **Connection pooling** with health monitoring and retry logic487- **Tool-based architecture** with consistent validation and error handling488- **Security-first design** with multi-layer input validation489- **Comprehensive testing** with 244 tests covering all scenarios490491## 🤝 **Contributing**4924931. Follow TypeScript strict mode and existing code patterns4942. Write tests for new features4953. Maintain security measures4964. Update documentation497498**Development:** `pnpm dev` • **Build:** `pnpm build` • **Test:** `pnpm test`499500## 📄 **License**501502MIT License - see [LICENSE](LICENSE) file for details.503504## 🔗 **Links**505506- [Model Context Protocol](https://modelcontextprotocol.io/)507- [MCP TypeScript SDK](https://github.com/modelcontextprotocol/typescript-sdk)508- [libSQL Documentation](https://docs.libsql.org/)509- [Claude Desktop](https://claude.ai/desktop)
Full transparency — inspect the skill content before installing.