s3db.js 8.0.0 โ 8.0.2
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/PLUGINS.md +114 -39
- package/README.md +227 -0
- package/dist/s3db.cjs.js +77 -31
- package/dist/s3db.cjs.min.js +1 -1
- package/dist/s3db.d.ts +5 -0
- package/dist/s3db.es.js +77 -31
- package/dist/s3db.es.min.js +1 -1
- package/dist/s3db.iife.js +77 -31
- package/dist/s3db.iife.min.js +1 -1
- package/mcp/server.js +0 -0
- package/package.json +25 -25
- package/src/client.class.js +5 -4
- package/src/plugins/cache/memory-cache.class.js +2 -2
- package/src/plugins/cache.plugin.js +75 -21
- package/src/s3db.d.ts +5 -0
- package/mcp/README.md +0 -1062
package/mcp/README.md
DELETED
|
@@ -1,1062 +0,0 @@
|
|
|
1
|
-
# ๐๏ธ S3DB MCP Server
|
|
2
|
-
|
|
3
|
-
<p align="center">
|
|
4
|
-
<img width="200" src="https://img.icons8.com/fluency/200/database.png" alt="S3DB MCP Server">
|
|
5
|
-
</p>
|
|
6
|
-
|
|
7
|
-
<p align="center">
|
|
8
|
-
<strong>Model Context Protocol (MCP) server for S3DB</strong><br>
|
|
9
|
-
<em>Transform AWS S3 into a powerful document database accessible by AI agents</em>
|
|
10
|
-
</p>
|
|
11
|
-
|
|
12
|
-
<p align="center">
|
|
13
|
-
<a href="https://www.npmjs.com/package/s3db-mcp-server"><img src="https://img.shields.io/npm/v/s3db-mcp-server.svg?style=flat&color=brightgreen" alt="npm version"></a>
|
|
14
|
-
|
|
15
|
-
<a href="https://github.com/forattini-dev/s3db.js"><img src="https://img.shields.io/github/stars/forattini-dev/s3db.js?style=flat&color=yellow" alt="GitHub stars"></a>
|
|
16
|
-
|
|
17
|
-
<a href="https://github.com/forattini-dev/s3db.js/blob/main/UNLICENSE"><img src="https://img.shields.io/badge/license-Unlicense-blue.svg?style=flat" alt="License"></a>
|
|
18
|
-
</p>
|
|
19
|
-
|
|
20
|
-
---
|
|
21
|
-
|
|
22
|
-
## ๐ Quick Start (5 minutes)
|
|
23
|
-
|
|
24
|
-
### 1. Instant Start with NPX
|
|
25
|
-
```bash
|
|
26
|
-
# Start immediately (no installation required)
|
|
27
|
-
npx s3db-mcp-server --transport=sse
|
|
28
|
-
|
|
29
|
-
# Server running at: http://localhost:8000/sse
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
### 2. Configure Your AI Client
|
|
33
|
-
|
|
34
|
-
**Claude Desktop** (`claude_desktop_config.json`):
|
|
35
|
-
```json
|
|
36
|
-
{
|
|
37
|
-
"mcpServers": {
|
|
38
|
-
"s3db": {
|
|
39
|
-
"transport": "sse",
|
|
40
|
-
"url": "http://localhost:8000/sse"
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
**Cursor IDE**:
|
|
47
|
-
```json
|
|
48
|
-
{
|
|
49
|
-
"mcpServers": {
|
|
50
|
-
"s3db": {
|
|
51
|
-
"url": "http://localhost:8000/sse"
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
### 3. Test with Your AI Agent
|
|
58
|
-
Your agent can now use these commands:
|
|
59
|
-
```javascript
|
|
60
|
-
// Connect to S3DB
|
|
61
|
-
dbConnect({
|
|
62
|
-
connectionString: "s3://ACCESS_KEY:SECRET_KEY@BUCKET/databases/myapp"
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
// Create a collection
|
|
66
|
-
dbCreateResource({
|
|
67
|
-
name: "users",
|
|
68
|
-
attributes: { name: "string|required", email: "email|unique" }
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
// Insert data
|
|
72
|
-
resourceInsert({
|
|
73
|
-
resourceName: "users",
|
|
74
|
-
data: { name: "John", email: "john@example.com" }
|
|
75
|
-
})
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
---
|
|
79
|
-
|
|
80
|
-
## ๐ Table of Contents
|
|
81
|
-
|
|
82
|
-
- [๐ Quick Start](#-quick-start-5-minutes)
|
|
83
|
-
- [๐พ Installation](#-installation)
|
|
84
|
-
- [โ๏ธ Configuration](#๏ธ-configuration)
|
|
85
|
-
- [๐ ๏ธ Available Tools](#๏ธ-available-tools)
|
|
86
|
-
- [๐ Usage Examples](#-usage-examples)
|
|
87
|
-
- [๐๏ธ Partitions & Performance](#๏ธ-partitions--performance)
|
|
88
|
-
- [๐ณ Docker Deployment](#-docker-deployment)
|
|
89
|
-
- [๐ค AI Agent Integration](#-ai-agent-integration)
|
|
90
|
-
- [๐ Security](#-security)
|
|
91
|
-
- [๐จ Troubleshooting](#-troubleshooting)
|
|
92
|
-
|
|
93
|
-
---
|
|
94
|
-
|
|
95
|
-
## ๐พ Installation
|
|
96
|
-
|
|
97
|
-
### Option 1: NPX (Recommended)
|
|
98
|
-
```bash
|
|
99
|
-
# SSE transport (web clients)
|
|
100
|
-
npx s3db-mcp-server --transport=sse
|
|
101
|
-
|
|
102
|
-
# STDIO transport (desktop clients)
|
|
103
|
-
npx s3db-mcp-server --transport=stdio
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
### Option 2: Global Installation
|
|
107
|
-
```bash
|
|
108
|
-
npm install -g s3db-mcp-server
|
|
109
|
-
s3db-mcp --transport=sse
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
### Option 3: Docker
|
|
113
|
-
```bash
|
|
114
|
-
docker run -p 8000:8000 -e S3DB_CONNECTION_STRING="s3://key:secret@bucket/db" s3db-mcp-server
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
---
|
|
118
|
-
|
|
119
|
-
## โ๏ธ Configuration
|
|
120
|
-
|
|
121
|
-
### Environment Variables
|
|
122
|
-
|
|
123
|
-
Create a `.env` file or set these environment variables:
|
|
124
|
-
|
|
125
|
-
#### **Server Configuration**
|
|
126
|
-
| Variable | Default | Description |
|
|
127
|
-
|----------|---------|-------------|
|
|
128
|
-
| `NODE_ENV` | `development` | Environment mode |
|
|
129
|
-
| `MCP_SERVER_HOST` | `0.0.0.0` | Server bind address |
|
|
130
|
-
| `MCP_SERVER_PORT` | `8000` | Server port |
|
|
131
|
-
| `MCP_TRANSPORT` | `sse` | Transport method (`sse` or `stdio`) |
|
|
132
|
-
|
|
133
|
-
#### **S3DB Configuration**
|
|
134
|
-
| Variable | Default | Description |
|
|
135
|
-
|----------|---------|-------------|
|
|
136
|
-
| `S3DB_CONNECTION_STRING` | **Required** | S3DB connection string |
|
|
137
|
-
| `S3DB_VERBOSE` | `false` | Enable verbose logging |
|
|
138
|
-
| `S3DB_PARALLELISM` | `10` | Number of parallel S3 operations |
|
|
139
|
-
| `S3DB_PASSPHRASE` | `secret` | Encryption passphrase |
|
|
140
|
-
| `S3DB_VERSIONING_ENABLED` | `false` | Enable resource versioning |
|
|
141
|
-
|
|
142
|
-
#### **Plugin Configuration**
|
|
143
|
-
| Variable | Default | Description |
|
|
144
|
-
|----------|---------|-------------|
|
|
145
|
-
| `S3DB_COSTS_ENABLED` | `true` | Enable automatic S3 costs tracking |
|
|
146
|
-
| `S3DB_CACHE_ENABLED` | `true` | Enable cache for performance |
|
|
147
|
-
| `S3DB_CACHE_DRIVER` | `memory` | Cache driver: `memory` or `filesystem` |
|
|
148
|
-
| `S3DB_CACHE_MAX_SIZE` | `1000` | Maximum items in memory cache (memory driver only) |
|
|
149
|
-
| `S3DB_CACHE_TTL` | `300000` | Cache TTL in milliseconds (5 minutes) |
|
|
150
|
-
| `S3DB_CACHE_DIRECTORY` | `./cache` | Directory for filesystem cache (filesystem driver only) |
|
|
151
|
-
| `S3DB_CACHE_PREFIX` | `s3db` | Prefix for cache files (filesystem driver only) |
|
|
152
|
-
|
|
153
|
-
#### **AWS Configuration**
|
|
154
|
-
| Variable | Default | Description |
|
|
155
|
-
|----------|---------|-------------|
|
|
156
|
-
| `AWS_ACCESS_KEY_ID` | - | AWS access key (optional with IAM roles) |
|
|
157
|
-
| `AWS_SECRET_ACCESS_KEY` | - | AWS secret key (optional with IAM roles) |
|
|
158
|
-
| `AWS_SESSION_TOKEN` | - | AWS session token (for temporary credentials) |
|
|
159
|
-
| `AWS_REGION` | `us-east-1` | AWS region |
|
|
160
|
-
|
|
161
|
-
#### **S3-Compatible Services**
|
|
162
|
-
| Variable | Default | Description |
|
|
163
|
-
|----------|---------|-------------|
|
|
164
|
-
| `S3_ENDPOINT` | - | Custom S3 endpoint (MinIO, DigitalOcean, etc.) |
|
|
165
|
-
| `S3_FORCE_PATH_STYLE` | `false` | Use path-style URLs |
|
|
166
|
-
|
|
167
|
-
### Connection String Examples
|
|
168
|
-
|
|
169
|
-
```bash
|
|
170
|
-
# AWS S3 with credentials
|
|
171
|
-
S3DB_CONNECTION_STRING="s3://ACCESS_KEY:SECRET_KEY@bucket-name/databases/myapp"
|
|
172
|
-
|
|
173
|
-
# AWS S3 with IAM roles (no credentials needed)
|
|
174
|
-
S3DB_CONNECTION_STRING="s3://bucket-name/databases/myapp"
|
|
175
|
-
|
|
176
|
-
# MinIO (local development)
|
|
177
|
-
S3DB_CONNECTION_STRING="s3://minioadmin:minioadmin@test-bucket/databases/dev?endpoint=http://localhost:9000&forcePathStyle=true"
|
|
178
|
-
|
|
179
|
-
# DigitalOcean Spaces
|
|
180
|
-
S3DB_CONNECTION_STRING="s3://DO_KEY:DO_SECRET@space-name/databases/prod?endpoint=https://nyc3.digitaloceanspaces.com"
|
|
181
|
-
|
|
182
|
-
# LocalStack (AWS simulation)
|
|
183
|
-
S3DB_CONNECTION_STRING="s3://test:test@test-bucket/databases/local?endpoint=http://localhost:4566&forcePathStyle=true"
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
### Command Line Options
|
|
187
|
-
|
|
188
|
-
```bash
|
|
189
|
-
# Transport options
|
|
190
|
-
s3db-mcp --transport=sse # HTTP-based transport
|
|
191
|
-
s3db-mcp --transport=stdio # Pipe-based transport
|
|
192
|
-
|
|
193
|
-
# Network options
|
|
194
|
-
s3db-mcp --host=0.0.0.0 --port=8000
|
|
195
|
-
|
|
196
|
-
# Example with environment
|
|
197
|
-
S3DB_CONNECTION_STRING="s3://..." s3db-mcp --transport=sse
|
|
198
|
-
```
|
|
199
|
-
|
|
200
|
-
---
|
|
201
|
-
|
|
202
|
-
## ๐ ๏ธ Available Tools
|
|
203
|
-
|
|
204
|
-
### Database Management
|
|
205
|
-
|
|
206
|
-
| Tool | Description | Parameters |
|
|
207
|
-
|------|-------------|------------|
|
|
208
|
-
| `dbConnect` | Connect to S3DB database with costs & cache | `connectionString`, `verbose?`, `parallelism?`, `passphrase?`, `versioningEnabled?`, `enableCache?`, `enableCosts?`, `cacheDriver?`, `cacheMaxSize?`, `cacheTtl?`, `cacheDirectory?`, `cachePrefix?` |
|
|
209
|
-
| `dbDisconnect` | Disconnect from database | - |
|
|
210
|
-
| `dbStatus` | Get connection status | - |
|
|
211
|
-
| `dbCreateResource` | Create resource/collection | `name`, `attributes`, `behavior?`, `timestamps?`, `partitions?`, `paranoid?` |
|
|
212
|
-
| `dbListResources` | List all resources | - |
|
|
213
|
-
| `dbGetStats` | Get database statistics (costs, cache, resources) | - |
|
|
214
|
-
| `dbClearCache` | Clear cache data | `resourceName?` (optional - clears all if not provided) |
|
|
215
|
-
|
|
216
|
-
### Document Operations
|
|
217
|
-
|
|
218
|
-
| Tool | Description | Parameters |
|
|
219
|
-
|------|-------------|------------|
|
|
220
|
-
| `resourceInsert` | Insert single document | `resourceName`, `data` |
|
|
221
|
-
| `resourceInsertMany` | Insert multiple documents | `resourceName`, `data[]` |
|
|
222
|
-
| `resourceGet` | Get document by ID | `resourceName`, `id` |
|
|
223
|
-
| `resourceGetMany` | Get multiple documents | `resourceName`, `ids[]` |
|
|
224
|
-
| `resourceUpdate` | Update document | `resourceName`, `id`, `data` |
|
|
225
|
-
| `resourceUpsert` | Insert or update | `resourceName`, `data` |
|
|
226
|
-
| `resourceDelete` | Delete document | `resourceName`, `id` |
|
|
227
|
-
| `resourceDeleteMany` | Delete multiple documents | `resourceName`, `ids[]` |
|
|
228
|
-
|
|
229
|
-
### Query Operations
|
|
230
|
-
|
|
231
|
-
| Tool | Description | Parameters |
|
|
232
|
-
|------|-------------|------------|
|
|
233
|
-
| `resourceExists` | Check if document exists | `resourceName`, `id` |
|
|
234
|
-
| `resourceList` | List with pagination | `resourceName`, `limit?`, `offset?`, `partition?`, `partitionValues?` |
|
|
235
|
-
| `resourceListIds` | List document IDs only | `resourceName`, `limit?`, `offset?` |
|
|
236
|
-
| `resourceCount` | Count documents | `resourceName`, `partition?`, `partitionValues?` |
|
|
237
|
-
| `resourceGetAll` | Get all documents | `resourceName` |
|
|
238
|
-
| `resourceDeleteAll` | Delete all documents | `resourceName`, `confirm: true` |
|
|
239
|
-
|
|
240
|
-
---
|
|
241
|
-
|
|
242
|
-
## ๐ Usage Examples
|
|
243
|
-
|
|
244
|
-
### Basic CRUD Operations
|
|
245
|
-
|
|
246
|
-
```javascript
|
|
247
|
-
// 1. Connect to database with automatic cache and costs tracking
|
|
248
|
-
await agent.callTool('dbConnect', {
|
|
249
|
-
connectionString: 's3://ACCESS_KEY:SECRET_KEY@bucket/databases/blog',
|
|
250
|
-
verbose: false,
|
|
251
|
-
parallelism: 10,
|
|
252
|
-
enableCache: true, // Cache enabled by default
|
|
253
|
-
enableCosts: true, // Costs tracking enabled by default
|
|
254
|
-
cacheDriver: 'memory', // 'memory' or 'filesystem'
|
|
255
|
-
cacheMaxSize: 1000, // Cache up to 1000 items (memory only)
|
|
256
|
-
cacheTtl: 300000, // 5 minute cache TTL
|
|
257
|
-
cacheDirectory: './cache', // Directory for filesystem cache
|
|
258
|
-
cachePrefix: 's3db' // Prefix for cache files
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
// 2. Create a resource with schema validation
|
|
262
|
-
await agent.callTool('dbCreateResource', {
|
|
263
|
-
name: 'posts',
|
|
264
|
-
attributes: {
|
|
265
|
-
title: 'string|required|min:3|max:200',
|
|
266
|
-
content: 'string|required',
|
|
267
|
-
author: 'string|required',
|
|
268
|
-
tags: 'array|items:string',
|
|
269
|
-
published: 'boolean',
|
|
270
|
-
publishDate: 'date',
|
|
271
|
-
metadata: {
|
|
272
|
-
views: 'number|positive',
|
|
273
|
-
likes: 'number|positive'
|
|
274
|
-
}
|
|
275
|
-
},
|
|
276
|
-
behavior: 'user-managed',
|
|
277
|
-
timestamps: true, // Adds createdAt/updatedAt automatically
|
|
278
|
-
paranoid: true // Soft deletes
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
// 3. Insert a blog post
|
|
282
|
-
const post = await agent.callTool('resourceInsert', {
|
|
283
|
-
resourceName: 'posts',
|
|
284
|
-
data: {
|
|
285
|
-
title: 'Getting Started with S3DB MCP',
|
|
286
|
-
content: 'S3DB transforms AWS S3 into a powerful document database...',
|
|
287
|
-
author: 'john-doe',
|
|
288
|
-
tags: ['tutorial', 's3db', 'mcp', 'ai'],
|
|
289
|
-
published: true,
|
|
290
|
-
publishDate: '2024-01-15',
|
|
291
|
-
metadata: {
|
|
292
|
-
views: 0,
|
|
293
|
-
likes: 0
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
// 4. Update the post
|
|
299
|
-
await agent.callTool('resourceUpdate', {
|
|
300
|
-
resourceName: 'posts',
|
|
301
|
-
id: post.data.id,
|
|
302
|
-
data: {
|
|
303
|
-
metadata: {
|
|
304
|
-
views: 150,
|
|
305
|
-
likes: 12
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
// 5. Query posts with pagination
|
|
311
|
-
const posts = await agent.callTool('resourceList', {
|
|
312
|
-
resourceName: 'posts',
|
|
313
|
-
limit: 10,
|
|
314
|
-
offset: 0
|
|
315
|
-
});
|
|
316
|
-
|
|
317
|
-
// 6. Check if post exists
|
|
318
|
-
const exists = await agent.callTool('resourceExists', {
|
|
319
|
-
resourceName: 'posts',
|
|
320
|
-
id: post.data.id
|
|
321
|
-
});
|
|
322
|
-
|
|
323
|
-
// 7. Check performance statistics
|
|
324
|
-
const stats = await agent.callTool('dbGetStats');
|
|
325
|
-
console.log('Cache hits:', stats.stats.cache.size);
|
|
326
|
-
console.log('S3 costs:', stats.stats.costs.estimatedCostUSD);
|
|
327
|
-
console.log('Total requests:', stats.stats.costs.totalRequests);
|
|
328
|
-
|
|
329
|
-
// 8. Clear cache if needed
|
|
330
|
-
await agent.callTool('dbClearCache', {
|
|
331
|
-
resourceName: 'posts' // Clear cache for specific resource
|
|
332
|
-
});
|
|
333
|
-
```
|
|
334
|
-
|
|
335
|
-
### Performance & Costs Monitoring
|
|
336
|
-
|
|
337
|
-
```javascript
|
|
338
|
-
// Monitor database performance and costs
|
|
339
|
-
const stats = await agent.callTool('dbGetStats');
|
|
340
|
-
|
|
341
|
-
console.log('Database Stats:', {
|
|
342
|
-
resources: stats.stats.database.resources,
|
|
343
|
-
totalCosts: `$${stats.stats.costs.estimatedCostUSD.toFixed(6)}`,
|
|
344
|
-
cacheHitRate: `${stats.stats.cache.keyCount}/${stats.stats.cache.maxSize}`,
|
|
345
|
-
s3Operations: stats.stats.costs.requestsByType
|
|
346
|
-
});
|
|
347
|
-
|
|
348
|
-
// Cache performance
|
|
349
|
-
if (stats.stats.cache.enabled) {
|
|
350
|
-
console.log('Cache Performance:', {
|
|
351
|
-
driver: stats.stats.cache.driver,
|
|
352
|
-
itemsCached: stats.stats.cache.size,
|
|
353
|
-
maxCapacity: stats.stats.cache.maxSize,
|
|
354
|
-
ttl: `${stats.stats.cache.ttl / 1000}s`,
|
|
355
|
-
sampleKeys: stats.stats.cache.sampleKeys
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
// S3 costs breakdown
|
|
360
|
-
if (stats.stats.costs) {
|
|
361
|
-
console.log('S3 Costs Breakdown:', {
|
|
362
|
-
totalRequests: stats.stats.costs.totalRequests,
|
|
363
|
-
getRequests: stats.stats.costs.requestsByType.get,
|
|
364
|
-
putRequests: stats.stats.costs.requestsByType.put,
|
|
365
|
-
listRequests: stats.stats.costs.requestsByType.list,
|
|
366
|
-
estimatedCost: `$${stats.stats.costs.estimatedCostUSD.toFixed(6)}`
|
|
367
|
-
});
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
// Clear cache for performance reset
|
|
371
|
-
await agent.callTool('dbClearCache'); // Clear all cache
|
|
372
|
-
// or
|
|
373
|
-
await agent.callTool('dbClearCache', { resourceName: 'posts' }); // Clear specific resource
|
|
374
|
-
```
|
|
375
|
-
|
|
376
|
-
### Batch Operations
|
|
377
|
-
|
|
378
|
-
```javascript
|
|
379
|
-
// Insert multiple documents at once
|
|
380
|
-
await agent.callTool('resourceInsertMany', {
|
|
381
|
-
resourceName: 'posts',
|
|
382
|
-
data: [
|
|
383
|
-
{
|
|
384
|
-
title: 'AI and Databases',
|
|
385
|
-
content: 'Exploring the intersection...',
|
|
386
|
-
author: 'jane-smith',
|
|
387
|
-
published: true
|
|
388
|
-
},
|
|
389
|
-
{
|
|
390
|
-
title: 'S3DB Performance Tips',
|
|
391
|
-
content: 'Best practices for...',
|
|
392
|
-
author: 'bob-wilson',
|
|
393
|
-
published: false
|
|
394
|
-
}
|
|
395
|
-
]
|
|
396
|
-
});
|
|
397
|
-
|
|
398
|
-
// Get multiple documents by ID
|
|
399
|
-
const multiplePosts = await agent.callTool('resourceGetMany', {
|
|
400
|
-
resourceName: 'posts',
|
|
401
|
-
ids: ['post_123', 'post_456', 'post_789']
|
|
402
|
-
});
|
|
403
|
-
|
|
404
|
-
// Delete multiple documents
|
|
405
|
-
await agent.callTool('resourceDeleteMany', {
|
|
406
|
-
resourceName: 'posts',
|
|
407
|
-
ids: ['post_old1', 'post_old2']
|
|
408
|
-
});
|
|
409
|
-
```
|
|
410
|
-
|
|
411
|
-
### E-commerce Example with Complex Schema
|
|
412
|
-
|
|
413
|
-
```javascript
|
|
414
|
-
// Create products resource
|
|
415
|
-
await agent.callTool('dbCreateResource', {
|
|
416
|
-
name: 'products',
|
|
417
|
-
attributes: {
|
|
418
|
-
sku: 'string|required|unique',
|
|
419
|
-
name: 'string|required|min:2|max:200',
|
|
420
|
-
description: 'string|required',
|
|
421
|
-
price: 'number|positive|required',
|
|
422
|
-
category: 'string|required',
|
|
423
|
-
subcategory: 'string|optional',
|
|
424
|
-
inStock: 'boolean',
|
|
425
|
-
inventory: {
|
|
426
|
-
quantity: 'number|integer|min:0',
|
|
427
|
-
reserved: 'number|integer|min:0',
|
|
428
|
-
warehouse: 'string|required'
|
|
429
|
-
},
|
|
430
|
-
specifications: {
|
|
431
|
-
weight: 'number|positive|optional',
|
|
432
|
-
dimensions: {
|
|
433
|
-
length: 'number|positive',
|
|
434
|
-
width: 'number|positive',
|
|
435
|
-
height: 'number|positive'
|
|
436
|
-
},
|
|
437
|
-
color: 'string|optional',
|
|
438
|
-
material: 'string|optional'
|
|
439
|
-
},
|
|
440
|
-
pricing: {
|
|
441
|
-
cost: 'number|positive',
|
|
442
|
-
markup: 'number|positive',
|
|
443
|
-
discountPercent: 'number|min:0|max:100'
|
|
444
|
-
},
|
|
445
|
-
tags: 'array|items:string',
|
|
446
|
-
images: 'array|items:url'
|
|
447
|
-
},
|
|
448
|
-
partitions: {
|
|
449
|
-
byCategory: {
|
|
450
|
-
fields: { category: 'string' },
|
|
451
|
-
description: 'Partition products by main category'
|
|
452
|
-
},
|
|
453
|
-
byCategoryAndSubcategory: {
|
|
454
|
-
fields: {
|
|
455
|
-
category: 'string',
|
|
456
|
-
subcategory: 'string'
|
|
457
|
-
},
|
|
458
|
-
description: 'Fine-grained category partitioning'
|
|
459
|
-
}
|
|
460
|
-
},
|
|
461
|
-
timestamps: true
|
|
462
|
-
});
|
|
463
|
-
|
|
464
|
-
// Insert a complex product
|
|
465
|
-
await agent.callTool('resourceInsert', {
|
|
466
|
-
resourceName: 'products',
|
|
467
|
-
data: {
|
|
468
|
-
sku: 'LAP-GAMING-001',
|
|
469
|
-
name: 'Gaming Laptop Pro 15"',
|
|
470
|
-
description: 'High-performance gaming laptop with RTX graphics',
|
|
471
|
-
price: 1299.99,
|
|
472
|
-
category: 'electronics',
|
|
473
|
-
subcategory: 'laptops',
|
|
474
|
-
inStock: true,
|
|
475
|
-
inventory: {
|
|
476
|
-
quantity: 25,
|
|
477
|
-
reserved: 3,
|
|
478
|
-
warehouse: 'US-WEST-1'
|
|
479
|
-
},
|
|
480
|
-
specifications: {
|
|
481
|
-
weight: 2.3,
|
|
482
|
-
dimensions: {
|
|
483
|
-
length: 35.5,
|
|
484
|
-
width: 25.0,
|
|
485
|
-
height: 2.2
|
|
486
|
-
},
|
|
487
|
-
color: 'black',
|
|
488
|
-
material: 'aluminum'
|
|
489
|
-
},
|
|
490
|
-
pricing: {
|
|
491
|
-
cost: 850.00,
|
|
492
|
-
markup: 0.53,
|
|
493
|
-
discountPercent: 0
|
|
494
|
-
},
|
|
495
|
-
tags: ['gaming', 'laptop', 'rtx', 'high-performance'],
|
|
496
|
-
images: [
|
|
497
|
-
'https://example.com/laptop-1.jpg',
|
|
498
|
-
'https://example.com/laptop-2.jpg'
|
|
499
|
-
]
|
|
500
|
-
}
|
|
501
|
-
});
|
|
502
|
-
```
|
|
503
|
-
|
|
504
|
-
---
|
|
505
|
-
|
|
506
|
-
## ๐๏ธ Partitions & Performance
|
|
507
|
-
|
|
508
|
-
Partitions organize data for better performance and logical separation.
|
|
509
|
-
|
|
510
|
-
### Creating Partitioned Resources
|
|
511
|
-
|
|
512
|
-
```javascript
|
|
513
|
-
await agent.callTool('dbCreateResource', {
|
|
514
|
-
name: 'orders',
|
|
515
|
-
attributes: {
|
|
516
|
-
orderId: 'string|required|unique',
|
|
517
|
-
customerId: 'string|required',
|
|
518
|
-
amount: 'number|positive|required',
|
|
519
|
-
status: 'string|enum:pending,paid,shipped,delivered,cancelled',
|
|
520
|
-
region: 'string|required',
|
|
521
|
-
orderDate: 'date|required',
|
|
522
|
-
items: 'array|items:object'
|
|
523
|
-
},
|
|
524
|
-
partitions: {
|
|
525
|
-
// Single field partitions
|
|
526
|
-
byRegion: {
|
|
527
|
-
fields: { region: 'string' },
|
|
528
|
-
description: 'Geographic distribution'
|
|
529
|
-
},
|
|
530
|
-
byStatus: {
|
|
531
|
-
fields: { status: 'string' },
|
|
532
|
-
description: 'Order status tracking'
|
|
533
|
-
},
|
|
534
|
-
byMonth: {
|
|
535
|
-
fields: { orderDate: 'date|maxlength:7' }, // YYYY-MM format
|
|
536
|
-
description: 'Monthly order archives'
|
|
537
|
-
},
|
|
538
|
-
|
|
539
|
-
// Multi-field partitions
|
|
540
|
-
byRegionAndStatus: {
|
|
541
|
-
fields: {
|
|
542
|
-
region: 'string',
|
|
543
|
-
status: 'string'
|
|
544
|
-
},
|
|
545
|
-
description: 'Regional status tracking'
|
|
546
|
-
},
|
|
547
|
-
byRegionAndMonth: {
|
|
548
|
-
fields: {
|
|
549
|
-
region: 'string',
|
|
550
|
-
orderDate: 'date|maxlength:7'
|
|
551
|
-
},
|
|
552
|
-
description: 'Regional monthly reports'
|
|
553
|
-
}
|
|
554
|
-
},
|
|
555
|
-
timestamps: true
|
|
556
|
-
});
|
|
557
|
-
```
|
|
558
|
-
|
|
559
|
-
### Querying with Partitions
|
|
560
|
-
|
|
561
|
-
```javascript
|
|
562
|
-
// Query specific partition - much faster than full scan
|
|
563
|
-
const northernOrders = await agent.callTool('resourceList', {
|
|
564
|
-
resourceName: 'orders',
|
|
565
|
-
partition: 'byRegion',
|
|
566
|
-
partitionValues: { region: 'north' },
|
|
567
|
-
limit: 100
|
|
568
|
-
});
|
|
569
|
-
|
|
570
|
-
// Multi-field partition query
|
|
571
|
-
const northPendingOrders = await agent.callTool('resourceList', {
|
|
572
|
-
resourceName: 'orders',
|
|
573
|
-
partition: 'byRegionAndStatus',
|
|
574
|
-
partitionValues: {
|
|
575
|
-
region: 'north',
|
|
576
|
-
status: 'pending'
|
|
577
|
-
}
|
|
578
|
-
});
|
|
579
|
-
|
|
580
|
-
// Time-based partition query
|
|
581
|
-
const januaryOrders = await agent.callTool('resourceList', {
|
|
582
|
-
resourceName: 'orders',
|
|
583
|
-
partition: 'byMonth',
|
|
584
|
-
partitionValues: { orderDate: '2024-01' }
|
|
585
|
-
});
|
|
586
|
-
|
|
587
|
-
// Count documents in partition
|
|
588
|
-
const pendingCount = await agent.callTool('resourceCount', {
|
|
589
|
-
resourceName: 'orders',
|
|
590
|
-
partition: 'byStatus',
|
|
591
|
-
partitionValues: { status: 'pending' }
|
|
592
|
-
});
|
|
593
|
-
```
|
|
594
|
-
|
|
595
|
-
### Partition Best Practices
|
|
596
|
-
|
|
597
|
-
**Common Partition Patterns:**
|
|
598
|
-
- **By Date**: `{ orderDate: 'date|maxlength:10' }` (YYYY-MM-DD)
|
|
599
|
-
- **By Month**: `{ orderDate: 'date|maxlength:7' }` (YYYY-MM)
|
|
600
|
-
- **By Category**: `{ category: 'string' }`
|
|
601
|
-
- **By User**: `{ userId: 'string' }`
|
|
602
|
-
- **By Status**: `{ status: 'string' }`
|
|
603
|
-
- **By Geographic Region**: `{ region: 'string', country: 'string' }`
|
|
604
|
-
|
|
605
|
-
**Performance Benefits:**
|
|
606
|
-
- โก **Faster queries** - scans only relevant partition
|
|
607
|
-
- ๐ฐ **Lower S3 costs** - fewer requests and data transfer
|
|
608
|
-
- ๐ **Better analytics** - efficient aggregations
|
|
609
|
-
- ๐ **Easier maintenance** - targeted operations
|
|
610
|
-
|
|
611
|
-
---
|
|
612
|
-
|
|
613
|
-
## ๐ณ Docker Deployment
|
|
614
|
-
|
|
615
|
-
### Quick Start with Docker Compose
|
|
616
|
-
|
|
617
|
-
```bash
|
|
618
|
-
# 1. Create project directory
|
|
619
|
-
mkdir s3db-mcp && cd s3db-mcp
|
|
620
|
-
|
|
621
|
-
# 2. Create docker-compose.yml
|
|
622
|
-
curl -o docker-compose.yml https://raw.githubusercontent.com/forattini-dev/s3db.js/main/mcp-server/docker-compose.yml
|
|
623
|
-
|
|
624
|
-
# 3. Create .env file
|
|
625
|
-
curl -o .env.example https://raw.githubusercontent.com/forattini-dev/s3db.js/main/mcp-server/.env.example
|
|
626
|
-
cp .env.example .env
|
|
627
|
-
|
|
628
|
-
# 4. Edit .env with your configuration
|
|
629
|
-
# 5. Start services
|
|
630
|
-
docker compose up
|
|
631
|
-
```
|
|
632
|
-
|
|
633
|
-
### Production Docker Setup
|
|
634
|
-
|
|
635
|
-
```yaml
|
|
636
|
-
services:
|
|
637
|
-
s3db-mcp-server:
|
|
638
|
-
image: s3db-mcp-server:latest
|
|
639
|
-
restart: unless-stopped
|
|
640
|
-
environment:
|
|
641
|
-
- NODE_ENV=production
|
|
642
|
-
- S3DB_CONNECTION_STRING=s3://bucket/databases/prod
|
|
643
|
-
- MCP_TRANSPORT=sse
|
|
644
|
-
- MCP_SERVER_PORT=8000
|
|
645
|
-
ports:
|
|
646
|
-
- "8000:8000"
|
|
647
|
-
healthcheck:
|
|
648
|
-
test: ["CMD", "curl", "-f", "http://localhost:8001/health"]
|
|
649
|
-
interval: 30s
|
|
650
|
-
timeout: 10s
|
|
651
|
-
retries: 3
|
|
652
|
-
logging:
|
|
653
|
-
driver: "json-file"
|
|
654
|
-
options:
|
|
655
|
-
max-size: "10m"
|
|
656
|
-
max-file: "3"
|
|
657
|
-
```
|
|
658
|
-
|
|
659
|
-
### Local Development with MinIO
|
|
660
|
-
|
|
661
|
-
```bash
|
|
662
|
-
# Start with MinIO for local S3 testing
|
|
663
|
-
docker compose --profile local-testing up
|
|
664
|
-
|
|
665
|
-
# Access:
|
|
666
|
-
# - MCP Server: http://localhost:8000/sse
|
|
667
|
-
# - MinIO Console: http://localhost:9001 (minioadmin/minioadmin)
|
|
668
|
-
# - Health Check: http://localhost:8001/health
|
|
669
|
-
```
|
|
670
|
-
|
|
671
|
-
### Docker Environment Variables
|
|
672
|
-
|
|
673
|
-
All the configuration variables mentioned above can be used in Docker:
|
|
674
|
-
|
|
675
|
-
```bash
|
|
676
|
-
docker run -p 8000:8000 \
|
|
677
|
-
-e S3DB_CONNECTION_STRING="s3://key:secret@bucket/db" \
|
|
678
|
-
-e S3DB_VERBOSE=true \
|
|
679
|
-
-e S3DB_PARALLELISM=20 \
|
|
680
|
-
-e MCP_TRANSPORT=sse \
|
|
681
|
-
s3db-mcp-server
|
|
682
|
-
```
|
|
683
|
-
|
|
684
|
-
---
|
|
685
|
-
|
|
686
|
-
## ๐ค AI Agent Integration
|
|
687
|
-
|
|
688
|
-
### Claude Desktop Integration
|
|
689
|
-
|
|
690
|
-
1. **Locate config file:**
|
|
691
|
-
- macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
692
|
-
- Windows: `%APPDATA%\Claude\claude_desktop_config.json`
|
|
693
|
-
|
|
694
|
-
2. **Add S3DB MCP server:**
|
|
695
|
-
```json
|
|
696
|
-
{
|
|
697
|
-
"mcpServers": {
|
|
698
|
-
"s3db": {
|
|
699
|
-
"transport": "sse",
|
|
700
|
-
"url": "http://localhost:8000/sse"
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
```
|
|
705
|
-
|
|
706
|
-
3. **For STDIO transport:**
|
|
707
|
-
```json
|
|
708
|
-
{
|
|
709
|
-
"mcpServers": {
|
|
710
|
-
"s3db": {
|
|
711
|
-
"transport": "stdio",
|
|
712
|
-
"command": "npx",
|
|
713
|
-
"args": ["s3db-mcp-server", "--transport=stdio"],
|
|
714
|
-
"env": {
|
|
715
|
-
"S3DB_CONNECTION_STRING": "s3://bucket/databases/myapp"
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
```
|
|
721
|
-
|
|
722
|
-
### Cursor IDE Integration
|
|
723
|
-
|
|
724
|
-
Add to your MCP settings:
|
|
725
|
-
```json
|
|
726
|
-
{
|
|
727
|
-
"mcpServers": {
|
|
728
|
-
"s3db": {
|
|
729
|
-
"url": "http://localhost:8000/sse"
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
```
|
|
734
|
-
|
|
735
|
-
### AI Agent Usage Rules
|
|
736
|
-
|
|
737
|
-
**Before any task:**
|
|
738
|
-
1. Always use `dbConnect` first to establish connection (cache and costs tracking are enabled by default)
|
|
739
|
-
2. Use `dbStatus` to verify connection and see resources
|
|
740
|
-
3. Use `dbListResources` to see available collections
|
|
741
|
-
|
|
742
|
-
**For data operations:**
|
|
743
|
-
1. Use `resourceExists` to check if documents exist before operations
|
|
744
|
-
2. Prefer batch operations (`resourceInsertMany`, `resourceGetMany`) for efficiency
|
|
745
|
-
3. Use partitions for performance when querying large datasets
|
|
746
|
-
4. Always use pagination (`resourceList` with `limit`/`offset`) for large results
|
|
747
|
-
|
|
748
|
-
**Schema design:**
|
|
749
|
-
- Define validation rules: `"email": "email|required|unique"`
|
|
750
|
-
- Use nested objects for complex data structures
|
|
751
|
-
- Enable timestamps for audit trails
|
|
752
|
-
- Consider partitioning strategy upfront
|
|
753
|
-
|
|
754
|
-
**Performance monitoring:**
|
|
755
|
-
- Use `dbGetStats` to monitor S3 costs and cache performance
|
|
756
|
-
- Cache is automatically enabled for read operations (get, list, count)
|
|
757
|
-
- Use `dbClearCache` to reset cache when needed
|
|
758
|
-
- Monitor costs to optimize S3 usage patterns
|
|
759
|
-
|
|
760
|
-
**Error handling:**
|
|
761
|
-
- Check connection status before operations
|
|
762
|
-
- Validate data structure matches schema
|
|
763
|
-
- Handle resource not found errors gracefully
|
|
764
|
-
- Use appropriate error messages for users
|
|
765
|
-
|
|
766
|
-
---
|
|
767
|
-
|
|
768
|
-
## ๐ Security
|
|
769
|
-
|
|
770
|
-
### AWS IAM Policy
|
|
771
|
-
|
|
772
|
-
Minimal S3 permissions required:
|
|
773
|
-
|
|
774
|
-
```json
|
|
775
|
-
{
|
|
776
|
-
"Version": "2012-10-17",
|
|
777
|
-
"Statement": [
|
|
778
|
-
{
|
|
779
|
-
"Effect": "Allow",
|
|
780
|
-
"Action": [
|
|
781
|
-
"s3:GetObject",
|
|
782
|
-
"s3:PutObject",
|
|
783
|
-
"s3:DeleteObject",
|
|
784
|
-
"s3:ListBucket",
|
|
785
|
-
"s3:HeadObject"
|
|
786
|
-
],
|
|
787
|
-
"Resource": [
|
|
788
|
-
"arn:aws:s3:::your-s3db-bucket",
|
|
789
|
-
"arn:aws:s3:::your-s3db-bucket/*"
|
|
790
|
-
]
|
|
791
|
-
}
|
|
792
|
-
]
|
|
793
|
-
}
|
|
794
|
-
```
|
|
795
|
-
|
|
796
|
-
### Security Best Practices
|
|
797
|
-
|
|
798
|
-
1. **Use IAM roles** when possible instead of access keys
|
|
799
|
-
2. **Rotate credentials** regularly
|
|
800
|
-
3. **Use environment variables** never hardcode credentials
|
|
801
|
-
4. **Enable S3 bucket encryption** and versioning
|
|
802
|
-
5. **Monitor access logs** and set up CloudTrail
|
|
803
|
-
6. **Use strong passphrases** for S3DB encryption
|
|
804
|
-
7. **Restrict network access** with security groups
|
|
805
|
-
8. **Enable HTTPS** for all connections
|
|
806
|
-
|
|
807
|
-
### Field-Level Encryption
|
|
808
|
-
|
|
809
|
-
```javascript
|
|
810
|
-
await agent.callTool('dbCreateResource', {
|
|
811
|
-
name: 'sensitive_data',
|
|
812
|
-
attributes: {
|
|
813
|
-
publicInfo: 'string',
|
|
814
|
-
privateData: 'secret', // Automatically encrypted
|
|
815
|
-
ssn: 'secret', // Encrypted with passphrase
|
|
816
|
-
creditCard: 'secret' // Encrypted
|
|
817
|
-
}
|
|
818
|
-
});
|
|
819
|
-
```
|
|
820
|
-
|
|
821
|
-
---
|
|
822
|
-
|
|
823
|
-
## ๐จ Troubleshooting
|
|
824
|
-
|
|
825
|
-
### Common Issues
|
|
826
|
-
|
|
827
|
-
**Connection Problems:**
|
|
828
|
-
```bash
|
|
829
|
-
# Check if server is running
|
|
830
|
-
curl http://localhost:8001/health
|
|
831
|
-
|
|
832
|
-
# Check MCP endpoint
|
|
833
|
-
curl http://localhost:8000/sse
|
|
834
|
-
|
|
835
|
-
# View server logs
|
|
836
|
-
docker compose logs -f s3db-mcp-server
|
|
837
|
-
```
|
|
838
|
-
|
|
839
|
-
**S3 Access Issues:**
|
|
840
|
-
```bash
|
|
841
|
-
# Test S3 connection
|
|
842
|
-
aws s3 ls s3://your-bucket
|
|
843
|
-
|
|
844
|
-
# Check credentials
|
|
845
|
-
aws sts get-caller-identity
|
|
846
|
-
|
|
847
|
-
# Test with MinIO
|
|
848
|
-
mc alias set local http://localhost:9000 minioadmin minioadmin
|
|
849
|
-
mc ls local
|
|
850
|
-
```
|
|
851
|
-
|
|
852
|
-
**Performance Issues:**
|
|
853
|
-
- Increase `S3DB_PARALLELISM` for better throughput
|
|
854
|
-
- Use partitions to reduce query scope
|
|
855
|
-
- Implement proper pagination
|
|
856
|
-
- Monitor S3 request patterns
|
|
857
|
-
|
|
858
|
-
**Memory Issues:**
|
|
859
|
-
- Avoid `resourceGetAll` on large datasets
|
|
860
|
-
- Use `resourceList` with pagination instead
|
|
861
|
-
- Increase Docker memory limits if needed
|
|
862
|
-
|
|
863
|
-
### Error Messages
|
|
864
|
-
|
|
865
|
-
| Error | Cause | Solution |
|
|
866
|
-
|-------|-------|----------|
|
|
867
|
-
| "Database not connected" | No `dbConnect` called | Call `dbConnect` tool first |
|
|
868
|
-
| "Resource not found" | Invalid resource name | Check with `dbListResources` |
|
|
869
|
-
| "Validation failed" | Data doesn't match schema | Review attribute definitions |
|
|
870
|
-
| "Connection string invalid" | Malformed connection string | Check format: `s3://key:secret@bucket/path` |
|
|
871
|
-
| "Health check failed" | Server not responding | Check if process is running on correct port |
|
|
872
|
-
|
|
873
|
-
### Debug Mode
|
|
874
|
-
|
|
875
|
-
Enable verbose logging:
|
|
876
|
-
```bash
|
|
877
|
-
# Environment variable
|
|
878
|
-
export S3DB_VERBOSE=true
|
|
879
|
-
|
|
880
|
-
# Command line
|
|
881
|
-
s3db-mcp --transport=sse
|
|
882
|
-
|
|
883
|
-
# Docker
|
|
884
|
-
docker run -e S3DB_VERBOSE=true s3db-mcp-server
|
|
885
|
-
```
|
|
886
|
-
|
|
887
|
-
### Health Monitoring
|
|
888
|
-
|
|
889
|
-
```bash
|
|
890
|
-
# Check server health
|
|
891
|
-
curl http://localhost:8001/health
|
|
892
|
-
|
|
893
|
-
# Response includes:
|
|
894
|
-
{
|
|
895
|
-
"status": "healthy",
|
|
896
|
-
"database": {
|
|
897
|
-
"connected": true,
|
|
898
|
-
"bucket": "my-bucket",
|
|
899
|
-
"resourceCount": 5
|
|
900
|
-
},
|
|
901
|
-
"memory": { "rss": 45000000 },
|
|
902
|
-
"uptime": 3600
|
|
903
|
-
}
|
|
904
|
-
```
|
|
905
|
-
|
|
906
|
-
---
|
|
907
|
-
|
|
908
|
-
## ๐ Built-in Performance Features
|
|
909
|
-
|
|
910
|
-
The S3DB MCP Server includes **automatic performance optimizations**:
|
|
911
|
-
|
|
912
|
-
### **๐๏ธ Configurable Cache (Enabled by Default)**
|
|
913
|
-
- **Two cache drivers**: Memory (fast, temporary) and Filesystem (persistent)
|
|
914
|
-
- **Automatic caching** of read operations (get, list, count, exists)
|
|
915
|
-
- **Partition-aware** caching for optimized queries
|
|
916
|
-
- **Configurable TTL** and size limits
|
|
917
|
-
- **Cache invalidation** on write operations
|
|
918
|
-
- **Performance monitoring** via `dbGetStats`
|
|
919
|
-
|
|
920
|
-
#### **Memory Cache**
|
|
921
|
-
- โก **Fastest performance** for frequently accessed data
|
|
922
|
-
- ๐ **Lost on restart** - ideal for temporary caching
|
|
923
|
-
- ๐ **Size-limited** by number of items
|
|
924
|
-
|
|
925
|
-
#### **Filesystem Cache**
|
|
926
|
-
- ๐พ **Persistent across restarts** - cache survives server restarts
|
|
927
|
-
- ๐๏ธ **Automatic compression** to save disk space
|
|
928
|
-
- ๐งน **Automatic cleanup** of expired files
|
|
929
|
-
- ๐ **Configurable directory** and file naming
|
|
930
|
-
|
|
931
|
-
### **๐ฐ Costs Tracking (Enabled by Default)**
|
|
932
|
-
- **Real-time S3 costs** calculation
|
|
933
|
-
- **Request counting** by operation type
|
|
934
|
-
- **Cost estimation** in USD
|
|
935
|
-
- **Performance analytics** for optimization
|
|
936
|
-
|
|
937
|
-
### **Configuration Options**
|
|
938
|
-
```javascript
|
|
939
|
-
// Connect with memory cache (fast, temporary)
|
|
940
|
-
await agent.callTool('dbConnect', {
|
|
941
|
-
connectionString: 's3://...',
|
|
942
|
-
enableCache: true, // Default: true
|
|
943
|
-
enableCosts: true, // Default: true
|
|
944
|
-
cacheDriver: 'memory', // Fast but lost on restart
|
|
945
|
-
cacheMaxSize: 2000, // Default: 1000
|
|
946
|
-
cacheTtl: 600000 // Default: 300000 (5 min)
|
|
947
|
-
});
|
|
948
|
-
|
|
949
|
-
// Connect with filesystem cache (persistent)
|
|
950
|
-
await agent.callTool('dbConnect', {
|
|
951
|
-
connectionString: 's3://...',
|
|
952
|
-
enableCache: true,
|
|
953
|
-
cacheDriver: 'filesystem', // Survives restarts
|
|
954
|
-
cacheDirectory: './data/cache',
|
|
955
|
-
cachePrefix: 'myapp',
|
|
956
|
-
cacheTtl: 1800000 // 30 minutes
|
|
957
|
-
});
|
|
958
|
-
|
|
959
|
-
// Monitor performance
|
|
960
|
-
const stats = await agent.callTool('dbGetStats');
|
|
961
|
-
console.log('Cache size:', stats.stats.cache.size);
|
|
962
|
-
console.log('Cache driver:', stats.stats.cache.driver);
|
|
963
|
-
console.log('S3 costs:', stats.stats.costs.estimatedCostUSD);
|
|
964
|
-
|
|
965
|
-
// Clear cache when needed
|
|
966
|
-
await agent.callTool('dbClearCache', { resourceName: 'users' });
|
|
967
|
-
```
|
|
968
|
-
|
|
969
|
-
### **Environment Variables**
|
|
970
|
-
```bash
|
|
971
|
-
S3DB_CACHE_ENABLED=true # Enable/disable cache
|
|
972
|
-
S3DB_CACHE_DRIVER=memory # Cache driver: 'memory' or 'filesystem'
|
|
973
|
-
S3DB_CACHE_MAX_SIZE=1000 # Cache capacity (memory driver)
|
|
974
|
-
S3DB_CACHE_TTL=300000 # 5 minute TTL
|
|
975
|
-
S3DB_CACHE_DIRECTORY=./cache # Filesystem cache directory
|
|
976
|
-
S3DB_CACHE_PREFIX=s3db # Filesystem cache file prefix
|
|
977
|
-
S3DB_COSTS_ENABLED=true # Enable/disable costs tracking
|
|
978
|
-
```
|
|
979
|
-
|
|
980
|
-
---
|
|
981
|
-
|
|
982
|
-
## ๐ **Cache Strategy Guide**
|
|
983
|
-
|
|
984
|
-
Choose the right cache driver for your use case:
|
|
985
|
-
|
|
986
|
-
### **When to Use Memory Cache**
|
|
987
|
-
- โก **Development & Testing** - fastest performance, no setup required
|
|
988
|
-
- ๐ **Short-lived processes** - containers that restart frequently
|
|
989
|
-
- ๐ **High-frequency reads** - when you need maximum speed
|
|
990
|
-
- ๐ฐ **Cost optimization** - minimize S3 requests for hot data
|
|
991
|
-
- โ ๏ธ **Limitation**: Cache is lost on restart
|
|
992
|
-
|
|
993
|
-
### **When to Use Filesystem Cache**
|
|
994
|
-
- ๐พ **Production environments** - cache survives server restarts
|
|
995
|
-
- ๐ **Long-running processes** - persistent data across deployments
|
|
996
|
-
- ๐ฆ **Containerized deployments** - mount cache volume for persistence
|
|
997
|
-
- ๐ง **Development consistency** - maintain cache between code changes
|
|
998
|
-
- ๐๏ธ **Large datasets** - no memory size limitations
|
|
999
|
-
|
|
1000
|
-
### **Configuration Examples**
|
|
1001
|
-
|
|
1002
|
-
```javascript
|
|
1003
|
-
// High-performance temporary cache
|
|
1004
|
-
await agent.callTool('dbConnect', {
|
|
1005
|
-
cacheDriver: 'memory',
|
|
1006
|
-
cacheMaxSize: 5000,
|
|
1007
|
-
cacheTtl: 600000 // 10 minutes
|
|
1008
|
-
});
|
|
1009
|
-
|
|
1010
|
-
// Production persistent cache
|
|
1011
|
-
await agent.callTool('dbConnect', {
|
|
1012
|
-
cacheDriver: 'filesystem',
|
|
1013
|
-
cacheDirectory: './data/cache',
|
|
1014
|
-
cachePrefix: 'prod',
|
|
1015
|
-
cacheTtl: 3600000 // 1 hour
|
|
1016
|
-
});
|
|
1017
|
-
```
|
|
1018
|
-
|
|
1019
|
-
### **Docker Volume Setup**
|
|
1020
|
-
```yaml
|
|
1021
|
-
# docker-compose.yml
|
|
1022
|
-
volumes:
|
|
1023
|
-
- ./cache-data:/app/cache # Persistent filesystem cache
|
|
1024
|
-
environment:
|
|
1025
|
-
- S3DB_CACHE_DRIVER=filesystem
|
|
1026
|
-
- S3DB_CACHE_DIRECTORY=/app/cache
|
|
1027
|
-
```
|
|
1028
|
-
|
|
1029
|
-
---
|
|
1030
|
-
|
|
1031
|
-
## ๐ Performance Tips
|
|
1032
|
-
|
|
1033
|
-
1. **Choose appropriate cache** - memory for speed, filesystem for persistence
|
|
1034
|
-
2. **Leverage built-in cache** - read operations are automatically cached
|
|
1035
|
-
3. **Use partitions** for large datasets to improve cache efficiency
|
|
1036
|
-
4. **Monitor costs** with `dbGetStats` to optimize S3 usage
|
|
1037
|
-
5. **Batch operations** when possible to reduce S3 requests
|
|
1038
|
-
6. **Proper pagination** - don't load everything at once
|
|
1039
|
-
7. **Connection reuse** - keep connections alive
|
|
1040
|
-
8. **Appropriate parallelism** - tune `S3DB_PARALLELISM`
|
|
1041
|
-
|
|
1042
|
-
---
|
|
1043
|
-
|
|
1044
|
-
## ๐ Resources
|
|
1045
|
-
|
|
1046
|
-
- **S3DB Documentation**: [github.com/forattini-dev/s3db.js](https://github.com/forattini-dev/s3db.js)
|
|
1047
|
-
- **Model Context Protocol**: [modelcontextprotocol.io](https://modelcontextprotocol.io/)
|
|
1048
|
-
- **Issues & Support**: [GitHub Issues](https://github.com/forattini-dev/s3db.js/issues)
|
|
1049
|
-
- **Discussions**: [GitHub Discussions](https://github.com/forattini-dev/s3db.js/discussions)
|
|
1050
|
-
|
|
1051
|
-
---
|
|
1052
|
-
|
|
1053
|
-
## ๐ License
|
|
1054
|
-
|
|
1055
|
-
This project is licensed under the same license as the parent S3DB project.
|
|
1056
|
-
|
|
1057
|
-
---
|
|
1058
|
-
|
|
1059
|
-
<p align="center">
|
|
1060
|
-
<strong>๐ Ready to supercharge your AI agents with persistent data storage!</strong><br>
|
|
1061
|
-
<em>Start building with S3DB MCP Server today</em>
|
|
1062
|
-
</p>
|