@fadlee/pocketbase-mcp 1.0.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.
Files changed (55) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +123 -0
  3. package/build/src/config/cli.d.ts +9 -0
  4. package/build/src/config/cli.js +31 -0
  5. package/build/src/config/environment.d.ts +9 -0
  6. package/build/src/config/environment.js +13 -0
  7. package/build/src/config/index.d.ts +13 -0
  8. package/build/src/config/index.js +20 -0
  9. package/build/src/index.d.ts +2 -0
  10. package/build/src/index.js +21 -0
  11. package/build/src/server.d.ts +10 -0
  12. package/build/src/server.js +211 -0
  13. package/build/src/tools/handlers/analysis.d.ts +10 -0
  14. package/build/src/tools/handlers/analysis.js +127 -0
  15. package/build/src/tools/handlers/auth.d.ts +10 -0
  16. package/build/src/tools/handlers/auth.js +51 -0
  17. package/build/src/tools/handlers/collection.d.ts +22 -0
  18. package/build/src/tools/handlers/collection.js +82 -0
  19. package/build/src/tools/handlers/file.d.ts +5 -0
  20. package/build/src/tools/handlers/file.js +124 -0
  21. package/build/src/tools/handlers/generation.d.ts +10 -0
  22. package/build/src/tools/handlers/generation.js +201 -0
  23. package/build/src/tools/handlers/index.d.ts +10 -0
  24. package/build/src/tools/handlers/index.js +17 -0
  25. package/build/src/tools/handlers/migration.d.ts +18 -0
  26. package/build/src/tools/handlers/migration.js +219 -0
  27. package/build/src/tools/handlers/record.d.ts +18 -0
  28. package/build/src/tools/handlers/record.js +94 -0
  29. package/build/src/tools/index.d.ts +5 -0
  30. package/build/src/tools/index.js +7 -0
  31. package/build/src/tools/schemas/analysis.d.ts +56 -0
  32. package/build/src/tools/schemas/analysis.js +54 -0
  33. package/build/src/tools/schemas/auth.d.ts +59 -0
  34. package/build/src/tools/schemas/auth.js +59 -0
  35. package/build/src/tools/schemas/collection.d.ts +192 -0
  36. package/build/src/tools/schemas/collection.js +194 -0
  37. package/build/src/tools/schemas/file.d.ts +70 -0
  38. package/build/src/tools/schemas/file.js +70 -0
  39. package/build/src/tools/schemas/generation.d.ts +49 -0
  40. package/build/src/tools/schemas/generation.js +49 -0
  41. package/build/src/tools/schemas/index.d.ts +10 -0
  42. package/build/src/tools/schemas/index.js +17 -0
  43. package/build/src/tools/schemas/migration.d.ts +133 -0
  44. package/build/src/tools/schemas/migration.js +146 -0
  45. package/build/src/tools/schemas/record.d.ts +103 -0
  46. package/build/src/tools/schemas/record.js +103 -0
  47. package/build/src/types/index.d.ts +188 -0
  48. package/build/src/types/index.js +1 -0
  49. package/build/src/utils/errors.d.ts +17 -0
  50. package/build/src/utils/errors.js +35 -0
  51. package/build/src/utils/response.d.ts +23 -0
  52. package/build/src/utils/response.js +62 -0
  53. package/build/src/utils/typescript.d.ts +24 -0
  54. package/build/src/utils/typescript.js +130 -0
  55. package/package.json +57 -0
