@baasix/mcp 0.1.0
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 +667 -0
- package/baasix/config.js +120 -0
- package/baasix/index.js +2694 -0
- package/package.json +59 -0
package/README.md
ADDED
|
@@ -0,0 +1,667 @@
|
|
|
1
|
+
# Baasix MCP Server
|
|
2
|
+
|
|
3
|
+
A Model Context Protocol (MCP) server that provides Claude Desktop and other MCP clients with direct access to Baasix Backend-as-a-Service operations.
|
|
4
|
+
|
|
5
|
+
**Baasix** is an open-source BaaS that generates REST APIs from data models, featuring 50+ filter operators, visual workflows, multi-tenancy, and real-time subscriptions.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **45+ MCP Tools** for comprehensive Baasix operations
|
|
10
|
+
- **Schema Management** - Create, update, delete collections and relationships
|
|
11
|
+
- **CRUD Operations** - Full item management with powerful query capabilities
|
|
12
|
+
- **50+ Filter Operators** - From basic comparison to geospatial and JSONB queries
|
|
13
|
+
- **Relations** - M2O, O2M, M2M, and polymorphic M2A relationships
|
|
14
|
+
- **Aggregation** - SUM, AVG, COUNT, MIN, MAX with groupBy
|
|
15
|
+
- **Permissions** - Role-based access control management
|
|
16
|
+
- **File Management** - Upload, list, and manage files
|
|
17
|
+
- **Authentication** - Login, register, magic links, invitations
|
|
18
|
+
- **Multi-tenancy** - Tenant management and switching
|
|
19
|
+
- **Realtime** - Enable/disable WAL-based realtime per collection
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
### 1. Install dependencies
|
|
24
|
+
```bash
|
|
25
|
+
cd mcp
|
|
26
|
+
npm install
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### 2. Configure environment
|
|
30
|
+
```bash
|
|
31
|
+
cp .env.example .env
|
|
32
|
+
# Edit .env with your Baasix server details
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### 3. Start the MCP server
|
|
36
|
+
```bash
|
|
37
|
+
npm start
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Configuration
|
|
41
|
+
|
|
42
|
+
### Environment Variables
|
|
43
|
+
|
|
44
|
+
| Variable | Required | Default | Description |
|
|
45
|
+
|----------|----------|---------|-------------|
|
|
46
|
+
| `BAASIX_URL` | Yes | `http://localhost:8056` | Baasix server URL |
|
|
47
|
+
| `BAASIX_AUTH_TOKEN` | No* | - | Pre-obtained JWT token |
|
|
48
|
+
| `BAASIX_EMAIL` | No* | - | Email for auto-authentication |
|
|
49
|
+
| `BAASIX_PASSWORD` | No* | - | Password for auto-authentication |
|
|
50
|
+
|
|
51
|
+
*Either `BAASIX_AUTH_TOKEN` OR both `BAASIX_EMAIL` and `BAASIX_PASSWORD` must be provided.
|
|
52
|
+
|
|
53
|
+
### Environment Files
|
|
54
|
+
- `.env` - Development environment (default)
|
|
55
|
+
- `.env.production` - Production environment
|
|
56
|
+
|
|
57
|
+
### Available Scripts
|
|
58
|
+
- `npm run development` - Start with development environment
|
|
59
|
+
- `npm start` - Start with production environment
|
|
60
|
+
- `npm run dev` - Development mode with auto-restart
|
|
61
|
+
- `npm test` - Run tests
|
|
62
|
+
- `npm run debug` - Start with MCP inspector for debugging
|
|
63
|
+
|
|
64
|
+
## IDE Integration
|
|
65
|
+
|
|
66
|
+
Baasix MCP Server integrates with various AI-powered development tools. Below are configuration examples for popular IDEs and tools.
|
|
67
|
+
|
|
68
|
+
### Claude Desktop
|
|
69
|
+
|
|
70
|
+
Add to your Claude Desktop configuration (`claude_desktop_config.json`):
|
|
71
|
+
|
|
72
|
+
**macOS:** `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
73
|
+
**Windows:** `%APPDATA%\Claude\claude_desktop_config.json`
|
|
74
|
+
|
|
75
|
+
```json
|
|
76
|
+
{
|
|
77
|
+
"mcpServers": {
|
|
78
|
+
"baasix": {
|
|
79
|
+
"command": "node",
|
|
80
|
+
"args": ["/path/to/baasix/mcp/server.js"],
|
|
81
|
+
"env": {
|
|
82
|
+
"BAASIX_URL": "http://localhost:8056",
|
|
83
|
+
"BAASIX_EMAIL": "admin@baasix.com",
|
|
84
|
+
"BAASIX_PASSWORD": "admin@123"
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Claude Code (Anthropic CLI)
|
|
92
|
+
|
|
93
|
+
For Claude Code CLI, create a `.mcp.json` file in your project root:
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
{
|
|
97
|
+
"mcpServers": {
|
|
98
|
+
"baasix": {
|
|
99
|
+
"command": "node",
|
|
100
|
+
"args": ["./mcp-server.js"],
|
|
101
|
+
"env": {
|
|
102
|
+
"BAASIX_URL": "http://localhost:8056",
|
|
103
|
+
"BAASIX_EMAIL": "admin@baasix.com",
|
|
104
|
+
"BAASIX_PASSWORD": "admin@123"
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Or add via CLI:
|
|
112
|
+
```bash
|
|
113
|
+
claude mcp add baasix npm run start
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### VS Code with GitHub Copilot
|
|
117
|
+
|
|
118
|
+
For VS Code with GitHub Copilot, create `.vscode/mcp.json` in your project:
|
|
119
|
+
|
|
120
|
+
```jsonc
|
|
121
|
+
{
|
|
122
|
+
"servers": {
|
|
123
|
+
"baasix": {
|
|
124
|
+
"type": "stdio",
|
|
125
|
+
"command": "node",
|
|
126
|
+
"args": ["./mcp-server.js"],
|
|
127
|
+
"env": {
|
|
128
|
+
"BAASIX_URL": "http://localhost:8056",
|
|
129
|
+
"BAASIX_EMAIL": "admin@baasix.com",
|
|
130
|
+
"BAASIX_PASSWORD": "admin@123"
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
"inputs": []
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Cursor IDE
|
|
139
|
+
|
|
140
|
+
For Cursor, add to your Cursor settings or create a project-level configuration:
|
|
141
|
+
|
|
142
|
+
```json
|
|
143
|
+
{
|
|
144
|
+
"mcpServers": {
|
|
145
|
+
"baasix": {
|
|
146
|
+
"command": "node",
|
|
147
|
+
"args": ["./mcp-server.js"],
|
|
148
|
+
"env": {
|
|
149
|
+
"BAASIX_URL": "http://localhost:8056",
|
|
150
|
+
"BAASIX_EMAIL": "admin@baasix.com",
|
|
151
|
+
"BAASIX_PASSWORD": "admin@123"
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Using the npm Package
|
|
159
|
+
|
|
160
|
+
If you're using the published npm package instead of the source:
|
|
161
|
+
|
|
162
|
+
```json
|
|
163
|
+
{
|
|
164
|
+
"mcpServers": {
|
|
165
|
+
"baasix": {
|
|
166
|
+
"command": "npx",
|
|
167
|
+
"args": ["@baasix/mcp"],
|
|
168
|
+
"env": {
|
|
169
|
+
"BAASIX_URL": "http://localhost:8056",
|
|
170
|
+
"BAASIX_EMAIL": "admin@baasix.com",
|
|
171
|
+
"BAASIX_PASSWORD": "admin@123"
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Available Tools
|
|
179
|
+
|
|
180
|
+
### Schema Management (13 tools)
|
|
181
|
+
| Tool | Description |
|
|
182
|
+
|------|-------------|
|
|
183
|
+
| `baasix_list_schemas` | List all collections with search/pagination |
|
|
184
|
+
| `baasix_get_schema` | Get detailed schema for a collection |
|
|
185
|
+
| `baasix_create_schema` | Create a new collection schema |
|
|
186
|
+
| `baasix_update_schema` | Update existing schema |
|
|
187
|
+
| `baasix_delete_schema` | Delete a collection schema |
|
|
188
|
+
| `baasix_add_index` | Add index to collection |
|
|
189
|
+
| `baasix_remove_index` | Remove index from collection |
|
|
190
|
+
| `baasix_migrate_indexes` | Add missing FK indexes to all collections |
|
|
191
|
+
| `baasix_create_relationship` | Create M2O/O2M/M2M/M2A relationship |
|
|
192
|
+
| `baasix_update_relationship` | Update existing relationship |
|
|
193
|
+
| `baasix_delete_relationship` | Delete a relationship |
|
|
194
|
+
| `baasix_export_schemas` | Export all schemas as JSON |
|
|
195
|
+
| `baasix_import_schemas` | Import schemas from JSON |
|
|
196
|
+
|
|
197
|
+
### Item Management (5 tools)
|
|
198
|
+
| Tool | Description |
|
|
199
|
+
|------|-------------|
|
|
200
|
+
| `baasix_list_items` | Query items with filters, sort, pagination |
|
|
201
|
+
| `baasix_get_item` | Get specific item by ID |
|
|
202
|
+
| `baasix_create_item` | Create new item |
|
|
203
|
+
| `baasix_update_item` | Update existing item |
|
|
204
|
+
| `baasix_delete_item` | Delete item |
|
|
205
|
+
|
|
206
|
+
### File Management (3 tools)
|
|
207
|
+
| Tool | Description |
|
|
208
|
+
|------|-------------|
|
|
209
|
+
| `baasix_list_files` | List files with metadata |
|
|
210
|
+
| `baasix_get_file_info` | Get file details |
|
|
211
|
+
| `baasix_delete_file` | Delete file |
|
|
212
|
+
|
|
213
|
+
### Authentication (10 tools)
|
|
214
|
+
| Tool | Description |
|
|
215
|
+
|------|-------------|
|
|
216
|
+
| `baasix_auth_status` | Check authentication status |
|
|
217
|
+
| `baasix_refresh_auth` | Refresh authentication token |
|
|
218
|
+
| `baasix_register_user` | Register new user |
|
|
219
|
+
| `baasix_login` | Login with email/password |
|
|
220
|
+
| `baasix_logout` | Logout current user |
|
|
221
|
+
| `baasix_get_current_user` | Get current user info |
|
|
222
|
+
| `baasix_send_invite` | Send user invitation |
|
|
223
|
+
| `baasix_verify_invite` | Verify invitation token |
|
|
224
|
+
| `baasix_send_magic_link` | Send magic link/code |
|
|
225
|
+
| `baasix_get_user_tenants` | Get user's available tenants |
|
|
226
|
+
| `baasix_switch_tenant` | Switch tenant context |
|
|
227
|
+
|
|
228
|
+
### Permissions (9 tools)
|
|
229
|
+
| Tool | Description |
|
|
230
|
+
|------|-------------|
|
|
231
|
+
| `baasix_list_roles` | List all roles |
|
|
232
|
+
| `baasix_list_permissions` | List all permissions |
|
|
233
|
+
| `baasix_get_permission` | Get permission by ID |
|
|
234
|
+
| `baasix_get_permissions` | Get permissions for a role |
|
|
235
|
+
| `baasix_create_permission` | Create new permission |
|
|
236
|
+
| `baasix_update_permission` | Update permission |
|
|
237
|
+
| `baasix_delete_permission` | Delete permission |
|
|
238
|
+
| `baasix_update_permissions` | Bulk update role permissions |
|
|
239
|
+
| `baasix_reload_permissions` | Reload permission cache |
|
|
240
|
+
|
|
241
|
+
### Reports & Analytics (2 tools)
|
|
242
|
+
| Tool | Description |
|
|
243
|
+
|------|-------------|
|
|
244
|
+
| `baasix_generate_report` | Generate reports with grouping |
|
|
245
|
+
| `baasix_collection_stats` | Get collection statistics |
|
|
246
|
+
|
|
247
|
+
### Notifications (3 tools)
|
|
248
|
+
| Tool | Description |
|
|
249
|
+
|------|-------------|
|
|
250
|
+
| `baasix_list_notifications` | List user notifications |
|
|
251
|
+
| `baasix_send_notification` | Send notification to users |
|
|
252
|
+
| `baasix_mark_notification_seen` | Mark notification as seen |
|
|
253
|
+
|
|
254
|
+
### Settings (2 tools)
|
|
255
|
+
| Tool | Description |
|
|
256
|
+
|------|-------------|
|
|
257
|
+
| `baasix_get_settings` | Get application settings |
|
|
258
|
+
| `baasix_update_settings` | Update settings |
|
|
259
|
+
|
|
260
|
+
### Realtime (5 tools)
|
|
261
|
+
| Tool | Description |
|
|
262
|
+
|------|-------------|
|
|
263
|
+
| `baasix_realtime_status` | Get realtime service status |
|
|
264
|
+
| `baasix_realtime_config` | Check PostgreSQL WAL configuration |
|
|
265
|
+
| `baasix_realtime_collections` | List collections with realtime enabled |
|
|
266
|
+
| `baasix_realtime_enable` | Enable realtime for a collection |
|
|
267
|
+
| `baasix_realtime_disable` | Disable realtime for a collection |
|
|
268
|
+
|
|
269
|
+
### Utilities (2 tools)
|
|
270
|
+
| Tool | Description |
|
|
271
|
+
|------|-------------|
|
|
272
|
+
| `baasix_server_info` | Get server health/info |
|
|
273
|
+
| `baasix_sort_items` | Reorder items in collection |
|
|
274
|
+
|
|
275
|
+
## Filter Operators Reference
|
|
276
|
+
|
|
277
|
+
When using `baasix_list_items`, the `filter` parameter supports 50+ operators:
|
|
278
|
+
|
|
279
|
+
### Comparison Operators
|
|
280
|
+
```json
|
|
281
|
+
{"field": {"eq": "value"}} // Equal
|
|
282
|
+
{"field": {"neq": "value"}} // Not equal
|
|
283
|
+
{"field": {"gt": 100}} // Greater than
|
|
284
|
+
{"field": {"gte": 100}} // Greater than or equal
|
|
285
|
+
{"field": {"lt": 100}} // Less than
|
|
286
|
+
{"field": {"lte": 100}} // Less than or equal
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### String Operators
|
|
290
|
+
```json
|
|
291
|
+
{"field": {"contains": "text"}} // Contains substring
|
|
292
|
+
{"field": {"icontains": "text"}} // Contains (case-insensitive)
|
|
293
|
+
{"field": {"startswith": "pre"}} // Starts with
|
|
294
|
+
{"field": {"istartswith": "pre"}} // Starts with (case-insensitive)
|
|
295
|
+
{"field": {"endswith": "fix"}} // Ends with
|
|
296
|
+
{"field": {"iendswith": "fix"}} // Ends with (case-insensitive)
|
|
297
|
+
{"field": {"like": "pat%tern"}} // SQL LIKE pattern
|
|
298
|
+
{"field": {"ilike": "pat%tern"}} // LIKE (case-insensitive)
|
|
299
|
+
{"field": {"regex": "^\\d+$"}} // Regular expression
|
|
300
|
+
{"field": {"iregex": "pattern"}} // Regex (case-insensitive)
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
### Null/Empty Operators
|
|
304
|
+
```json
|
|
305
|
+
{"field": {"isNull": true}} // IS NULL
|
|
306
|
+
{"field": {"isNull": false}} // IS NOT NULL
|
|
307
|
+
{"field": {"empty": true}} // Empty string or null
|
|
308
|
+
{"field": {"empty": false}} // Not empty
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### List Operators
|
|
312
|
+
```json
|
|
313
|
+
{"field": {"in": ["a", "b", "c"]}} // In list
|
|
314
|
+
{"field": {"nin": ["x", "y"]}} // Not in list
|
|
315
|
+
{"field": {"between": [10, 100]}} // Between range
|
|
316
|
+
{"field": {"nbetween": [10, 100]}} // Not between
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
### Array Operators
|
|
320
|
+
```json
|
|
321
|
+
{"tags": {"arraycontains": ["a", "b"]}} // Contains all elements
|
|
322
|
+
{"tags": {"arraycontainsany": ["a", "b"]}} // Contains any element
|
|
323
|
+
{"tags": {"arraylength": 3}} // Array has exact length
|
|
324
|
+
{"tags": {"arrayempty": true}} // Array is empty
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### JSONB Operators (PostgreSQL)
|
|
328
|
+
```json
|
|
329
|
+
{"meta": {"jsoncontains": {"key": "val"}}} // JSON contains
|
|
330
|
+
{"meta": {"jsoncontainedby": {"a": 1}}} // JSON contained by
|
|
331
|
+
{"meta": {"jsonhaskey": "key"}} // Has key
|
|
332
|
+
{"meta": {"jsonhasanykeys": ["a", "b"]}} // Has any keys
|
|
333
|
+
{"meta": {"jsonhasallkeys": ["a", "b"]}} // Has all keys
|
|
334
|
+
{"meta": {"jsonpath": "$.store.book[0].title"}} // JSONPath query
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
### Geospatial Operators (PostGIS)
|
|
338
|
+
```json
|
|
339
|
+
{"location": {"dwithin": {"geometry": {"type": "Point", "coordinates": [-73.9, 40.7]}, "distance": 5000}}}
|
|
340
|
+
{"location": {"intersects": {"type": "Polygon", "coordinates": [...]}}}
|
|
341
|
+
{"location": {"contains": {"type": "Point", "coordinates": [...]}}}
|
|
342
|
+
{"location": {"within": {"type": "Polygon", "coordinates": [...]}}}
|
|
343
|
+
{"location": {"overlaps": {"type": "Polygon", "coordinates": [...]}}}
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
### Logical Operators
|
|
347
|
+
```json
|
|
348
|
+
{"AND": [{"status": {"eq": "active"}}, {"price": {"lt": 100}}]}
|
|
349
|
+
{"OR": [{"type": {"eq": "A"}}, {"type": {"eq": "B"}}]}
|
|
350
|
+
{"NOT": {"deleted": {"eq": true}}}
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
### Dynamic Variables
|
|
354
|
+
```json
|
|
355
|
+
{"author_Id": {"eq": "$CURRENT_USER"}} // Current user's ID
|
|
356
|
+
{"createdAt": {"gte": "$NOW"}} // Current timestamp
|
|
357
|
+
{"createdAt": {"gte": "$NOW-DAYS_7"}} // 7 days ago
|
|
358
|
+
{"dueDate": {"lte": "$NOW+MONTHS_1"}} // 1 month from now
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
### Relation Filtering
|
|
362
|
+
```json
|
|
363
|
+
// Filter by related collection fields
|
|
364
|
+
{"category.name": {"eq": "Electronics"}}
|
|
365
|
+
{"author.role.name": {"eq": "admin"}}
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
## Query Parameters for baasix_list_items
|
|
369
|
+
|
|
370
|
+
```javascript
|
|
371
|
+
{
|
|
372
|
+
collection: "products", // Required: collection name
|
|
373
|
+
filter: {...}, // Filter object (see above)
|
|
374
|
+
sort: "createdAt:desc", // Sort: "field:asc" or "field:desc"
|
|
375
|
+
page: 1, // Page number
|
|
376
|
+
limit: 10, // Items per page (-1 for all)
|
|
377
|
+
fields: ["*", "category.*"], // Fields to include (* for all)
|
|
378
|
+
search: "keyword", // Full-text search
|
|
379
|
+
searchFields: ["name", "desc"], // Fields to search in
|
|
380
|
+
aggregate: { // Aggregation functions
|
|
381
|
+
total: {function: "sum", field: "price"},
|
|
382
|
+
count: {function: "count", field: "id"}
|
|
383
|
+
},
|
|
384
|
+
groupBy: ["category_Id"], // Group by fields
|
|
385
|
+
relConditions: { // Filter related records
|
|
386
|
+
"reviews": {"approved": {"eq": true}}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
## Schema Definition Example
|
|
392
|
+
|
|
393
|
+
When using `baasix_create_schema`:
|
|
394
|
+
|
|
395
|
+
```javascript
|
|
396
|
+
{
|
|
397
|
+
collection: "products",
|
|
398
|
+
schema: {
|
|
399
|
+
name: "Product",
|
|
400
|
+
timestamps: true, // Adds createdAt, updatedAt
|
|
401
|
+
paranoid: false, // Set true for soft deletes
|
|
402
|
+
fields: {
|
|
403
|
+
id: {
|
|
404
|
+
type: "UUID",
|
|
405
|
+
primaryKey: true,
|
|
406
|
+
defaultValue: {type: "UUIDV4"}
|
|
407
|
+
},
|
|
408
|
+
sku: {
|
|
409
|
+
type: "SUID",
|
|
410
|
+
unique: true,
|
|
411
|
+
defaultValue: {type: "SUID"}
|
|
412
|
+
},
|
|
413
|
+
name: {
|
|
414
|
+
type: "String",
|
|
415
|
+
allowNull: false,
|
|
416
|
+
values: {length: 255},
|
|
417
|
+
validate: {notEmpty: true, len: [3, 255]}
|
|
418
|
+
},
|
|
419
|
+
price: {
|
|
420
|
+
type: "Decimal",
|
|
421
|
+
values: {precision: 10, scale: 2},
|
|
422
|
+
defaultValue: 0.00,
|
|
423
|
+
validate: {min: 0, max: 999999.99}
|
|
424
|
+
},
|
|
425
|
+
quantity: {
|
|
426
|
+
type: "Integer",
|
|
427
|
+
defaultValue: 0,
|
|
428
|
+
validate: {isInt: true, min: 0}
|
|
429
|
+
},
|
|
430
|
+
email: {
|
|
431
|
+
type: "String",
|
|
432
|
+
validate: {isEmail: true}
|
|
433
|
+
},
|
|
434
|
+
tags: {
|
|
435
|
+
type: "Array",
|
|
436
|
+
values: {type: "String"},
|
|
437
|
+
defaultValue: []
|
|
438
|
+
},
|
|
439
|
+
metadata: {
|
|
440
|
+
type: "JSONB",
|
|
441
|
+
defaultValue: {}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
### Field Validation Rules
|
|
449
|
+
|
|
450
|
+
| Rule | Type | Description |
|
|
451
|
+
|------|------|-------------|
|
|
452
|
+
| `min` | number | Minimum value for numeric fields |
|
|
453
|
+
| `max` | number | Maximum value for numeric fields |
|
|
454
|
+
| `isInt` | boolean | Validate as integer |
|
|
455
|
+
| `notEmpty` | boolean | String cannot be empty |
|
|
456
|
+
| `isEmail` | boolean | Valid email format |
|
|
457
|
+
| `isUrl` | boolean | Valid URL format |
|
|
458
|
+
| `len` | [min, max] | String length range |
|
|
459
|
+
| `is` / `matches` | regex | Pattern matching |
|
|
460
|
+
|
|
461
|
+
```javascript
|
|
462
|
+
// Validation examples
|
|
463
|
+
{
|
|
464
|
+
"email": {
|
|
465
|
+
"type": "String",
|
|
466
|
+
"validate": {"isEmail": true, "notEmpty": true}
|
|
467
|
+
},
|
|
468
|
+
"age": {
|
|
469
|
+
"type": "Integer",
|
|
470
|
+
"validate": {"isInt": true, "min": 0, "max": 120}
|
|
471
|
+
},
|
|
472
|
+
"username": {
|
|
473
|
+
"type": "String",
|
|
474
|
+
"validate": {"notEmpty": true, "len": [3, 50]}
|
|
475
|
+
},
|
|
476
|
+
"phone": {
|
|
477
|
+
"type": "String",
|
|
478
|
+
"validate": {"matches": "^\\+?[1-9]\\d{1,14}$"}
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
### Default Value Types
|
|
484
|
+
|
|
485
|
+
| Type | Description |
|
|
486
|
+
|------|-------------|
|
|
487
|
+
| `UUIDV4` | Random UUID v4 |
|
|
488
|
+
| `SUID` | Short unique ID (compact, URL-safe) |
|
|
489
|
+
| `NOW` | Current timestamp |
|
|
490
|
+
| `AUTOINCREMENT` | Auto-incrementing integer |
|
|
491
|
+
| `SQL` | Custom SQL expression |
|
|
492
|
+
| Static | Any constant value (`"active"`, `false`, `0`) |
|
|
493
|
+
|
|
494
|
+
```javascript
|
|
495
|
+
// Default value examples
|
|
496
|
+
{
|
|
497
|
+
"id": {"type": "UUID", "defaultValue": {"type": "UUIDV4"}},
|
|
498
|
+
"shortCode": {"type": "SUID", "defaultValue": {"type": "SUID"}},
|
|
499
|
+
"createdAt": {"type": "DateTime", "defaultValue": {"type": "NOW"}},
|
|
500
|
+
"orderNum": {"type": "Integer", "defaultValue": {"type": "AUTOINCREMENT"}},
|
|
501
|
+
"sortOrder": {"type": "Integer", "defaultValue": {"type": "SQL", "value": "(SELECT MAX(sort)+1 FROM items)"}},
|
|
502
|
+
"status": {"type": "String", "defaultValue": "pending"},
|
|
503
|
+
"isActive": {"type": "Boolean", "defaultValue": true}
|
|
504
|
+
}
|
|
505
|
+
```
|
|
506
|
+
|
|
507
|
+
### Supported Field Types
|
|
508
|
+
- **String**: `values: {length: 255}` for VARCHAR
|
|
509
|
+
- **Text**: Unlimited length text
|
|
510
|
+
- **Integer**, **BigInt**: Whole numbers
|
|
511
|
+
- **Decimal**: `values: {precision: 10, scale: 2}`
|
|
512
|
+
- **Float**, **Real**, **Double**: Floating point
|
|
513
|
+
- **Boolean**: true/false
|
|
514
|
+
- **Date**, **DateTime**, **Time**: Date/time values
|
|
515
|
+
- **UUID**: `defaultValue: {type: "UUIDV4"}`
|
|
516
|
+
- **SUID**: `defaultValue: {type: "SUID"}` - Short unique ID
|
|
517
|
+
- **JSONB**: JSON with indexing
|
|
518
|
+
- **Array**: `values: {type: "String|Integer|etc"}`
|
|
519
|
+
- **Geometry**, **Geography**: PostGIS spatial types
|
|
520
|
+
- **Enum**: `values: {values: ["A", "B", "C"]}`
|
|
521
|
+
|
|
522
|
+
## Relationship Types
|
|
523
|
+
|
|
524
|
+
When using `baasix_create_relationship`:
|
|
525
|
+
|
|
526
|
+
```javascript
|
|
527
|
+
// Many-to-One (products.category_Id → categories.id)
|
|
528
|
+
{
|
|
529
|
+
sourceCollection: "products",
|
|
530
|
+
relationshipData: {
|
|
531
|
+
type: "M2O",
|
|
532
|
+
name: "category", // Creates category_Id field
|
|
533
|
+
target: "categories",
|
|
534
|
+
alias: "products" // Reverse relation name
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
// Many-to-Many (products ↔ tags)
|
|
539
|
+
// Auto-generates junction table: products_tags_tags_junction
|
|
540
|
+
{
|
|
541
|
+
sourceCollection: "products",
|
|
542
|
+
relationshipData: {
|
|
543
|
+
type: "M2M",
|
|
544
|
+
name: "tags",
|
|
545
|
+
target: "tags",
|
|
546
|
+
alias: "products"
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
// Many-to-Many with custom junction table name
|
|
551
|
+
// Useful when auto-generated name exceeds PostgreSQL's 63 char limit
|
|
552
|
+
{
|
|
553
|
+
sourceCollection: "products",
|
|
554
|
+
relationshipData: {
|
|
555
|
+
type: "M2M",
|
|
556
|
+
name: "tags",
|
|
557
|
+
target: "tags",
|
|
558
|
+
alias: "products",
|
|
559
|
+
through: "product_tags" // Custom junction table name (max 63 chars)
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
// Many-to-Any (polymorphic - comments can belong to posts OR products)
|
|
564
|
+
{
|
|
565
|
+
sourceCollection: "comments",
|
|
566
|
+
relationshipData: {
|
|
567
|
+
type: "M2A",
|
|
568
|
+
name: "commentable",
|
|
569
|
+
tables: ["posts", "products"],
|
|
570
|
+
alias: "comments",
|
|
571
|
+
through: "comment_refs" // Optional custom junction table name
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
```
|
|
575
|
+
|
|
576
|
+
### Junction Tables (M2M/M2A)
|
|
577
|
+
|
|
578
|
+
- **Auto-generated name**: `{source}_{target}_{name}_junction`
|
|
579
|
+
- **Custom name**: Use `through` property (max 63 characters for PostgreSQL)
|
|
580
|
+
- **Schema property**: Junction tables have `isJunction: true` in their schema definition
|
|
581
|
+
- **Auto-indexed**: Foreign key columns are automatically indexed for better query performance
|
|
582
|
+
|
|
583
|
+
## Permission Structure
|
|
584
|
+
|
|
585
|
+
When using `baasix_create_permission`:
|
|
586
|
+
|
|
587
|
+
```javascript
|
|
588
|
+
{
|
|
589
|
+
role_Id: "uuid-of-role",
|
|
590
|
+
collection: "products",
|
|
591
|
+
action: "read", // read, create, update, delete
|
|
592
|
+
fields: ["*"], // Or specific: ["name", "price"]
|
|
593
|
+
conditions: { // Row-level security
|
|
594
|
+
"published": {"eq": true}
|
|
595
|
+
},
|
|
596
|
+
relConditions: { // Filter related data
|
|
597
|
+
"reviews": {"approved": {"eq": true}}
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
```
|
|
601
|
+
|
|
602
|
+
## Package Usage
|
|
603
|
+
|
|
604
|
+
### Installation
|
|
605
|
+
```bash
|
|
606
|
+
npm install @baasix/mcp
|
|
607
|
+
```
|
|
608
|
+
|
|
609
|
+
### Usage
|
|
610
|
+
```javascript
|
|
611
|
+
import { startMCPServer } from '@baasix/mcp';
|
|
612
|
+
|
|
613
|
+
startMCPServer().catch((error) => {
|
|
614
|
+
console.error('Failed to start MCP server:', error);
|
|
615
|
+
process.exit(1);
|
|
616
|
+
});
|
|
617
|
+
```
|
|
618
|
+
|
|
619
|
+
### Custom Server Instance
|
|
620
|
+
```javascript
|
|
621
|
+
import { BaasixMCPServer } from '@baasix/mcp';
|
|
622
|
+
|
|
623
|
+
const server = new BaasixMCPServer();
|
|
624
|
+
server.run().catch(console.error);
|
|
625
|
+
```
|
|
626
|
+
|
|
627
|
+
## Claude Code CLI Commands
|
|
628
|
+
|
|
629
|
+
```bash
|
|
630
|
+
# Add MCP server
|
|
631
|
+
claude mcp add baasix npm run start
|
|
632
|
+
|
|
633
|
+
# Remove MCP server
|
|
634
|
+
claude mcp remove baasix
|
|
635
|
+
```
|
|
636
|
+
|
|
637
|
+
## File Structure
|
|
638
|
+
|
|
639
|
+
```
|
|
640
|
+
mcp/
|
|
641
|
+
├── server.js # Entry point
|
|
642
|
+
├── package.json # Dependencies and scripts
|
|
643
|
+
├── .env # Development config
|
|
644
|
+
├── .env.example # Template
|
|
645
|
+
├── .env.production # Production config
|
|
646
|
+
├── README.md # This file
|
|
647
|
+
└── baasix/
|
|
648
|
+
├── index.js # MCP server implementation
|
|
649
|
+
└── config.js # Configuration management
|
|
650
|
+
```
|
|
651
|
+
|
|
652
|
+
## Requirements
|
|
653
|
+
|
|
654
|
+
- Node.js 18+
|
|
655
|
+
- Baasix server running (v0.1.0-alpha.2+)
|
|
656
|
+
- PostgreSQL 14+ (with PostGIS for geospatial)
|
|
657
|
+
|
|
658
|
+
## Links
|
|
659
|
+
|
|
660
|
+
- **Baasix Website**: https://baasix.dev
|
|
661
|
+
- **Documentation**: https://baasix.dev/docs
|
|
662
|
+
- **GitHub**: https://github.com/baasix/baasix
|
|
663
|
+
- **npm Package**: https://www.npmjs.com/package/@baasix/baasix
|
|
664
|
+
|
|
665
|
+
## License
|
|
666
|
+
|
|
667
|
+
MIT
|