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.
- package/README.md +138 -0
- package/dist/s3db.cjs.js +67 -2
- package/dist/s3db.cjs.js.map +1 -1
- package/dist/s3db.d.ts +3 -1
- package/dist/s3db.es.js +67 -2
- package/dist/s3db.es.js.map +1 -1
- package/mcp/.env.example +117 -0
- package/mcp/CLAUDE_CLI_SETUP.md +302 -0
- package/mcp/Dockerfile +45 -0
- package/mcp/Makefile +162 -0
- package/mcp/NPX_SETUP.md +327 -0
- package/mcp/PUBLISHING.md +281 -0
- package/mcp/README.md +125 -0
- package/mcp/docker-compose.yml +120 -0
- package/mcp/{server.js → entrypoint.js} +1941 -683
- package/mcp/examples/test-filesystem-cache.js +147 -0
- package/mcp/examples/test-mcp.js +433 -0
- package/mcp/package.json +66 -0
- package/mcp/tools/bulk.js +112 -0
- package/mcp/tools/connection.js +228 -0
- package/mcp/tools/crud.js +579 -0
- package/mcp/tools/debugging.js +299 -0
- package/mcp/tools/export-import.js +281 -0
- package/mcp/tools/index.js +67 -0
- package/mcp/tools/partitions.js +223 -0
- package/mcp/tools/query.js +150 -0
- package/mcp/tools/resources.js +96 -0
- package/mcp/tools/stats.js +281 -0
- package/package.json +17 -7
- package/src/database.class.js +1 -1
- package/src/resource.class.js +79 -0
- package/src/s3db.d.ts +3 -1
package/README.md
CHANGED
|
@@ -110,6 +110,7 @@
|
|
|
110
110
|
- [🎣 Advanced Hooks System](#-advanced-hooks-system)
|
|
111
111
|
- [🧩 Resource Middlewares](#-resource-middlewares)
|
|
112
112
|
- [🎧 Event Listeners Configuration](#-event-listeners-configuration)
|
|
113
|
+
- [🤖 MCP Server](#-mcp-server)
|
|
113
114
|
- [🔧 Troubleshooting](#-troubleshooting)
|
|
114
115
|
- [📖 API Reference](#-api-reference)
|
|
115
116
|
|
|
@@ -1866,6 +1867,143 @@ await users.insert({ name: 'John' });
|
|
|
1866
1867
|
|
|
1867
1868
|
---
|
|
1868
1869
|
|
|
1870
|
+
## 🤖 MCP Server
|
|
1871
|
+
|
|
1872
|
+
S3DB includes a powerful **Model Context Protocol (MCP) server** that enables AI assistants like Claude to interact with your S3DB databases. The MCP server provides **28 specialized tools** for database operations, debugging, monitoring, and data management.
|
|
1873
|
+
|
|
1874
|
+
### ⚡ Quick Start with npx
|
|
1875
|
+
|
|
1876
|
+
**For Claude CLI** (one command setup):
|
|
1877
|
+
```bash
|
|
1878
|
+
claude mcp add s3db \
|
|
1879
|
+
--transport stdio \
|
|
1880
|
+
-- npx -y s3db.js s3db-mcp --transport=stdio
|
|
1881
|
+
```
|
|
1882
|
+
|
|
1883
|
+
**For Claude Desktop** - Add to `~/Library/Application Support/Claude/claude_desktop_config.json`:
|
|
1884
|
+
```json
|
|
1885
|
+
{
|
|
1886
|
+
"mcpServers": {
|
|
1887
|
+
"s3db": {
|
|
1888
|
+
"command": "npx",
|
|
1889
|
+
"args": ["-y", "s3db.js", "s3db-mcp", "--transport=sse"],
|
|
1890
|
+
"env": {
|
|
1891
|
+
"S3DB_CONNECTION_STRING": "s3://ACCESS_KEY:SECRET_KEY@bucket/databases/myapp",
|
|
1892
|
+
"S3DB_CACHE_ENABLED": "true",
|
|
1893
|
+
"S3DB_COSTS_ENABLED": "true"
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
```
|
|
1899
|
+
|
|
1900
|
+
**Standalone Server:**
|
|
1901
|
+
```bash
|
|
1902
|
+
# Start HTTP server
|
|
1903
|
+
npx s3db.js s3db-mcp --transport=sse
|
|
1904
|
+
```
|
|
1905
|
+
|
|
1906
|
+
📖 **Complete setup guides:**
|
|
1907
|
+
- [NPX Setup Guide](./mcp/NPX_SETUP.md) - Use with `npx` (recommended)
|
|
1908
|
+
- [Claude CLI Setup](./mcp/CLAUDE_CLI_SETUP.md) - Detailed configuration
|
|
1909
|
+
|
|
1910
|
+
### Available Tools
|
|
1911
|
+
|
|
1912
|
+
The MCP server provides 28 tools organized into 7 categories:
|
|
1913
|
+
|
|
1914
|
+
#### 🔌 **Connection Management** (3 tools)
|
|
1915
|
+
- `dbConnect` - Connect with cache and costs tracking
|
|
1916
|
+
- `dbDisconnect` - Graceful disconnection
|
|
1917
|
+
- `dbStatus` - Check connection status
|
|
1918
|
+
|
|
1919
|
+
#### 🔍 **Debugging Tools** (5 tools)
|
|
1920
|
+
- `dbInspectResource` - Deep resource inspection
|
|
1921
|
+
- `dbGetMetadata` - View raw metadata.json
|
|
1922
|
+
- `resourceValidate` - Validate data against schema
|
|
1923
|
+
- `dbHealthCheck` - Comprehensive health check
|
|
1924
|
+
- `resourceGetRaw` - View raw S3 object data
|
|
1925
|
+
|
|
1926
|
+
#### 📊 **Query & Filtering** (2 tools)
|
|
1927
|
+
- `resourceQuery` - Complex queries with filters
|
|
1928
|
+
- `resourceSearch` - Full-text search
|
|
1929
|
+
|
|
1930
|
+
#### 🔧 **Partition Management** (4 tools)
|
|
1931
|
+
- `resourceListPartitions` - List all partitions
|
|
1932
|
+
- `resourceListPartitionValues` - Get partition values
|
|
1933
|
+
- `dbFindOrphanedPartitions` - Detect orphaned partitions
|
|
1934
|
+
- `dbRemoveOrphanedPartitions` - Clean up orphaned partitions
|
|
1935
|
+
|
|
1936
|
+
#### 🚀 **Bulk Operations** (3 tools)
|
|
1937
|
+
- `resourceUpdateMany` - Update with filters
|
|
1938
|
+
- `resourceBulkUpsert` - Bulk upsert operations
|
|
1939
|
+
- `resourceDeleteAll` - Delete all documents
|
|
1940
|
+
|
|
1941
|
+
#### 💾 **Export/Import** (3 tools)
|
|
1942
|
+
- `resourceExport` - Export to JSON/CSV/NDJSON
|
|
1943
|
+
- `resourceImport` - Import from JSON/NDJSON
|
|
1944
|
+
- `dbBackupMetadata` - Create metadata backups
|
|
1945
|
+
|
|
1946
|
+
#### 📈 **Monitoring** (4 tools)
|
|
1947
|
+
- `dbGetStats` - Database statistics
|
|
1948
|
+
- `resourceGetStats` - Resource-specific stats
|
|
1949
|
+
- `cacheGetStats` - Cache performance metrics
|
|
1950
|
+
- `dbClearCache` - Clear cache
|
|
1951
|
+
|
|
1952
|
+
Plus **standard CRUD operations**: insert, get, update, delete, list, count, and more.
|
|
1953
|
+
|
|
1954
|
+
### Features
|
|
1955
|
+
|
|
1956
|
+
- ✅ **Automatic Performance**: Cache and cost tracking enabled by default
|
|
1957
|
+
- ✅ **Multiple Transports**: SSE for web clients, stdio for CLI
|
|
1958
|
+
- ✅ **Partition-Aware**: Intelligent caching with partition support
|
|
1959
|
+
- ✅ **Debugging**: Comprehensive tools for troubleshooting
|
|
1960
|
+
- ✅ **Bulk Operations**: Efficient batch processing
|
|
1961
|
+
- ✅ **Export/Import**: Data migration and backup
|
|
1962
|
+
|
|
1963
|
+
### Full Documentation
|
|
1964
|
+
|
|
1965
|
+
**Complete MCP documentation**: [**docs/mcp.md**](./docs/mcp.md)
|
|
1966
|
+
|
|
1967
|
+
Includes:
|
|
1968
|
+
- Tool reference with all 28 tools
|
|
1969
|
+
- Configuration examples (AWS, MinIO, DigitalOcean)
|
|
1970
|
+
- Docker deployment guides
|
|
1971
|
+
- Performance optimization
|
|
1972
|
+
- Troubleshooting
|
|
1973
|
+
- Security best practices
|
|
1974
|
+
|
|
1975
|
+
### Example Usage
|
|
1976
|
+
|
|
1977
|
+
```javascript
|
|
1978
|
+
// Connect to database
|
|
1979
|
+
await dbConnect({
|
|
1980
|
+
connectionString: "s3://bucket/databases/app",
|
|
1981
|
+
enableCache: true,
|
|
1982
|
+
enableCosts: true
|
|
1983
|
+
})
|
|
1984
|
+
|
|
1985
|
+
// Inspect resource
|
|
1986
|
+
await dbInspectResource({ resourceName: "users" })
|
|
1987
|
+
|
|
1988
|
+
// Query with filters
|
|
1989
|
+
await resourceQuery({
|
|
1990
|
+
resourceName: "users",
|
|
1991
|
+
filters: { status: "active", age: { $gt: 18 } }
|
|
1992
|
+
})
|
|
1993
|
+
|
|
1994
|
+
// Export data
|
|
1995
|
+
await resourceExport({
|
|
1996
|
+
resourceName: "users",
|
|
1997
|
+
format: "csv",
|
|
1998
|
+
filters: { status: "active" }
|
|
1999
|
+
})
|
|
2000
|
+
|
|
2001
|
+
// Check health
|
|
2002
|
+
await dbHealthCheck({ includeOrphanedPartitions: true })
|
|
2003
|
+
```
|
|
2004
|
+
|
|
2005
|
+
---
|
|
2006
|
+
|
|
1869
2007
|
## 📖 API Reference
|
|
1870
2008
|
|
|
1871
2009
|
### 📚 Core Classes Documentation
|
package/dist/s3db.cjs.js
CHANGED
|
@@ -13125,6 +13125,71 @@ ${errorDetails}`,
|
|
|
13125
13125
|
}
|
|
13126
13126
|
return true;
|
|
13127
13127
|
}
|
|
13128
|
+
/**
|
|
13129
|
+
* Find orphaned partitions (partitions that reference non-existent fields)
|
|
13130
|
+
* @returns {Object} Object with orphaned partition names as keys and details as values
|
|
13131
|
+
* @example
|
|
13132
|
+
* const orphaned = resource.findOrphanedPartitions();
|
|
13133
|
+
* // Returns: { byRegion: { missingFields: ['region'], definition: {...} } }
|
|
13134
|
+
*/
|
|
13135
|
+
findOrphanedPartitions() {
|
|
13136
|
+
const orphaned = {};
|
|
13137
|
+
if (!this.config.partitions) {
|
|
13138
|
+
return orphaned;
|
|
13139
|
+
}
|
|
13140
|
+
for (const [partitionName, partitionDef] of Object.entries(this.config.partitions)) {
|
|
13141
|
+
if (!partitionDef.fields) {
|
|
13142
|
+
continue;
|
|
13143
|
+
}
|
|
13144
|
+
const missingFields = [];
|
|
13145
|
+
for (const fieldName of Object.keys(partitionDef.fields)) {
|
|
13146
|
+
if (!this.fieldExistsInAttributes(fieldName)) {
|
|
13147
|
+
missingFields.push(fieldName);
|
|
13148
|
+
}
|
|
13149
|
+
}
|
|
13150
|
+
if (missingFields.length > 0) {
|
|
13151
|
+
orphaned[partitionName] = {
|
|
13152
|
+
missingFields,
|
|
13153
|
+
definition: partitionDef,
|
|
13154
|
+
allFields: Object.keys(partitionDef.fields)
|
|
13155
|
+
};
|
|
13156
|
+
}
|
|
13157
|
+
}
|
|
13158
|
+
return orphaned;
|
|
13159
|
+
}
|
|
13160
|
+
/**
|
|
13161
|
+
* Remove orphaned partitions (partitions that reference non-existent fields)
|
|
13162
|
+
* WARNING: This will modify the resource configuration and should be followed by uploadMetadataFile()
|
|
13163
|
+
* @param {Object} options - Options
|
|
13164
|
+
* @param {boolean} options.dryRun - If true, only returns what would be removed without modifying (default: false)
|
|
13165
|
+
* @returns {Object} Object with removed partition names and details
|
|
13166
|
+
* @example
|
|
13167
|
+
* // Dry run to see what would be removed
|
|
13168
|
+
* const toRemove = resource.removeOrphanedPartitions({ dryRun: true });
|
|
13169
|
+
* console.log('Would remove:', toRemove);
|
|
13170
|
+
*
|
|
13171
|
+
* // Actually remove orphaned partitions
|
|
13172
|
+
* const removed = resource.removeOrphanedPartitions();
|
|
13173
|
+
* await database.uploadMetadataFile(); // Save changes to S3
|
|
13174
|
+
*/
|
|
13175
|
+
removeOrphanedPartitions({ dryRun = false } = {}) {
|
|
13176
|
+
const orphaned = this.findOrphanedPartitions();
|
|
13177
|
+
if (Object.keys(orphaned).length === 0) {
|
|
13178
|
+
return {};
|
|
13179
|
+
}
|
|
13180
|
+
if (dryRun) {
|
|
13181
|
+
return orphaned;
|
|
13182
|
+
}
|
|
13183
|
+
for (const partitionName of Object.keys(orphaned)) {
|
|
13184
|
+
delete this.config.partitions[partitionName];
|
|
13185
|
+
}
|
|
13186
|
+
this.emit("orphanedPartitionsRemoved", {
|
|
13187
|
+
resourceName: this.name,
|
|
13188
|
+
removed: Object.keys(orphaned),
|
|
13189
|
+
details: orphaned
|
|
13190
|
+
});
|
|
13191
|
+
return orphaned;
|
|
13192
|
+
}
|
|
13128
13193
|
/**
|
|
13129
13194
|
* Apply a single partition rule to a field value
|
|
13130
13195
|
* @param {*} value - The field value
|
|
@@ -15218,7 +15283,7 @@ class Database extends EventEmitter {
|
|
|
15218
15283
|
this.id = idGenerator(7);
|
|
15219
15284
|
this.version = "1";
|
|
15220
15285
|
this.s3dbVersion = (() => {
|
|
15221
|
-
const [ok, err, version] = tryFn(() => true ? "11.
|
|
15286
|
+
const [ok, err, version] = tryFn(() => true ? "11.3.1" : "latest");
|
|
15222
15287
|
return ok ? version : "latest";
|
|
15223
15288
|
})();
|
|
15224
15289
|
this.resources = {};
|
|
@@ -16022,7 +16087,7 @@ class Database extends EventEmitter {
|
|
|
16022
16087
|
autoDecrypt: config.autoDecrypt !== void 0 ? config.autoDecrypt : true,
|
|
16023
16088
|
hooks: hooks || {},
|
|
16024
16089
|
versioningEnabled: this.versioningEnabled,
|
|
16025
|
-
strictValidation: this.strictValidation,
|
|
16090
|
+
strictValidation: config.strictValidation !== void 0 ? config.strictValidation : this.strictValidation,
|
|
16026
16091
|
map: config.map,
|
|
16027
16092
|
idGenerator: config.idGenerator,
|
|
16028
16093
|
idSize: config.idSize,
|