@ibm/ibmi-mcp-server 0.3.2 → 0.4.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/dist/cli/commands/columns.d.ts +7 -0
- package/dist/cli/commands/columns.d.ts.map +1 -0
- package/dist/cli/commands/columns.js +29 -0
- package/dist/cli/commands/columns.js.map +1 -0
- package/dist/cli/commands/completion.d.ts +10 -0
- package/dist/cli/commands/completion.d.ts.map +1 -0
- package/dist/cli/commands/completion.js +225 -0
- package/dist/cli/commands/completion.js.map +1 -0
- package/dist/cli/commands/related.d.ts +7 -0
- package/dist/cli/commands/related.d.ts.map +1 -0
- package/dist/cli/commands/related.js +32 -0
- package/dist/cli/commands/related.js.map +1 -0
- package/dist/cli/commands/schemas.d.ts +7 -0
- package/dist/cli/commands/schemas.d.ts.map +1 -0
- package/dist/cli/commands/schemas.js +49 -0
- package/dist/cli/commands/schemas.js.map +1 -0
- package/dist/cli/commands/sql.d.ts +8 -0
- package/dist/cli/commands/sql.d.ts.map +1 -0
- package/dist/cli/commands/sql.js +106 -0
- package/dist/cli/commands/sql.js.map +1 -0
- package/dist/cli/commands/system.d.ts +11 -0
- package/dist/cli/commands/system.d.ts.map +1 -0
- package/dist/cli/commands/system.js +263 -0
- package/dist/cli/commands/system.js.map +1 -0
- package/dist/cli/commands/tables.d.ts +7 -0
- package/dist/cli/commands/tables.d.ts.map +1 -0
- package/dist/cli/commands/tables.js +48 -0
- package/dist/cli/commands/tables.js.map +1 -0
- package/dist/cli/commands/tool.d.ts +18 -0
- package/dist/cli/commands/tool.d.ts.map +1 -0
- package/dist/cli/commands/tool.js +194 -0
- package/dist/cli/commands/tool.js.map +1 -0
- package/dist/cli/commands/tools-list.d.ts +20 -0
- package/dist/cli/commands/tools-list.d.ts.map +1 -0
- package/dist/cli/commands/tools-list.js +209 -0
- package/dist/cli/commands/tools-list.js.map +1 -0
- package/dist/cli/commands/validate.d.ts +7 -0
- package/dist/cli/commands/validate.d.ts.map +1 -0
- package/dist/cli/commands/validate.js +77 -0
- package/dist/cli/commands/validate.js.map +1 -0
- package/dist/cli/config/credentials.d.ts +21 -0
- package/dist/cli/config/credentials.d.ts.map +1 -0
- package/dist/cli/config/credentials.js +96 -0
- package/dist/cli/config/credentials.js.map +1 -0
- package/dist/cli/config/index.d.ts +10 -0
- package/dist/cli/config/index.d.ts.map +1 -0
- package/dist/cli/config/index.js +9 -0
- package/dist/cli/config/index.js.map +1 -0
- package/dist/cli/config/loader.d.ts +36 -0
- package/dist/cli/config/loader.d.ts.map +1 -0
- package/dist/cli/config/loader.js +206 -0
- package/dist/cli/config/loader.js.map +1 -0
- package/dist/cli/config/resolver.d.ts +26 -0
- package/dist/cli/config/resolver.d.ts.map +1 -0
- package/dist/cli/config/resolver.js +102 -0
- package/dist/cli/config/resolver.js.map +1 -0
- package/dist/cli/config/schema.d.ts +128 -0
- package/dist/cli/config/schema.d.ts.map +1 -0
- package/dist/cli/config/schema.js +37 -0
- package/dist/cli/config/schema.js.map +1 -0
- package/dist/cli/config/types.d.ts +59 -0
- package/dist/cli/config/types.d.ts.map +1 -0
- package/dist/cli/config/types.js +6 -0
- package/dist/cli/config/types.js.map +1 -0
- package/dist/cli/formatters/output.d.ts +60 -0
- package/dist/cli/formatters/output.d.ts.map +1 -0
- package/dist/cli/formatters/output.js +190 -0
- package/dist/cli/formatters/output.js.map +1 -0
- package/dist/cli/index.d.ts +13 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +98 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/utils/command-helpers.d.ts +47 -0
- package/dist/cli/utils/command-helpers.d.ts.map +1 -0
- package/dist/cli/utils/command-helpers.js +211 -0
- package/dist/cli/utils/command-helpers.js.map +1 -0
- package/dist/cli/utils/connection.d.ts +20 -0
- package/dist/cli/utils/connection.d.ts.map +1 -0
- package/dist/cli/utils/connection.js +37 -0
- package/dist/cli/utils/connection.js.map +1 -0
- package/dist/cli/utils/exit-codes.d.ts +48 -0
- package/dist/cli/utils/exit-codes.d.ts.map +1 -0
- package/dist/cli/utils/exit-codes.js +111 -0
- package/dist/cli/utils/exit-codes.js.map +1 -0
- package/dist/cli/utils/yaml-loader.d.ts +69 -0
- package/dist/cli/utils/yaml-loader.d.ts.map +1 -0
- package/dist/cli/utils/yaml-loader.js +135 -0
- package/dist/cli/utils/yaml-loader.js.map +1 -0
- package/dist/cli/utils/yaml-to-commander.d.ts +26 -0
- package/dist/cli/utils/yaml-to-commander.d.ts.map +1 -0
- package/dist/cli/utils/yaml-to-commander.js +156 -0
- package/dist/cli/utils/yaml-to-commander.js.map +1 -0
- package/dist/config/index.d.ts +1 -0
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +9 -10
- package/dist/config/index.js.map +1 -1
- package/dist/ibmi-mcp-server/tools/executeSql.tool.d.ts.map +1 -1
- package/dist/ibmi-mcp-server/tools/executeSql.tool.js +6 -2
- package/dist/ibmi-mcp-server/tools/executeSql.tool.js.map +1 -1
- package/dist/ibmi-mcp-server/tools/generateSql.tool.js +1 -1
- package/dist/ibmi-mcp-server/tools/generateSql.tool.js.map +1 -1
- package/dist/ibmi-mcp-server/tools/getRelatedObjects.tool.d.ts +93 -0
- package/dist/ibmi-mcp-server/tools/getRelatedObjects.tool.d.ts.map +1 -0
- package/dist/ibmi-mcp-server/tools/getRelatedObjects.tool.js +198 -0
- package/dist/ibmi-mcp-server/tools/getRelatedObjects.tool.js.map +1 -0
- package/dist/ibmi-mcp-server/tools/getTableColumns.tool.d.ts +87 -0
- package/dist/ibmi-mcp-server/tools/getTableColumns.tool.d.ts.map +1 -0
- package/dist/ibmi-mcp-server/tools/getTableColumns.tool.js +163 -0
- package/dist/ibmi-mcp-server/tools/getTableColumns.tool.js.map +1 -0
- package/dist/ibmi-mcp-server/tools/index.d.ts +175 -0
- package/dist/ibmi-mcp-server/tools/index.d.ts.map +1 -1
- package/dist/ibmi-mcp-server/tools/index.js +27 -1
- package/dist/ibmi-mcp-server/tools/index.js.map +1 -1
- package/dist/ibmi-mcp-server/tools/listSchemas.tool.d.ts +107 -0
- package/dist/ibmi-mcp-server/tools/listSchemas.tool.d.ts.map +1 -0
- package/dist/ibmi-mcp-server/tools/listSchemas.tool.js +195 -0
- package/dist/ibmi-mcp-server/tools/listSchemas.tool.js.map +1 -0
- package/dist/ibmi-mcp-server/tools/listTablesInSchema.tool.d.ts +107 -0
- package/dist/ibmi-mcp-server/tools/listTablesInSchema.tool.d.ts.map +1 -0
- package/dist/ibmi-mcp-server/tools/listTablesInSchema.tool.js +198 -0
- package/dist/ibmi-mcp-server/tools/listTablesInSchema.tool.js.map +1 -0
- package/dist/ibmi-mcp-server/tools/validateQuery.tool.d.ts +229 -0
- package/dist/ibmi-mcp-server/tools/validateQuery.tool.d.ts.map +1 -0
- package/dist/ibmi-mcp-server/tools/validateQuery.tool.js +401 -0
- package/dist/ibmi-mcp-server/tools/validateQuery.tool.js.map +1 -0
- package/dist/ibmi-mcp-server/utils/security/sqlSecurityValidator.js +1 -1
- package/dist/ibmi-mcp-server/utils/security/sqlSecurityValidator.js.map +1 -1
- package/package.json +6 -4
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* List Schemas Tool
|
|
3
|
+
*
|
|
4
|
+
* Lists available schemas/libraries on the IBM i system.
|
|
5
|
+
* Part of the default text-to-SQL toolset.
|
|
6
|
+
*
|
|
7
|
+
* @module listSchemas.tool
|
|
8
|
+
*/
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
import { JsonRpcErrorCode, McpError } from "../../types-global/errors.js";
|
|
11
|
+
import { logger } from "../../utils/internal/logger.js";
|
|
12
|
+
import { IBMiConnectionPool } from "../services/connectionPool.js";
|
|
13
|
+
import { defineTool } from "../../mcp-server/tools/utils/tool-factory.js";
|
|
14
|
+
// =============================================================================
|
|
15
|
+
// Schemas
|
|
16
|
+
// =============================================================================
|
|
17
|
+
const ListSchemasInputSchema = z.object({
|
|
18
|
+
filter: z
|
|
19
|
+
.string()
|
|
20
|
+
.max(128, "Filter pattern cannot exceed 128 characters.")
|
|
21
|
+
.optional()
|
|
22
|
+
.describe("Optional schema name pattern to filter results (e.g., 'MY%', 'LIB%'). Uses SQL LIKE syntax."),
|
|
23
|
+
include_system: z
|
|
24
|
+
.boolean()
|
|
25
|
+
.default(false)
|
|
26
|
+
.describe("Include system schemas (Q* and SYS* prefixed). Default: false."),
|
|
27
|
+
limit: z
|
|
28
|
+
.number()
|
|
29
|
+
.int()
|
|
30
|
+
.min(1)
|
|
31
|
+
.max(500)
|
|
32
|
+
.default(50)
|
|
33
|
+
.describe("Maximum number of rows to return per page (1-500, default 50)."),
|
|
34
|
+
offset: z
|
|
35
|
+
.number()
|
|
36
|
+
.int()
|
|
37
|
+
.min(0)
|
|
38
|
+
.default(0)
|
|
39
|
+
.describe("Number of rows to skip for pagination (default 0)."),
|
|
40
|
+
});
|
|
41
|
+
const ListSchemasOutputSchema = z.object({
|
|
42
|
+
success: z.boolean().describe("Whether the query executed successfully."),
|
|
43
|
+
data: z
|
|
44
|
+
.array(z.record(z.unknown()))
|
|
45
|
+
.optional()
|
|
46
|
+
.describe("Array of schema records. Each record contains: SCHEMA_NAME, SCHEMA_TEXT, SYSTEM_SCHEMA_NAME, SCHEMA_SIZE."),
|
|
47
|
+
rowCount: z.number().optional().describe("Number of schemas returned."),
|
|
48
|
+
hasMore: z
|
|
49
|
+
.boolean()
|
|
50
|
+
.optional()
|
|
51
|
+
.describe("Whether more results exist beyond this page."),
|
|
52
|
+
limit: z.number().optional().describe("Page size used for this request."),
|
|
53
|
+
offset: z.number().optional().describe("Offset used for this request."),
|
|
54
|
+
executionTime: z
|
|
55
|
+
.number()
|
|
56
|
+
.optional()
|
|
57
|
+
.describe("Query execution time in milliseconds."),
|
|
58
|
+
error: z
|
|
59
|
+
.object({
|
|
60
|
+
code: z.string().describe("Error code"),
|
|
61
|
+
message: z.string().describe("Error message"),
|
|
62
|
+
details: z.record(z.unknown()).optional().describe("Error details"),
|
|
63
|
+
})
|
|
64
|
+
.optional()
|
|
65
|
+
.describe("Error information if the query failed."),
|
|
66
|
+
});
|
|
67
|
+
// =============================================================================
|
|
68
|
+
// Business Logic
|
|
69
|
+
// =============================================================================
|
|
70
|
+
export async function listSchemasLogic(params, appContext, _sdkContext) {
|
|
71
|
+
logger.debug({ ...appContext, toolInput: params }, "Processing list schemas logic.");
|
|
72
|
+
const startTime = Date.now();
|
|
73
|
+
// Build WHERE conditions dynamically
|
|
74
|
+
const conditions = [];
|
|
75
|
+
const bindParams = [];
|
|
76
|
+
if (!params.include_system) {
|
|
77
|
+
conditions.push("SCHEMA_NAME NOT LIKE 'Q%' AND SCHEMA_NAME NOT LIKE 'SYS%'");
|
|
78
|
+
}
|
|
79
|
+
if (params.filter) {
|
|
80
|
+
conditions.push("SCHEMA_NAME LIKE UPPER(?)");
|
|
81
|
+
bindParams.push(params.filter);
|
|
82
|
+
}
|
|
83
|
+
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
84
|
+
const sql = `
|
|
85
|
+
SELECT SCHEMA_NAME,
|
|
86
|
+
SCHEMA_TEXT,
|
|
87
|
+
SYSTEM_SCHEMA_NAME,
|
|
88
|
+
SCHEMA_SIZE
|
|
89
|
+
FROM QSYS2.SYSSCHEMAS
|
|
90
|
+
${whereClause}
|
|
91
|
+
ORDER BY SCHEMA_NAME
|
|
92
|
+
OFFSET ? ROWS FETCH FIRST ? ROWS ONLY
|
|
93
|
+
`.trim();
|
|
94
|
+
// Fetch limit+1 to detect if more rows exist beyond this page
|
|
95
|
+
const fetchLimit = params.limit + 1;
|
|
96
|
+
bindParams.push(params.offset, fetchLimit);
|
|
97
|
+
try {
|
|
98
|
+
const result = await IBMiConnectionPool.executeQuery(sql, bindParams, appContext);
|
|
99
|
+
const executionTime = Date.now() - startTime;
|
|
100
|
+
if (!result.data) {
|
|
101
|
+
return {
|
|
102
|
+
success: true,
|
|
103
|
+
data: [],
|
|
104
|
+
rowCount: 0,
|
|
105
|
+
hasMore: false,
|
|
106
|
+
limit: params.limit,
|
|
107
|
+
offset: params.offset,
|
|
108
|
+
executionTime,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
const typedData = result.data;
|
|
112
|
+
// Detect if more rows exist beyond this page
|
|
113
|
+
const hasMore = (typedData?.length ?? 0) > params.limit;
|
|
114
|
+
if (hasMore && typedData) {
|
|
115
|
+
typedData.pop(); // Remove the extra detection row
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
success: true,
|
|
119
|
+
data: typedData,
|
|
120
|
+
rowCount: typedData?.length ?? 0,
|
|
121
|
+
hasMore,
|
|
122
|
+
limit: params.limit,
|
|
123
|
+
offset: params.offset,
|
|
124
|
+
executionTime,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
const executionTime = Date.now() - startTime;
|
|
129
|
+
logger.error({
|
|
130
|
+
...appContext,
|
|
131
|
+
error: error instanceof Error ? error.message : String(error),
|
|
132
|
+
executionTime,
|
|
133
|
+
}, "List schemas query failed.");
|
|
134
|
+
if (error instanceof McpError) {
|
|
135
|
+
return {
|
|
136
|
+
success: false,
|
|
137
|
+
executionTime,
|
|
138
|
+
error: {
|
|
139
|
+
code: String(error.code),
|
|
140
|
+
message: error.message,
|
|
141
|
+
details: error.details,
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
success: false,
|
|
147
|
+
executionTime,
|
|
148
|
+
error: {
|
|
149
|
+
code: String(JsonRpcErrorCode.DatabaseError),
|
|
150
|
+
message: `Failed to list schemas: ${error instanceof Error ? error.message : String(error)}`,
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
// =============================================================================
|
|
156
|
+
// Response Formatter
|
|
157
|
+
// =============================================================================
|
|
158
|
+
const listSchemasResponseFormatter = (result) => {
|
|
159
|
+
if (!result.success) {
|
|
160
|
+
const errorMessage = result.error?.message || "Failed to list schemas";
|
|
161
|
+
const errorDetails = result.error?.details
|
|
162
|
+
? `\n\nDetails:\n${JSON.stringify(result.error.details, null, 2)}`
|
|
163
|
+
: "";
|
|
164
|
+
return [{ type: "text", text: `Error: ${errorMessage}${errorDetails}` }];
|
|
165
|
+
}
|
|
166
|
+
let paginationInfo = "";
|
|
167
|
+
if (result.hasMore !== undefined) {
|
|
168
|
+
paginationInfo = ` (offset ${result.offset}, limit ${result.limit}, hasMore: ${result.hasMore})`;
|
|
169
|
+
}
|
|
170
|
+
const resultJson = JSON.stringify(result.data, null, 2);
|
|
171
|
+
return [
|
|
172
|
+
{
|
|
173
|
+
type: "text",
|
|
174
|
+
text: `Found ${result.rowCount} schemas${paginationInfo}.\nExecution time: ${result.executionTime}ms\n\nSchemas:\n${resultJson}`,
|
|
175
|
+
},
|
|
176
|
+
];
|
|
177
|
+
};
|
|
178
|
+
// =============================================================================
|
|
179
|
+
// Tool Definition
|
|
180
|
+
// =============================================================================
|
|
181
|
+
export const listSchemasTool = defineTool({
|
|
182
|
+
name: "list_schemas",
|
|
183
|
+
title: "List Schemas",
|
|
184
|
+
description: "List available schemas/libraries on the IBM i system. Use this as the first step in schema discovery to find which schemas contain relevant tables.",
|
|
185
|
+
inputSchema: ListSchemasInputSchema,
|
|
186
|
+
outputSchema: ListSchemasOutputSchema,
|
|
187
|
+
logic: listSchemasLogic,
|
|
188
|
+
responseFormatter: listSchemasResponseFormatter,
|
|
189
|
+
annotations: {
|
|
190
|
+
readOnlyHint: true,
|
|
191
|
+
destructiveHint: false,
|
|
192
|
+
openWorldHint: false,
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
//# sourceMappingURL=listSchemas.tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listSchemas.tool.js","sourceRoot":"","sources":["../../../src/ibmi-mcp-server/tools/listSchemas.tool.ts"],"names":[],"mappings":"AAAA;;;;;;;GA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AE,gBAAgB;IACvB,iBAAiB,EAAE,4BAA4B;IAC/C,WAAW,EAAE;QACX,YAAY,EAAE,IAAI;QAClB,eAAe,EAAE,KAAK;QACtB,aAAa,EAAE,KAAK;KACrB;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* List Tables in Schema Tool
|
|
3
|
+
*
|
|
4
|
+
* Lists tables, views, and physical files in a specific schema with metadata
|
|
5
|
+
* including row counts. Promoted from YAML tool definition.
|
|
6
|
+
*
|
|
7
|
+
* @module listTablesInSchema.tool
|
|
8
|
+
*/
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
import type { RequestContext } from "../../utils/index.js";
|
|
11
|
+
import type { SdkContext } from "../../mcp-server/tools/utils/types.js";
|
|
12
|
+
declare const ListTablesInputSchema: z.ZodObject<{
|
|
13
|
+
schema_name: z.ZodString;
|
|
14
|
+
table_filter: z.ZodDefault<z.ZodString>;
|
|
15
|
+
limit: z.ZodDefault<z.ZodNumber>;
|
|
16
|
+
offset: z.ZodDefault<z.ZodNumber>;
|
|
17
|
+
}, "strip", z.ZodTypeAny, {
|
|
18
|
+
limit: number;
|
|
19
|
+
offset: number;
|
|
20
|
+
schema_name: string;
|
|
21
|
+
table_filter: string;
|
|
22
|
+
}, {
|
|
23
|
+
schema_name: string;
|
|
24
|
+
limit?: number | undefined;
|
|
25
|
+
offset?: number | undefined;
|
|
26
|
+
table_filter?: string | undefined;
|
|
27
|
+
}>;
|
|
28
|
+
declare const ListTablesOutputSchema: z.ZodObject<{
|
|
29
|
+
success: z.ZodBoolean;
|
|
30
|
+
data: z.ZodOptional<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>, "many">>;
|
|
31
|
+
rowCount: z.ZodOptional<z.ZodNumber>;
|
|
32
|
+
hasMore: z.ZodOptional<z.ZodBoolean>;
|
|
33
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
34
|
+
offset: z.ZodOptional<z.ZodNumber>;
|
|
35
|
+
executionTime: z.ZodOptional<z.ZodNumber>;
|
|
36
|
+
error: z.ZodOptional<z.ZodObject<{
|
|
37
|
+
code: z.ZodString;
|
|
38
|
+
message: z.ZodString;
|
|
39
|
+
details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
40
|
+
}, "strip", z.ZodTypeAny, {
|
|
41
|
+
code: string;
|
|
42
|
+
message: string;
|
|
43
|
+
details?: Record<string, unknown> | undefined;
|
|
44
|
+
}, {
|
|
45
|
+
code: string;
|
|
46
|
+
message: string;
|
|
47
|
+
details?: Record<string, unknown> | undefined;
|
|
48
|
+
}>>;
|
|
49
|
+
}, "strip", z.ZodTypeAny, {
|
|
50
|
+
success: boolean;
|
|
51
|
+
error?: {
|
|
52
|
+
code: string;
|
|
53
|
+
message: string;
|
|
54
|
+
details?: Record<string, unknown> | undefined;
|
|
55
|
+
} | undefined;
|
|
56
|
+
limit?: number | undefined;
|
|
57
|
+
data?: Record<string, unknown>[] | undefined;
|
|
58
|
+
executionTime?: number | undefined;
|
|
59
|
+
rowCount?: number | undefined;
|
|
60
|
+
offset?: number | undefined;
|
|
61
|
+
hasMore?: boolean | undefined;
|
|
62
|
+
}, {
|
|
63
|
+
success: boolean;
|
|
64
|
+
error?: {
|
|
65
|
+
code: string;
|
|
66
|
+
message: string;
|
|
67
|
+
details?: Record<string, unknown> | undefined;
|
|
68
|
+
} | undefined;
|
|
69
|
+
limit?: number | undefined;
|
|
70
|
+
data?: Record<string, unknown>[] | undefined;
|
|
71
|
+
executionTime?: number | undefined;
|
|
72
|
+
rowCount?: number | undefined;
|
|
73
|
+
offset?: number | undefined;
|
|
74
|
+
hasMore?: boolean | undefined;
|
|
75
|
+
}>;
|
|
76
|
+
type ListTablesInput = z.infer<typeof ListTablesInputSchema>;
|
|
77
|
+
type ListTablesOutput = z.infer<typeof ListTablesOutputSchema>;
|
|
78
|
+
export declare function listTablesLogic(params: ListTablesInput, appContext: RequestContext, _sdkContext: SdkContext): Promise<ListTablesOutput>;
|
|
79
|
+
export declare const listTablesInSchemaTool: import("../../mcp-server/tools/utils/types.js").ToolDefinition<{
|
|
80
|
+
schema_name: z.ZodString;
|
|
81
|
+
table_filter: z.ZodDefault<z.ZodString>;
|
|
82
|
+
limit: z.ZodDefault<z.ZodNumber>;
|
|
83
|
+
offset: z.ZodDefault<z.ZodNumber>;
|
|
84
|
+
}, {
|
|
85
|
+
success: z.ZodBoolean;
|
|
86
|
+
data: z.ZodOptional<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodUnknown>, "many">>;
|
|
87
|
+
rowCount: z.ZodOptional<z.ZodNumber>;
|
|
88
|
+
hasMore: z.ZodOptional<z.ZodBoolean>;
|
|
89
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
90
|
+
offset: z.ZodOptional<z.ZodNumber>;
|
|
91
|
+
executionTime: z.ZodOptional<z.ZodNumber>;
|
|
92
|
+
error: z.ZodOptional<z.ZodObject<{
|
|
93
|
+
code: z.ZodString;
|
|
94
|
+
message: z.ZodString;
|
|
95
|
+
details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
96
|
+
}, "strip", z.ZodTypeAny, {
|
|
97
|
+
code: string;
|
|
98
|
+
message: string;
|
|
99
|
+
details?: Record<string, unknown> | undefined;
|
|
100
|
+
}, {
|
|
101
|
+
code: string;
|
|
102
|
+
message: string;
|
|
103
|
+
details?: Record<string, unknown> | undefined;
|
|
104
|
+
}>>;
|
|
105
|
+
}>;
|
|
106
|
+
export {};
|
|
107
|
+
//# sourceMappingURL=listTablesInSchema.tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listTablesInSchema.tool.d.ts","sourceRoot":"","sources":["../../../src/ibmi-mcp-server/tools/listTablesInSchema.tool.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAI3D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AAMxE,QAAA,MAAM,qBAAqB;;;;;;;;;;;;;;;EA4BzB,CAAC;AAEH,QAAA,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2B1B,CAAC;AAEH,KAAK,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAC7D,KAAK,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAM/D,wBAAsB,eAAe,CACnC,MAAM,EAAE,eAAe,EACvB,UAAU,EAAE,cAAc,EAC1B,WAAW,EAAE,UAAU,GACtB,OAAO,CAAC,gBAAgB,CAAC,CA2G3B;AAoCD,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;EAcjC,CAAC"}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* List Tables in Schema Tool
|
|
3
|
+
*
|
|
4
|
+
* Lists tables, views, and physical files in a specific schema with metadata
|
|
5
|
+
* including row counts. Promoted from YAML tool definition.
|
|
6
|
+
*
|
|
7
|
+
* @module listTablesInSchema.tool
|
|
8
|
+
*/
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
import { JsonRpcErrorCode, McpError } from "../../types-global/errors.js";
|
|
11
|
+
import { logger } from "../../utils/internal/logger.js";
|
|
12
|
+
import { IBMiConnectionPool } from "../services/connectionPool.js";
|
|
13
|
+
import { defineTool } from "../../mcp-server/tools/utils/tool-factory.js";
|
|
14
|
+
// =============================================================================
|
|
15
|
+
// Schemas
|
|
16
|
+
// =============================================================================
|
|
17
|
+
const ListTablesInputSchema = z.object({
|
|
18
|
+
schema_name: z
|
|
19
|
+
.string()
|
|
20
|
+
.min(1, "Schema name cannot be empty.")
|
|
21
|
+
.max(128, "Schema name cannot exceed 128 characters.")
|
|
22
|
+
.describe("Schema name to list tables from (e.g., 'QIWS', 'SAMPLE', 'MYLIB')"),
|
|
23
|
+
table_filter: z
|
|
24
|
+
.string()
|
|
25
|
+
.max(128, "Table filter cannot exceed 128 characters.")
|
|
26
|
+
.default("*ALL")
|
|
27
|
+
.describe("Filter tables by name pattern (e.g., 'CUST%', 'ORD%'). Use '*ALL' for all tables."),
|
|
28
|
+
limit: z
|
|
29
|
+
.number()
|
|
30
|
+
.int()
|
|
31
|
+
.min(1)
|
|
32
|
+
.max(500)
|
|
33
|
+
.default(50)
|
|
34
|
+
.describe("Maximum number of rows to return per page (1-500, default 50)."),
|
|
35
|
+
offset: z
|
|
36
|
+
.number()
|
|
37
|
+
.int()
|
|
38
|
+
.min(0)
|
|
39
|
+
.default(0)
|
|
40
|
+
.describe("Number of rows to skip for pagination (default 0)."),
|
|
41
|
+
});
|
|
42
|
+
const ListTablesOutputSchema = z.object({
|
|
43
|
+
success: z.boolean().describe("Whether the query executed successfully."),
|
|
44
|
+
data: z
|
|
45
|
+
.array(z.record(z.unknown()))
|
|
46
|
+
.optional()
|
|
47
|
+
.describe("Array of table records. Each record contains: TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE (T=Table, V=View, P=Physical file), TABLE_TEXT, NUMBER_ROWS, COLUMN_COUNT."),
|
|
48
|
+
rowCount: z.number().optional().describe("Number of tables returned."),
|
|
49
|
+
hasMore: z
|
|
50
|
+
.boolean()
|
|
51
|
+
.optional()
|
|
52
|
+
.describe("Whether more results exist beyond this page."),
|
|
53
|
+
limit: z.number().optional().describe("Page size used for this request."),
|
|
54
|
+
offset: z.number().optional().describe("Offset used for this request."),
|
|
55
|
+
executionTime: z
|
|
56
|
+
.number()
|
|
57
|
+
.optional()
|
|
58
|
+
.describe("Query execution time in milliseconds."),
|
|
59
|
+
error: z
|
|
60
|
+
.object({
|
|
61
|
+
code: z.string().describe("Error code"),
|
|
62
|
+
message: z.string().describe("Error message"),
|
|
63
|
+
details: z.record(z.unknown()).optional().describe("Error details"),
|
|
64
|
+
})
|
|
65
|
+
.optional()
|
|
66
|
+
.describe("Error information if the query failed."),
|
|
67
|
+
});
|
|
68
|
+
// =============================================================================
|
|
69
|
+
// Business Logic
|
|
70
|
+
// =============================================================================
|
|
71
|
+
export async function listTablesLogic(params, appContext, _sdkContext) {
|
|
72
|
+
logger.debug({ ...appContext, toolInput: params }, "Processing list tables in schema logic.");
|
|
73
|
+
const startTime = Date.now();
|
|
74
|
+
const sql = `
|
|
75
|
+
SELECT T.TABLE_SCHEMA,
|
|
76
|
+
T.TABLE_NAME,
|
|
77
|
+
T.TABLE_TYPE,
|
|
78
|
+
T.TABLE_TEXT,
|
|
79
|
+
COALESCE(S.NUMBER_ROWS, 0) AS NUMBER_ROWS,
|
|
80
|
+
T.COLUMN_COUNT
|
|
81
|
+
FROM QSYS2.SYSTABLES T
|
|
82
|
+
LEFT JOIN QSYS2.SYSTABLESTAT S
|
|
83
|
+
ON T.TABLE_SCHEMA = S.TABLE_SCHEMA
|
|
84
|
+
AND T.TABLE_NAME = S.TABLE_NAME
|
|
85
|
+
WHERE T.TABLE_SCHEMA = UPPER(?)
|
|
86
|
+
AND T.TABLE_TYPE IN ('T', 'V', 'P')
|
|
87
|
+
AND (? = '*ALL' OR T.TABLE_NAME LIKE UPPER(?))
|
|
88
|
+
ORDER BY T.TABLE_TYPE, T.TABLE_NAME
|
|
89
|
+
OFFSET ? ROWS FETCH FIRST ? ROWS ONLY
|
|
90
|
+
`.trim();
|
|
91
|
+
// Fetch limit+1 to detect if more rows exist beyond this page
|
|
92
|
+
const fetchLimit = params.limit + 1;
|
|
93
|
+
try {
|
|
94
|
+
const result = await IBMiConnectionPool.executeQuery(sql, [
|
|
95
|
+
params.schema_name,
|
|
96
|
+
params.table_filter,
|
|
97
|
+
params.table_filter,
|
|
98
|
+
params.offset,
|
|
99
|
+
fetchLimit,
|
|
100
|
+
], appContext);
|
|
101
|
+
const executionTime = Date.now() - startTime;
|
|
102
|
+
if (!result.data) {
|
|
103
|
+
return {
|
|
104
|
+
success: true,
|
|
105
|
+
data: [],
|
|
106
|
+
rowCount: 0,
|
|
107
|
+
hasMore: false,
|
|
108
|
+
limit: params.limit,
|
|
109
|
+
offset: params.offset,
|
|
110
|
+
executionTime,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
const typedData = result.data;
|
|
114
|
+
// Detect if more rows exist beyond this page
|
|
115
|
+
const hasMore = (typedData?.length ?? 0) > params.limit;
|
|
116
|
+
if (hasMore && typedData) {
|
|
117
|
+
typedData.pop(); // Remove the extra detection row
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
success: true,
|
|
121
|
+
data: typedData,
|
|
122
|
+
rowCount: typedData?.length ?? 0,
|
|
123
|
+
hasMore,
|
|
124
|
+
limit: params.limit,
|
|
125
|
+
offset: params.offset,
|
|
126
|
+
executionTime,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
const executionTime = Date.now() - startTime;
|
|
131
|
+
logger.error({
|
|
132
|
+
...appContext,
|
|
133
|
+
error: error instanceof Error ? error.message : String(error),
|
|
134
|
+
schema: params.schema_name,
|
|
135
|
+
executionTime,
|
|
136
|
+
}, "List tables query failed.");
|
|
137
|
+
if (error instanceof McpError) {
|
|
138
|
+
return {
|
|
139
|
+
success: false,
|
|
140
|
+
executionTime,
|
|
141
|
+
error: {
|
|
142
|
+
code: String(error.code),
|
|
143
|
+
message: error.message,
|
|
144
|
+
details: error.details,
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
success: false,
|
|
150
|
+
executionTime,
|
|
151
|
+
error: {
|
|
152
|
+
code: String(JsonRpcErrorCode.DatabaseError),
|
|
153
|
+
message: `Failed to list tables: ${error instanceof Error ? error.message : String(error)}`,
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
// =============================================================================
|
|
159
|
+
// Response Formatter
|
|
160
|
+
// =============================================================================
|
|
161
|
+
const listTablesResponseFormatter = (result) => {
|
|
162
|
+
if (!result.success) {
|
|
163
|
+
const errorMessage = result.error?.message || "Failed to list tables in schema";
|
|
164
|
+
const errorDetails = result.error?.details
|
|
165
|
+
? `\n\nDetails:\n${JSON.stringify(result.error.details, null, 2)}`
|
|
166
|
+
: "";
|
|
167
|
+
return [{ type: "text", text: `Error: ${errorMessage}${errorDetails}` }];
|
|
168
|
+
}
|
|
169
|
+
let paginationInfo = "";
|
|
170
|
+
if (result.hasMore !== undefined) {
|
|
171
|
+
paginationInfo = ` (offset ${result.offset}, limit ${result.limit}, hasMore: ${result.hasMore})`;
|
|
172
|
+
}
|
|
173
|
+
const resultJson = JSON.stringify(result.data, null, 2);
|
|
174
|
+
return [
|
|
175
|
+
{
|
|
176
|
+
type: "text",
|
|
177
|
+
text: `Found ${result.rowCount} tables${paginationInfo}.\nExecution time: ${result.executionTime}ms\n\nTables:\n${resultJson}`,
|
|
178
|
+
},
|
|
179
|
+
];
|
|
180
|
+
};
|
|
181
|
+
// =============================================================================
|
|
182
|
+
// Tool Definition
|
|
183
|
+
// =============================================================================
|
|
184
|
+
export const listTablesInSchemaTool = defineTool({
|
|
185
|
+
name: "list_tables_in_schema",
|
|
186
|
+
title: "List Tables in Schema",
|
|
187
|
+
description: "List tables, views, and physical files in a specific schema with metadata including row counts. Use after list_schemas to find tables before querying column details.",
|
|
188
|
+
inputSchema: ListTablesInputSchema,
|
|
189
|
+
outputSchema: ListTablesOutputSchema,
|
|
190
|
+
logic: listTablesLogic,
|
|
191
|
+
responseFormatter: listTablesResponseFormatter,
|
|
192
|
+
annotations: {
|
|
193
|
+
readOnlyHint: true,
|
|
194
|
+
destructiveHint: false,
|
|
195
|
+
openWorldHint: false,
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
//# sourceMappingURL=listTablesInSchema.tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3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