@ibm/ibmi-mcp-server 0.2.0 → 0.3.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 (197) hide show
  1. package/README.md +140 -0
  2. package/dist/config/index.d.ts +2 -0
  3. package/dist/config/index.d.ts.map +1 -1
  4. package/dist/config/index.js +14 -0
  5. package/dist/config/index.js.map +1 -1
  6. package/dist/config/resolver.d.ts.map +1 -1
  7. package/dist/config/resolver.js.map +1 -1
  8. package/dist/ibmi-mcp-server/tools/executeSql.tool.d.ts +80 -0
  9. package/dist/ibmi-mcp-server/tools/executeSql.tool.d.ts.map +1 -0
  10. package/dist/ibmi-mcp-server/tools/executeSql.tool.js +356 -0
  11. package/dist/ibmi-mcp-server/tools/executeSql.tool.js.map +1 -0
  12. package/dist/ibmi-mcp-server/tools/generateSql.tool.d.ts +36 -0
  13. package/dist/ibmi-mcp-server/tools/generateSql.tool.d.ts.map +1 -0
  14. package/dist/ibmi-mcp-server/tools/generateSql.tool.js +281 -0
  15. package/dist/ibmi-mcp-server/tools/generateSql.tool.js.map +1 -0
  16. package/dist/ibmi-mcp-server/tools/index.d.ts +85 -0
  17. package/dist/ibmi-mcp-server/tools/index.d.ts.map +1 -0
  18. package/dist/ibmi-mcp-server/tools/index.js +21 -0
  19. package/dist/ibmi-mcp-server/tools/index.js.map +1 -0
  20. package/dist/ibmi-mcp-server/utils/config/configParser.d.ts +9 -0
  21. package/dist/ibmi-mcp-server/utils/config/configParser.d.ts.map +1 -1
  22. package/dist/ibmi-mcp-server/utils/config/configParser.js +58 -0
  23. package/dist/ibmi-mcp-server/utils/config/configParser.js.map +1 -1
  24. package/dist/ibmi-mcp-server/utils/config/toolDefinitions.d.ts +4 -4
  25. package/dist/ibmi-mcp-server/utils/config/toolDefinitions.d.ts.map +1 -1
  26. package/dist/ibmi-mcp-server/utils/config/toolDefinitions.js +7 -8
  27. package/dist/ibmi-mcp-server/utils/config/toolDefinitions.js.map +1 -1
  28. package/dist/ibmi-mcp-server/utils/config/toolFactory.d.ts +0 -8
  29. package/dist/ibmi-mcp-server/utils/config/toolFactory.d.ts.map +1 -1
  30. package/dist/ibmi-mcp-server/utils/config/toolFactory.js +0 -31
  31. package/dist/ibmi-mcp-server/utils/config/toolFactory.js.map +1 -1
  32. package/dist/ibmi-mcp-server/utils/config/toolsetManager.d.ts +1 -1
  33. package/dist/ibmi-mcp-server/utils/config/toolsetManager.d.ts.map +1 -1
  34. package/dist/ibmi-mcp-server/utils/config/toolsetManager.js +2 -2
  35. package/dist/ibmi-mcp-server/utils/config/toolsetManager.js.map +1 -1
  36. package/dist/ibmi-mcp-server/utils/language/document.d.ts +26 -0
  37. package/dist/ibmi-mcp-server/utils/language/document.d.ts.map +1 -0
  38. package/dist/ibmi-mcp-server/utils/language/document.js +318 -0
  39. package/dist/ibmi-mcp-server/utils/language/document.js.map +1 -0
  40. package/dist/ibmi-mcp-server/utils/language/statement.d.ts +43 -0
  41. package/dist/ibmi-mcp-server/utils/language/statement.d.ts.map +1 -0
  42. package/dist/ibmi-mcp-server/utils/language/statement.js +796 -0
  43. package/dist/ibmi-mcp-server/utils/language/statement.js.map +1 -0
  44. package/dist/ibmi-mcp-server/utils/language/tokens.d.ts +32 -0
  45. package/dist/ibmi-mcp-server/utils/language/tokens.d.ts.map +1 -0
  46. package/dist/ibmi-mcp-server/utils/language/tokens.js +532 -0
  47. package/dist/ibmi-mcp-server/utils/language/tokens.js.map +1 -0
  48. package/dist/ibmi-mcp-server/utils/language/types.d.ts +138 -0
  49. package/dist/ibmi-mcp-server/utils/language/types.d.ts.map +1 -0
  50. package/dist/ibmi-mcp-server/utils/language/types.js +93 -0
  51. package/dist/ibmi-mcp-server/utils/language/types.js.map +1 -0
  52. package/dist/ibmi-mcp-server/utils/security/ibmiSqlParser.d.ts +48 -0
  53. package/dist/ibmi-mcp-server/utils/security/ibmiSqlParser.d.ts.map +1 -0
  54. package/dist/ibmi-mcp-server/utils/security/ibmiSqlParser.js +93 -0
  55. package/dist/ibmi-mcp-server/utils/security/ibmiSqlParser.js.map +1 -0
  56. package/dist/ibmi-mcp-server/utils/security/sqlSecurityValidator.d.ts +35 -59
  57. package/dist/ibmi-mcp-server/utils/security/sqlSecurityValidator.d.ts.map +1 -1
  58. package/dist/ibmi-mcp-server/utils/security/sqlSecurityValidator.js +108 -288
  59. package/dist/ibmi-mcp-server/utils/security/sqlSecurityValidator.js.map +1 -1
  60. package/dist/ibmi-mcp-server/utils/security/sqlSecurityValidatorFallback.d.ts +54 -0
  61. package/dist/ibmi-mcp-server/utils/security/sqlSecurityValidatorFallback.d.ts.map +1 -0
  62. package/dist/ibmi-mcp-server/utils/security/sqlSecurityValidatorFallback.js +91 -0
  63. package/dist/ibmi-mcp-server/utils/security/sqlSecurityValidatorFallback.js.map +1 -0
  64. package/dist/mcp-server/tools/index.d.ts +13 -2
  65. package/dist/mcp-server/tools/index.d.ts.map +1 -1
  66. package/dist/mcp-server/tools/index.js +29 -9
  67. package/dist/mcp-server/tools/index.js.map +1 -1
  68. package/dist/mcp-server/tools/utils/index.d.ts +7 -0
  69. package/dist/mcp-server/tools/utils/index.d.ts.map +1 -0
  70. package/dist/mcp-server/tools/utils/index.js +7 -0
  71. package/dist/mcp-server/tools/utils/index.js.map +1 -0
  72. package/dist/mcp-server/tools/utils/tool-factory.d.ts +129 -0
  73. package/dist/mcp-server/tools/utils/tool-factory.d.ts.map +1 -0
  74. package/dist/mcp-server/tools/utils/tool-factory.js +179 -0
  75. package/dist/mcp-server/tools/utils/tool-factory.js.map +1 -0
  76. package/dist/mcp-server/tools/utils/types.d.ts +117 -0
  77. package/dist/mcp-server/tools/utils/types.d.ts.map +1 -0
  78. package/dist/mcp-server/tools/utils/types.js +11 -0
  79. package/dist/mcp-server/tools/utils/types.js.map +1 -0
  80. package/dist/mcp-server/transports/core/cleanupTransformStream.d.ts +26 -0
  81. package/dist/mcp-server/transports/core/cleanupTransformStream.d.ts.map +1 -0
  82. package/dist/mcp-server/transports/core/cleanupTransformStream.js +60 -0
  83. package/dist/mcp-server/transports/core/cleanupTransformStream.js.map +1 -0
  84. package/dist/mcp-server/transports/core/statefulTransportManager.d.ts +1 -1
  85. package/dist/mcp-server/transports/core/statefulTransportManager.d.ts.map +1 -1
  86. package/dist/mcp-server/transports/core/statefulTransportManager.js +50 -40
  87. package/dist/mcp-server/transports/core/statefulTransportManager.js.map +1 -1
  88. package/dist/mcp-server/transports/core/statelessTransportManager.d.ts +2 -13
  89. package/dist/mcp-server/transports/core/statelessTransportManager.d.ts.map +1 -1
  90. package/dist/mcp-server/transports/core/statelessTransportManager.js +35 -62
  91. package/dist/mcp-server/transports/core/statelessTransportManager.js.map +1 -1
  92. package/dist/mcp-server/transports/core/transportRequest.d.ts +1 -2
  93. package/dist/mcp-server/transports/core/transportRequest.d.ts.map +1 -1
  94. package/dist/mcp-server/transports/http/mcpTransportMiddleware.d.ts.map +1 -1
  95. package/dist/mcp-server/transports/http/mcpTransportMiddleware.js +1 -3
  96. package/dist/mcp-server/transports/http/mcpTransportMiddleware.js.map +1 -1
  97. package/package.json +21 -22
  98. package/dist/ibmi-mcp-server/tools/executeSql/index.d.ts +0 -9
  99. package/dist/ibmi-mcp-server/tools/executeSql/index.d.ts.map +0 -1
  100. package/dist/ibmi-mcp-server/tools/executeSql/index.js +0 -9
  101. package/dist/ibmi-mcp-server/tools/executeSql/index.js.map +0 -1
  102. package/dist/ibmi-mcp-server/tools/executeSql/logic.d.ts +0 -51
  103. package/dist/ibmi-mcp-server/tools/executeSql/logic.d.ts.map +0 -1
  104. package/dist/ibmi-mcp-server/tools/executeSql/logic.js +0 -179
  105. package/dist/ibmi-mcp-server/tools/executeSql/logic.js.map +0 -1
  106. package/dist/ibmi-mcp-server/tools/executeSql/registration.d.ts +0 -52
  107. package/dist/ibmi-mcp-server/tools/executeSql/registration.d.ts.map +0 -1
  108. package/dist/ibmi-mcp-server/tools/executeSql/registration.js +0 -161
  109. package/dist/ibmi-mcp-server/tools/executeSql/registration.js.map +0 -1
  110. package/dist/ibmi-mcp-server/tools/generateSql/index.d.ts +0 -13
  111. package/dist/ibmi-mcp-server/tools/generateSql/index.d.ts.map +0 -1
  112. package/dist/ibmi-mcp-server/tools/generateSql/index.js +0 -13
  113. package/dist/ibmi-mcp-server/tools/generateSql/index.js.map +0 -1
  114. package/dist/ibmi-mcp-server/tools/generateSql/logic.d.ts +0 -64
  115. package/dist/ibmi-mcp-server/tools/generateSql/logic.d.ts.map +0 -1
  116. package/dist/ibmi-mcp-server/tools/generateSql/logic.js +0 -190
  117. package/dist/ibmi-mcp-server/tools/generateSql/logic.js.map +0 -1
  118. package/dist/ibmi-mcp-server/tools/generateSql/registration.d.ts +0 -18
  119. package/dist/ibmi-mcp-server/tools/generateSql/registration.d.ts.map +0 -1
  120. package/dist/ibmi-mcp-server/tools/generateSql/registration.js +0 -64
  121. package/dist/ibmi-mcp-server/tools/generateSql/registration.js.map +0 -1
  122. package/dist/mcp-server/tools/catFactFetcher/index.d.ts +0 -8
  123. package/dist/mcp-server/tools/catFactFetcher/index.d.ts.map +0 -1
  124. package/dist/mcp-server/tools/catFactFetcher/index.js +0 -8
  125. package/dist/mcp-server/tools/catFactFetcher/index.js.map +0 -1
  126. package/dist/mcp-server/tools/catFactFetcher/logic.d.ts +0 -52
  127. package/dist/mcp-server/tools/catFactFetcher/logic.d.ts.map +0 -1
  128. package/dist/mcp-server/tools/catFactFetcher/logic.js +0 -95
  129. package/dist/mcp-server/tools/catFactFetcher/logic.js.map +0 -1
  130. package/dist/mcp-server/tools/catFactFetcher/registration.d.ts +0 -9
  131. package/dist/mcp-server/tools/catFactFetcher/registration.d.ts.map +0 -1
  132. package/dist/mcp-server/tools/catFactFetcher/registration.js +0 -43
  133. package/dist/mcp-server/tools/catFactFetcher/registration.js.map +0 -1
  134. package/dist/mcp-server/tools/echoTool/index.d.ts +0 -13
  135. package/dist/mcp-server/tools/echoTool/index.d.ts.map +0 -1
  136. package/dist/mcp-server/tools/echoTool/index.js +0 -13
  137. package/dist/mcp-server/tools/echoTool/index.js.map +0 -1
  138. package/dist/mcp-server/tools/echoTool/logic.d.ts +0 -69
  139. package/dist/mcp-server/tools/echoTool/logic.d.ts.map +0 -1
  140. package/dist/mcp-server/tools/echoTool/logic.js +0 -119
  141. package/dist/mcp-server/tools/echoTool/logic.js.map +0 -1
  142. package/dist/mcp-server/tools/echoTool/registration.d.ts +0 -9
  143. package/dist/mcp-server/tools/echoTool/registration.d.ts.map +0 -1
  144. package/dist/mcp-server/tools/echoTool/registration.js +0 -45
  145. package/dist/mcp-server/tools/echoTool/registration.js.map +0 -1
  146. package/dist/mcp-server/tools/imageTest/index.d.ts +0 -7
  147. package/dist/mcp-server/tools/imageTest/index.d.ts.map +0 -1
  148. package/dist/mcp-server/tools/imageTest/index.js +0 -7
  149. package/dist/mcp-server/tools/imageTest/index.js.map +0 -1
  150. package/dist/mcp-server/tools/imageTest/logic.d.ts +0 -27
  151. package/dist/mcp-server/tools/imageTest/logic.d.ts.map +0 -1
  152. package/dist/mcp-server/tools/imageTest/logic.js +0 -44
  153. package/dist/mcp-server/tools/imageTest/logic.js.map +0 -1
  154. package/dist/mcp-server/tools/imageTest/registration.d.ts +0 -9
  155. package/dist/mcp-server/tools/imageTest/registration.d.ts.map +0 -1
  156. package/dist/mcp-server/tools/imageTest/registration.js +0 -49
  157. package/dist/mcp-server/tools/imageTest/registration.js.map +0 -1
  158. package/dist/mcp-server/tools/utils/tool-utils.d.ts +0 -43
  159. package/dist/mcp-server/tools/utils/tool-utils.d.ts.map +0 -1
  160. package/dist/mcp-server/tools/utils/tool-utils.js +0 -44
  161. package/dist/mcp-server/tools/utils/tool-utils.js.map +0 -1
  162. package/dist/mcp-server/transports/core/headerUtils.d.ts +0 -27
  163. package/dist/mcp-server/transports/core/headerUtils.d.ts.map +0 -1
  164. package/dist/mcp-server/transports/core/headerUtils.js +0 -53
  165. package/dist/mcp-server/transports/core/headerUtils.js.map +0 -1
  166. package/dist/mcp-server/transports/core/honoNodeBridge.d.ts +0 -77
  167. package/dist/mcp-server/transports/core/honoNodeBridge.d.ts.map +0 -1
  168. package/dist/mcp-server/transports/core/honoNodeBridge.js +0 -150
  169. package/dist/mcp-server/transports/core/honoNodeBridge.js.map +0 -1
  170. package/dist/services/duck-db/duckDBConnectionManager.d.ts +0 -55
  171. package/dist/services/duck-db/duckDBConnectionManager.d.ts.map +0 -1
  172. package/dist/services/duck-db/duckDBConnectionManager.js +0 -184
  173. package/dist/services/duck-db/duckDBConnectionManager.js.map +0 -1
  174. package/dist/services/duck-db/duckDBQueryExecutor.d.ts +0 -18
  175. package/dist/services/duck-db/duckDBQueryExecutor.d.ts.map +0 -1
  176. package/dist/services/duck-db/duckDBQueryExecutor.js +0 -115
  177. package/dist/services/duck-db/duckDBQueryExecutor.js.map +0 -1
  178. package/dist/services/duck-db/duckDBService.d.ts +0 -27
  179. package/dist/services/duck-db/duckDBService.d.ts.map +0 -1
  180. package/dist/services/duck-db/duckDBService.js +0 -151
  181. package/dist/services/duck-db/duckDBService.js.map +0 -1
  182. package/dist/services/duck-db/types.d.ts +0 -135
  183. package/dist/services/duck-db/types.d.ts.map +0 -1
  184. package/dist/services/duck-db/types.js +0 -6
  185. package/dist/services/duck-db/types.js.map +0 -1
  186. package/dist/services/llm-providers/openRouterProvider.d.ts +0 -36
  187. package/dist/services/llm-providers/openRouterProvider.d.ts.map +0 -1
  188. package/dist/services/llm-providers/openRouterProvider.js +0 -235
  189. package/dist/services/llm-providers/openRouterProvider.js.map +0 -1
  190. package/dist/services/supabase/supabaseClient.d.ts +0 -25
  191. package/dist/services/supabase/supabaseClient.d.ts.map +0 -1
  192. package/dist/services/supabase/supabaseClient.js +0 -68
  193. package/dist/services/supabase/supabaseClient.js.map +0 -1
  194. package/dist/storage/duckdbExample.d.ts +0 -8
  195. package/dist/storage/duckdbExample.d.ts.map +0 -1
  196. package/dist/storage/duckdbExample.js +0 -197
  197. package/dist/storage/duckdbExample.js.map +0 -1
