s3db.js 11.2.5 โ†’ 11.3.1

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.
@@ -0,0 +1,147 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Test script to demonstrate FilesystemCache functionality
5
+ * This tests the cache directly without the full MCP server
6
+ */
7
+
8
+ import { FilesystemCache } from '../src/plugins/cache/filesystem-cache.class.js';
9
+ import path from 'path';
10
+ import { fileURLToPath } from 'url';
11
+
12
+ const __filename = fileURLToPath(import.meta.url);
13
+ const __dirname = path.dirname(__filename);
14
+
15
+ async function testFilesystemCache() {
16
+ console.log('๐Ÿงช Testing FilesystemCache Implementation');
17
+ console.log('=========================================\n');
18
+
19
+ const cacheDir = path.join(__dirname, '../test-cache-demo');
20
+
21
+ // Create cache instance
22
+ const cache = new FilesystemCache({
23
+ directory: cacheDir,
24
+ prefix: 'demo',
25
+ ttl: 10000, // 10 seconds for quick testing
26
+ enableCompression: true,
27
+ enableStats: true,
28
+ enableCleanup: true,
29
+ cleanupInterval: 5000, // 5 seconds for quick testing
30
+ createDirectory: true
31
+ });
32
+
33
+ console.log('๐Ÿ“ Cache directory:', cacheDir);
34
+ console.log('โš™๏ธ Configuration:', {
35
+ ttl: '10 seconds',
36
+ compression: 'enabled',
37
+ cleanup: 'enabled (5s interval)'
38
+ });
39
+ console.log();
40
+
41
+ try {
42
+ // Test 1: Set some cache data
43
+ console.log('๐Ÿ“ Test 1: Setting cache data');
44
+ await cache.set('user:123', {
45
+ id: 123,
46
+ name: 'John Doe',
47
+ email: 'john@example.com',
48
+ profile: { bio: 'Software developer', avatar: 'https://example.com/avatar.jpg' }
49
+ });
50
+ await cache.set('user:456', {
51
+ id: 456,
52
+ name: 'Jane Smith',
53
+ email: 'jane@example.com'
54
+ });
55
+ await cache.set('config:app', {
56
+ theme: 'dark',
57
+ language: 'en',
58
+ notifications: true
59
+ });
60
+ console.log('โœ… Set 3 cache entries');
61
+ console.log();
62
+
63
+ // Test 2: Get cache data
64
+ console.log('๐Ÿ“– Test 2: Getting cache data');
65
+ const user123 = await cache.get('user:123');
66
+ const user456 = await cache.get('user:456');
67
+ const config = await cache.get('config:app');
68
+ console.log('โœ… User 123:', user123?.name);
69
+ console.log('โœ… User 456:', user456?.name);
70
+ console.log('โœ… Config theme:', config?.theme);
71
+ console.log();
72
+
73
+ // Test 3: Cache size and keys
74
+ console.log('๐Ÿ“Š Test 3: Cache statistics');
75
+ const size = await cache.size();
76
+ const keys = await cache.keys();
77
+ console.log('โœ… Cache size:', size);
78
+ console.log('โœ… Cache keys:', keys);
79
+ console.log();
80
+
81
+ // Test 4: Cache stats
82
+ console.log('๐Ÿ“ˆ Test 4: Cache performance stats');
83
+ const stats = cache.getStats();
84
+ console.log('โœ… Statistics:', {
85
+ hits: stats.hits,
86
+ misses: stats.misses,
87
+ sets: stats.sets,
88
+ directory: stats.directory,
89
+ compression: stats.compression
90
+ });
91
+ console.log();
92
+
93
+ // Test 5: Non-existent key
94
+ console.log('โ“ Test 5: Getting non-existent key');
95
+ const notFound = await cache.get('user:999');
96
+ console.log('โœ… Non-existent key result:', notFound);
97
+ console.log();
98
+
99
+ // Test 6: Clear specific key
100
+ console.log('๐Ÿ—‘๏ธ Test 6: Deleting specific key');
101
+ await cache.del('user:456');
102
+ const deletedUser = await cache.get('user:456');
103
+ console.log('โœ… Deleted user result:', deletedUser);
104
+ console.log();
105
+
106
+ // Test 7: Wait for TTL expiration
107
+ console.log('โฑ๏ธ Test 7: Waiting for TTL expiration (10 seconds)...');
108
+ console.log(' This demonstrates automatic cleanup of expired files');
109
+
110
+ // Wait 12 seconds to ensure TTL expiration
111
+ await new Promise(resolve => setTimeout(resolve, 12000));
112
+
113
+ const expiredUser = await cache.get('user:123');
114
+ const expiredConfig = await cache.get('config:app');
115
+ console.log('โœ… Expired user (should be null):', expiredUser);
116
+ console.log('โœ… Expired config (should be null):', expiredConfig);
117
+ console.log();
118
+
119
+ // Test 8: Final cache state
120
+ console.log('๐Ÿ“Š Test 8: Final cache state');
121
+ const finalSize = await cache.size();
122
+ const finalKeys = await cache.keys();
123
+ console.log('โœ… Final cache size:', finalSize);
124
+ console.log('โœ… Final cache keys:', finalKeys);
125
+ console.log();
126
+
127
+ // Test 9: Clear all cache
128
+ console.log('๐Ÿงน Test 9: Clearing all cache');
129
+ await cache.clear();
130
+ const clearedSize = await cache.size();
131
+ console.log('โœ… Cache size after clear:', clearedSize);
132
+ console.log();
133
+
134
+ // Cleanup
135
+ cache.destroy();
136
+ console.log('โœ… All FilesystemCache tests completed successfully!');
137
+ console.log('๐Ÿ—‚๏ธ Check the cache directory for any remaining files:', cacheDir);
138
+
139
+ } catch (error) {
140
+ console.error('โŒ Test failed:', error.message);
141
+ console.error(error.stack);
142
+ process.exit(1);
143
+ }
144
+ }
145
+
146
+ // Run the test
147
+ testFilesystemCache().catch(console.error);
@@ -0,0 +1,433 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * S3DB MCP Server Test Script
5
+ *
6
+ * This script demonstrates how to test the S3DB MCP server functionality
7
+ * by making direct tool calls and showing the expected responses.
8
+ */
9
+
10
+ import { createRequire } from 'module';
11
+ const require = createRequire(import.meta.url);
12
+
13
+ // Mock MCP client for testing
14
+ class MockMCPClient {
15
+ constructor(serverUrl) {
16
+ this.serverUrl = serverUrl;
17
+ this.tools = [];
18
+ }
19
+
20
+ async initialize() {
21
+ console.log('๐Ÿ”Œ Initializing MCP Client...');
22
+ console.log(`๐Ÿ“ก Server URL: ${this.serverUrl}`);
23
+
24
+ // In a real implementation, this would connect to the MCP server
25
+ // and fetch the available tools
26
+ this.tools = [
27
+ 'dbConnect', 'dbDisconnect', 'dbStatus', 'dbCreateResource', 'dbListResources', 'dbGetStats', 'dbClearCache',
28
+ 'resourceInsert', 'resourceGet', 'resourceUpdate', 'resourceDelete', 'resourceList'
29
+ ];
30
+
31
+ console.log(`โœ… Found ${this.tools.length} available tools`);
32
+ return this.tools;
33
+ }
34
+
35
+ async callTool(name, args = {}) {
36
+ console.log(`\n๐Ÿ”ง Calling tool: ${name}`);
37
+ console.log(`๐Ÿ“ฅ Arguments:`, JSON.stringify(args, null, 2));
38
+
39
+ // Mock successful responses for demonstration
40
+ const mockResponses = {
41
+ dbConnect: {
42
+ success: true,
43
+ message: 'Connected to S3DB database',
44
+ status: {
45
+ connected: true,
46
+ bucket: 'test-bucket',
47
+ keyPrefix: 'databases/test',
48
+ version: '7.2.1'
49
+ }
50
+ },
51
+
52
+ dbStatus: {
53
+ connected: true,
54
+ bucket: 'test-bucket',
55
+ keyPrefix: 'databases/test',
56
+ version: '7.2.1',
57
+ resourceCount: 2,
58
+ resources: ['users', 'posts']
59
+ },
60
+
61
+ dbCreateResource: {
62
+ success: true,
63
+ resource: {
64
+ name: args.name,
65
+ behavior: args.behavior || 'user-managed',
66
+ attributes: args.attributes,
67
+ partitions: args.partitions || {},
68
+ timestamps: args.timestamps || false
69
+ }
70
+ },
71
+
72
+ dbListResources: {
73
+ success: true,
74
+ resources: [
75
+ { name: 'users' },
76
+ { name: 'posts' }
77
+ ],
78
+ count: 2
79
+ },
80
+
81
+ resourceInsert: {
82
+ success: true,
83
+ data: {
84
+ id: 'doc_' + Math.random().toString(36).substr(2, 9),
85
+ ...args.data,
86
+ createdAt: new Date().toISOString(),
87
+ updatedAt: new Date().toISOString()
88
+ }
89
+ },
90
+
91
+ resourceGet: {
92
+ success: true,
93
+ data: {
94
+ id: args.id,
95
+ name: 'John Doe',
96
+ email: 'john@example.com',
97
+ createdAt: '2024-01-15T10:30:00Z',
98
+ updatedAt: '2024-01-15T10:30:00Z'
99
+ }
100
+ },
101
+
102
+ resourceList: {
103
+ success: true,
104
+ data: [
105
+ {
106
+ id: 'doc_123',
107
+ name: 'John Doe',
108
+ email: 'john@example.com',
109
+ createdAt: '2024-01-15T10:30:00Z'
110
+ },
111
+ {
112
+ id: 'doc_456',
113
+ name: 'Jane Smith',
114
+ email: 'jane@example.com',
115
+ createdAt: '2024-01-15T11:30:00Z'
116
+ }
117
+ ],
118
+ count: 2,
119
+ pagination: {
120
+ limit: args.limit || 100,
121
+ offset: args.offset || 0,
122
+ hasMore: false
123
+ }
124
+ },
125
+
126
+ resourceCount: {
127
+ success: true,
128
+ count: 42,
129
+ resource: args.resourceName
130
+ },
131
+
132
+ dbGetStats: {
133
+ success: true,
134
+ stats: {
135
+ database: {
136
+ connected: true,
137
+ bucket: 'test-bucket',
138
+ keyPrefix: 'databases/test',
139
+ version: '7.2.1',
140
+ resourceCount: 2,
141
+ resources: ['users', 'posts']
142
+ },
143
+ costs: {
144
+ total: 0.000042,
145
+ totalRequests: 156,
146
+ requestsByType: { get: 89, put: 45, list: 12, delete: 10 },
147
+ eventsByType: { GetObjectCommand: 89, PutObjectCommand: 45 },
148
+ estimatedCostUSD: 0.000042
149
+ },
150
+ cache: {
151
+ enabled: true,
152
+ driver: 'FilesystemCache',
153
+ size: 23,
154
+ directory: './test-cache',
155
+ ttl: 300000,
156
+ keyCount: 23,
157
+ sampleKeys: ['resource=users/action=list.json.gz', 'resource=posts/action=count.json.gz']
158
+ }
159
+ }
160
+ },
161
+
162
+ dbClearCache: {
163
+ success: true,
164
+ message: args.resourceName
165
+ ? `Cache cleared for resource: ${args.resourceName}`
166
+ : 'All cache cleared'
167
+ }
168
+ };
169
+
170
+ const response = mockResponses[name] || { success: false, error: 'Tool not found' };
171
+
172
+ console.log(`๐Ÿ“ค Response:`, JSON.stringify(response, null, 2));
173
+ return response;
174
+ }
175
+ }
176
+
177
+ // Test scenarios
178
+ async function runTests() {
179
+ console.log('๐Ÿงช S3DB MCP Server Test Suite');
180
+ console.log('================================\n');
181
+
182
+ const client = new MockMCPClient('http://localhost:8000/sse');
183
+
184
+ try {
185
+ // Initialize client
186
+ await client.initialize();
187
+
188
+ // Test 1: Connect to database
189
+ console.log('\n๐Ÿ“‹ Test 1: Database Connection');
190
+ console.log('-------------------------------');
191
+ await client.callTool('dbConnect', {
192
+ connectionString: 's3://test-key:test-secret@test-bucket/databases/demo',
193
+ verbose: false,
194
+ parallelism: 10,
195
+ enableCache: true,
196
+ enableCosts: true,
197
+ cacheDriver: 'filesystem', // Test filesystem cache
198
+ cacheDirectory: './test-cache',
199
+ cachePrefix: 'test',
200
+ cacheTtl: 300000
201
+ });
202
+
203
+ // Test 2: Check database status
204
+ console.log('\n๐Ÿ“‹ Test 2: Database Status');
205
+ console.log('---------------------------');
206
+ await client.callTool('dbStatus');
207
+
208
+ // Test 3: Create a resource
209
+ console.log('\n๐Ÿ“‹ Test 3: Create Resource');
210
+ console.log('---------------------------');
211
+ await client.callTool('dbCreateResource', {
212
+ name: 'users',
213
+ attributes: {
214
+ name: 'string|required',
215
+ email: 'email|required|unique',
216
+ age: 'number|positive',
217
+ profile: {
218
+ bio: 'string|optional',
219
+ avatar: 'url|optional'
220
+ }
221
+ },
222
+ behavior: 'user-managed',
223
+ timestamps: true,
224
+ partitions: {
225
+ byAge: {
226
+ fields: { ageGroup: 'string' }
227
+ }
228
+ }
229
+ });
230
+
231
+ // Test 4: List resources
232
+ console.log('\n๐Ÿ“‹ Test 4: List Resources');
233
+ console.log('--------------------------');
234
+ await client.callTool('dbListResources');
235
+
236
+ // Test 5: Insert data
237
+ console.log('\n๐Ÿ“‹ Test 5: Insert Document');
238
+ console.log('---------------------------');
239
+ await client.callTool('resourceInsert', {
240
+ resourceName: 'users',
241
+ data: {
242
+ name: 'John Doe',
243
+ email: 'john@example.com',
244
+ age: 30,
245
+ profile: {
246
+ bio: 'Software developer and AI enthusiast',
247
+ avatar: 'https://example.com/avatar.jpg'
248
+ }
249
+ }
250
+ });
251
+
252
+ // Test 6: Get document
253
+ console.log('\n๐Ÿ“‹ Test 6: Get Document');
254
+ console.log('------------------------');
255
+ await client.callTool('resourceGet', {
256
+ resourceName: 'users',
257
+ id: 'doc_123'
258
+ });
259
+
260
+ // Test 7: List documents
261
+ console.log('\n๐Ÿ“‹ Test 7: List Documents');
262
+ console.log('--------------------------');
263
+ await client.callTool('resourceList', {
264
+ resourceName: 'users',
265
+ limit: 10,
266
+ offset: 0
267
+ });
268
+
269
+ // Test 8: Count documents
270
+ console.log('\n๐Ÿ“‹ Test 8: Count Documents');
271
+ console.log('---------------------------');
272
+ await client.callTool('resourceCount', {
273
+ resourceName: 'users'
274
+ });
275
+
276
+ // Test 9: Get database statistics
277
+ console.log('\n๐Ÿ“‹ Test 9: Database Statistics');
278
+ console.log('-------------------------------');
279
+ await client.callTool('dbGetStats');
280
+
281
+ // Test 10: Clear cache
282
+ console.log('\n๐Ÿ“‹ Test 10: Clear Cache');
283
+ console.log('------------------------');
284
+ await client.callTool('dbClearCache', {
285
+ resourceName: 'users'
286
+ });
287
+
288
+ console.log('\nโœ… All tests completed successfully!');
289
+ console.log('\n๐Ÿ’ก To run against a real S3DB MCP server:');
290
+ console.log(' 1. Start the server: npm start');
291
+ console.log(' 2. Configure your .env file');
292
+ console.log(' 3. Use a real MCP client to connect');
293
+
294
+ } catch (error) {
295
+ console.error('\nโŒ Test failed:', error.message);
296
+ process.exit(1);
297
+ }
298
+ }
299
+
300
+ // Real MCP client example (commented out - requires actual MCP client library)
301
+ async function realMCPExample() {
302
+ console.log('\n๐Ÿ”— Real MCP Client Example');
303
+ console.log('===========================');
304
+
305
+ console.log(`
306
+ This is how you would connect to a real S3DB MCP server:
307
+
308
+ import { MCPClient } from '@modelcontextprotocol/client';
309
+
310
+ const client = new MCPClient({
311
+ transport: 'sse',
312
+ url: 'http://localhost:8000/sse'
313
+ });
314
+
315
+ await client.connect();
316
+
317
+ // Connect to S3DB
318
+ const result = await client.callTool('dbConnect', {
319
+ connectionString: process.env.S3DB_CONNECTION_STRING
320
+ });
321
+
322
+ // Create a resource
323
+ await client.callTool('dbCreateResource', {
324
+ name: 'products',
325
+ attributes: {
326
+ name: 'string|required',
327
+ price: 'number|positive|required',
328
+ category: 'string|required'
329
+ },
330
+ timestamps: true
331
+ });
332
+
333
+ // Insert data
334
+ await client.callTool('resourceInsert', {
335
+ resourceName: 'products',
336
+ data: {
337
+ name: 'Laptop Pro',
338
+ price: 1299.99,
339
+ category: 'electronics'
340
+ }
341
+ });
342
+ `);
343
+ }
344
+
345
+ // Configuration examples
346
+ function showConfigurationExamples() {
347
+ console.log('\nโš™๏ธ Configuration Examples');
348
+ console.log('===========================');
349
+
350
+ console.log(`
351
+ # AWS S3 Configuration
352
+ S3DB_CONNECTION_STRING=s3://ACCESS_KEY:SECRET_KEY@bucket/databases/myapp
353
+
354
+ # MinIO Configuration (local development)
355
+ S3DB_CONNECTION_STRING=s3://minioadmin:minioadmin@test-bucket/databases/dev?endpoint=http://localhost:9000&forcePathStyle=true
356
+
357
+ # DigitalOcean Spaces Configuration
358
+ S3DB_CONNECTION_STRING=s3://DO_KEY:DO_SECRET@space-name/databases/prod?endpoint=https://nyc3.digitaloceanspaces.com
359
+
360
+ # Claude Desktop Configuration (claude_desktop_config.json)
361
+ {
362
+ "mcpServers": {
363
+ "s3db": {
364
+ "transport": "sse",
365
+ "url": "http://localhost:8000/sse"
366
+ }
367
+ }
368
+ }
369
+
370
+ # Cursor IDE Configuration
371
+ {
372
+ "mcpServers": {
373
+ "s3db": {
374
+ "url": "http://localhost:8000/sse"
375
+ }
376
+ }
377
+ }
378
+ `);
379
+ }
380
+
381
+ // Main execution
382
+ async function main() {
383
+ const args = process.argv.slice(2);
384
+
385
+ if (args.includes('--help') || args.includes('-h')) {
386
+ console.log(`
387
+ S3DB MCP Server Test Script
388
+
389
+ Usage:
390
+ node test-mcp.js [options]
391
+
392
+ Options:
393
+ --help, -h Show this help message
394
+ --config Show configuration examples
395
+ --real Show real MCP client examples
396
+
397
+ Examples:
398
+ node test-mcp.js # Run mock tests
399
+ node test-mcp.js --config # Show configuration examples
400
+ node test-mcp.js --real # Show real client examples
401
+ `);
402
+ return;
403
+ }
404
+
405
+ if (args.includes('--config')) {
406
+ showConfigurationExamples();
407
+ return;
408
+ }
409
+
410
+ if (args.includes('--real')) {
411
+ await realMCPExample();
412
+ return;
413
+ }
414
+
415
+ // Run the test suite
416
+ await runTests();
417
+ }
418
+
419
+ // Handle errors
420
+ process.on('unhandledRejection', (error) => {
421
+ console.error('โŒ Unhandled rejection:', error);
422
+ process.exit(1);
423
+ });
424
+
425
+ process.on('uncaughtException', (error) => {
426
+ console.error('โŒ Uncaught exception:', error);
427
+ process.exit(1);
428
+ });
429
+
430
+ // Run main function
431
+ if (import.meta.url === `file://${process.argv[1]}`) {
432
+ main().catch(console.error);
433
+ }
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "s3db-mcp-server",
3
+ "version": "1.0.0",
4
+ "description": "Model Context Protocol (MCP) server for S3DB - Transform AWS S3 into a powerful document database",
5
+ "type": "module",
6
+ "main": "s3db_mcp_server.js",
7
+ "bin": {
8
+ "s3db-mcp": "./s3db_mcp_server.js"
9
+ },
10
+ "scripts": {
11
+ "start": "node s3db_mcp_server.js",
12
+ "start:sse": "node s3db_mcp_server.js --transport=sse",
13
+ "start:stdio": "node s3db_mcp_server.js --transport=stdio",
14
+ "dev": "node --watch s3db_mcp_server.js --transport=sse",
15
+ "docker:build": "docker build -t s3db-mcp-server .",
16
+ "docker:run": "docker run -p 8000:8000 --env-file .env s3db-mcp-server",
17
+ "docker:compose": "docker compose up",
18
+ "docker:compose:build": "docker compose up --build",
19
+ "test": "echo 'Tests coming soon!' && exit 0"
20
+ },
21
+ "keywords": [
22
+ "mcp",
23
+ "model-context-protocol",
24
+ "s3db",
25
+ "s3",
26
+ "aws",
27
+ "database",
28
+ "document-database",
29
+ "ai-agent",
30
+ "llm"
31
+ ],
32
+ "author": "S3DB Community",
33
+ "license": "UNLICENSED",
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "git+https://github.com/forattini-dev/s3db.js.git",
37
+ "directory": "mcp-server"
38
+ },
39
+ "bugs": {
40
+ "url": "https://github.com/forattini-dev/s3db.js/issues"
41
+ },
42
+ "homepage": "https://github.com/forattini-dev/s3db.js/tree/main/mcp-server#readme",
43
+ "engines": {
44
+ "node": ">=18.0.0"
45
+ },
46
+ "dependencies": {
47
+ "@modelcontextprotocol/sdk": "^1.0.0",
48
+ "s3db.js": "^7.2.1",
49
+ "dotenv": "^16.4.5"
50
+ },
51
+ "devDependencies": {
52
+ "@types/node": "^20.11.0"
53
+ },
54
+ "files": [
55
+ "s3db_mcp_server.js",
56
+ "README.md",
57
+ "Dockerfile",
58
+ "docker-compose.yml",
59
+ ".env.example",
60
+ "Makefile",
61
+ "examples/"
62
+ ],
63
+ "publishConfig": {
64
+ "access": "public"
65
+ }
66
+ }