sqlcipher-mcp-server 1.0.0 → 1.0.3
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 +210 -282
- package/index.js +14 -226
- package/package.json +29 -27
- package/server-http.js +14 -0
- package/src/config/constants.js +40 -0
- package/src/config/environment.js +63 -0
- package/src/handlers/http-handlers.js +89 -0
- package/src/handlers/mcp-handlers.js +69 -0
- package/src/server/http-server.js +54 -0
- package/src/server/mcp-server.js +76 -0
- package/src/services/database-service.js +55 -0
- package/src/utils/errors.js +69 -0
- package/src/utils/formatters.js +64 -0
- package/src/utils/validators.js +58 -0
package/README.md
CHANGED
|
@@ -1,282 +1,210 @@
|
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
```bash
|
|
61
|
-
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
###
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
{
|
|
128
|
-
"
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
**
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
-
|
|
172
|
-
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
##
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
- **Password Protection**: Database password is read from environment variable and never exposed in logs or error messages.
|
|
212
|
-
- **Query Validation**: All queries are validated to ensure they are SELECT queries only.
|
|
213
|
-
- **Error Handling**: Sensitive information is not exposed in error messages.
|
|
214
|
-
|
|
215
|
-
## Error Handling
|
|
216
|
-
|
|
217
|
-
The server handles various error scenarios:
|
|
218
|
-
|
|
219
|
-
- **Database file not found**: Returns clear error message
|
|
220
|
-
- **Invalid password**: Returns generic error (doesn't expose password details)
|
|
221
|
-
- **SQL syntax errors**: Returns specific syntax error messages
|
|
222
|
-
- **Table/column not found**: Returns specific error messages
|
|
223
|
-
- **Non-SELECT queries**: Returns error explaining read-only restriction
|
|
224
|
-
|
|
225
|
-
## Database Location
|
|
226
|
-
|
|
227
|
-
The database file path should be provided each time you execute a query. Common locations for Windows applications:
|
|
228
|
-
|
|
229
|
-
- `C:\Users\<Username>\AppData\Local\<AppName>\database.db`
|
|
230
|
-
- `C:\Users\<Username>\AppData\Roaming\<AppName>\database.db`
|
|
231
|
-
- `C:\ProgramData\<AppName>\database.db`
|
|
232
|
-
|
|
233
|
-
## Limitations
|
|
234
|
-
|
|
235
|
-
- **Read-Only**: Only SELECT queries are supported
|
|
236
|
-
- **Single Connection**: Each query opens and closes a new database connection
|
|
237
|
-
- **Result Size**: Results are limited to 1000 rows for display (full results available in JSON)
|
|
238
|
-
- **SQLCipher 3 Only**: Uses SQLCipher 3 default encryption settings
|
|
239
|
-
|
|
240
|
-
## Troubleshooting
|
|
241
|
-
|
|
242
|
-
### "Database password not found" Error
|
|
243
|
-
- Ensure `SQLCIPHER_PASSWORD` environment variable is set
|
|
244
|
-
- Restart your MCP client after setting the environment variable
|
|
245
|
-
- Check that the environment variable is available to the Node.js process
|
|
246
|
-
|
|
247
|
-
### "Database file not found" Error
|
|
248
|
-
- Verify the database path is correct
|
|
249
|
-
- Use absolute paths instead of relative paths
|
|
250
|
-
- Check file permissions
|
|
251
|
-
|
|
252
|
-
### "Invalid password" Error
|
|
253
|
-
- Verify the password matches the one used to encrypt the database
|
|
254
|
-
- Ensure SQLCipher 3 defaults are used (as this server expects)
|
|
255
|
-
- Check for extra spaces or special characters in the password
|
|
256
|
-
|
|
257
|
-
### Connection Issues
|
|
258
|
-
- Ensure the database file is not locked by another application
|
|
259
|
-
- Verify the database file is a valid SQLCipher database
|
|
260
|
-
- Check that SQLCipher 3 encryption was used (not SQLCipher 4)
|
|
261
|
-
|
|
262
|
-
## Development
|
|
263
|
-
|
|
264
|
-
### Project Structure
|
|
265
|
-
|
|
266
|
-
```
|
|
267
|
-
MyMCP/
|
|
268
|
-
├── index.js # Main MCP server entry point
|
|
269
|
-
├── lib/
|
|
270
|
-
│ └── database.js # Database connection and query logic
|
|
271
|
-
├── package.json # Project dependencies
|
|
272
|
-
└── README.md # This file
|
|
273
|
-
```
|
|
274
|
-
|
|
275
|
-
### Dependencies
|
|
276
|
-
|
|
277
|
-
- `@modelcontextprotocol/sdk`: MCP SDK for Node.js
|
|
278
|
-
- `@journeyapps/sqlcipher`: SQLCipher bindings for Node.js
|
|
279
|
-
|
|
280
|
-
## License
|
|
281
|
-
|
|
282
|
-
MIT
|
|
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
|