@@ -0,0 +1,356 @@
1
+ /**
2
+ * Execute SQL Tool
3
+ *
4
+ * Executes SQL queries on IBM i database with optional security restrictions.
5
+ * Migrated from 3-file pattern to factory pattern.
6
+ *
7
+ * @module executeSql.tool
8
+ * @feature 001-tool-factory
9
+ */
10
+ import { z } from "zod";
11
+ import { JsonRpcErrorCode, McpError } from "../../types-global/errors.js";
12
+ import { getRequestContext, requestContextService, } from "../../utils/index.js";
13
+ import { logger } from "../../utils/internal/logger.js";
14
+ import { SqlSecurityValidator } from "../utils/security/sqlSecurityValidator.js";
15
+ import { logOperationStart, logOperationSuccess, } from "../../utils/internal/logging-helpers.js";
16
+ import { IBMiConnectionPool } from "../services/connectionPool.js";
17
+ import { defineTool } from "../../mcp-server/tools/utils/tool-factory.js";
18
+ import { config } from "../../config/index.js";
19
+ // =============================================================================
20
+ // Constants & Configuration
21
+ // =============================================================================
22
+ const TOOL_NAME = "execute_sql";
23
+ const TOOL_DESCRIPTION = "Executes a SELECT query on the IBM i database and returns the results. Use this tool to retrieve data from database tables and views.";
24
+ /**
25
+ * Default tool configuration
26
+ * Readonly mode is controlled by IBMI_EXECUTE_SQL_READONLY environment variable (defaults to true)
27
+ * This ensures write operations are opt-in for security
28
+ */
29
+ let toolConfig = {
30
+ enabled: true,
31
+ security: {
32
+ readOnly: config.ibmi_executeSqlReadonly,
33
+ maxQueryLength: 10000,
34
+ },
35
+ };
36
+ /**
37
+ * Configure the execute SQL tool
38
+ * @param config - Configuration options
39
+ */
40
+ export function configureExecuteSqlTool(config) {
41
+ const context = getRequestContext() ??
42
+ requestContextService.createRequestContext({
43
+ operation: "ConfigureExecuteSqlTool",
44
+ });
45
+ logOperationStart(context, "Configuring Execute SQL tool", {
46
+ config,
47
+ toolName: TOOL_NAME,
48
+ });
49
+ // Merge with existing config
50
+ toolConfig = {
51
+ ...toolConfig,
52
+ ...config,
53
+ security: {
54
+ ...toolConfig.security,
55
+ ...config.security,
56
+ },
57
+ };
58
+ logOperationSuccess(context, "Execute SQL tool configuration updated", {
59
+ enabled: toolConfig.enabled,
60
+ readOnly: toolConfig.security?.readOnly,
61
+ maxQueryLength: toolConfig.security?.maxQueryLength,
62
+ });
63
+ }
64
+ /**
65
+ * Get the current configuration for the execute SQL tool
66
+ * @returns Current tool configuration
67
+ */
68
+ export function getExecuteSqlConfig() {
69
+ return toolConfig;
70
+ }
71
+ /**
72
+ * Check if the execute SQL tool is enabled
73
+ * @returns True if the tool is enabled
74
+ */
75
+ export function isExecuteSqlEnabled() {
76
+ return toolConfig.enabled;
77
+ }
78
+ // =============================================================================
79
+ // Schemas
80
+ // =============================================================================
81
+ /**
82
+ * Input schema for executing SQL queries
83
+ */
84
+ const ExecuteSqlInputSchema = z.object({
85
+ sql: z
86
+ .string()
87
+ .min(1, "SQL query cannot be empty.")
88
+ .max(10000, "SQL query exceeds maximum length of 10000 characters.")
89
+ .describe("The SQL query to execute on the IBM i database."),
90
+ });
91
+ /**
92
+ * Output schema for SQL execution results
93
+ */
94
+ const ExecuteSqlResponseSchema = z.object({
95
+ success: z.boolean().describe("Whether the query executed successfully."),
96
+ data: z
97
+ .array(z.record(z.unknown()))
98
+ .optional()
99
+ .describe("Array of result rows if query was successful."),
100
+ rowCount: z
101
+ .number()
102
+ .optional()
103
+ .describe("Number of rows returned by the query."),
104
+ executionTime: z
105
+ .number()
106
+ .optional()
107
+ .describe("Query execution time in milliseconds."),
108
+ metadata: z
109
+ .object({
110
+ columns: z
111
+ .array(z.object({
112
+ name: z.string().describe("Column name"),
113
+ type: z.string().describe("Column data type"),
114
+ }))
115
+ .optional()
116
+ .describe("Column metadata for the result set."),
117
+ })
118
+ .optional()
119
+ .describe("Additional metadata about the query results."),
120
+ error: z
121
+ .object({
122
+ code: z.string().describe("Error code"),
123
+ message: z.string().describe("Error message"),
124
+ details: z.record(z.unknown()).optional().describe("Error details"),
125
+ })
126
+ .optional()
127
+ .describe("Error information if the query failed."),
128
+ });
129
+ // =============================================================================
130
+ // Security Validation
131
+ // =============================================================================
132
+ /**
133
+ * Validates SQL query against security restrictions
134
+ * Delegates to centralized SqlSecurityValidator
135
+ * @param sql - SQL query to validate
136
+ * @param appContext - Request context for logging
137
+ * @throws McpError if query violates security restrictions
138
+ */
139
+ function validateSqlSecurity(sql, appContext) {
140
+ const config = getExecuteSqlConfig();
141
+ const securityConfig = {
142
+ readOnly: config.security?.readOnly ?? true,
143
+ maxQueryLength: config.security?.maxQueryLength ?? 10000,
144
+ };
145
+ // Use centralized validator
146
+ SqlSecurityValidator.validateQuery(sql, securityConfig, appContext);
147
+ }
148
+ /**
149
+ * Validate SQL query using IBM i PARSE_STATEMENT
150
+ * Verifies statement type matches readOnly configuration
151
+ * Uses IBM i's native SQL parser for authoritative statement type detection
152
+ *
153
+ * @param sql - SQL query to validate (should be pre-sanitized without trailing semicolons)
154
+ * @param readOnly - Whether readonly mode is enabled
155
+ * @param appContext - Request context for logging
156
+ * @throws {McpError} If validation fails (syntax error, non-query in readonly mode, or execution failure)
157
+ *
158
+ * @see https://www.ibm.com/docs/en/i/7.5?topic=services-parse-statement-table-function
159
+ */
160
+ async function validateWithParseStatement(sql, readOnly, appContext) {
161
+ // Build PARSE_STATEMENT query with named parameters
162
+ const parseQuery = `
163
+ SELECT DISTINCT SQL_STATEMENT_TYPE
164
+ FROM TABLE(QSYS2.PARSE_STATEMENT(
165
+ SQL_STATEMENT => ?,
166
+ NAMING => '*SQL',
167
+ DECIMAL_POINT => '*PERIOD',
168
+ SQL_STRING_DELIMITER => '*APOSTSQL'
169
+ )) AS P
170
+ `.trim();
171
+ try {
172
+ // Execute PARSE_STATEMENT via connection pool
173
+ const result = await IBMiConnectionPool.executeQuery(parseQuery, [sql], appContext);
174
+ // Empty result = syntax error (PARSE_STATEMENT returns no rows on parse failure)
175
+ if (!result.data || result.data.length === 0) {
176
+ throw new McpError(JsonRpcErrorCode.ValidationError, "SQL syntax error: Query could not be parsed by IBM i", {
177
+ query: sql.substring(0, 100) + (sql.length > 100 ? "..." : ""),
178
+ validationMethod: "parse_statement",
179
+ });
180
+ }
181
+ // Extract statement type from first row
182
+ const firstRow = result.data[0];
183
+ const statementType = (firstRow.SQL_STATEMENT_TYPE || "").toUpperCase();
184
+ // Validate statement type against readOnly mode
185
+ if (readOnly && statementType !== "QUERY") {
186
+ throw new McpError(JsonRpcErrorCode.ValidationError, `Non-query statement '${statementType}' not allowed in read-only mode`, {
187
+ query: sql.substring(0, 100) + (sql.length > 100 ? "..." : ""),
188
+ sqlStatementType: statementType,
189
+ readOnly: true,
190
+ validationMethod: "parse_statement",
191
+ });
192
+ }
193
+ logger.debug({
194
+ ...appContext,
195
+ sqlStatementType: statementType,
196
+ readOnly,
197
+ }, "PARSE_STATEMENT validation passed");
198
+ }
199
+ catch (error) {
200
+ // Re-throw McpError as-is
201
+ if (error instanceof McpError) {
202
+ throw error;
203
+ }
204
+ // Fail closed on unexpected errors
205
+ throw new McpError(JsonRpcErrorCode.ValidationError, "SQL validation failed: Unable to execute PARSE_STATEMENT", {
206
+ query: sql.substring(0, 100) + (sql.length > 100 ? "..." : ""),
207
+ validationMethod: "parse_statement",
208
+ originalError: error instanceof Error ? error.message : String(error),
209
+ });
210
+ }
211
+ }
212
+ // =============================================================================
213
+ // Business Logic
214
+ // =============================================================================
215
+ /**
216
+ * Core logic for executing SQL queries
217
+ * Validates security restrictions and executes the query
218
+ */
219
+ async function executeSqlLogic(params, appContext, _sdkContext) {
220
+ // Sanitize SQL: Remove trailing semicolons (statement terminators)
221
+ // IBM i SQL execution and PARSE_STATEMENT expect pure SQL without terminators
222
+ const sanitizedSql = params.sql.trim().replace(/;+\s*$/, "");
223
+ logger.debug({
224
+ ...appContext,
225
+ toolInput: params,
226
+ sanitized: sanitizedSql !== params.sql,
227
+ }, "Processing execute SQL logic.");
228
+ const startTime = Date.now();
229
+ try {
230
+ // Validate security restrictions (AST/Regex - Layer 1)
231
+ validateSqlSecurity(sanitizedSql, appContext);
232
+ // Validate with PARSE_STATEMENT (IBM i native validation - Layer 2)
233
+ const config = getExecuteSqlConfig();
234
+ await validateWithParseStatement(sanitizedSql, config.security?.readOnly ?? true, appContext);
235
+ // Execute the query with sanitized SQL
236
+ const result = await IBMiConnectionPool.executeQueryWithPagination(sanitizedSql, [], appContext, 1000);
237
+ const executionTime = Date.now() - startTime;
238
+ if (!result.success) {
239
+ // Return error response that matches schema
240
+ return {
241
+ success: false,
242
+ executionTime,
243
+ error: {
244
+ code: String(JsonRpcErrorCode.DatabaseError),
245
+ message: "SQL query execution failed",
246
+ details: {
247
+ sql: sanitizedSql,
248
+ sqlReturnCode: result.sql_rc,
249
+ },
250
+ },
251
+ };
252
+ }
253
+ // Type assertion for result data - we know this is an array of records from the database
254
+ const typedData = result.data;
255
+ const response = {
256
+ success: true,
257
+ data: typedData,
258
+ rowCount: typedData?.length ?? 0,
259
+ executionTime,
260
+ metadata: typedData && typedData.length > 0 && typedData[0]
261
+ ? {
262
+ columns: Object.keys(typedData[0]).map((key) => ({
263
+ name: key,
264
+ type: typeof typedData[0][key],
265
+ })),
266
+ }
267
+ : undefined,
268
+ };
269
+ logger.debug({
270
+ ...appContext,
271
+ rowCount: response.rowCount,
272
+ executionTime,
273
+ hasData: !!response.data,
274
+ }, "SQL query executed successfully.");
275
+ return response;
276
+ }
277
+ catch (error) {
278
+ const executionTime = Date.now() - startTime;
279
+ logger.error({
280
+ ...appContext,
281
+ error: error instanceof Error ? error.message : String(error),
282
+ sql: sanitizedSql,
283
+ executionTime,
284
+ }, "SQL query execution failed.");
285
+ // Return error response that matches schema instead of throwing
286
+ if (error instanceof McpError) {
287
+ return {
288
+ success: false,
289
+ executionTime,
290
+ error: {
291
+ code: String(error.code),
292
+ message: error.message,
293
+ details: error.details,
294
+ },
295
+ };
296
+ }
297
+ // Handle unexpected errors
298
+ return {
299
+ success: false,
300
+ executionTime,
301
+ error: {
302
+ code: String(JsonRpcErrorCode.DatabaseError),
303
+ message: `SQL query execution failed: ${error instanceof Error ? error.message : String(error)}`,
304
+ details: {
305
+ sql: sanitizedSql,
306
+ originalError: error instanceof Error ? error.name : "Unknown",
307
+ },
308
+ },
309
+ };
310
+ }
311
+ }
312
+ // =============================================================================
313
+ // Custom Response Formatter
314
+ // =============================================================================
315
+ const executeSqlResponseFormatter = (result) => {
316
+ if (!result.success) {
317
+ // Format error response
318
+ const errorMessage = result.error?.message || "SQL query execution failed";
319
+ const errorDetails = result.error?.details
320
+ ? `\n\nDetails:\n${JSON.stringify(result.error.details, null, 2)}`
321
+ : "";
322
+ return [
323
+ {
324
+ type: "text",
325
+ text: `Error: ${errorMessage}${errorDetails}`,
326
+ },
327
+ ];
328
+ }
329
+ // Format the result as a table-like JSON representation
330
+ const resultJson = JSON.stringify(result.data, null, 2);
331
+ return [
332
+ {
333
+ type: "text",
334
+ text: `SQL query executed successfully.\n\nRows returned: ${result.rowCount}\nExecution time: ${result.executionTime}ms\n\nResults:\n${resultJson}`,
335
+ },
336
+ ];
337
+ };
338
+ // =============================================================================
339
+ // Tool Definition
340
+ // =============================================================================
341
+ export const executeSqlTool = defineTool({
342
+ name: TOOL_NAME,
343
+ title: "Execute SQL",
344
+ description: toolConfig.description || TOOL_DESCRIPTION,
345
+ inputSchema: ExecuteSqlInputSchema,
346
+ outputSchema: ExecuteSqlResponseSchema,
347
+ logic: executeSqlLogic,
348
+ responseFormatter: executeSqlResponseFormatter,
349
+ annotations: {
350
+ readOnlyHint: toolConfig.security?.readOnly ?? true, // Default to true for safety
351
+ destructiveHint: !(toolConfig.security?.readOnly ?? true), // Destructive if not read-only
352
+ openWorldHint: !(toolConfig.security?.readOnly ?? true), // Open world if not read-only
353
+ },
354
+ enabled: () => toolConfig.enabled, // Use function to dynamically check enabled state
355
+ });
356
+ //# sourceMappingURL=executeSql.tool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executeSql.tool.js","sourceRoot":"","sources":["../../../src/ibmi-mcp-server/tools/executeSql.tool.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,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AClF,eAAe,EAAE,CAAC,CAAC,UAAU,CAAC,QAAQ,EAAE,QAAQ,IAAI,IAAI,CAAC,EAAE,+BAA+B;QAC1F,aAAa,EAAE,CAAC,CAAC,UAAU,CAAC,QAAQ,EAAE,QAAQ,IAAI,IAAI,CAAC,EAAE,8BAA8B;KACxF;IACD,OAAO,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,kDAAkD;CACtF,CAAC,CAAC"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Generate SQL DDL Tool
3
+ *
4
+ * Generates SQL DDL statements for IBM i database objects using the QSYS2.GENERATE_SQL procedure.
5
+ * Migrated from 3-file pattern to factory pattern.
6
+ *
7
+ * @module generateSql.tool
8
+ * @feature 001-tool-factory
9
+ */
10
+ import { z } from "zod";
11
+ export declare const generateSqlTool: import("../../mcp-server/tools/utils/types.js").ToolDefinition<{
12
+ object_name: z.ZodString;
13
+ object_library: z.ZodDefault<z.ZodString>;
14
+ object_type: z.ZodDefault<z.ZodEnum<["ALIAS", "CONSTRAINT", "FUNCTION", "INDEX", "MASK", "PERMISSION", "PROCEDURE", "SCHEMA", "SEQUENCE", "TABLE", "TRIGGER", "TYPE", "VARIABLE", "VIEW", "XSR"]>>;
15
+ }, {
16
+ success: z.ZodBoolean;
17
+ sql: z.ZodOptional<z.ZodString>;
18
+ object_name: z.ZodString;
19
+ object_library: z.ZodString;
20
+ object_type: z.ZodString;
21
+ executionTime: z.ZodOptional<z.ZodNumber>;
22
+ error: z.ZodOptional<z.ZodObject<{
23
+ code: z.ZodString;
24
+ message: z.ZodString;
25
+ details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
26
+ }, "strip", z.ZodTypeAny, {
27
+ code: string;
28
+ message: string;
29
+ details?: Record<string, unknown> | undefined;
30
+ }, {
31
+ code: string;
32
+ message: string;
33
+ details?: Record<string, unknown> | undefined;
34
+ }>>;
35
+ }>;
36
+ //# sourceMappingURL=generateSql.tool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateSql.tool.d.ts","sourceRoot":"","sources":["../../../src/ibmi-mcp-server/tools/generateSql.tool.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAoUxB,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;EAc1B,CAAC"}