@@ -0,0 +1,133 @@
1
+ /**
2
+ * Tool input schemas for migration and backup operations
3
+ */
4
+ export declare const migrateCollectionSchema: {
5
+ type: string;
6
+ properties: {
7
+ collection: {
8
+ type: string;
9
+ description: string;
10
+ };
11
+ fields: {
12
+ type: string;
13
+ description: string;
14
+ items: {
15
+ type: string;
16
+ properties: {
17
+ name: {
18
+ type: string;
19
+ description: string;
20
+ };
21
+ type: {
22
+ type: string;
23
+ description: string;
24
+ enum: string[];
25
+ };
26
+ required: {
27
+ type: string;
28
+ description: string;
29
+ };
30
+ options: {
31
+ type: string;
32
+ description: string;
33
+ };
34
+ };
35
+ required: string[];
36
+ };
37
+ };
38
+ dataTransforms: {
39
+ type: string;
40
+ description: string;
41
+ };
42
+ name: {
43
+ type: string;
44
+ description: string;
45
+ };
46
+ listRule: {
47
+ type: string;
48
+ description: string;
49
+ };
50
+ viewRule: {
51
+ type: string;
52
+ description: string;
53
+ };
54
+ createRule: {
55
+ type: string;
56
+ description: string;
57
+ };
58
+ updateRule: {
59
+ type: string;
60
+ description: string;
61
+ };
62
+ deleteRule: {
63
+ type: string;
64
+ description: string;
65
+ };
66
+ };
67
+ required: string[];
68
+ };
69
+ export declare const backupDatabaseSchema: {
70
+ type: string;
71
+ properties: {
72
+ format: {
73
+ type: string;
74
+ enum: string[];
75
+ description: string;
76
+ };
77
+ };
78
+ };
79
+ export declare const importDataSchema: {
80
+ type: string;
81
+ properties: {
82
+ collection: {
83
+ type: string;
84
+ description: string;
85
+ };
86
+ data: {
87
+ type: string;
88
+ description: string;
89
+ items: {
90
+ type: string;
91
+ };
92
+ };
93
+ mode: {
94
+ type: string;
95
+ enum: string[];
96
+ description: string;
97
+ };
98
+ };
99
+ required: string[];
100
+ };
101
+ export declare const manageIndexesSchema: {
102
+ type: string;
103
+ properties: {
104
+ collection: {
105
+ type: string;
106
+ description: string;
107
+ };
108
+ action: {
109
+ type: string;
110
+ enum: string[];
111
+ description: string;
112
+ };
113
+ index: {
114
+ type: string;
115
+ description: string;
116
+ properties: {
117
+ name: {
118
+ type: string;
119
+ };
120
+ fields: {
121
+ type: string;
122
+ items: {
123
+ type: string;
124
+ };
125
+ };
126
+ unique: {
127
+ type: string;
128
+ };
129
+ };
130
+ };
131
+ };
132
+ required: string[];
133
+ };
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Tool input schemas for migration and backup operations
3
+ */
4
+ export const migrateCollectionSchema = {
5
+ type: "object",
6
+ properties: {
7
+ collection: {
8
+ type: "string",
9
+ description: "Collection name",
10
+ },
11
+ fields: {
12
+ type: "array",
13
+ description: "New collection fields configuration",
14
+ items: {
15
+ type: "object",
16
+ properties: {
17
+ name: {
18
+ type: "string",
19
+ description: "Field name",
20
+ },
21
+ type: {
22
+ type: "string",
23
+ description: "Field type",
24
+ enum: [
25
+ "text",
26
+ "number",
27
+ "bool",
28
+ "email",
29
+ "url",
30
+ "date",
31
+ "select",
32
+ "relation",
33
+ "file",
34
+ "json",
35
+ "editor",
36
+ "autodate",
37
+ ],
38
+ },
39
+ required: {
40
+ type: "boolean",
41
+ description: "Whether the field is required",
42
+ },
43
+ options: {
44
+ type: "object",
45
+ description: "Field-specific options",
46
+ },
47
+ },
48
+ required: ["name", "type"],
49
+ },
50
+ },
51
+ dataTransforms: {
52
+ type: "object",
53
+ description: "Field transformation mappings for converting old field values to new ones",
54
+ },
55
+ name: {
56
+ type: "string",
57
+ description: "Optional new collection name if you want to rename the collection",
58
+ },
59
+ listRule: {
60
+ type: "string",
61
+ description: "Optional new rule for listing records",
62
+ },
63
+ viewRule: {
64
+ type: "string",
65
+ description: "Optional new rule for viewing records",
66
+ },
67
+ createRule: {
68
+ type: "string",
69
+ description: "Optional new rule for creating records",
70
+ },
71
+ updateRule: {
72
+ type: "string",
73
+ description: "Optional new rule for updating records",
74
+ },
75
+ deleteRule: {
76
+ type: "string",
77
+ description: "Optional new rule for deleting records",
78
+ },
79
+ },
80
+ required: ["collection", "fields"],
81
+ };
82
+ export const backupDatabaseSchema = {
83
+ type: "object",
84
+ properties: {
85
+ format: {
86
+ type: "string",
87
+ enum: ["json", "csv"],
88
+ description: "Export format (default: json)",
89
+ },
90
+ },
91
+ };
92
+ export const importDataSchema = {
93
+ type: "object",
94
+ properties: {
95
+ collection: {
96
+ type: "string",
97
+ description: "Collection name",
98
+ },
99
+ data: {
100
+ type: "array",
101
+ description: "Array of records to import",
102
+ items: {
103
+ type: "object",
104
+ },
105
+ },
106
+ mode: {
107
+ type: "string",
108
+ enum: ["create", "update", "upsert"],
109
+ description: "Import mode (default: create)",
110
+ },
111
+ },
112
+ required: ["collection", "data"],
113
+ };
114
+ export const manageIndexesSchema = {
115
+ type: "object",
116
+ properties: {
117
+ collection: {
118
+ type: "string",
119
+ description: "Collection name",
120
+ },
121
+ action: {
122
+ type: "string",
123
+ enum: ["create", "delete", "list"],
124
+ description: "Action to perform",
125
+ },
126
+ index: {
127
+ type: "object",
128
+ description: "Index configuration (for create)",
129
+ properties: {
130
+ name: {
131
+ type: "string",
132
+ },
133
+ fields: {
134
+ type: "array",
135
+ items: {
136
+ type: "string",
137
+ },
138
+ },
139
+ unique: {
140
+ type: "boolean",
141
+ },
142
+ },
143
+ },
144
+ },
145
+ required: ["collection", "action"],
146
+ };
@@ -0,0 +1,103 @@
1
+ /**
2
+ * Tool input schemas for record-related operations
3
+ */
4
+ export declare const createRecordSchema: {
5
+ type: string;
6
+ properties: {
7
+ collection: {
8
+ type: string;
9
+ description: string;
10
+ };
11
+ data: {
12
+ type: string;
13
+ description: string;
14
+ };
15
+ expand: {
16
+ type: string;
17
+ description: string;
18
+ };
19
+ fields: {
20
+ type: string;
21
+ description: string;
22
+ };
23
+ };
24
+ required: string[];
25
+ };
26
+ export declare const listRecordsSchema: {
27
+ type: string;
28
+ properties: {
29
+ collection: {
30
+ type: string;
31
+ description: string;
32
+ };
33
+ filter: {
34
+ type: string;
35
+ description: string;
36
+ };
37
+ sort: {
38
+ type: string;
39
+ description: string;
40
+ };
41
+ page: {
42
+ type: string;
43
+ description: string;
44
+ };
45
+ perPage: {
46
+ type: string;
47
+ description: string;
48
+ };
49
+ expand: {
50
+ type: string;
51
+ description: string;
52
+ };
53
+ fields: {
54
+ type: string;
55
+ description: string;
56
+ };
57
+ skipTotal: {
58
+ type: string;
59
+ description: string;
60
+ };
61
+ };
62
+ required: string[];
63
+ };
64
+ export declare const updateRecordSchema: {
65
+ type: string;
66
+ properties: {
67
+ collection: {
68
+ type: string;
69
+ description: string;
70
+ };
71
+ id: {
72
+ type: string;
73
+ description: string;
74
+ };
75
+ data: {
76
+ type: string;
77
+ description: string;
78
+ };
79
+ expand: {
80
+ type: string;
81
+ description: string;
82
+ };
83
+ fields: {
84
+ type: string;
85
+ description: string;
86
+ };
87
+ };
88
+ required: string[];
89
+ };
90
+ export declare const deleteRecordSchema: {
91
+ type: string;
92
+ properties: {
93
+ collection: {
94
+ type: string;
95
+ description: string;
96
+ };
97
+ id: {
98
+ type: string;
99
+ description: string;
100
+ };
101
+ };
102
+ required: string[];
103
+ };
@@ -0,0 +1,103 @@
1
+ /**
2
+ * Tool input schemas for record-related operations
3
+ */
4
+ export const createRecordSchema = {
5
+ type: "object",
6
+ properties: {
7
+ collection: {
8
+ type: "string",
9
+ description: "Collection name",
10
+ },
11
+ data: {
12
+ type: "object",
13
+ description: "Record data with field values matching the collection schema",
14
+ },
15
+ expand: {
16
+ type: "string",
17
+ description: "Comma-separated list of relation fields to expand in the response (e.g. 'author,comments.user')",
18
+ },
19
+ fields: {
20
+ type: "string",
21
+ description: "Comma-separated fields to return in the response (e.g. 'id,title,author')",
22
+ },
23
+ },
24
+ required: ["collection", "data"],
25
+ };
26
+ export const listRecordsSchema = {
27
+ type: "object",
28
+ properties: {
29
+ collection: {
30
+ type: "string",
31
+ description: "Collection name",
32
+ },
33
+ filter: {
34
+ type: "string",
35
+ description: "Filter query using PocketBase filter syntax (e.g. 'status = true && created > \"2022-08-01 10:00:00\"')",
36
+ },
37
+ sort: {
38
+ type: "string",
39
+ description: "Sort field and direction (e.g. '-created,title' for descending created date followed by ascending title)",
40
+ },
41
+ page: {
42
+ type: "number",
43
+ description: "Page number for pagination (default: 1)",
44
+ },
45
+ perPage: {
46
+ type: "number",
47
+ description: "Items per page (default: 50, max: 500)",
48
+ },
49
+ expand: {
50
+ type: "string",
51
+ description: "Comma-separated list of relation fields to expand (e.g. 'author,comments.user')",
52
+ },
53
+ fields: {
54
+ type: "string",
55
+ description: "Comma-separated fields to return in the response (e.g. 'id,title,author')",
56
+ },
57
+ skipTotal: {
58
+ type: "boolean",
59
+ description: "If set to true, the total count query will be skipped to improve performance",
60
+ },
61
+ },
62
+ required: ["collection"],
63
+ };
64
+ export const updateRecordSchema = {
65
+ type: "object",
66
+ properties: {
67
+ collection: {
68
+ type: "string",
69
+ description: "Collection name",
70
+ },
71
+ id: {
72
+ type: "string",
73
+ description: "Record ID",
74
+ },
75
+ data: {
76
+ type: "object",
77
+ description: "Updated record data with field values matching the collection schema. Can use field modifiers like fieldName+, +fieldName, fieldName-.",
78
+ },
79
+ expand: {
80
+ type: "string",
81
+ description: "Comma-separated list of relation fields to expand in the response (e.g. 'author,comments.user')",
82
+ },
83
+ fields: {
84
+ type: "string",
85
+ description: "Comma-separated fields to return in the response (e.g. 'id,title,author')",
86
+ },
87
+ },
88
+ required: ["collection", "id", "data"],
89
+ };
90
+ export const deleteRecordSchema = {
91
+ type: "object",
92
+ properties: {
93
+ collection: {
94
+ type: "string",
95
+ description: "Collection name",
96
+ },
97
+ id: {
98
+ type: "string",
99
+ description: "Record ID",
100
+ },
101
+ },
102
+ required: ["collection", "id"],
103
+ };
@@ -0,0 +1,188 @@
1
+ import type { CollectionModel, CollectionField } from "pocketbase";
2
+ declare module "pocketbase" {
3
+ interface PocketBase {
4
+ admins: {
5
+ authWithPassword(email: string, password: string): Promise<any>;
6
+ };
7
+ }
8
+ }
9
+ export type ToolHandler = (args: any) => Promise<ToolResponse>;
10
+ export interface ToolResponse {
11
+ content: Array<{
12
+ type: string;
13
+ text: string;
14
+ }>;
15
+ }
16
+ export interface CollectionFieldConfig {
17
+ name: string;
18
+ type: string;
19
+ required?: boolean;
20
+ system?: boolean;
21
+ unique?: boolean;
22
+ min?: number;
23
+ max?: number;
24
+ pattern?: string;
25
+ autogeneratePattern?: string;
26
+ collectionId?: string;
27
+ cascadeDelete?: boolean;
28
+ maxSelect?: number;
29
+ onCreate?: boolean;
30
+ onUpdate?: boolean;
31
+ presentable?: boolean;
32
+ hidden?: boolean;
33
+ values?: string[];
34
+ id?: string;
35
+ }
36
+ export interface CreateCollectionArgs {
37
+ name: string;
38
+ type?: "base" | "auth" | "view";
39
+ fields: CollectionFieldConfig[];
40
+ listRule?: string;
41
+ viewRule?: string;
42
+ createRule?: string;
43
+ updateRule?: string;
44
+ deleteRule?: string;
45
+ indexes?: string[];
46
+ viewQuery?: string;
47
+ passwordAuth?: {
48
+ enabled: boolean;
49
+ identityFields: string[];
50
+ };
51
+ }
52
+ export interface UpdateCollectionArgs {
53
+ collection: string;
54
+ name?: string;
55
+ type?: "base" | "auth" | "view";
56
+ fields?: CollectionFieldConfig[];
57
+ listRule?: string;
58
+ viewRule?: string;
59
+ createRule?: string;
60
+ updateRule?: string;
61
+ deleteRule?: string;
62
+ indexes?: string[];
63
+ viewQuery?: string;
64
+ passwordAuth?: {
65
+ enabled: boolean;
66
+ identityFields: string[];
67
+ };
68
+ }
69
+ export interface TruncateCollectionArgs {
70
+ collection: string;
71
+ }
72
+ export interface CreateRecordArgs {
73
+ collection: string;
74
+ data: Record<string, any>;
75
+ expand?: string;
76
+ fields?: string;
77
+ }
78
+ export interface ListRecordsArgs {
79
+ collection: string;
80
+ filter?: string;
81
+ sort?: string;
82
+ page?: number;
83
+ perPage?: number;
84
+ expand?: string;
85
+ fields?: string;
86
+ skipTotal?: boolean;
87
+ }
88
+ export interface UpdateRecordArgs {
89
+ collection: string;
90
+ id: string;
91
+ data: Record<string, any>;
92
+ expand?: string;
93
+ fields?: string;
94
+ }
95
+ export interface DeleteRecordArgs {
96
+ collection: string;
97
+ id: string;
98
+ }
99
+ export interface AuthenticateUserArgs {
100
+ collection?: string;
101
+ email: string;
102
+ password: string;
103
+ autoRefreshThreshold?: number;
104
+ }
105
+ export interface CreateUserArgs {
106
+ collection?: string;
107
+ email: string;
108
+ password: string;
109
+ passwordConfirm: string;
110
+ verified?: boolean;
111
+ emailVisibility?: boolean;
112
+ additionalData?: Record<string, any>;
113
+ }
114
+ export interface AnalyzeCollectionDataArgs {
115
+ collection: string;
116
+ options?: {
117
+ sampleSize?: number;
118
+ fields?: string[];
119
+ };
120
+ }
121
+ export interface QueryCollectionArgs {
122
+ collection: string;
123
+ filter?: string;
124
+ sort?: string;
125
+ aggregate?: Record<string, string>;
126
+ expand?: string;
127
+ }
128
+ export interface MigrateCollectionArgs {
129
+ collection: string;
130
+ fields: CollectionFieldConfig[];
131
+ dataTransforms?: Record<string, any>;
132
+ name?: string;
133
+ listRule?: string;
134
+ viewRule?: string;
135
+ createRule?: string;
136
+ updateRule?: string;
137
+ deleteRule?: string;
138
+ }
139
+ export interface BackupDatabaseArgs {
140
+ format?: "json" | "csv";
141
+ }
142
+ export interface ImportDataArgs {
143
+ collection: string;
144
+ data: Record<string, any>[];
145
+ mode?: "create" | "update" | "upsert";
146
+ }
147
+ export interface ManageIndexesArgs {
148
+ collection: string;
149
+ action: "create" | "delete" | "list";
150
+ index?: {
151
+ name: string;
152
+ fields: string[];
153
+ unique?: boolean;
154
+ };
155
+ }
156
+ export interface GeneratePbSchemaArgs {
157
+ sourceCode: string;
158
+ options?: {
159
+ includeAuthentication?: boolean;
160
+ includeTimestamps?: boolean;
161
+ };
162
+ }
163
+ export interface GenerateTypescriptInterfacesArgs {
164
+ collections?: string[];
165
+ options?: {
166
+ includeRelations?: boolean;
167
+ };
168
+ }
169
+ export interface UploadFileArgs {
170
+ collection: string;
171
+ recordId: string;
172
+ fileField: string;
173
+ fileContent: string;
174
+ fileName: string;
175
+ }
176
+ export interface DownloadFileArgs {
177
+ collection: string;
178
+ recordId: string;
179
+ fileField: string;
180
+ }
181
+ export interface UploadFileFromUrlArgs {
182
+ collection: string;
183
+ recordId: string;
184
+ fileField: string;
185
+ url: string;
186
+ fileName?: string;
187
+ }
188
+ export type { CollectionModel, CollectionField };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ import { McpError, ErrorCode } from "@modelcontextprotocol/sdk/types.js";
2
+ /**
3
+ * Create a standardized MCP error with proper error message formatting
4
+ */
5
+ export declare function createMcpError(code: ErrorCode, message: string, error?: unknown): McpError;
6
+ /**
7
+ * Handle and format errors from PocketBase operations
8
+ */
9
+ export declare function handlePocketBaseError(operation: string, error: unknown): McpError;
10
+ /**
11
+ * Validate required parameters and throw appropriate errors
12
+ */
13
+ export declare function validateRequiredParams(params: Record<string, any>, requiredFields: string[]): void;
14
+ /**
15
+ * Validate enum values
16
+ */
17
+ export declare function validateEnumValue(value: any, allowedValues: string[], fieldName: string): void;