@iflow-mcp/xexr_mcp-libsql 1.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/LICENSE +21 -0
- package/README.md +509 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +327 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/base-tool.d.ts +29 -0
- package/dist/lib/base-tool.d.ts.map +1 -0
- package/dist/lib/base-tool.js +175 -0
- package/dist/lib/base-tool.js.map +1 -0
- package/dist/lib/constants.d.ts +26 -0
- package/dist/lib/constants.d.ts.map +1 -0
- package/dist/lib/constants.js +47 -0
- package/dist/lib/constants.js.map +1 -0
- package/dist/lib/database.d.ts +39 -0
- package/dist/lib/database.d.ts.map +1 -0
- package/dist/lib/database.js +284 -0
- package/dist/lib/database.js.map +1 -0
- package/dist/lib/logger.d.ts +23 -0
- package/dist/lib/logger.d.ts.map +1 -0
- package/dist/lib/logger.js +124 -0
- package/dist/lib/logger.js.map +1 -0
- package/dist/lib/server-manager.d.ts +31 -0
- package/dist/lib/server-manager.d.ts.map +1 -0
- package/dist/lib/server-manager.js +283 -0
- package/dist/lib/server-manager.js.map +1 -0
- package/dist/schemas/alter-table.d.ts +23 -0
- package/dist/schemas/alter-table.d.ts.map +1 -0
- package/dist/schemas/alter-table.js +85 -0
- package/dist/schemas/alter-table.js.map +1 -0
- package/dist/schemas/create-table.d.ts +23 -0
- package/dist/schemas/create-table.d.ts.map +1 -0
- package/dist/schemas/create-table.js +81 -0
- package/dist/schemas/create-table.js.map +1 -0
- package/dist/schemas/describe-table.d.ts +26 -0
- package/dist/schemas/describe-table.d.ts.map +1 -0
- package/dist/schemas/describe-table.js +47 -0
- package/dist/schemas/describe-table.js.map +1 -0
- package/dist/schemas/list-tables.d.ts +29 -0
- package/dist/schemas/list-tables.d.ts.map +1 -0
- package/dist/schemas/list-tables.js +37 -0
- package/dist/schemas/list-tables.js.map +1 -0
- package/dist/schemas/read-query.d.ts +17 -0
- package/dist/schemas/read-query.d.ts.map +1 -0
- package/dist/schemas/read-query.js +66 -0
- package/dist/schemas/read-query.js.map +1 -0
- package/dist/schemas/write-query.d.ts +20 -0
- package/dist/schemas/write-query.d.ts.map +1 -0
- package/dist/schemas/write-query.js +58 -0
- package/dist/schemas/write-query.js.map +1 -0
- package/dist/tools/alter-table.d.ts +31 -0
- package/dist/tools/alter-table.d.ts.map +1 -0
- package/dist/tools/alter-table.js +139 -0
- package/dist/tools/alter-table.js.map +1 -0
- package/dist/tools/create-table.d.ts +31 -0
- package/dist/tools/create-table.d.ts.map +1 -0
- package/dist/tools/create-table.js +121 -0
- package/dist/tools/create-table.js.map +1 -0
- package/dist/tools/describe-table.d.ts +30 -0
- package/dist/tools/describe-table.d.ts.map +1 -0
- package/dist/tools/describe-table.js +165 -0
- package/dist/tools/describe-table.js.map +1 -0
- package/dist/tools/list-tables.d.ts +32 -0
- package/dist/tools/list-tables.d.ts.map +1 -0
- package/dist/tools/list-tables.js +210 -0
- package/dist/tools/list-tables.js.map +1 -0
- package/dist/tools/read-query.d.ts +17 -0
- package/dist/tools/read-query.d.ts.map +1 -0
- package/dist/tools/read-query.js +112 -0
- package/dist/tools/read-query.js.map +1 -0
- package/dist/tools/write-query.d.ts +20 -0
- package/dist/tools/write-query.d.ts.map +1 -0
- package/dist/tools/write-query.js +63 -0
- package/dist/tools/write-query.js.map +1 -0
- package/dist/types/index.d.ts +50 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/error-handler.d.ts +22 -0
- package/dist/utils/error-handler.d.ts.map +1 -0
- package/dist/utils/error-handler.js +85 -0
- package/dist/utils/error-handler.js.map +1 -0
- package/dist/utils/performance.d.ts +16 -0
- package/dist/utils/performance.d.ts.map +1 -0
- package/dist/utils/performance.js +40 -0
- package/dist/utils/performance.js.map +1 -0
- package/package.json +1 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Input schema for list-tables tool
|
|
4
|
+
* Validates options for database table listing
|
|
5
|
+
*/
|
|
6
|
+
export const ListTablesInputSchema = z.object({
|
|
7
|
+
includeSystemTables: z
|
|
8
|
+
.boolean()
|
|
9
|
+
.optional()
|
|
10
|
+
.default(false)
|
|
11
|
+
.describe('Whether to include SQLite system tables (sqlite_*) in the output'),
|
|
12
|
+
includeViews: z
|
|
13
|
+
.boolean()
|
|
14
|
+
.optional()
|
|
15
|
+
.default(false)
|
|
16
|
+
.describe('Whether to include database views in the output'),
|
|
17
|
+
includeIndexes: z
|
|
18
|
+
.boolean()
|
|
19
|
+
.optional()
|
|
20
|
+
.default(false)
|
|
21
|
+
.describe('Whether to include database indexes in the output'),
|
|
22
|
+
includeDetails: z
|
|
23
|
+
.boolean()
|
|
24
|
+
.optional()
|
|
25
|
+
.default(false)
|
|
26
|
+
.describe('Whether to include detailed information like row counts and CREATE statements'),
|
|
27
|
+
pattern: z
|
|
28
|
+
.string()
|
|
29
|
+
.optional()
|
|
30
|
+
.describe('SQL LIKE pattern to filter table names (e.g., "user%" for tables starting with "user")'),
|
|
31
|
+
format: z
|
|
32
|
+
.enum(['table', 'json', 'list'])
|
|
33
|
+
.optional()
|
|
34
|
+
.default('list')
|
|
35
|
+
.describe('Output format - table for detailed view, json for structured data, list for simple names')
|
|
36
|
+
});
|
|
37
|
+
//# sourceMappingURL=list-tables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list-tables.js","sourceRoot":"","sources":["../../src/schemas/list-tables.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5C,mBAAmB,EAAE,CAAC;SACnB,OAAO,EAAE;SACT,QAAQ,EAAE;SACV,OAAO,CAAC,KAAK,CAAC;SACd,QAAQ,CAAC,kEAAkE,CAAC;IAC/E,YAAY,EAAE,CAAC;SACZ,OAAO,EAAE;SACT,QAAQ,EAAE;SACV,OAAO,CAAC,KAAK,CAAC;SACd,QAAQ,CAAC,iDAAiD,CAAC;IAC9D,cAAc,EAAE,CAAC;SACd,OAAO,EAAE;SACT,QAAQ,EAAE;SACV,OAAO,CAAC,KAAK,CAAC;SACd,QAAQ,CAAC,mDAAmD,CAAC;IAChE,cAAc,EAAE,CAAC;SACd,OAAO,EAAE;SACT,QAAQ,EAAE;SACV,OAAO,CAAC,KAAK,CAAC;SACd,QAAQ,CAAC,+EAA+E,CAAC;IAC5F,OAAO,EAAE,CAAC;SACP,MAAM,EAAE;SACR,QAAQ,EAAE;SACV,QAAQ,CACP,wFAAwF,CACzF;IACH,MAAM,EAAE,CAAC;SACN,IAAI,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;SAC/B,QAAQ,EAAE;SACV,OAAO,CAAC,MAAM,CAAC;SACf,QAAQ,CACP,0FAA0F,CAC3F;CACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Input schema for read-query tool
|
|
4
|
+
* Validates SELECT queries with security measures
|
|
5
|
+
*/
|
|
6
|
+
export declare const ReadQueryInputSchema: z.ZodObject<{
|
|
7
|
+
query: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>, string, string>, string, string>;
|
|
8
|
+
parameters: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>, "many">>>, (string | number | boolean | null)[], (string | number | boolean | null)[] | undefined>;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
query: string;
|
|
11
|
+
parameters: (string | number | boolean | null)[];
|
|
12
|
+
}, {
|
|
13
|
+
query: string;
|
|
14
|
+
parameters?: (string | number | boolean | null)[] | undefined;
|
|
15
|
+
}>;
|
|
16
|
+
export type ReadQueryInput = z.infer<typeof ReadQueryInputSchema>;
|
|
17
|
+
//# sourceMappingURL=read-query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-query.d.ts","sourceRoot":"","sources":["../../src/schemas/read-query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;GAGG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;EAuE/B,CAAC;AAEH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Input schema for read-query tool
|
|
4
|
+
* Validates SELECT queries with security measures
|
|
5
|
+
*/
|
|
6
|
+
export const ReadQueryInputSchema = z.object({
|
|
7
|
+
query: z
|
|
8
|
+
.string()
|
|
9
|
+
.min(1, 'Query cannot be empty')
|
|
10
|
+
.max(10000, 'Query too long (max 10,000 characters)')
|
|
11
|
+
.refine(query => {
|
|
12
|
+
const trimmed = query.trim().toLowerCase();
|
|
13
|
+
return trimmed.startsWith('select');
|
|
14
|
+
}, {
|
|
15
|
+
message: 'Only SELECT queries are allowed for read operations'
|
|
16
|
+
})
|
|
17
|
+
.refine(query => {
|
|
18
|
+
// Check for common dangerous patterns
|
|
19
|
+
const dangerous = [
|
|
20
|
+
'pragma',
|
|
21
|
+
'attach',
|
|
22
|
+
'detach',
|
|
23
|
+
'drop',
|
|
24
|
+
'delete',
|
|
25
|
+
'update',
|
|
26
|
+
'insert',
|
|
27
|
+
'create',
|
|
28
|
+
'alter',
|
|
29
|
+
'truncate',
|
|
30
|
+
'union',
|
|
31
|
+
'except',
|
|
32
|
+
'intersect',
|
|
33
|
+
'--',
|
|
34
|
+
'/*',
|
|
35
|
+
'*/',
|
|
36
|
+
'load_extension',
|
|
37
|
+
'randomblob'
|
|
38
|
+
];
|
|
39
|
+
const lowerQuery = query.toLowerCase();
|
|
40
|
+
return !dangerous.some(pattern => lowerQuery.includes(pattern));
|
|
41
|
+
}, {
|
|
42
|
+
message: 'Query contains prohibited operations'
|
|
43
|
+
})
|
|
44
|
+
.refine(query => {
|
|
45
|
+
// Check for system table access
|
|
46
|
+
const systemTables = ['sqlite_master', 'sqlite_temp_master', 'sqlite_sequence', 'pragma_'];
|
|
47
|
+
const lowerQuery = query.toLowerCase();
|
|
48
|
+
return !systemTables.some(table => lowerQuery.includes(table));
|
|
49
|
+
}, {
|
|
50
|
+
message: 'Query attempts to access system tables'
|
|
51
|
+
})
|
|
52
|
+
.refine(query => {
|
|
53
|
+
// Check for multi-statement patterns - semicolon is the key indicator
|
|
54
|
+
return !query.includes(';');
|
|
55
|
+
}, {
|
|
56
|
+
message: 'Multi-statement queries are not allowed'
|
|
57
|
+
}),
|
|
58
|
+
parameters: z
|
|
59
|
+
.array(z.union([z.string(), z.number(), z.boolean(), z.null()]))
|
|
60
|
+
.optional()
|
|
61
|
+
.default([])
|
|
62
|
+
.refine(params => params.length <= 100, {
|
|
63
|
+
message: 'Too many parameters (max 100)'
|
|
64
|
+
})
|
|
65
|
+
});
|
|
66
|
+
//# sourceMappingURL=read-query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-query.js","sourceRoot":"","sources":["../../src/schemas/read-query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3C,KAAK,EAAE,CAAC;SACL,MAAM,EAAE;SACR,GAAG,CAAC,CAAC,EAAE,uBAAuB,CAAC;SAC/B,GAAG,CAAC,KAAK,EAAE,wCAAwC,CAAC;SACpD,MAAM,CAC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nD,CACF;IACH,UAAU,EAAE,CAAC;SACV,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;SAC/D,QAAQ,EAAE;SACV,OAAO,CAAC,EAAE,CAAC;SACX,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,IAAI,GAAG,EAAE;QACtC,OAAO,EAAE,+BAA+B;KACzC,CAAC;CACL,CAAC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Input schema for write-query tool
|
|
4
|
+
* Validates INSERT, UPDATE, DELETE queries with security measures
|
|
5
|
+
*/
|
|
6
|
+
export declare const WriteQueryInputSchema: z.ZodObject<{
|
|
7
|
+
query: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>, string, string>;
|
|
8
|
+
parameters: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>, "many">>>, (string | number | boolean | null)[], (string | number | boolean | null)[] | undefined>;
|
|
9
|
+
useTransaction: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
10
|
+
}, "strip", z.ZodTypeAny, {
|
|
11
|
+
query: string;
|
|
12
|
+
parameters: (string | number | boolean | null)[];
|
|
13
|
+
useTransaction: boolean;
|
|
14
|
+
}, {
|
|
15
|
+
query: string;
|
|
16
|
+
parameters?: (string | number | boolean | null)[] | undefined;
|
|
17
|
+
useTransaction?: boolean | undefined;
|
|
18
|
+
}>;
|
|
19
|
+
export type WriteQueryInput = z.infer<typeof WriteQueryInputSchema>;
|
|
20
|
+
//# sourceMappingURL=write-query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write-query.d.ts","sourceRoot":"","sources":["../../src/schemas/write-query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;GAGG;AACH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;EA4DhC,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Input schema for write-query tool
|
|
4
|
+
* Validates INSERT, UPDATE, DELETE queries with security measures
|
|
5
|
+
*/
|
|
6
|
+
export const WriteQueryInputSchema = z.object({
|
|
7
|
+
query: z
|
|
8
|
+
.string()
|
|
9
|
+
.min(1, 'Query cannot be empty')
|
|
10
|
+
.max(10000, 'Query too long (max 10,000 characters)')
|
|
11
|
+
.refine(query => {
|
|
12
|
+
const trimmed = query.trim().toLowerCase();
|
|
13
|
+
const writeOperations = ['insert', 'update', 'delete'];
|
|
14
|
+
return writeOperations.some(op => trimmed.startsWith(op));
|
|
15
|
+
}, {
|
|
16
|
+
message: 'Only INSERT, UPDATE, DELETE queries are allowed for write operations'
|
|
17
|
+
})
|
|
18
|
+
.refine(query => {
|
|
19
|
+
// Check for dangerous patterns that shouldn't be in write queries
|
|
20
|
+
const prohibited = [
|
|
21
|
+
'pragma',
|
|
22
|
+
'attach',
|
|
23
|
+
'detach',
|
|
24
|
+
'drop database',
|
|
25
|
+
'drop table',
|
|
26
|
+
'create',
|
|
27
|
+
'alter',
|
|
28
|
+
'truncate',
|
|
29
|
+
'vacuum',
|
|
30
|
+
'reindex'
|
|
31
|
+
];
|
|
32
|
+
const lowerQuery = query.toLowerCase();
|
|
33
|
+
return !prohibited.some(pattern => lowerQuery.includes(pattern));
|
|
34
|
+
}, {
|
|
35
|
+
message: 'Query contains prohibited operations'
|
|
36
|
+
})
|
|
37
|
+
.refine(query => {
|
|
38
|
+
// Prevent queries that try to read from sensitive system tables
|
|
39
|
+
const systemTables = ['sqlite_master', 'sqlite_temp_master', 'sqlite_sequence', 'pragma_'];
|
|
40
|
+
const lowerQuery = query.toLowerCase();
|
|
41
|
+
return !systemTables.some(table => lowerQuery.includes(table));
|
|
42
|
+
}, {
|
|
43
|
+
message: 'Query attempts to access system tables'
|
|
44
|
+
}),
|
|
45
|
+
parameters: z
|
|
46
|
+
.array(z.union([z.string(), z.number(), z.boolean(), z.null()]))
|
|
47
|
+
.optional()
|
|
48
|
+
.default([])
|
|
49
|
+
.refine(params => params.length <= 100, {
|
|
50
|
+
message: 'Too many parameters (max 100)'
|
|
51
|
+
}),
|
|
52
|
+
useTransaction: z
|
|
53
|
+
.boolean()
|
|
54
|
+
.optional()
|
|
55
|
+
.default(true)
|
|
56
|
+
.describe('Whether to wrap the query in a transaction for automatic rollback on errors')
|
|
57
|
+
});
|
|
58
|
+
//# sourceMappingURL=write-query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write-query.js","sourceRoot":"","sources":["../../src/schemas/write-query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5C,KAAK,EAAE,CAAC;SACL,MAAM,EAAE;SACR,GAAG,CAAC,CAAC,EAAE,uBAAuB,CAAC;SAC/B,GAAG,CAAC,KAAK,EAAE,wCAAwC,CAAC;SACpD,MAAM,CACL,KAAK,CAAC,EAAE;QACN,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QAC3C,MAAM,eAAe,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;QACvD,OAAO,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,U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AC;IACJ,cAAc,EAAE,CAAC;SACd,OAAO,EAAE;SACT,QAAQ,EAAE;SACV,OAAO,CAAC,IAAI,CAAC;SACb,QAAQ,CAAC,6EAA6E,CAAC;CAC3F,CAAC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { BaseTool, type ToolExecutionContext, type ToolExecutionResult } from '../lib/base-tool.js';
|
|
2
|
+
export declare class AlterTableTool extends BaseTool {
|
|
3
|
+
readonly name = "alter-table";
|
|
4
|
+
readonly description = "Execute ALTER TABLE DDL statements on the libSQL database. Supports adding columns, renaming tables/columns, and dropping columns with transaction support for safety.";
|
|
5
|
+
readonly inputSchema: import("zod").ZodObject<{
|
|
6
|
+
query: import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, string, string>, string, string>, string, string>, string, string>;
|
|
7
|
+
parameters: import("zod").ZodEffects<import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodUnion<[import("zod").ZodString, import("zod").ZodNumber, import("zod").ZodBoolean, import("zod").ZodNull]>, "many">>>, (string | number | boolean | null)[], (string | number | boolean | null)[] | undefined>;
|
|
8
|
+
useTransaction: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodBoolean>>;
|
|
9
|
+
ifExists: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodBoolean>>;
|
|
10
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
11
|
+
query: string;
|
|
12
|
+
parameters: (string | number | boolean | null)[];
|
|
13
|
+
useTransaction: boolean;
|
|
14
|
+
ifExists: boolean;
|
|
15
|
+
}, {
|
|
16
|
+
query: string;
|
|
17
|
+
parameters?: (string | number | boolean | null)[] | undefined;
|
|
18
|
+
useTransaction?: boolean | undefined;
|
|
19
|
+
ifExists?: boolean | undefined;
|
|
20
|
+
}>;
|
|
21
|
+
protected executeImpl(context: ToolExecutionContext): Promise<ToolExecutionResult>;
|
|
22
|
+
/**
|
|
23
|
+
* Additional validation for ALTER TABLE statements
|
|
24
|
+
*/
|
|
25
|
+
private validateAlterTableQuery;
|
|
26
|
+
/**
|
|
27
|
+
* Extract table name and operation from ALTER TABLE statement
|
|
28
|
+
*/
|
|
29
|
+
private extractTableInfo;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=alter-table.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alter-table.d.ts","sourceRoot":"","sources":["../../src/tools/alter-table.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,oBAAoB,EAAE,KAAK,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAIpG,qBAAa,cAAe,SAAQ,QAAQ;IAC1C,QAAQ,CAAC,IAAI,iBAAiB;IAC9B,QAAQ,CAAC,WAAW,4KACuJ;IAC3K,QAAQ,CAAC,WAAW;;;;;;;;;;;;;;;OAAyB;cAE7B,WAAW,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAoFxF;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAqB/B;;OAEG;IACH,OAAO,CAAC,gBAAgB;CAyCzB"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { BaseTool } from '../lib/base-tool.js';
|
|
2
|
+
import { formatPerformanceMetrics } from '../utils/performance.js';
|
|
3
|
+
import { AlterTableInputSchema } from '../schemas/alter-table.js';
|
|
4
|
+
export class AlterTableTool extends BaseTool {
|
|
5
|
+
name = 'alter-table';
|
|
6
|
+
description = 'Execute ALTER TABLE DDL statements on the libSQL database. Supports adding columns, renaming tables/columns, and dropping columns with transaction support for safety.';
|
|
7
|
+
inputSchema = AlterTableInputSchema;
|
|
8
|
+
async executeImpl(context) {
|
|
9
|
+
const { query, parameters, useTransaction, ifExists } = context.arguments;
|
|
10
|
+
try {
|
|
11
|
+
const startTime = Date.now();
|
|
12
|
+
// Process the query to add IF EXISTS if requested (for DROP COLUMN operations)
|
|
13
|
+
const processedQuery = query;
|
|
14
|
+
if (ifExists &&
|
|
15
|
+
query.toLowerCase().includes('drop column') &&
|
|
16
|
+
!query.toLowerCase().includes('if exists')) {
|
|
17
|
+
// Note: SQLite doesn't support IF EXISTS for DROP COLUMN, but we'll note this in output
|
|
18
|
+
// The query remains unchanged but we'll mention the limitation
|
|
19
|
+
}
|
|
20
|
+
// Validate the processed query
|
|
21
|
+
this.validateAlterTableQuery(processedQuery);
|
|
22
|
+
let result;
|
|
23
|
+
if (useTransaction) {
|
|
24
|
+
// Use transaction for automatic rollback on errors
|
|
25
|
+
result = await context.connection.transaction(async (tx) => {
|
|
26
|
+
return parameters && parameters.length > 0
|
|
27
|
+
? await tx.execute({ sql: processedQuery, args: parameters })
|
|
28
|
+
: await tx.execute(processedQuery);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
// Execute directly without transaction
|
|
33
|
+
result =
|
|
34
|
+
parameters && parameters.length > 0
|
|
35
|
+
? await context.connection.execute(processedQuery, parameters)
|
|
36
|
+
: await context.connection.execute(processedQuery);
|
|
37
|
+
}
|
|
38
|
+
const executionTime = Date.now() - startTime;
|
|
39
|
+
const metrics = formatPerformanceMetrics({
|
|
40
|
+
executionTime,
|
|
41
|
+
rowsAffected: result.rowsAffected
|
|
42
|
+
});
|
|
43
|
+
// Extract table name and operation from query for user feedback
|
|
44
|
+
const { tableName, operation } = this.extractTableInfo(processedQuery);
|
|
45
|
+
let output = `Table altered successfully${useTransaction ? ' (with transaction)' : ''}\n\n`;
|
|
46
|
+
output += `Table: ${tableName}\n`;
|
|
47
|
+
output += `Operation: ${operation}\n`;
|
|
48
|
+
if (ifExists && query.toLowerCase().includes('drop column')) {
|
|
49
|
+
output += 'Note: SQLite does not support IF EXISTS for DROP COLUMN operations\n';
|
|
50
|
+
}
|
|
51
|
+
if (result.rowsAffected !== undefined) {
|
|
52
|
+
output += `Rows affected: ${result.rowsAffected}\n`;
|
|
53
|
+
}
|
|
54
|
+
output += `\n${metrics}`;
|
|
55
|
+
return {
|
|
56
|
+
content: [
|
|
57
|
+
{
|
|
58
|
+
type: 'text',
|
|
59
|
+
text: output
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
66
|
+
const rollbackMessage = useTransaction ? ' (transaction rolled back)' : '';
|
|
67
|
+
return {
|
|
68
|
+
content: [
|
|
69
|
+
{
|
|
70
|
+
type: 'text',
|
|
71
|
+
text: `Error altering table: ${errorMessage}${rollbackMessage}`
|
|
72
|
+
}
|
|
73
|
+
],
|
|
74
|
+
isError: true
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Additional validation for ALTER TABLE statements
|
|
80
|
+
*/
|
|
81
|
+
validateAlterTableQuery(query) {
|
|
82
|
+
const lowerQuery = query.toLowerCase();
|
|
83
|
+
// Check for dangerous patterns
|
|
84
|
+
if (lowerQuery.includes('trigger') || lowerQuery.includes('view')) {
|
|
85
|
+
throw new Error('ALTER TABLE cannot contain TRIGGER or VIEW clauses');
|
|
86
|
+
}
|
|
87
|
+
// Validate that we have a proper table name
|
|
88
|
+
if (!lowerQuery.match(/alter\s+table\s+[\w"`[\]]+/)) {
|
|
89
|
+
throw new Error('ALTER TABLE must specify a valid table name');
|
|
90
|
+
}
|
|
91
|
+
// Check for minimum required elements based on operation
|
|
92
|
+
if (lowerQuery.includes('add column') || lowerQuery.includes('add ')) {
|
|
93
|
+
if (!lowerQuery.match(/add\s+(column\s+)?[\w"`[\]]+/)) {
|
|
94
|
+
throw new Error('ADD COLUMN must specify a valid column name and type');
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Extract table name and operation from ALTER TABLE statement
|
|
100
|
+
*/
|
|
101
|
+
extractTableInfo(query) {
|
|
102
|
+
// Normalize whitespace
|
|
103
|
+
const normalizedQuery = query.replace(/\s+/g, ' ').trim();
|
|
104
|
+
// Extract table name - handle quoted and unquoted names
|
|
105
|
+
const tablePatterns = [
|
|
106
|
+
/ALTER TABLE "([^"]+)"/i, // Double quotes
|
|
107
|
+
/ALTER TABLE '([^']+)'/i, // Single quotes
|
|
108
|
+
/ALTER TABLE `([^`]+)`/i, // Backticks
|
|
109
|
+
/ALTER TABLE \[([^\]]+)\]/i, // Square brackets
|
|
110
|
+
/ALTER TABLE (\w+)/i // Unquoted
|
|
111
|
+
];
|
|
112
|
+
let tableName = 'unknown';
|
|
113
|
+
for (const pattern of tablePatterns) {
|
|
114
|
+
const match = normalizedQuery.match(pattern);
|
|
115
|
+
if (match && match[1]) {
|
|
116
|
+
tableName = match[1];
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// Determine operation type
|
|
121
|
+
const lowerQuery = normalizedQuery.toLowerCase();
|
|
122
|
+
let operation = 'unknown';
|
|
123
|
+
if (lowerQuery.includes('add column') ||
|
|
124
|
+
(lowerQuery.includes('add ') && !lowerQuery.includes('add constraint'))) {
|
|
125
|
+
operation = 'ADD COLUMN';
|
|
126
|
+
}
|
|
127
|
+
else if (lowerQuery.includes('rename to')) {
|
|
128
|
+
operation = 'RENAME TABLE';
|
|
129
|
+
}
|
|
130
|
+
else if (lowerQuery.includes('rename column')) {
|
|
131
|
+
operation = 'RENAME COLUMN';
|
|
132
|
+
}
|
|
133
|
+
else if (lowerQuery.includes('drop column')) {
|
|
134
|
+
operation = 'DROP COLUMN';
|
|
135
|
+
}
|
|
136
|
+
return { tableName, operation };
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=alter-table.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alter-table.js","sourceRoot":"","sources":["../../src/tools/alter-table.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,Q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ecutionResult } from '../lib/base-tool.js';
|
|
2
|
+
export declare class CreateTableTool extends BaseTool {
|
|
3
|
+
readonly name = "create-table";
|
|
4
|
+
readonly description = "Execute CREATE TABLE DDL statements on the libSQL database. Supports table creation with automatic IF NOT EXISTS handling and transaction support for safety.";
|
|
5
|
+
readonly inputSchema: import("zod").ZodObject<{
|
|
6
|
+
query: import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, string, string>, string, string>, string, string>, string, string>;
|
|
7
|
+
parameters: import("zod").ZodEffects<import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodUnion<[import("zod").ZodString, import("zod").ZodNumber, import("zod").ZodBoolean, import("zod").ZodNull]>, "many">>>, (string | number | boolean | null)[], (string | number | boolean | null)[] | undefined>;
|
|
8
|
+
useTransaction: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodBoolean>>;
|
|
9
|
+
ifNotExists: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodBoolean>>;
|
|
10
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
11
|
+
query: string;
|
|
12
|
+
parameters: (string | number | boolean | null)[];
|
|
13
|
+
useTransaction: boolean;
|
|
14
|
+
ifNotExists: boolean;
|
|
15
|
+
}, {
|
|
16
|
+
query: string;
|
|
17
|
+
parameters?: (string | number | boolean | null)[] | undefined;
|
|
18
|
+
useTransaction?: boolean | undefined;
|
|
19
|
+
ifNotExists?: boolean | undefined;
|
|
20
|
+
}>;
|
|
21
|
+
protected executeImpl(context: ToolExecutionContext): Promise<ToolExecutionResult>;
|
|
22
|
+
/**
|
|
23
|
+
* Additional validation for CREATE TABLE statements
|
|
24
|
+
*/
|
|
25
|
+
private validateCreateTableQuery;
|
|
26
|
+
/**
|
|
27
|
+
* Extract table name from CREATE TABLE statement
|
|
28
|
+
*/
|
|
29
|
+
private extractTableName;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=create-table.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-table.d.ts","sourceRoot":"","sources":["../../src/tools/create-table.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,oBAAoB,EAAE,KAAK,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAIpG,qBAAa,eAAgB,SAAQ,QAAQ;IAC3C,QAAQ,CAAC,IAAI,kBAAkB;IAC/B,QAAQ,CAAC,WAAW,mKAC8I;IAClK,QAAQ,CAAC,WAAW;;;;;;;;;;;;;;;OAA0B;cAE9B,WAAW,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAgFxF;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAqBhC;;OAEG;IACH,OAAO,CAAC,gBAAgB;CAyBzB"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { BaseTool } from '../lib/base-tool.js';
|
|
2
|
+
import { formatPerformanceMetrics } from '../utils/performance.js';
|
|
3
|
+
import { CreateTableInputSchema } from '../schemas/create-table.js';
|
|
4
|
+
export class CreateTableTool extends BaseTool {
|
|
5
|
+
name = 'create-table';
|
|
6
|
+
description = 'Execute CREATE TABLE DDL statements on the libSQL database. Supports table creation with automatic IF NOT EXISTS handling and transaction support for safety.';
|
|
7
|
+
inputSchema = CreateTableInputSchema;
|
|
8
|
+
async executeImpl(context) {
|
|
9
|
+
const { query, parameters, useTransaction, ifNotExists } = context.arguments;
|
|
10
|
+
try {
|
|
11
|
+
const startTime = Date.now();
|
|
12
|
+
// Process the query to add IF NOT EXISTS if requested
|
|
13
|
+
let processedQuery = query;
|
|
14
|
+
if (ifNotExists && !query.toLowerCase().includes('if not exists')) {
|
|
15
|
+
// Insert IF NOT EXISTS after CREATE TABLE
|
|
16
|
+
processedQuery = query.replace(/create\s+table\s+/i, 'CREATE TABLE IF NOT EXISTS ');
|
|
17
|
+
}
|
|
18
|
+
// Validate the processed query
|
|
19
|
+
this.validateCreateTableQuery(processedQuery);
|
|
20
|
+
let result;
|
|
21
|
+
if (useTransaction) {
|
|
22
|
+
// Use transaction for automatic rollback on errors
|
|
23
|
+
result = await context.connection.transaction(async (tx) => {
|
|
24
|
+
return parameters && parameters.length > 0
|
|
25
|
+
? await tx.execute({ sql: processedQuery, args: parameters })
|
|
26
|
+
: await tx.execute(processedQuery);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
// Execute directly without transaction
|
|
31
|
+
result =
|
|
32
|
+
parameters && parameters.length > 0
|
|
33
|
+
? await context.connection.execute(processedQuery, parameters)
|
|
34
|
+
: await context.connection.execute(processedQuery);
|
|
35
|
+
}
|
|
36
|
+
const executionTime = Date.now() - startTime;
|
|
37
|
+
const metrics = formatPerformanceMetrics({
|
|
38
|
+
executionTime,
|
|
39
|
+
rowsAffected: result.rowsAffected
|
|
40
|
+
});
|
|
41
|
+
// Extract table name from query for user feedback
|
|
42
|
+
const tableName = this.extractTableName(processedQuery);
|
|
43
|
+
let output = `Table created successfully${useTransaction ? ' (with transaction)' : ''}\n\n`;
|
|
44
|
+
output += `Table name: ${tableName}\n`;
|
|
45
|
+
if (ifNotExists && !query.toLowerCase().includes('if not exists')) {
|
|
46
|
+
output += 'Note: Added IF NOT EXISTS clause\n';
|
|
47
|
+
}
|
|
48
|
+
if (result.rowsAffected !== undefined) {
|
|
49
|
+
output += `Rows affected: ${result.rowsAffected}\n`;
|
|
50
|
+
}
|
|
51
|
+
output += `\n${metrics}`;
|
|
52
|
+
return {
|
|
53
|
+
content: [
|
|
54
|
+
{
|
|
55
|
+
type: 'text',
|
|
56
|
+
text: output
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
63
|
+
const rollbackMessage = useTransaction ? ' (transaction rolled back)' : '';
|
|
64
|
+
return {
|
|
65
|
+
content: [
|
|
66
|
+
{
|
|
67
|
+
type: 'text',
|
|
68
|
+
text: `Error creating table: ${errorMessage}${rollbackMessage}`
|
|
69
|
+
}
|
|
70
|
+
],
|
|
71
|
+
isError: true
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Additional validation for CREATE TABLE statements
|
|
77
|
+
*/
|
|
78
|
+
validateCreateTableQuery(query) {
|
|
79
|
+
const lowerQuery = query.toLowerCase();
|
|
80
|
+
// Check for trigger or view patterns that don't belong in CREATE TABLE
|
|
81
|
+
if (lowerQuery.includes(' trigger ') || lowerQuery.includes(' view ')) {
|
|
82
|
+
throw new Error('CREATE TABLE cannot contain TRIGGER or VIEW clauses');
|
|
83
|
+
}
|
|
84
|
+
// Validate parentheses balance
|
|
85
|
+
const openParens = (query.match(/\(/g) || []).length;
|
|
86
|
+
const closeParens = (query.match(/\)/g) || []).length;
|
|
87
|
+
if (openParens !== closeParens) {
|
|
88
|
+
throw new Error('Unbalanced parentheses in CREATE TABLE statement');
|
|
89
|
+
}
|
|
90
|
+
// Check for minimum required elements
|
|
91
|
+
if (!lowerQuery.includes('(') || !lowerQuery.includes(')')) {
|
|
92
|
+
throw new Error('CREATE TABLE must include column definitions in parentheses');
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Extract table name from CREATE TABLE statement
|
|
97
|
+
*/
|
|
98
|
+
extractTableName(query) {
|
|
99
|
+
// Remove IF NOT EXISTS and normalize whitespace
|
|
100
|
+
const normalizedQuery = query
|
|
101
|
+
.replace(/\s+/g, ' ')
|
|
102
|
+
.replace(/create\s+table\s+if\s+not\s+exists\s+/i, 'CREATE TABLE ')
|
|
103
|
+
.replace(/create\s+table\s+/i, 'CREATE TABLE ');
|
|
104
|
+
// Extract table name - handle quoted and unquoted names
|
|
105
|
+
const patterns = [
|
|
106
|
+
/CREATE TABLE "([^"]+)"/i, // Double quotes
|
|
107
|
+
/CREATE TABLE '([^']+)'/i, // Single quotes
|
|
108
|
+
/CREATE TABLE `([^`]+)`/i, // Backticks
|
|
109
|
+
/CREATE TABLE \[([^\]]+)\]/i, // Square brackets
|
|
110
|
+
/CREATE TABLE (\w+)/i // Unquoted
|
|
111
|
+
];
|
|
112
|
+
for (const pattern of patterns) {
|
|
113
|
+
const match = normalizedQuery.match(pattern);
|
|
114
|
+
if (match && match[1]) {
|
|
115
|
+
return match[1];
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return 'unknown';
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=create-table.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-table.js","sourceRoot":"","sources":["../../src/tools/create-table.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAuD,MAAM,qBAAqB,CAAC;AACpG,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAyB,MAAM,4BAA4B,CAAC;AAE3F,MAAM,OAAO,eAAgB,SAAQ,QAAQ;IAClC,IAAI,GAAG,cAAc,CAAC;IACtB,WAAW,GAClB,+JAA+J,CAAC;IACzJ,WAAW,GAAG,sBAAsB,CAAC;IAEpC,KAAK,CAAC,WAAW,CAAC,OAA6B;QACvD,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,WAAW,EAAE,GACtD,OAAO,CAAC,SAA6B,CAAC;QAExC,IAAI,CAAC;YACH,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YAE7B,sDAAsD;YACtD,IAAI,cAAc,GAAG,KAAK,CAAC;YAC3B,IAAI,WAAW,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC;gBAClE,0CAA0C;gBAC1C,cAAc,GAAG,KAAK,CAAC,OAAO,CAAC,oBAAoB,EAAE,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,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;QACtD,IAAI,UAAU,KAAK,WAAW,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;QACtE,CAAC;QAED,sCAAsC;QACtC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YAC3D,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;QACjF,CAAC;IACH,CAAC;IAED;;OAEG;IACK,gBAAgB,CAAC,KAAa;QACpC,gDAAgD;QAChD,MAAM,eAAe,GAAG,KAAK;aAC1B,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;aACpB,OAAO,CAAC,wCAAwC,EAAE,eAAe,CAAC;aAClE,OAAO,CAAC,oBAAoB,EAAE,eAAe,CAAC,CAAC;QAElD,wDAAwD;QACxD,MAAM,QAAQ,GAAG;YACf,yBAAyB,EAAG,gBAAgB;YAC5C,yBAAyB,EAAG,gBAAgB;YAC5C,yBAAyB,EAAG,YAAY;YACxC,4BAA4B,EAAE,kBAAkB;YAChD,qBAAqB,CAAO,WAAW;SACxC,CAAC;QAEF,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC/B,MAAM,KAAK,GAAG,eAAe,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAC7C,IAAI,KAAK,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;gBACtB,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;YAClB,CAAC;QACH,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BaseTool, type ToolExecutionContext, type ToolExecutionResult } from '../lib/base-tool.js';
|
|
2
|
+
export declare class DescribeTableTool extends BaseTool {
|
|
3
|
+
readonly name = "describe-table";
|
|
4
|
+
readonly description = "Get comprehensive schema information for a specific table including columns, indexes, foreign keys, and constraints. Supports both human-readable and JSON output formats.";
|
|
5
|
+
readonly inputSchema: import("zod").ZodObject<{
|
|
6
|
+
tableName: import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodString, string, string>, string, string>;
|
|
7
|
+
includeIndexes: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodBoolean>>;
|
|
8
|
+
includeForeignKeys: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodBoolean>>;
|
|
9
|
+
includeConstraints: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodBoolean>>;
|
|
10
|
+
format: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodEnum<["table", "json"]>>>;
|
|
11
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
12
|
+
tableName: string;
|
|
13
|
+
includeIndexes: boolean;
|
|
14
|
+
format: "table" | "json";
|
|
15
|
+
includeForeignKeys: boolean;
|
|
16
|
+
includeConstraints: boolean;
|
|
17
|
+
}, {
|
|
18
|
+
tableName: string;
|
|
19
|
+
includeIndexes?: boolean | undefined;
|
|
20
|
+
format?: "table" | "json" | undefined;
|
|
21
|
+
includeForeignKeys?: boolean | undefined;
|
|
22
|
+
includeConstraints?: boolean | undefined;
|
|
23
|
+
}>;
|
|
24
|
+
protected executeImpl(context: ToolExecutionContext): Promise<ToolExecutionResult>;
|
|
25
|
+
/**
|
|
26
|
+
* Sanitize table name for safe use in PRAGMA queries
|
|
27
|
+
*/
|
|
28
|
+
private sanitizeTableName;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=describe-table.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"describe-table.d.ts","sourceRoot":"","sources":["../../src/tools/describe-table.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,oBAAoB,EAAE,KAAK,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAIpG,qBAAa,iBAAkB,SAAQ,QAAQ;IAC7C,QAAQ,CAAC,IAAI,oBAAoB;IACjC,QAAQ,CAAC,WAAW,gLAC2J;IAC/K,QAAQ,CAAC,WAAW;;;;;;;;;;;;;;;;;;OAA4B;cAEhC,WAAW,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IA+KxF;;OAEG;IACH,OAAO,CAAC,iBAAiB;CAI1B"}
|