s3db.js 11.2.6 → 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 +2 -2
- package/dist/s3db.es.js +2 -2
- 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/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
|
@@ -15283,7 +15283,7 @@ class Database extends EventEmitter {
|
|
|
15283
15283
|
this.id = idGenerator(7);
|
|
15284
15284
|
this.version = "1";
|
|
15285
15285
|
this.s3dbVersion = (() => {
|
|
15286
|
-
const [ok, err, version] = tryFn(() => true ? "11.
|
|
15286
|
+
const [ok, err, version] = tryFn(() => true ? "11.3.1" : "latest");
|
|
15287
15287
|
return ok ? version : "latest";
|
|
15288
15288
|
})();
|
|
15289
15289
|
this.resources = {};
|
|
@@ -16087,7 +16087,7 @@ class Database extends EventEmitter {
|
|
|
16087
16087
|
autoDecrypt: config.autoDecrypt !== void 0 ? config.autoDecrypt : true,
|
|
16088
16088
|
hooks: hooks || {},
|
|
16089
16089
|
versioningEnabled: this.versioningEnabled,
|
|
16090
|
-
strictValidation: this.strictValidation,
|
|
16090
|
+
strictValidation: config.strictValidation !== void 0 ? config.strictValidation : this.strictValidation,
|
|
16091
16091
|
map: config.map,
|
|
16092
16092
|
idGenerator: config.idGenerator,
|
|
16093
16093
|
idSize: config.idSize,
|
package/dist/s3db.es.js
CHANGED
|
@@ -15279,7 +15279,7 @@ class Database extends EventEmitter {
|
|
|
15279
15279
|
this.id = idGenerator(7);
|
|
15280
15280
|
this.version = "1";
|
|
15281
15281
|
this.s3dbVersion = (() => {
|
|
15282
|
-
const [ok, err, version] = tryFn(() => true ? "11.
|
|
15282
|
+
const [ok, err, version] = tryFn(() => true ? "11.3.1" : "latest");
|
|
15283
15283
|
return ok ? version : "latest";
|
|
15284
15284
|
})();
|
|
15285
15285
|
this.resources = {};
|
|
@@ -16083,7 +16083,7 @@ class Database extends EventEmitter {
|
|
|
16083
16083
|
autoDecrypt: config.autoDecrypt !== void 0 ? config.autoDecrypt : true,
|
|
16084
16084
|
hooks: hooks || {},
|
|
16085
16085
|
versioningEnabled: this.versioningEnabled,
|
|
16086
|
-
strictValidation: this.strictValidation,
|
|
16086
|
+
strictValidation: config.strictValidation !== void 0 ? config.strictValidation : this.strictValidation,
|
|
16087
16087
|
map: config.map,
|
|
16088
16088
|
idGenerator: config.idGenerator,
|
|
16089
16089
|
idSize: config.idSize,
|
package/mcp/.env.example
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# ==============================================================================
|
|
2
|
+
# S3DB MCP Server Configuration
|
|
3
|
+
# ==============================================================================
|
|
4
|
+
|
|
5
|
+
# Server Configuration
|
|
6
|
+
NODE_ENV=development
|
|
7
|
+
MCP_SERVER_HOST=0.0.0.0
|
|
8
|
+
MCP_SERVER_PORT=8000
|
|
9
|
+
MCP_TRANSPORT=sse
|
|
10
|
+
|
|
11
|
+
# ==============================================================================
|
|
12
|
+
# S3DB Database Configuration
|
|
13
|
+
# ==============================================================================
|
|
14
|
+
|
|
15
|
+
# Primary S3DB connection string
|
|
16
|
+
# Format: s3://ACCESS_KEY:SECRET_KEY@BUCKET_NAME/database/path
|
|
17
|
+
# Example: s3://AKIAIOSFODNN7EXAMPLE:wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY@my-s3db-bucket/databases/production
|
|
18
|
+
S3DB_CONNECTION_STRING=s3://YOUR_ACCESS_KEY:YOUR_SECRET_KEY@YOUR_BUCKET/databases/development
|
|
19
|
+
|
|
20
|
+
# S3DB Options
|
|
21
|
+
S3DB_VERBOSE=false
|
|
22
|
+
S3DB_PARALLELISM=10
|
|
23
|
+
S3DB_PASSPHRASE=your-encryption-passphrase
|
|
24
|
+
S3DB_VERSIONING_ENABLED=false
|
|
25
|
+
|
|
26
|
+
# Plugin Configuration
|
|
27
|
+
S3DB_COSTS_ENABLED=true # Enable automatic S3 costs tracking
|
|
28
|
+
S3DB_CACHE_ENABLED=true # Enable cache for performance
|
|
29
|
+
S3DB_CACHE_DRIVER=memory # Cache driver: 'memory' or 'filesystem'
|
|
30
|
+
S3DB_CACHE_MAX_SIZE=1000 # Maximum items in memory cache (memory driver only)
|
|
31
|
+
S3DB_CACHE_TTL=300000 # Cache TTL in milliseconds (5 minutes)
|
|
32
|
+
S3DB_CACHE_DIRECTORY=./cache # Directory for filesystem cache (filesystem driver only)
|
|
33
|
+
S3DB_CACHE_PREFIX=s3db # Prefix for cache files (filesystem driver only)
|
|
34
|
+
|
|
35
|
+
# ==============================================================================
|
|
36
|
+
# AWS Configuration
|
|
37
|
+
# ==============================================================================
|
|
38
|
+
|
|
39
|
+
# AWS Credentials (required unless using IAM roles)
|
|
40
|
+
AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
|
|
41
|
+
AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
|
|
42
|
+
AWS_SESSION_TOKEN=
|
|
43
|
+
AWS_REGION=us-east-1
|
|
44
|
+
|
|
45
|
+
# ==============================================================================
|
|
46
|
+
# S3-Compatible Services (MinIO, DigitalOcean Spaces, etc.)
|
|
47
|
+
# ==============================================================================
|
|
48
|
+
|
|
49
|
+
# Uncomment and configure for S3-compatible services
|
|
50
|
+
# S3_ENDPOINT=http://localhost:9000
|
|
51
|
+
# S3_FORCE_PATH_STYLE=true
|
|
52
|
+
|
|
53
|
+
# MinIO specific (for local testing)
|
|
54
|
+
# S3_ENDPOINT=http://minio:9000
|
|
55
|
+
# MINIO_ROOT_USER=minioadmin
|
|
56
|
+
# MINIO_ROOT_PASSWORD=minioadmin
|
|
57
|
+
|
|
58
|
+
# DigitalOcean Spaces example
|
|
59
|
+
# S3_ENDPOINT=https://nyc3.digitaloceanspaces.com
|
|
60
|
+
# S3_FORCE_PATH_STYLE=false
|
|
61
|
+
|
|
62
|
+
# ==============================================================================
|
|
63
|
+
# Development & Testing
|
|
64
|
+
# ==============================================================================
|
|
65
|
+
|
|
66
|
+
# LocalStack configuration (for local AWS testing)
|
|
67
|
+
# S3_ENDPOINT=http://localhost:4566
|
|
68
|
+
# S3_FORCE_PATH_STYLE=true
|
|
69
|
+
|
|
70
|
+
# Debug options
|
|
71
|
+
DEBUG=false
|
|
72
|
+
LOG_LEVEL=info
|
|
73
|
+
|
|
74
|
+
# ==============================================================================
|
|
75
|
+
# Example Connection Strings for Different Providers
|
|
76
|
+
# ==============================================================================
|
|
77
|
+
|
|
78
|
+
# AWS S3 (with credentials in connection string)
|
|
79
|
+
# S3DB_CONNECTION_STRING=s3://ACCESS_KEY:SECRET_KEY@bucket-name/databases/myapp
|
|
80
|
+
|
|
81
|
+
# AWS S3 (using IAM roles - no credentials needed)
|
|
82
|
+
# S3DB_CONNECTION_STRING=s3://bucket-name/databases/myapp
|
|
83
|
+
|
|
84
|
+
# MinIO local development
|
|
85
|
+
# S3DB_CONNECTION_STRING=s3://minioadmin:minioadmin@test-bucket/databases/dev?endpoint=http://localhost:9000&forcePathStyle=true
|
|
86
|
+
|
|
87
|
+
# DigitalOcean Spaces
|
|
88
|
+
# S3DB_CONNECTION_STRING=s3://DO_ACCESS_KEY:DO_SECRET_KEY@space-name/databases/prod?endpoint=https://nyc3.digitaloceanspaces.com
|
|
89
|
+
|
|
90
|
+
# LocalStack (local AWS simulation)
|
|
91
|
+
# S3DB_CONNECTION_STRING=s3://test:test@test-bucket/databases/local?endpoint=http://localhost:4566&forcePathStyle=true
|
|
92
|
+
|
|
93
|
+
# ==============================================================================
|
|
94
|
+
# Security Notes
|
|
95
|
+
# ==============================================================================
|
|
96
|
+
|
|
97
|
+
# IMPORTANT SECURITY CONSIDERATIONS:
|
|
98
|
+
# 1. Never commit real credentials to version control
|
|
99
|
+
# 2. Use IAM roles when possible instead of access keys
|
|
100
|
+
# 3. Rotate credentials regularly
|
|
101
|
+
# 4. Use least-privilege access policies
|
|
102
|
+
# 5. Enable S3 bucket encryption and versioning
|
|
103
|
+
# 6. Monitor access logs and CloudTrail events
|
|
104
|
+
# 7. Use strong passphrases for S3DB encryption
|
|
105
|
+
|
|
106
|
+
# ==============================================================================
|
|
107
|
+
# Production Recommendations
|
|
108
|
+
# ==============================================================================
|
|
109
|
+
|
|
110
|
+
# For production environments:
|
|
111
|
+
# - Use IAM roles instead of access keys when possible
|
|
112
|
+
# - Enable S3DB versioning for data protection
|
|
113
|
+
# - Use environment-specific bucket names
|
|
114
|
+
# - Enable comprehensive logging
|
|
115
|
+
# - Set up monitoring and alerting
|
|
116
|
+
# - Use encrypted connections (HTTPS)
|
|
117
|
+
# - Implement backup strategies
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
# 🚀 Claude CLI Setup Guide
|
|
2
|
+
|
|
3
|
+
Este guia mostra como configurar o S3DB MCP Server para usar com o Claude CLI.
|
|
4
|
+
|
|
5
|
+
## 📋 Pré-requisitos
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Verificar se Claude CLI está instalado
|
|
9
|
+
claude --version
|
|
10
|
+
|
|
11
|
+
# Verificar se o projeto está instalado
|
|
12
|
+
cd /home/ff/work/martech/s3db.js
|
|
13
|
+
pnpm install
|
|
14
|
+
|
|
15
|
+
# Instalar dependências do MCP (se ainda não estiver)
|
|
16
|
+
pnpm add zod@3 express
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## 🔌 Métodos de Configuração
|
|
20
|
+
|
|
21
|
+
### Método 1: Stdio Transport (Recomendado para desenvolvimento)
|
|
22
|
+
|
|
23
|
+
O Claude CLI vai spawnar o servidor automaticamente quando necessário.
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
claude mcp add s3db \
|
|
27
|
+
--transport stdio \
|
|
28
|
+
-- node /home/ff/work/martech/s3db.js/mcp/entrypoint.js --transport=stdio
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
**Variáveis de ambiente** (opcional):
|
|
32
|
+
```bash
|
|
33
|
+
# Editar configuração para adicionar env vars
|
|
34
|
+
claude mcp edit s3db
|
|
35
|
+
|
|
36
|
+
# Adicionar na seção env:
|
|
37
|
+
{
|
|
38
|
+
"s3db": {
|
|
39
|
+
"transport": "stdio",
|
|
40
|
+
"command": "node",
|
|
41
|
+
"args": ["/home/ff/work/martech/s3db.js/mcp/entrypoint.js", "--transport=stdio"],
|
|
42
|
+
"env": {
|
|
43
|
+
"S3DB_CONNECTION_STRING": "s3://minioadmin:minioadmin123@localhost:9000/dev-bucket?forcePathStyle=true",
|
|
44
|
+
"S3DB_CACHE_ENABLED": "true",
|
|
45
|
+
"S3DB_CACHE_DRIVER": "memory",
|
|
46
|
+
"S3DB_VERBOSE": "false"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Método 2: HTTP Transport (Recomendado para produção)
|
|
53
|
+
|
|
54
|
+
Primeiro, inicie o servidor em background:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
# Inicie o servidor HTTP
|
|
58
|
+
cd /home/ff/work/martech/s3db.js
|
|
59
|
+
node mcp/entrypoint.js --transport=sse &
|
|
60
|
+
|
|
61
|
+
# Ou com PM2 para auto-restart
|
|
62
|
+
pm2 start mcp/entrypoint.js --name s3db-mcp -- --transport=sse
|
|
63
|
+
pm2 save
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Depois configure o Claude CLI:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
claude mcp add s3db --transport http http://localhost:17500/sse
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## 🧪 Testando a Configuração
|
|
73
|
+
|
|
74
|
+
### 1. Verificar servidores configurados
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
claude mcp list
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Você deve ver:
|
|
81
|
+
```
|
|
82
|
+
s3db - stdio://node /home/ff/work/martech/s3db.js/mcp/entrypoint.js --transport=stdio
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### 2. Testar conexão
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
# Iniciar sessão do Claude
|
|
89
|
+
claude
|
|
90
|
+
|
|
91
|
+
# No chat, testar as tools:
|
|
92
|
+
# "Can you connect to the S3DB database and list available resources?"
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### 3. Comandos de teste no Claude Chat
|
|
96
|
+
|
|
97
|
+
```
|
|
98
|
+
1. Conectar ao banco:
|
|
99
|
+
"Connect to the S3DB database using dbConnect"
|
|
100
|
+
|
|
101
|
+
2. Listar recursos:
|
|
102
|
+
"List all resources in the database using dbListResources"
|
|
103
|
+
|
|
104
|
+
3. Criar um recurso de teste:
|
|
105
|
+
"Create a resource called 'test_users' with fields: name (string, required), email (string, required), age (number)"
|
|
106
|
+
|
|
107
|
+
4. Inserir dados:
|
|
108
|
+
"Insert a test user with name 'John Doe', email 'john@example.com', age 30"
|
|
109
|
+
|
|
110
|
+
5. Ver estatísticas:
|
|
111
|
+
"Show me database statistics including cache and costs"
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## 🔧 Configurações Avançadas
|
|
115
|
+
|
|
116
|
+
### Configurar para múltiplos ambientes
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
# Development (local MinIO)
|
|
120
|
+
claude mcp add s3db-dev \
|
|
121
|
+
--transport stdio \
|
|
122
|
+
-- node /home/ff/work/martech/s3db.js/mcp/entrypoint.js --transport=stdio
|
|
123
|
+
|
|
124
|
+
# Production (AWS S3)
|
|
125
|
+
claude mcp add s3db-prod \
|
|
126
|
+
--transport http \
|
|
127
|
+
http://production-server:17500/sse
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Editar configuração existente
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
# Ver configuração atual
|
|
134
|
+
claude mcp show s3db
|
|
135
|
+
|
|
136
|
+
# Editar configuração
|
|
137
|
+
claude mcp edit s3db
|
|
138
|
+
|
|
139
|
+
# Remover servidor
|
|
140
|
+
claude mcp remove s3db
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## 📊 Tools Disponíveis (39 total)
|
|
144
|
+
|
|
145
|
+
### 🔌 Connection Management (3)
|
|
146
|
+
- `dbConnect` - Connect to S3DB database
|
|
147
|
+
- `dbDisconnect` - Disconnect from database
|
|
148
|
+
- `dbStatus` - Get connection status
|
|
149
|
+
|
|
150
|
+
### 📦 Resource Management (2)
|
|
151
|
+
- `dbCreateResource` - Create new resource/collection
|
|
152
|
+
- `dbListResources` - List all resources
|
|
153
|
+
|
|
154
|
+
### 🔍 Debugging Tools (5)
|
|
155
|
+
- `dbInspectResource` - Detailed resource inspection
|
|
156
|
+
- `dbGetMetadata` - Get raw metadata.json
|
|
157
|
+
- `resourceValidate` - Validate data against schema
|
|
158
|
+
- `dbHealthCheck` - Comprehensive health check
|
|
159
|
+
- `resourceGetRaw` - Get raw S3 object data
|
|
160
|
+
|
|
161
|
+
### 📊 Query & Filtering (2)
|
|
162
|
+
- `resourceQuery` - Complex queries with filters
|
|
163
|
+
- `resourceSearch` - Text search in fields
|
|
164
|
+
|
|
165
|
+
### 🔧 Partition Management (4)
|
|
166
|
+
- `resourceListPartitions` - List all partitions
|
|
167
|
+
- `resourceListPartitionValues` - List partition values
|
|
168
|
+
- `dbFindOrphanedPartitions` - Find orphaned partitions
|
|
169
|
+
- `dbRemoveOrphanedPartitions` - Remove orphaned partitions
|
|
170
|
+
|
|
171
|
+
### ✏️ CRUD Operations (14)
|
|
172
|
+
- `resourceInsert` - Insert single document
|
|
173
|
+
- `resourceInsertMany` - Insert multiple documents
|
|
174
|
+
- `resourceGet` - Get document by ID
|
|
175
|
+
- `resourceGetMany` - Get multiple documents
|
|
176
|
+
- `resourceUpdate` - Update document
|
|
177
|
+
- `resourceUpsert` - Insert or update
|
|
178
|
+
- `resourceDelete` - Delete document
|
|
179
|
+
- `resourceDeleteMany` - Delete multiple documents
|
|
180
|
+
- `resourceExists` - Check if document exists
|
|
181
|
+
- `resourceList` - List with pagination
|
|
182
|
+
- `resourceListIds` - List document IDs
|
|
183
|
+
- `resourceCount` - Count documents
|
|
184
|
+
- `resourceGetAll` - Get all documents
|
|
185
|
+
- `resourceDeleteAll` - Delete all documents
|
|
186
|
+
|
|
187
|
+
### 🚀 Bulk Operations (2)
|
|
188
|
+
- `resourceUpdateMany` - Update multiple documents
|
|
189
|
+
- `resourceBulkUpsert` - Bulk upsert operation
|
|
190
|
+
|
|
191
|
+
### 💾 Export/Import (3)
|
|
192
|
+
- `resourceExport` - Export to JSON/CSV/NDJSON
|
|
193
|
+
- `resourceImport` - Import from JSON/NDJSON
|
|
194
|
+
- `dbBackupMetadata` - Backup metadata.json
|
|
195
|
+
|
|
196
|
+
### 📈 Monitoring (4)
|
|
197
|
+
- `dbGetStats` - Database statistics
|
|
198
|
+
- `dbClearCache` - Clear cache
|
|
199
|
+
- `resourceGetStats` - Resource statistics
|
|
200
|
+
- `cacheGetStats` - Cache statistics
|
|
201
|
+
|
|
202
|
+
## 🐛 Troubleshooting
|
|
203
|
+
|
|
204
|
+
### Erro: "Command not found"
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
# Usar caminho absoluto completo
|
|
208
|
+
claude mcp add s3db \
|
|
209
|
+
--transport stdio \
|
|
210
|
+
-- /home/ff/.nvm/versions/node/v22.6.0/bin/node \
|
|
211
|
+
/home/ff/work/martech/s3db.js/mcp/entrypoint.js --transport=stdio
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### Erro: "Connection refused" (HTTP)
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
# Verificar se o servidor está rodando
|
|
218
|
+
curl http://localhost:17500/health
|
|
219
|
+
|
|
220
|
+
# Se não estiver, inicie:
|
|
221
|
+
cd /home/ff/work/martech/s3db.js
|
|
222
|
+
node mcp/entrypoint.js --transport=sse
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Erro: "Database not connected"
|
|
226
|
+
|
|
227
|
+
No chat do Claude, sempre conecte primeiro:
|
|
228
|
+
```
|
|
229
|
+
"Please connect to the database first using dbConnect with connection string: s3://minioadmin:minioadmin123@localhost:9000/dev-bucket"
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### Ver logs do servidor
|
|
233
|
+
|
|
234
|
+
```bash
|
|
235
|
+
# Se usando PM2
|
|
236
|
+
pm2 logs s3db-mcp
|
|
237
|
+
|
|
238
|
+
# Se rodando diretamente
|
|
239
|
+
# Os logs aparecem no terminal onde iniciou o servidor
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
## 📚 Recursos Adicionais
|
|
243
|
+
|
|
244
|
+
- [MCP Documentation](https://modelcontextprotocol.io)
|
|
245
|
+
- [S3DB Documentation](../README.md)
|
|
246
|
+
- [Full MCP Documentation](../docs/mcp.md)
|
|
247
|
+
- [Claude CLI Documentation](https://docs.claude.com/en/docs/claude-code)
|
|
248
|
+
|
|
249
|
+
## 🎯 Exemplos de Uso
|
|
250
|
+
|
|
251
|
+
### Exemplo 1: CRUD Básico
|
|
252
|
+
|
|
253
|
+
```
|
|
254
|
+
User: Connect to local MinIO and create a users resource
|
|
255
|
+
|
|
256
|
+
Claude will:
|
|
257
|
+
1. Use dbConnect with MinIO connection string
|
|
258
|
+
2. Use dbCreateResource to create 'users' resource
|
|
259
|
+
3. Confirm creation with dbListResources
|
|
260
|
+
|
|
261
|
+
User: Insert 5 test users
|
|
262
|
+
|
|
263
|
+
Claude will:
|
|
264
|
+
1. Use resourceInsertMany with test data
|
|
265
|
+
2. Confirm with resourceCount
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
### Exemplo 2: Análise de Performance
|
|
269
|
+
|
|
270
|
+
```
|
|
271
|
+
User: Analyze database performance and suggest optimizations
|
|
272
|
+
|
|
273
|
+
Claude will:
|
|
274
|
+
1. Use dbGetStats to get overall statistics
|
|
275
|
+
2. Use cacheGetStats to check cache performance
|
|
276
|
+
3. Use dbHealthCheck to find issues
|
|
277
|
+
4. Provide optimization suggestions
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
### Exemplo 3: Partition Recovery
|
|
281
|
+
|
|
282
|
+
```
|
|
283
|
+
User: Check for orphaned partitions and fix them
|
|
284
|
+
|
|
285
|
+
Claude will:
|
|
286
|
+
1. Use dbFindOrphanedPartitions to detect issues
|
|
287
|
+
2. Use dbRemoveOrphanedPartitions with dryRun:true to preview
|
|
288
|
+
3. Execute removal with dryRun:false
|
|
289
|
+
4. Verify with dbHealthCheck
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
## ✅ Checklist de Configuração
|
|
293
|
+
|
|
294
|
+
- [ ] Claude CLI instalado e funcionando
|
|
295
|
+
- [ ] S3DB.js projeto instalado (pnpm install)
|
|
296
|
+
- [ ] Servidor MCP configurado (claude mcp add)
|
|
297
|
+
- [ ] Conexão testada (claude mcp list)
|
|
298
|
+
- [ ] Tools testadas no chat do Claude
|
|
299
|
+
- [ ] Environment variables configuradas (se necessário)
|
|
300
|
+
- [ ] Backup da configuração (claude mcp show s3db > backup.json)
|
|
301
|
+
|
|
302
|
+
Pronto! Agora você pode usar todas as 39 tools do S3DB diretamente no Claude CLI! 🎉
|
package/mcp/Dockerfile
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# syntax=docker/dockerfile:1.9
|
|
2
|
+
FROM node:20-slim
|
|
3
|
+
|
|
4
|
+
# Set working directory
|
|
5
|
+
WORKDIR /app
|
|
6
|
+
|
|
7
|
+
# Install system dependencies
|
|
8
|
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
9
|
+
curl \
|
|
10
|
+
ca-certificates \
|
|
11
|
+
&& rm -rf /var/lib/apt/lists/*
|
|
12
|
+
|
|
13
|
+
# Copy package files first for better caching
|
|
14
|
+
COPY package*.json ./
|
|
15
|
+
|
|
16
|
+
# Install dependencies
|
|
17
|
+
RUN npm ci --only=production && npm cache clean --force
|
|
18
|
+
|
|
19
|
+
# Copy application code
|
|
20
|
+
COPY s3db_mcp_server.js ./
|
|
21
|
+
|
|
22
|
+
# Create non-root user
|
|
23
|
+
RUN groupadd -r s3dbmcp && useradd -r -d /app -g s3dbmcp s3dbmcp
|
|
24
|
+
|
|
25
|
+
# Change ownership to app user
|
|
26
|
+
RUN chown -Rv s3dbmcp:s3dbmcp /app
|
|
27
|
+
|
|
28
|
+
# Switch to non-root user
|
|
29
|
+
USER s3dbmcp
|
|
30
|
+
|
|
31
|
+
# Set environment variables
|
|
32
|
+
ENV NODE_ENV=production \
|
|
33
|
+
MCP_SERVER_HOST=0.0.0.0 \
|
|
34
|
+
MCP_SERVER_PORT=8000 \
|
|
35
|
+
MCP_TRANSPORT=sse
|
|
36
|
+
|
|
37
|
+
# Expose port
|
|
38
|
+
EXPOSE 8000
|
|
39
|
+
|
|
40
|
+
# Health check
|
|
41
|
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
|
42
|
+
CMD curl -f http://localhost:8001/health || exit 1
|
|
43
|
+
|
|
44
|
+
# Default command
|
|
45
|
+
CMD ["node", "s3db_mcp_server.js", "--transport=sse"]
|