DSN Format
SQLite connection strings use thesqlite:// protocol:
Basic Examples
Connection Options
Read-Only Mode
SQLite supports SDK-level read-only mode at the database level::memory:) cannot be opened in readonly mode.
This prevents all write operations:
- INSERT, UPDATE, DELETE
- CREATE, ALTER, DROP
- PRAGMA statements that modify database
No Timeouts
SQLite is a local file-based database and does not support connection or query timeouts. Theconnection_timeout and query_timeout options are accepted for interface compliance but have no effect.
Implementation: src/connectors/sqlite/index.ts:127-129
Supported Features
Schemas
SQLite does not have schemas like PostgreSQL or MySQL. Each database file is a single namespace. The connector always returns["main"] as the schema list.
Implementation: src/connectors/sqlite/index.ts:179-189
Note: SQLite supports “attached databases” with ATTACH DATABASE, but this is not exposed through the connector interface.
Tables and Views
Get all tables in the database:sqlite_master system table:
Table Schema
Get column information for a table:PRAGMA table_info(tablename) to retrieve schema information.
Note: SQLite does not support column comments, so description is always null.
Indexes
SQLite indexes include:- Primary keys (reported as
PRIMARYindex) - Unique indexes
- Multi-column indexes
- Partial indexes (filtered)
- Expression indexes
PRAGMA index_list(tablename) and PRAGMA index_info(indexname) to retrieve index information.
Stored Procedures and Functions
SQLite does not support stored procedures or user-defined functions in the database. Functions must be registered programmatically via the SQLite C API or language bindings.Table Comments
SQLite does not support table-level comments. This method is not implemented.Row Count
SQLite does not support fast row count estimation. This method is not implemented, and the search-objects tool falls back toCOUNT(*).
Query Execution
Parameterized Queries
SQLite uses? placeholders for positional parameters:
better-sqlite3’s prepared statement execution.
Multi-Statement Support
SQLite supports multi-statement execution:- Separates read and write statements
- Executes write statements individually, tracking changes
- Executes read statements individually, collecting results
- Returns aggregated rows and total change count
Row Limiting
Applies database-native LIMIT clause for efficiency:Synchronous Execution
SQLite operations inbetter-sqlite3 are synchronous, but the connector wraps them in async methods for interface consistency:
Common Scenarios
Development Database
Testing with In-Memory Database
- Exist only in RAM
- Are destroyed when connection is closed
- Are extremely fast
- Cannot be opened in readonly mode
- Are isolated per connection
Production Embedded Database
Read-Only Archive Database
Multiple SQLite Databases
source_id parameter in MCP tools to query different databases.
SQLite-Specific SQL Examples
JSON Functions (SQLite 3.38+)
Window Functions (SQLite 3.25+)
CTEs and Recursive Queries
Full-Text Search (FTS5)
PRAGMA Queries
File Path Considerations
Unix/Linux/macOS
Windows
- Unix absolute paths:
///path/to/db.sqlite→/path/to/db.sqlite - Windows absolute paths:
///C:/path/to/db.sqlite→C:/path/to/db.sqlite - Relative paths:
//./path/to/db.sqlite→./path/to/db.sqlite
Troubleshooting
File Not Found
Error:SQLITE_CANTOPEN: unable to open database file
Solutions:
- Verify the file path exists
- Check parent directory permissions
- Use absolute paths to avoid ambiguity
- Verify path expansion in TOML (use
~/for home directory)
Database Locked
Error:SQLITE_BUSY: database is locked
Solutions:
- Close other connections to the database
- Enable WAL mode for better concurrency:
- Increase busy timeout:
- Consider using a client-server database for multi-user scenarios
Readonly Database
Error:SQLITE_READONLY: attempt to write a readonly database
Solutions:
- Remove
readonly = truefrom TOML configuration - Check file permissions (needs write access)
- Verify the database file itself is not readonly
Disk I/O Error
Error:SQLITE_IOERR: disk I/O error
Solutions:
- Check disk space:
df -h - Verify file system is not corrupted
- Check permissions on database file and directory
- Run
PRAGMA integrity_check;to verify database integrity
Cannot Open :memory: in Readonly Mode
Error: Configuration error with readonly :memory: database Solution: Removereadonly = true for in-memory databases:
Performance Tips
-
Enable WAL mode for better concurrency:
-
Increase cache size for better performance:
-
Use transactions for bulk operations:
-
Create indexes for frequently queried columns:
-
Use ANALYZE to update statistics:
-
Avoid SELECT * - specify needed columns:
- Use prepared statements via parameterized queries to enable query plan caching
-
Vacuum periodically to reclaim space:
When to Use SQLite
Good use cases:- Development and testing
- Embedded applications
- Mobile applications
- Small to medium single-user applications
- Configuration storage
- Local caching
- Data analysis on local files
- Prototyping
- High-concurrency write scenarios
- Multi-user web applications
- Network file systems (NFS, SMB)
- Very large databases (>100GB)
- Applications requiring user access control
- Distributed systems