sqlcipher-mcp-server 1.0.4 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,210 +1,433 @@
1
- # SQLCipher MCP Server
2
-
3
- An MCP (Model Context Protocol) server that provides read-only access to SQLCipher-encrypted SQLite databases. This server allows you to query encrypted SQLite databases using SQLCipher 3 default encryption settings.
4
-
5
- ## Overview
6
-
7
- This MCP server enables you to:
8
- - Connect to SQLCipher-encrypted SQLite databases
9
- - Execute SELECT queries (read-only mode)
10
- - Retrieve query results in a structured format
11
- - Use SQLCipher 3 default encryption settings
12
-
13
- ## Prerequisites
14
-
15
- - Node.js (v18 or higher)
16
- - npm or yarn package manager
17
- - Access to a SQLCipher-encrypted SQLite database file
18
- - Database password (will be provided via environment variable)
19
-
20
- ## Installation
21
-
22
- 1. Clone or download this repository
23
- 2. Install dependencies:
24
-
25
- ```bash
26
- npm install
27
- ```
28
-
29
- ## Configuration
30
-
31
- ### Environment Variable
32
-
33
- Set the `SQLCIPHER_PASSWORD` environment variable with your database password:
34
-
35
- **Windows (PowerShell):**
36
- ```powershell
37
- $env:SQLCIPHER_PASSWORD = "your_database_password"
38
- ```
39
-
40
- **Windows (Command Prompt):**
41
- ```cmd
42
- set SQLCIPHER_PASSWORD=your_database_password
43
- ```
44
-
45
- **Linux/macOS:**
46
- ```bash
47
- export SQLCIPHER_PASSWORD="your_database_password"
48
- ```
49
-
50
- **Permanent setup (recommended):**
51
- - Add the environment variable to your system settings
52
- - Or use a `.env` file with a tool like `dotenv` (requires additional setup)
53
-
54
- ## Usage
55
-
56
- ### Starting the Server
57
-
58
- The MCP server communicates via stdio (standard input/output). Start it with:
59
-
60
- ```bash
61
- npm start
62
- ```
63
-
64
- Or directly:
65
-
66
- ```bash
67
- node index.js
68
- ```
69
-
70
- ### MCP Client Configuration
71
-
72
- Configure your MCP client to use this server. Example configuration:
73
-
74
- ```json
75
- {
76
- "mcpServers": {
77
- "sqlcipher": {
78
- "command": "node",
79
- "args": ["C:\\Repos\\MyMCP\\index.js"],
80
- "env": {
81
- "SQLCIPHER_PASSWORD": "your_database_password"
82
- }
83
- }
84
- }
85
- }
86
- ```
87
-
88
- ### Available Tools
89
-
90
- #### `execute_query`
91
-
92
- Execute a SELECT query on a SQLCipher-encrypted database.
93
-
94
- **Parameters:**
95
- - `database_path` (string, required): Full path to the SQLCipher database file
96
- - `query` (string, required): SQL SELECT query to execute
97
-
98
- **Returns:**
99
- - Formatted text output with query results
100
- - JSON representation of results including:
101
- - `columns`: Array of column names
102
- - `rows`: Array of row objects
103
- - `rowCount`: Number of rows returned
104
-
105
- **Example Usage:**
106
-
107
- ```javascript
108
- // Example 1: Simple SELECT query
109
- {
110
- "tool": "execute_query",
111
- "arguments": {
112
- "database_path": "C:\\Users\\Username\\AppData\\Local\\AppName\\database.db",
113
- "query": "SELECT * FROM users LIMIT 10"
114
- }
115
- }
116
-
117
- // Example 2: SELECT with WHERE clause
118
- {
119
- "tool": "execute_query",
120
- "arguments": {
121
- "database_path": "C:\\Users\\Username\\AppData\\Local\\AppName\\database.db",
122
- "query": "SELECT id, name, email FROM users WHERE active = 1"
123
- }
124
- }
125
-
126
- // Example 3: SELECT with JOIN
127
- {
128
- "tool": "execute_query",
129
- "arguments": {
130
- "database_path": "C:\\Users\\Username\\AppData\\Local\\AppName\\database.db",
131
- "query": "SELECT u.name, o.order_id FROM users u JOIN orders o ON u.id = o.user_id"
132
- }
133
- }
134
- ```
135
-
136
- ## Security Features
137
-
138
- - **Read-Only Mode**: Only SELECT queries are allowed. INSERT, UPDATE, DELETE, and other modifying operations are blocked.
139
- - **Password Protection**: Database password is read from environment variable and never exposed in logs or error messages.
140
- - **Query Validation**: All queries are validated to ensure they are SELECT queries only.
141
- - **Error Handling**: Sensitive information is not exposed in error messages.
142
-
143
- ## Error Handling
144
-
145
- The server handles various error scenarios:
146
-
147
- - **Database file not found**: Returns clear error message
148
- - **Invalid password**: Returns generic error (doesn't expose password details)
149
- - **SQL syntax errors**: Returns specific syntax error messages
150
- - **Table/column not found**: Returns specific error messages
151
- - **Non-SELECT queries**: Returns error explaining read-only restriction
152
-
153
- ## Database Location
154
-
155
- The database file path should be provided each time you execute a query. Common locations for Windows applications:
156
-
157
- - `C:\Users\<Username>\AppData\Local\<AppName>\database.db`
158
- - `C:\Users\<Username>\AppData\Roaming\<AppName>\database.db`
159
- - `C:\ProgramData\<AppName>\database.db`
160
-
161
- ## Limitations
162
-
163
- - **Read-Only**: Only SELECT queries are supported
164
- - **Single Connection**: Each query opens and closes a new database connection
165
- - **Result Size**: Results are limited to 1000 rows for display (full results available in JSON)
166
- - **SQLCipher 3 Only**: Uses SQLCipher 3 default encryption settings
167
-
168
- ## Troubleshooting
169
-
170
- ### "Database password not found" Error
171
- - Ensure `SQLCIPHER_PASSWORD` environment variable is set
172
- - Restart your MCP client after setting the environment variable
173
- - Check that the environment variable is available to the Node.js process
174
-
175
- ### "Database file not found" Error
176
- - Verify the database path is correct
177
- - Use absolute paths instead of relative paths
178
- - Check file permissions
179
-
180
- ### "Invalid password" Error
181
- - Verify the password matches the one used to encrypt the database
182
- - Ensure SQLCipher 3 defaults are used (as this server expects)
183
- - Check for extra spaces or special characters in the password
184
-
185
- ### Connection Issues
186
- - Ensure the database file is not locked by another application
187
- - Verify the database file is a valid SQLCipher database
188
- - Check that SQLCipher 3 encryption was used (not SQLCipher 4)
189
-
190
- ## Development
191
-
192
- ### Project Structure
193
-
194
- ```
195
- MyMCP/
196
- ├── index.js # Main MCP server entry point
197
- ├── lib/
198
- │ └── database.js # Database connection and query logic
199
- ├── package.json # Project dependencies
200
- └── README.md # This file
201
- ```
202
-
203
- ### Dependencies
204
-
205
- - `@modelcontextprotocol/sdk`: MCP SDK for Node.js
206
- - `@journeyapps/sqlcipher`: SQLCipher bindings for Node.js
207
-
208
- ## License
209
-
210
- MIT
1
+ # SQLCipher MCP Server
2
+
3
+ An MCP (Model Context Protocol) server that provides comprehensive read-only access to both encrypted (SQLCipher) and unencrypted SQLite databases. This server offers extensive tools for database exploration, schema analysis, query optimization, and data profiling.
4
+
5
+ ## Overview
6
+
7
+ This MCP server enables you to:
8
+ - Connect to both SQLCipher-encrypted and plain SQLite databases
9
+ - Execute SELECT queries (read-only mode)
10
+ - Explore database schemas and relationships
11
+ - Analyze table statistics and data quality
12
+ - Generate and optimize SQL queries
13
+ - Search for tables and columns across the database
14
+ - Use interactive prompts for common workflows
15
+
16
+ ## Prerequisites
17
+
18
+ - Node.js (v18 or higher)
19
+ - npm or yarn package manager
20
+ - Access to a SQLCipher-encrypted SQLite database file
21
+ - Database password (will be provided via environment variable)
22
+
23
+ ## Installation
24
+
25
+ 1. Clone or download this repository
26
+ 2. Install dependencies:
27
+
28
+ ```bash
29
+ npm install
30
+ ```
31
+
32
+ ## Configuration
33
+
34
+ ### Environment Variable
35
+
36
+ Set the `SQLCIPHER_PASSWORD` environment variable with your database password:
37
+
38
+ **Windows (PowerShell):**
39
+ ```powershell
40
+ $env:SQLCIPHER_PASSWORD = "your_database_password"
41
+ ```
42
+
43
+ **Windows (Command Prompt):**
44
+ ```cmd
45
+ set SQLCIPHER_PASSWORD=your_database_password
46
+ ```
47
+
48
+ **Linux/macOS:**
49
+ ```bash
50
+ export SQLCIPHER_PASSWORD="your_database_password"
51
+ ```
52
+
53
+ **Permanent setup (recommended):**
54
+ - Add the environment variable to your system settings
55
+ - Or use a `.env` file with a tool like `dotenv` (requires additional setup)
56
+
57
+ ## Usage
58
+
59
+ ### Starting the Server
60
+
61
+ The MCP server communicates via stdio (standard input/output). Start it with:
62
+
63
+ ```bash
64
+ npm start
65
+ ```
66
+
67
+ Or directly:
68
+
69
+ ```bash
70
+ node index.js
71
+ ```
72
+
73
+ ### MCP Client Configuration
74
+
75
+ Configure your MCP client to use this server. Example configuration:
76
+
77
+ ```json
78
+ {
79
+ "mcpServers": {
80
+ "sqlcipher": {
81
+ "command": "node",
82
+ "args": ["C:\\Repos\\MyMCP\\index.js"],
83
+ "env": {
84
+ "SQLCIPHER_PASSWORD": "your_database_password"
85
+ }
86
+ }
87
+ }
88
+ }
89
+ ```
90
+
91
+ ### Available Tools
92
+
93
+ The server provides 18 comprehensive tools organized into 5 categories:
94
+
95
+ #### Schema Exploration Tools
96
+
97
+ ##### `list_tables`
98
+ List all tables in the database with row counts and types.
99
+
100
+ **Parameters:**
101
+ - `database_path` (string, optional): Path to database file
102
+ - `table_names` (array, optional): Filter by specific table names
103
+
104
+ **Example:**
105
+ ```json
106
+ {
107
+ "tool": "list_tables",
108
+ "arguments": {
109
+ "database_path": "C:\\path\\to\\database.db"
110
+ }
111
+ }
112
+ ```
113
+
114
+ ##### `get_table_schema`
115
+ Get detailed schema for one or more tables including columns, types, constraints, foreign keys, and indexes.
116
+
117
+ **Parameters:**
118
+ - `database_path` (string, optional): Path to database file
119
+ - `table_name` (string or array, required): Table name(s)
120
+
121
+ **Example:**
122
+ ```json
123
+ {
124
+ "tool": "get_table_schema",
125
+ "arguments": {
126
+ "table_name": "users"
127
+ }
128
+ }
129
+ ```
130
+
131
+ ##### `list_columns`
132
+ List all columns in a table with their types and constraints.
133
+
134
+ **Parameters:**
135
+ - `database_path` (string, optional): Path to database file
136
+ - `table_name` (string, required): Table name
137
+
138
+ ##### `get_foreign_keys`
139
+ Get foreign key relationships for a table or entire database.
140
+
141
+ **Parameters:**
142
+ - `database_path` (string, optional): Path to database file
143
+ - `table_name` (string, optional): Table name (omit for all relationships)
144
+
145
+ ##### `get_indexes`
146
+ Get index information for a table or entire database.
147
+
148
+ **Parameters:**
149
+ - `database_path` (string, optional): Path to database file
150
+ - `table_name` (string, optional): Table name (omit for all indexes)
151
+
152
+ #### Database Metadata Tools
153
+
154
+ ##### `get_database_info`
155
+ Get database metadata including SQLite version, size, page size, and encoding.
156
+
157
+ **Parameters:**
158
+ - `database_path` (string, optional): Path to database file
159
+
160
+ ##### `get_table_info`
161
+ Get detailed information about a specific table including row count and column count.
162
+
163
+ **Parameters:**
164
+ - `database_path` (string, optional): Path to database file
165
+ - `table_name` (string, required): Table name
166
+
167
+ ##### `test_connection`
168
+ Test database connection without executing queries.
169
+
170
+ **Parameters:**
171
+ - `database_path` (string, optional): Path to database file
172
+
173
+ #### Query Helper Tools
174
+
175
+ ##### `execute_query`
176
+ Execute a SELECT query on the database.
177
+
178
+ **Parameters:**
179
+ - `database_path` (string, optional): Path to database file
180
+ - `query` (string, required): SQL SELECT query
181
+
182
+ **Example:**
183
+ ```json
184
+ {
185
+ "tool": "execute_query",
186
+ "arguments": {
187
+ "query": "SELECT * FROM users LIMIT 10"
188
+ }
189
+ }
190
+ ```
191
+
192
+ ##### `explain_query`
193
+ Get query execution plan for optimization analysis.
194
+
195
+ **Parameters:**
196
+ - `database_path` (string, optional): Path to database file
197
+ - `query` (string, required): SQL query to explain
198
+
199
+ ##### `validate_query_syntax`
200
+ Validate SQL query syntax without executing it.
201
+
202
+ **Parameters:**
203
+ - `database_path` (string, optional): Path to database file
204
+ - `query` (string, required): SQL query to validate
205
+
206
+ ##### `suggest_query`
207
+ Generate SQL query templates based on table schema and intent.
208
+
209
+ **Parameters:**
210
+ - `database_path` (string, optional): Path to database file
211
+ - `table_name` (string, optional): Table name
212
+ - `intent` (string, optional): Query intent ("count", "sample", "join", "aggregate", "search")
213
+
214
+ #### Data Analysis Tools
215
+
216
+ ##### `get_table_statistics`
217
+ Get comprehensive statistics for a table including min, max, avg, and distinct counts.
218
+
219
+ **Parameters:**
220
+ - `database_path` (string, optional): Path to database file
221
+ - `table_name` (string, required): Table name
222
+ - `max_sample_size` (number, optional): Maximum rows to sample (default: 10000)
223
+ - `timeout_ms` (number, optional): Timeout in milliseconds (default: 30000)
224
+
225
+ ##### `sample_table_data`
226
+ Get a sample of rows from a table for quick preview.
227
+
228
+ **Parameters:**
229
+ - `database_path` (string, optional): Path to database file
230
+ - `table_name` (string, required): Table name
231
+ - `limit` (number, optional): Number of rows (default: 10)
232
+ - `offset` (number, optional): Row offset (default: 0)
233
+ - `columns` (array, optional): Specific columns to include
234
+
235
+ ##### `get_column_statistics`
236
+ Get detailed statistics for specific columns.
237
+
238
+ **Parameters:**
239
+ - `database_path` (string, optional): Path to database file
240
+ - `table_name` (string, required): Table name
241
+ - `column_name` (string or array, required): Column name(s)
242
+ - `max_sample_size` (number, optional): Maximum sample size (default: 10000)
243
+
244
+ #### Search and Discovery Tools
245
+
246
+ ##### `search_tables`
247
+ Search for tables by name pattern using SQL LIKE syntax.
248
+
249
+ **Parameters:**
250
+ - `database_path` (string, optional): Path to database file
251
+ - `pattern` (string, required): SQL LIKE pattern (e.g., "user%")
252
+
253
+ ##### `search_columns`
254
+ Search for columns across all tables by name pattern.
255
+
256
+ **Parameters:**
257
+ - `database_path` (string, optional): Path to database file
258
+ - `pattern` (string, required): SQL LIKE pattern (e.g., "%_id")
259
+
260
+ ##### `find_related_tables`
261
+ Find tables related via foreign keys (incoming and outgoing).
262
+
263
+ **Parameters:**
264
+ - `database_path` (string, optional): Path to database file
265
+ - `table_name` (string, required): Table name
266
+
267
+ ### Available Prompts
268
+
269
+ The server provides 7 interactive prompts for common workflows:
270
+
271
+ #### `explore_database_schema`
272
+ Comprehensive database schema exploration showing all tables and their structures.
273
+
274
+ **Arguments:**
275
+ - `database_path` (optional): Path to database file
276
+
277
+ #### `describe_table_structure`
278
+ Detailed table description including schema, relationships, and sample data.
279
+
280
+ **Arguments:**
281
+ - `database_path` (optional): Path to database file
282
+ - `table_name` (required): Table name
283
+
284
+ #### `find_data_relationships`
285
+ Discover and visualize foreign key relationships between tables.
286
+
287
+ **Arguments:**
288
+ - `database_path` (optional): Path to database file
289
+ - `table_name` (optional): Focus on specific table
290
+
291
+ #### `generate_query_template`
292
+ Generate SQL query templates based on table schema and intent.
293
+
294
+ **Arguments:**
295
+ - `database_path` (optional): Path to database file
296
+ - `table_name` (required): Table name
297
+ - `intent` (optional): Query intent
298
+
299
+ #### `optimize_query`
300
+ Analyze query execution plan and provide optimization suggestions.
301
+
302
+ **Arguments:**
303
+ - `database_path` (optional): Path to database file
304
+ - `query` (required): SQL query to optimize
305
+
306
+ #### `analyze_table_data`
307
+ Comprehensive data analysis including statistics and quality checks.
308
+
309
+ **Arguments:**
310
+ - `database_path` (optional): Path to database file
311
+ - `table_name` (required): Table name
312
+
313
+ #### `compare_tables`
314
+ Compare structure and statistics of two tables.
315
+
316
+ **Arguments:**
317
+ - `database_path` (optional): Path to database file
318
+ - `table1_name` (required): First table name
319
+ - `table2_name` (required): Second table name
320
+
321
+ ## Features
322
+
323
+ ### Database Support
324
+ - **Encrypted Databases**: Full support for SQLCipher-encrypted databases (SQLCipher 3)
325
+ - **Unencrypted Databases**: Also supports plain SQLite databases
326
+ - **Automatic Detection**: Gracefully handles both encrypted and unencrypted databases
327
+
328
+ ### Output Formats
329
+ - **Dual Format**: All tools return both structured JSON and human-readable formatted text
330
+ - **Programmatic Access**: JSON format for integration with other tools
331
+ - **Human-Friendly**: Formatted text for easy reading and display
332
+
333
+ ### Performance
334
+ - **Configurable Limits**: Set maximum sample sizes and timeouts for large tables
335
+ - **Efficient Queries**: Optimized database operations for fast response times
336
+ - **Batch Operations**: Support for batch operations on multiple tables/columns
337
+
338
+ ## Security Features
339
+
340
+ - **Read-Only Mode**: Only SELECT queries and read-only PRAGMA statements are allowed
341
+ - **Password Protection**: Database password is read from environment variable and never exposed
342
+ - **Query Validation**: All queries are validated to prevent SQL injection
343
+ - **Strict Error Handling**: Clear error messages without exposing sensitive information
344
+ - **Input Sanitization**: Table and column names are validated to prevent injection attacks
345
+
346
+ ## Error Handling
347
+
348
+ The server handles various error scenarios:
349
+
350
+ - **Database file not found**: Returns clear error message
351
+ - **Invalid password**: Returns generic error (doesn't expose password details)
352
+ - **SQL syntax errors**: Returns specific syntax error messages
353
+ - **Table/column not found**: Returns specific error messages
354
+ - **Non-SELECT queries**: Returns error explaining read-only restriction
355
+
356
+ ## Database Location
357
+
358
+ The database file path should be provided each time you execute a query. Common locations for Windows applications:
359
+
360
+ - `C:\Users\<Username>\AppData\Local\<AppName>\database.db`
361
+ - `C:\Users\<Username>\AppData\Roaming\<AppName>\database.db`
362
+ - `C:\ProgramData\<AppName>\database.db`
363
+
364
+ ## Limitations
365
+
366
+ - **Read-Only**: Only SELECT queries and read-only PRAGMA statements are supported
367
+ - **Single Connection**: Each tool call opens and closes a new database connection
368
+ - **Display Limits**: Results are limited to 1000 rows for display (full results available in JSON)
369
+ - **SQLCipher 3**: Encrypted databases must use SQLCipher 3 default encryption settings
370
+ - **No Caching**: All queries fetch fresh data from the database (no caching)
371
+
372
+ ## Troubleshooting
373
+
374
+ ### "Database password not found" Error
375
+ - Ensure `SQLCIPHER_PASSWORD` environment variable is set
376
+ - Restart your MCP client after setting the environment variable
377
+ - Check that the environment variable is available to the Node.js process
378
+
379
+ ### "Database file not found" Error
380
+ - Verify the database path is correct
381
+ - Use absolute paths instead of relative paths
382
+ - Check file permissions
383
+
384
+ ### "Invalid password" Error
385
+ - Verify the password matches the one used to encrypt the database
386
+ - Ensure SQLCipher 3 defaults are used (as this server expects)
387
+ - Check for extra spaces or special characters in the password
388
+
389
+ ### Connection Issues
390
+ - Ensure the database file is not locked by another application
391
+ - Verify the database file is a valid SQLCipher database
392
+ - Check that SQLCipher 3 encryption was used (not SQLCipher 4)
393
+
394
+ ## Development
395
+
396
+ ### Project Structure
397
+
398
+ ```
399
+ SQLLiteMCP/
400
+ ├── index.js # Main MCP server entry point
401
+ ├── server-http.js # HTTP test server entry point
402
+ ├── lib/
403
+ │ └── database.js # Low-level database operations
404
+ ├── src/
405
+ │ ├── config/
406
+ │ │ ├── constants.js # Tool and prompt definitions
407
+ │ │ └── environment.js # Environment variable management
408
+ │ ├── handlers/
409
+ │ │ ├── mcp-handlers.js # MCP tool handlers
410
+ │ │ ├── prompt-handlers.js # MCP prompt handlers
411
+ │ │ └── http-handlers.js # HTTP API handlers
412
+ │ ├── services/
413
+ │ │ └── database-service.js # Business logic layer
414
+ │ ├── utils/
415
+ │ │ ├── validators.js # Input validation
416
+ │ │ ├── formatters.js # Output formatting
417
+ │ │ ├── detectors.js # Database type detection
418
+ │ │ └── errors.js # Error handling
419
+ │ └── server/
420
+ │ ├── mcp-server.js # MCP server setup
421
+ │ └── http-server.js # HTTP server setup
422
+ ├── package.json # Project dependencies
423
+ └── README.md # This file
424
+ ```
425
+
426
+ ### Dependencies
427
+
428
+ - `@modelcontextprotocol/sdk`: MCP SDK for Node.js
429
+ - `@journeyapps/sqlcipher`: SQLCipher bindings for Node.js
430
+
431
+ ## License
432
+
433
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sqlcipher-mcp-server",
3
- "version": "1.0.4",
3
+ "version": "2.0.0",
4
4
  "description": "MCP Server for querying SQLCipher-encrypted SQLite databases",
5
5
  "keywords": [
6
6
  "mcp",