@ibm/ibmi-mcp-server 0.3.2 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -24
- 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/config/resolver.d.ts.map +1 -1
- package/dist/config/resolver.js +6 -0
- package/dist/config/resolver.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/cli/argumentParser.d.ts +2 -0
- package/dist/ibmi-mcp-server/utils/cli/argumentParser.d.ts.map +1 -1
- package/dist/ibmi-mcp-server/utils/cli/argumentParser.js +21 -7
- package/dist/ibmi-mcp-server/utils/cli/argumentParser.js.map +1 -1
- package/dist/ibmi-mcp-server/utils/security/sqlSecurityValidator.js +1 -1
- package/dist/ibmi-mcp-server/utils/security/sqlSecurityValidator.js.map +1 -1
- package/dist/mcp-server/tools/index.d.ts.map +1 -1
- package/dist/mcp-server/tools/index.js +5 -3
- package/dist/mcp-server/tools/index.js.map +1 -1
- package/package.json +6 -4
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Zod schemas for validating CLI configuration files.
|
|
3
|
+
* @module cli/config/schema
|
|
4
|
+
*/
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
/** Schema for a single system configuration entry. */
|
|
7
|
+
export const SystemConfigSchema = z.object({
|
|
8
|
+
description: z.string().optional(),
|
|
9
|
+
host: z.string().min(1, "host is required"),
|
|
10
|
+
port: z.coerce.number().int().positive().default(8076),
|
|
11
|
+
user: z.string().min(1, "user is required"),
|
|
12
|
+
password: z.string().optional(),
|
|
13
|
+
defaultSchema: z.string().optional(),
|
|
14
|
+
readOnly: z.boolean().default(false),
|
|
15
|
+
confirm: z.boolean().default(false),
|
|
16
|
+
timeout: z.coerce.number().int().positive().default(60),
|
|
17
|
+
maxRows: z.coerce.number().int().positive().default(5000),
|
|
18
|
+
ignoreUnauthorized: z.boolean().default(true),
|
|
19
|
+
tools: z.array(z.string()).optional(),
|
|
20
|
+
});
|
|
21
|
+
/** Valid output format values. */
|
|
22
|
+
const OutputFormatEnum = z.enum(["table", "json", "csv", "markdown"]);
|
|
23
|
+
/** Schema for the full CLI config file. */
|
|
24
|
+
export const CliConfigSchema = z.object({
|
|
25
|
+
default: z.string().optional(),
|
|
26
|
+
format: OutputFormatEnum.optional(),
|
|
27
|
+
systems: z.record(z.string(), SystemConfigSchema).default({}),
|
|
28
|
+
});
|
|
29
|
+
/** Validate that the default system references an existing system. */
|
|
30
|
+
export function validateConfig(config) {
|
|
31
|
+
const errors = [];
|
|
32
|
+
if (config.default && !config.systems[config.default]) {
|
|
33
|
+
errors.push(`Default system "${config.default}" is not defined in systems. Available: ${Object.keys(config.systems).join(", ") || "(none)"}`);
|
|
34
|
+
}
|
|
35
|
+
return errors;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/cli/config/schema.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,sDAAsD;AACtD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,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AC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC9B,MAAM,EAAE,gBAAgB,CAAC,QAAQ,EAAE;IACnC,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,kBAAkB,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;CAC9D,CAAC,CAAC;AAEH,sEAAsE;AACtE,MAAM,UAAU,cAAc,CAC5B,MAAuC;IAEvC,MAAM,MAAM,GAAa,EAAE,CAAC;IAE5B,IAAI,MAAM,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;QACtD,MAAM,CAAC,IAAI,CACT,mBAAmB,MAAM,CAAC,OAAO,2CAA2C,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,QAAQ,EAAE,CACjI,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview TypeScript types for the IBM i CLI configuration system.
|
|
3
|
+
* @module cli/config/types
|
|
4
|
+
*/
|
|
5
|
+
/** Connection configuration for a single IBM i system. */
|
|
6
|
+
export interface SystemConfig {
|
|
7
|
+
/** Human-readable description of this system. */
|
|
8
|
+
description?: string;
|
|
9
|
+
/** Hostname or IP address of the IBM i system. */
|
|
10
|
+
host: string;
|
|
11
|
+
/** Mapepire WebSocket port. Default: 8076. */
|
|
12
|
+
port: number;
|
|
13
|
+
/** User profile for authentication. */
|
|
14
|
+
user: string;
|
|
15
|
+
/** Password (supports ${ENV_VAR} expansion). */
|
|
16
|
+
password?: string;
|
|
17
|
+
/** Default schema/library for queries. */
|
|
18
|
+
defaultSchema?: string;
|
|
19
|
+
/** Block mutation queries (INSERT, UPDATE, DELETE, DROP). */
|
|
20
|
+
readOnly: boolean;
|
|
21
|
+
/** Require interactive confirmation before executing queries. */
|
|
22
|
+
confirm: boolean;
|
|
23
|
+
/** Query execution timeout in seconds. */
|
|
24
|
+
timeout: number;
|
|
25
|
+
/** Maximum rows returned per query. */
|
|
26
|
+
maxRows: number;
|
|
27
|
+
/** Ignore unauthorized SSL certificates. */
|
|
28
|
+
ignoreUnauthorized: boolean;
|
|
29
|
+
/** Additional YAML tool files for this system. */
|
|
30
|
+
tools?: string[];
|
|
31
|
+
}
|
|
32
|
+
/** Full CLI configuration file structure. */
|
|
33
|
+
export interface CliConfig {
|
|
34
|
+
/** Name of the default system to use. */
|
|
35
|
+
default?: string;
|
|
36
|
+
/** Default output format (table, json, csv, markdown). Overrides TTY auto-detection. */
|
|
37
|
+
format?: OutputFormat;
|
|
38
|
+
/** Named system configurations. */
|
|
39
|
+
systems: Record<string, SystemConfig>;
|
|
40
|
+
}
|
|
41
|
+
/** Resolved system context for a CLI command execution. */
|
|
42
|
+
export interface ResolvedSystem {
|
|
43
|
+
/** The system name (from config, "env" for legacy env vars). */
|
|
44
|
+
name: string;
|
|
45
|
+
/** The resolved system configuration. */
|
|
46
|
+
config: SystemConfig;
|
|
47
|
+
/** How this system was resolved. */
|
|
48
|
+
source: "flag" | "env" | "config-default" | "legacy-env";
|
|
49
|
+
}
|
|
50
|
+
/** Output format options. */
|
|
51
|
+
export type OutputFormat = "table" | "json" | "csv" | "markdown";
|
|
52
|
+
/** Global CLI options passed to every command. */
|
|
53
|
+
export interface GlobalOptions {
|
|
54
|
+
system?: string;
|
|
55
|
+
format?: OutputFormat;
|
|
56
|
+
raw?: boolean;
|
|
57
|
+
noColor?: boolean;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/cli/config/types.ts"],"names":[],"mappings":"AA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,CAAC;IAChB,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/cli/config/types.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Central output controller for the IBM i CLI.
|
|
3
|
+
* Handles TTY detection, format routing, and consistent output rendering.
|
|
4
|
+
*
|
|
5
|
+
* Supports two JSON output modes:
|
|
6
|
+
* - **Envelope** (default): `{ok, system, host, command, data, meta}` — full result in one object
|
|
7
|
+
* - **NDJSON** (--stream): One JSON object per row, newline-delimited — for piped workflows
|
|
8
|
+
*
|
|
9
|
+
* @module cli/formatters/output
|
|
10
|
+
*/
|
|
11
|
+
import type { OutputFormat, ResolvedSystem } from "../config/types.js";
|
|
12
|
+
import { type ErrorCodeValue } from "../utils/exit-codes.js";
|
|
13
|
+
/**
|
|
14
|
+
* Set the output file path. When set, all output is buffered and written
|
|
15
|
+
* to the file on `finalizeOutput()`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function setOutputFile(filePath: string | undefined): void;
|
|
18
|
+
/**
|
|
19
|
+
* Finalize file output — write buffered content to file and print confirmation to stderr.
|
|
20
|
+
*/
|
|
21
|
+
export declare function finalizeOutput(): void;
|
|
22
|
+
/** Result metadata for output rendering. */
|
|
23
|
+
export interface OutputMeta {
|
|
24
|
+
/** Number of rows returned. */
|
|
25
|
+
rowCount: number;
|
|
26
|
+
/** Whether more rows exist beyond the current result. */
|
|
27
|
+
hasMore?: boolean;
|
|
28
|
+
/** Time taken for the query in milliseconds. */
|
|
29
|
+
elapsedMs?: number;
|
|
30
|
+
/** The resolved system used for this command. */
|
|
31
|
+
system?: ResolvedSystem;
|
|
32
|
+
/** The command name (e.g., "schemas", "sql", "tool:system_status"). */
|
|
33
|
+
command?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Detect the appropriate output format.
|
|
37
|
+
*
|
|
38
|
+
* Priority: --raw → --format → config format → TTY auto-detect (table/json).
|
|
39
|
+
*/
|
|
40
|
+
export declare function detectFormat(explicitFormat?: OutputFormat, raw?: boolean, configFormat?: OutputFormat): OutputFormat;
|
|
41
|
+
/**
|
|
42
|
+
* Render query results to stdout in the specified format.
|
|
43
|
+
*/
|
|
44
|
+
export declare function renderOutput(data: Record<string, unknown>[], format: OutputFormat, meta?: OutputMeta): void;
|
|
45
|
+
/**
|
|
46
|
+
* Render results as NDJSON (newline-delimited JSON) for streaming.
|
|
47
|
+
* Each row is a separate JSON object on its own line.
|
|
48
|
+
* Agents and tools like `jq` can process rows incrementally.
|
|
49
|
+
*/
|
|
50
|
+
export declare function renderNdjson(data: Record<string, unknown>[]): void;
|
|
51
|
+
/**
|
|
52
|
+
* Render an error to stderr. In JSON mode, outputs structured error JSON to stdout
|
|
53
|
+
* with an error code for programmatic consumption.
|
|
54
|
+
*/
|
|
55
|
+
export declare function renderError(error: Error, format: OutputFormat, system?: ResolvedSystem, errorCode?: ErrorCodeValue): void;
|
|
56
|
+
/**
|
|
57
|
+
* Render a simple message to stdout (e.g., success confirmation).
|
|
58
|
+
*/
|
|
59
|
+
export declare function renderMessage(message: string, format: OutputFormat): void;
|
|
60
|
+
//# sourceMappingURL=output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../../src/cli/formatters/output.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAEL,KAAK,cAAc,EACpB,MAAM,wBAAwB,CAAC;AAMhC;;;GAGG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAGhE;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,IAAI,CAOrC;AAWD,4CAA4C;AAC5C,MAAM,WAAW,UAAU;IACzB,+BAA+B;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,yDAAyD;IACzD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,gDAAgD;IAChD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iDAAiD;IACjD,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,uEAAuE;IACvE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,cAAc,CAAC,EAAE,YAAY,EAC7B,GAAG,CAAC,EAAE,OAAO,EACb,YAAY,CAAC,EAAE,YAAY,GAC1B,YAAY,CAKd;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAC/B,MAAM,EAAE,YAAY,EACpB,IAAI,CAAC,EAAE,UAAU,GAChB,IAAI,CAgBN;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAC9B,IAAI,CAIN;AAuFD;;;GAGG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,YAAY,EACpB,MAAM,CAAC,EAAE,cAAc,EACvB,SAAS,CAAC,EAAE,cAAc,GACzB,IAAI,CAeN;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,YAAY,GACnB,IAAI,CAMN"}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Central output controller for the IBM i CLI.
|
|
3
|
+
* Handles TTY detection, format routing, and consistent output rendering.
|
|
4
|
+
*
|
|
5
|
+
* Supports two JSON output modes:
|
|
6
|
+
* - **Envelope** (default): `{ok, system, host, command, data, meta}` — full result in one object
|
|
7
|
+
* - **NDJSON** (--stream): One JSON object per row, newline-delimited — for piped workflows
|
|
8
|
+
*
|
|
9
|
+
* @module cli/formatters/output
|
|
10
|
+
*/
|
|
11
|
+
import { writeFileSync } from "fs";
|
|
12
|
+
import { tableFormatter } from "../../utils/formatting/tableFormatter.js";
|
|
13
|
+
import { classifyError, } from "../utils/exit-codes.js";
|
|
14
|
+
/** Module-level output file path set by --output global option. */
|
|
15
|
+
let outputFilePath;
|
|
16
|
+
let outputBuffer;
|
|
17
|
+
/**
|
|
18
|
+
* Set the output file path. When set, all output is buffered and written
|
|
19
|
+
* to the file on `finalizeOutput()`.
|
|
20
|
+
*/
|
|
21
|
+
export function setOutputFile(filePath) {
|
|
22
|
+
outputFilePath = filePath;
|
|
23
|
+
outputBuffer = filePath ? [] : undefined;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Finalize file output — write buffered content to file and print confirmation to stderr.
|
|
27
|
+
*/
|
|
28
|
+
export function finalizeOutput() {
|
|
29
|
+
if (outputBuffer && outputFilePath) {
|
|
30
|
+
writeFileSync(outputFilePath, outputBuffer.join(""), "utf-8");
|
|
31
|
+
process.stderr.write(`Output written to ${outputFilePath}\n`);
|
|
32
|
+
outputBuffer = undefined;
|
|
33
|
+
outputFilePath = undefined;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** Write to the current output destination (file buffer or stdout). */
|
|
37
|
+
function writeOutput(data) {
|
|
38
|
+
if (outputBuffer) {
|
|
39
|
+
outputBuffer.push(data);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
process.stdout.write(data);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Detect the appropriate output format.
|
|
47
|
+
*
|
|
48
|
+
* Priority: --raw → --format → config format → TTY auto-detect (table/json).
|
|
49
|
+
*/
|
|
50
|
+
export function detectFormat(explicitFormat, raw, configFormat) {
|
|
51
|
+
if (raw)
|
|
52
|
+
return "json";
|
|
53
|
+
if (explicitFormat)
|
|
54
|
+
return explicitFormat;
|
|
55
|
+
if (configFormat)
|
|
56
|
+
return configFormat;
|
|
57
|
+
return process.stdout.isTTY ? "table" : "json";
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Render query results to stdout in the specified format.
|
|
61
|
+
*/
|
|
62
|
+
export function renderOutput(data, format, meta) {
|
|
63
|
+
switch (format) {
|
|
64
|
+
case "json":
|
|
65
|
+
renderJson(data, meta);
|
|
66
|
+
break;
|
|
67
|
+
case "csv":
|
|
68
|
+
renderCsv(data);
|
|
69
|
+
break;
|
|
70
|
+
case "markdown":
|
|
71
|
+
renderTable(data, "markdown", meta);
|
|
72
|
+
break;
|
|
73
|
+
case "table":
|
|
74
|
+
default:
|
|
75
|
+
renderTable(data, "grid", meta);
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Render results as NDJSON (newline-delimited JSON) for streaming.
|
|
81
|
+
* Each row is a separate JSON object on its own line.
|
|
82
|
+
* Agents and tools like `jq` can process rows incrementally.
|
|
83
|
+
*/
|
|
84
|
+
export function renderNdjson(data) {
|
|
85
|
+
for (const row of data) {
|
|
86
|
+
writeOutput(JSON.stringify(row) + "\n");
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Render as JSON envelope to stdout.
|
|
91
|
+
*/
|
|
92
|
+
function renderJson(data, meta) {
|
|
93
|
+
const output = {
|
|
94
|
+
ok: true,
|
|
95
|
+
...(meta?.system ? { system: meta.system.name, host: meta.system.config.host } : {}),
|
|
96
|
+
...(meta?.command ? { command: meta.command } : {}),
|
|
97
|
+
data,
|
|
98
|
+
meta: {
|
|
99
|
+
rows: meta?.rowCount ?? data.length,
|
|
100
|
+
hasMore: meta?.hasMore ?? false,
|
|
101
|
+
...(meta?.elapsedMs !== undefined ? { elapsed_ms: meta.elapsedMs } : {}),
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
writeOutput(JSON.stringify(output, null, 2) + "\n");
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Render as CSV to stdout.
|
|
108
|
+
*/
|
|
109
|
+
function renderCsv(data) {
|
|
110
|
+
if (data.length === 0)
|
|
111
|
+
return;
|
|
112
|
+
const headers = Object.keys(data[0]);
|
|
113
|
+
// Header row
|
|
114
|
+
writeOutput(headers.map(escapeCsvField).join(",") + "\n");
|
|
115
|
+
// Data rows
|
|
116
|
+
for (const row of data) {
|
|
117
|
+
const values = headers.map((h) => {
|
|
118
|
+
const val = row[h];
|
|
119
|
+
return val === null || val === undefined ? "" : String(val);
|
|
120
|
+
});
|
|
121
|
+
writeOutput(values.map(escapeCsvField).join(",") + "\n");
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function escapeCsvField(field) {
|
|
125
|
+
if (field.includes(",") || field.includes('"') || field.includes("\n")) {
|
|
126
|
+
return `"${field.replace(/"/g, '""')}"`;
|
|
127
|
+
}
|
|
128
|
+
return field;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Render as a formatted table to stdout.
|
|
132
|
+
*/
|
|
133
|
+
function renderTable(data, style, meta) {
|
|
134
|
+
if (data.length === 0) {
|
|
135
|
+
writeOutput("No results.\n");
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const table = tableFormatter.format(data, { style, headerStyle: "uppercase" });
|
|
139
|
+
writeOutput(table + "\n");
|
|
140
|
+
// Footer with metadata
|
|
141
|
+
const parts = [];
|
|
142
|
+
if (meta?.system) {
|
|
143
|
+
parts.push(`[${meta.system.name}] ${meta.system.config.host}`);
|
|
144
|
+
}
|
|
145
|
+
if (meta?.rowCount !== undefined) {
|
|
146
|
+
parts.push(`${meta.rowCount} row${meta.rowCount !== 1 ? "s" : ""}`);
|
|
147
|
+
}
|
|
148
|
+
if (meta?.hasMore) {
|
|
149
|
+
parts.push("(more available — use --limit/--offset)");
|
|
150
|
+
}
|
|
151
|
+
if (meta?.elapsedMs !== undefined) {
|
|
152
|
+
parts.push(`${(meta.elapsedMs / 1000).toFixed(2)}s`);
|
|
153
|
+
}
|
|
154
|
+
if (parts.length > 0) {
|
|
155
|
+
writeOutput(parts.join(" · ") + "\n");
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Render an error to stderr. In JSON mode, outputs structured error JSON to stdout
|
|
160
|
+
* with an error code for programmatic consumption.
|
|
161
|
+
*/
|
|
162
|
+
export function renderError(error, format, system, errorCode) {
|
|
163
|
+
if (format === "json") {
|
|
164
|
+
const classified = classifyError(error);
|
|
165
|
+
const output = {
|
|
166
|
+
ok: false,
|
|
167
|
+
...(system ? { system: system.name } : {}),
|
|
168
|
+
error: {
|
|
169
|
+
code: errorCode ?? classified.errorCode,
|
|
170
|
+
message: error.message,
|
|
171
|
+
},
|
|
172
|
+
};
|
|
173
|
+
writeOutput(JSON.stringify(output, null, 2) + "\n");
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
process.stderr.write(`Error: ${error.message}\n`);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Render a simple message to stdout (e.g., success confirmation).
|
|
181
|
+
*/
|
|
182
|
+
export function renderMessage(message, format) {
|
|
183
|
+
if (format === "json") {
|
|
184
|
+
writeOutput(JSON.stringify({ ok: true, message }) + "\n");
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
writeOutput(message + "\n");
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
//# sourceMappingURL=output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../../../src/cli/formatters/output.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;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and agent-friendly command-line interface to IBM i systems,
|
|
5
|
+
* reusing the same tool infrastructure as the MCP server.
|
|
6
|
+
* @module cli/index
|
|
7
|
+
*/
|
|
8
|
+
import { Command } from "commander";
|
|
9
|
+
/**
|
|
10
|
+
* Create and configure the CLI program.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createProgram(): Command;
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";AAEA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA0CpC;;GAEG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAmCvC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Entry point for the IBM i CLI (`ibmi`).
|
|
4
|
+
* Provides a human-friendly and agent-friendly command-line interface to IBM i systems,
|
|
5
|
+
* reusing the same tool infrastructure as the MCP server.
|
|
6
|
+
* @module cli/index
|
|
7
|
+
*/
|
|
8
|
+
import { Command } from "commander";
|
|
9
|
+
import { readFileSync } from "fs";
|
|
10
|
+
import path from "path";
|
|
11
|
+
import { fileURLToPath } from "url";
|
|
12
|
+
import { registerSystemCommand } from "./commands/system.js";
|
|
13
|
+
import { registerSchemasCommand } from "./commands/schemas.js";
|
|
14
|
+
import { registerTablesCommand } from "./commands/tables.js";
|
|
15
|
+
import { registerColumnsCommand } from "./commands/columns.js";
|
|
16
|
+
import { registerRelatedCommand } from "./commands/related.js";
|
|
17
|
+
import { registerValidateCommand } from "./commands/validate.js";
|
|
18
|
+
import { registerSqlCommand } from "./commands/sql.js";
|
|
19
|
+
import { registerToolCommand } from "./commands/tool.js";
|
|
20
|
+
import { registerToolsCommand, registerToolsetsCommand } from "./commands/tools-list.js";
|
|
21
|
+
import { registerCompletionCommand } from "./commands/completion.js";
|
|
22
|
+
/**
|
|
23
|
+
* Load version from package.json.
|
|
24
|
+
*/
|
|
25
|
+
function getVersion() {
|
|
26
|
+
try {
|
|
27
|
+
const currentDir = path.dirname(fileURLToPath(import.meta.url));
|
|
28
|
+
// Walk up to find package.json (handles both src/ and dist/)
|
|
29
|
+
let dir = currentDir;
|
|
30
|
+
for (let i = 0; i < 5; i++) {
|
|
31
|
+
try {
|
|
32
|
+
const pkg = JSON.parse(readFileSync(path.join(dir, "package.json"), "utf-8"));
|
|
33
|
+
if (pkg.name === "@ibm/ibmi-mcp-server") {
|
|
34
|
+
return pkg.version;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// Continue searching
|
|
39
|
+
}
|
|
40
|
+
dir = path.dirname(dir);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
// Fallback
|
|
45
|
+
}
|
|
46
|
+
return "0.0.0";
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Create and configure the CLI program.
|
|
50
|
+
*/
|
|
51
|
+
export function createProgram() {
|
|
52
|
+
const program = new Command();
|
|
53
|
+
program
|
|
54
|
+
.name("ibmi")
|
|
55
|
+
.description("IBM i command-line interface — query, explore, and manage IBM i systems")
|
|
56
|
+
.version(getVersion(), "-v, --version")
|
|
57
|
+
.option("--system <name>", "Target system name (overrides IBMI_SYSTEM and config default)")
|
|
58
|
+
.option("--format <type>", "Output format: table, json, csv, markdown", undefined)
|
|
59
|
+
.option("--raw", "Output as JSON (shorthand for --format json)")
|
|
60
|
+
.option("--no-color", "Disable colored output")
|
|
61
|
+
.option("--tools <path>", "Path to YAML tool file(s) or directory (comma-separated)")
|
|
62
|
+
.option("--stream", "Stream results as NDJSON (one JSON object per line)")
|
|
63
|
+
.option("--watch <seconds>", "Re-run command at interval (seconds)")
|
|
64
|
+
.option("--output <path>", "Write output to file instead of stdout");
|
|
65
|
+
// Register command groups
|
|
66
|
+
registerSystemCommand(program);
|
|
67
|
+
registerSchemasCommand(program);
|
|
68
|
+
registerTablesCommand(program);
|
|
69
|
+
registerColumnsCommand(program);
|
|
70
|
+
registerRelatedCommand(program);
|
|
71
|
+
registerValidateCommand(program);
|
|
72
|
+
registerSqlCommand(program);
|
|
73
|
+
registerToolCommand(program);
|
|
74
|
+
registerToolsCommand(program);
|
|
75
|
+
registerToolsetsCommand(program);
|
|
76
|
+
registerCompletionCommand(program);
|
|
77
|
+
// Add a helpful message for when no command is given
|
|
78
|
+
program.action(() => {
|
|
79
|
+
program.outputHelp();
|
|
80
|
+
});
|
|
81
|
+
return program;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Main entry point.
|
|
85
|
+
*/
|
|
86
|
+
async function main() {
|
|
87
|
+
const program = createProgram();
|
|
88
|
+
try {
|
|
89
|
+
await program.parseAsync(process.argv);
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
// Commander handles most errors, but catch anything unexpected
|
|
93
|
+
process.stderr.write(`Error: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
94
|
+
process.exitCode = 1; // Top-level catch uses code 1 (general)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
main();
|
|
98
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";AAEA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAClC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,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C;QACH,MAAM,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACzC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,+DAA+D;QAC/D,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,UAAU,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAC/D,CAAC;QACF,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,wCAAwC;IAChE,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Shared utilities for CLI command implementations.
|
|
3
|
+
* Provides the `withConnection` wrapper that handles the full lifecycle
|
|
4
|
+
* of system resolution, connection setup, execution, rendering, and cleanup.
|
|
5
|
+
*
|
|
6
|
+
* @module cli/utils/command-helpers
|
|
7
|
+
*/
|
|
8
|
+
import { Command } from "commander";
|
|
9
|
+
import type { OutputFormat, ResolvedSystem } from "../config/types.js";
|
|
10
|
+
import type { RequestContext } from "../../utils/internal/requestContext.js";
|
|
11
|
+
import { type OutputMeta } from "../formatters/output.js";
|
|
12
|
+
/**
|
|
13
|
+
* Get the effective output format from parent command options and config.
|
|
14
|
+
*
|
|
15
|
+
* Priority: --raw → --format → config format → TTY auto-detect.
|
|
16
|
+
*/
|
|
17
|
+
export declare function getFormat(cmd: Command): OutputFormat;
|
|
18
|
+
/**
|
|
19
|
+
* Check if --stream mode is enabled.
|
|
20
|
+
*/
|
|
21
|
+
export declare function isStreaming(cmd: Command): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Create a minimal RequestContext for CLI tool execution.
|
|
24
|
+
* Avoids importing the full server utils (which would trigger OpenTelemetry).
|
|
25
|
+
*/
|
|
26
|
+
export declare function createCliContext(toolName: string): RequestContext;
|
|
27
|
+
/** Result shape expected from command actions. */
|
|
28
|
+
export interface CommandResult {
|
|
29
|
+
data: Record<string, unknown>[];
|
|
30
|
+
meta?: Partial<OutputMeta>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Standard command action wrapper.
|
|
34
|
+
*
|
|
35
|
+
* Handles the full lifecycle:
|
|
36
|
+
* 1. Resolve target system from --system flag / env / config
|
|
37
|
+
* 2. Connect (set env vars for IBMiConnectionPool)
|
|
38
|
+
* 3. Run the action callback
|
|
39
|
+
* 4. Render output in the requested format (or NDJSON if --stream)
|
|
40
|
+
* 5. Cleanup (close pool) in finally block
|
|
41
|
+
* 6. Set semantic exit code on error
|
|
42
|
+
*
|
|
43
|
+
* When --watch <seconds> is set, the connect-execute-render cycle repeats
|
|
44
|
+
* at the given interval until Ctrl+C is received.
|
|
45
|
+
*/
|
|
46
|
+
export declare function withConnection(cmd: Command, toolName: string, action: (resolved: ResolvedSystem, ctx: RequestContext) => Promise<CommandResult>): Promise<void>;
|
|
47
|
+
//# sourceMappingURL=command-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-helpers.d.ts","sourceRoot":"","sources":["../../../src/cli/utils/command-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAK7E,OAAO,EAOL,KAAK,UAAU,EAChB,MAAM,yBAAyB,CAAC;AAEjC;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,OAAO,GAAG,YAAY,CAapD;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAGjD;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,cAAc,CAOjE;AAED,kDAAkD;AAClD,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;IAChC,IAAI,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;CAC5B;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,OAAO,EACZ,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,CACN,QAAQ,EAAE,cAAc,EACxB,GAAG,EAAE,cAAc,KAChB,OAAO,CAAC,aAAa,CAAC,GAC1B,OAAO,CAAC,IAAI,CAAC,CAsDf"}
|