@alcyone-labs/arg-parser 1.0.0 → 1.2.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.
@@ -0,0 +1,148 @@
1
+ import { ArgParserBase } from "./ArgParserBase";
2
+ import type { GenerateMcpToolsOptions, IMcpToolStructure } from "./mcp-integration";
3
+ /**
4
+ * Configuration for a single MCP transport
5
+ */
6
+ export type McpTransportConfig = {
7
+ type: "stdio" | "sse" | "streamable-http";
8
+ port?: number;
9
+ host?: string;
10
+ path?: string;
11
+ sessionIdGenerator?: () => string;
12
+ };
13
+ /**
14
+ * Configuration options for MCP sub-command
15
+ */
16
+ export type McpSubCommandOptions = {
17
+ /** Preset transport configurations to use when no CLI flags are provided */
18
+ defaultTransports?: McpTransportConfig[];
19
+ /** Single preset transport configuration (alternative to defaultTransports) */
20
+ defaultTransport?: McpTransportConfig;
21
+ };
22
+ /**
23
+ * ArgParser with Model Context Protocol (MCP) integration capabilities.
24
+ *
25
+ * This class adds MCP server functionality on top of the standard ArgParser,
26
+ * allowing CLI tools to be easily exposed as MCP tools with minimal boilerplate.
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * const parser = new ArgParser({
31
+ * appName: "My CLI",
32
+ * appCommandName: "my-cli",
33
+ * handler: async (ctx) => ({ result: "success" })
34
+ * })
35
+ * .addFlags([...])
36
+ * .addMcpSubCommand("serve", {
37
+ * name: "my-cli-mcp-server",
38
+ * version: "1.0.0"
39
+ * });
40
+ * ```
41
+ */
42
+ export declare class ArgParser<THandlerReturn = any> extends ArgParserBase<THandlerReturn> {
43
+ #private;
44
+ /**
45
+ * Generate MCP tools from this ArgParser instance
46
+ * @param options Optional configuration for MCP tool generation
47
+ * @returns Array of MCP tool structures ready for server registration
48
+ */
49
+ toMcpTools(options?: GenerateMcpToolsOptions): IMcpToolStructure[];
50
+ /**
51
+ * Create an MCP server with tools generated from this ArgParser
52
+ * @param serverInfo Server configuration
53
+ * @param toolOptions Optional MCP tool generation options
54
+ * @returns Configured MCP server instance
55
+ */
56
+ createMcpServer(serverInfo: {
57
+ name: string;
58
+ version: string;
59
+ description?: string;
60
+ }, toolOptions?: GenerateMcpToolsOptions): Promise<any>;
61
+ /**
62
+ * Start an MCP server using stdio transport
63
+ * @param serverInfo Server configuration
64
+ * @param toolOptions Optional MCP tool generation options
65
+ * @returns Promise that resolves when server is connected
66
+ */
67
+ startMcpServer(serverInfo: {
68
+ name: string;
69
+ version: string;
70
+ description?: string;
71
+ }, toolOptions?: GenerateMcpToolsOptions): Promise<void>;
72
+ /**
73
+ * Start an MCP server with multiple transport types simultaneously
74
+ * @param serverInfo Server configuration
75
+ * @param transports Array of transport configurations
76
+ * @param toolOptions Optional MCP tool generation options
77
+ * @returns Promise that resolves when all servers are started
78
+ */
79
+ startMcpServerWithMultipleTransports(serverInfo: {
80
+ name: string;
81
+ version: string;
82
+ description?: string;
83
+ }, transports: Array<{
84
+ type: "stdio" | "sse" | "streamable-http";
85
+ port?: number;
86
+ host?: string;
87
+ path?: string;
88
+ sessionIdGenerator?: () => string;
89
+ }>, toolOptions?: GenerateMcpToolsOptions): Promise<void>;
90
+ /**
91
+ * Start an MCP server with a specific transport type
92
+ * @param serverInfo Server configuration
93
+ * @param transportType Type of transport to use
94
+ * @param transportOptions Transport-specific options
95
+ * @param toolOptions Optional MCP tool generation options
96
+ * @returns Promise that resolves when server is connected
97
+ */
98
+ startMcpServerWithTransport(serverInfo: {
99
+ name: string;
100
+ version: string;
101
+ description?: string;
102
+ }, transportType: "stdio" | "sse" | "streamable-http", transportOptions?: {
103
+ port?: number;
104
+ host?: string;
105
+ path?: string;
106
+ sessionIdGenerator?: () => string;
107
+ }, toolOptions?: GenerateMcpToolsOptions): Promise<void>;
108
+ parse(processArgs: string[], options?: any): any;
109
+ /**
110
+ * Async version of parse for when async handlers are detected
111
+ */
112
+ parseAsync(processArgs: string[], options?: any): Promise<any>;
113
+ /**
114
+ * Add an MCP sub-command that starts an MCP server exposing this parser's functionality
115
+ * @param subCommandName Name of the sub-command (default: "mcp-server")
116
+ * @param serverInfo Server configuration
117
+ * @param options Optional configuration including preset transports and tool options
118
+ * @returns This ArgParserWithMcp instance for chaining
119
+ */
120
+ addMcpSubCommand(subCommandName: string | undefined, serverInfo: {
121
+ name: string;
122
+ version: string;
123
+ description?: string;
124
+ }, options?: McpSubCommandOptions & {
125
+ toolOptions?: GenerateMcpToolsOptions;
126
+ }): this;
127
+ /**
128
+ * Add an MCP sub-command that starts an MCP server exposing this parser's functionality
129
+ * @param subCommandName Name of the sub-command (default: "mcp-server")
130
+ * @param serverInfo Server configuration
131
+ * @param toolOptions Optional MCP tool generation options (backward compatibility)
132
+ * @returns This ArgParserWithMcp instance for chaining
133
+ * @deprecated Use the options parameter instead for better configurability
134
+ */
135
+ addMcpSubCommand(subCommandName: string | undefined, serverInfo: {
136
+ name: string;
137
+ version: string;
138
+ description?: string;
139
+ }, toolOptions?: GenerateMcpToolsOptions): this;
140
+ /**
141
+ * Factory method to create an ArgParser instance with MCP capabilities
142
+ * This provides a clean API for users who want MCP functionality from the start
143
+ * Automatically sets handleErrors: false for MCP compatibility
144
+ */
145
+ static withMcp<T = any>(options?: ConstructorParameters<typeof ArgParserBase>[0], initialFlags?: ConstructorParameters<typeof ArgParserBase>[1]): ArgParser<T>;
146
+ static fromArgParser<T = any>(parser: ArgParserBase<T>): ArgParser<T>;
147
+ }
148
+ //# sourceMappingURL=ArgParser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ArgParser.d.ts","sourceRoot":"","sources":["../../src/ArgParser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAIhD,OAAO,KAAK,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAGpF;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,OAAO,GAAG,KAAK,GAAG,iBAAiB,CAAC;IAC1C,IAA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QAChB,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,EACD,WAAW,CAAC,EAAE,uBAAuB,GACpC,IAAI;IAyIP;;;;OAIG;WACW,OAAO,CAAC,CAAC,GAAG,GAAG,EAC3B,OAAO,CAAC,EAAE,qBAAqB,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC,CAAC,EACxD,YAAY,CAAC,EAAE,qBAAqB,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC,CAAC,GAC5D,SAAS,CAAC,CAAC,CAAC;WAUD,aAAa,CAAC,CAAC,GAAG,GAAG,EACjC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,GACvB,SAAS,CAAC,CAAC,CAAC;CA+BhB"}
@@ -1,10 +1,16 @@
1
- import { HandlerContext, IFlag, ISubCommand, ProcessedFlag, TParsedArgs } from "./types";
1
+ import type { IFlag, IHandlerContext, ISubCommand, ProcessedFlag, TParsedArgs } from "./types";
2
2
  export declare class ArgParserError extends Error {
3
3
  cmdChain: string[];
4
4
  commandChain: string[];
5
5
  constructor(message: string, cmdChain?: string[]);
6
6
  }
7
- interface IArgParserParams {
7
+ export interface IArgParserParams<THandlerReturn = any> {
8
+ /**
9
+ * This is the display name of the app, used in help text
10
+ */
11
+ appName?: string;
12
+ subCommands?: ISubCommand[];
13
+ handler?: (ctx: IHandlerContext<any, any>) => THandlerReturn | Promise<THandlerReturn>;
8
14
  /**
9
15
  * Add an extra new line between each flag group,
10
16
  * makes the text more readable but uses more space
@@ -48,8 +54,7 @@ interface IArgParserParams {
48
54
  handleErrors?: boolean;
49
55
  /**
50
56
  * The command name to display in help suggestions (e.g., 'dabl').
51
- * If not provided, it falls back to appName or guessing from the script path.
52
- * @since 1.5.1
57
+ * If not provided, it falls back to guessing from the script path.
53
58
  */
54
59
  appCommandName?: string;
55
60
  /**
@@ -76,18 +81,20 @@ type TParsedArgsWithRouting<T = any> = T & {
76
81
  $commandChain?: string[];
77
82
  handlerToExecute?: {
78
83
  handler: Function;
79
- context: HandlerContext;
84
+ context: IHandlerContext;
80
85
  };
81
86
  };
82
- export declare class ArgParser {
87
+ export declare class ArgParserBase<THandlerReturn = any> {
83
88
  #private;
84
- constructor(options?: IArgParserParams & {
85
- appName?: string;
86
- subCommands?: ISubCommand[];
87
- handler?: (ctx: HandlerContext) => void;
88
- }, initialFlags?: readonly IFlag[]);
89
+ constructor(options?: IArgParserParams<THandlerReturn>, initialFlags?: readonly IFlag[]);
89
90
  get flags(): ProcessedFlag[];
90
91
  get flagNames(): string[];
92
+ getAppName(): string | undefined;
93
+ getAppCommandName(): string | undefined;
94
+ getSubCommandName(): string;
95
+ getDescription(): string | undefined;
96
+ getHandler(): ((ctx: IHandlerContext) => void) | undefined;
97
+ getSubCommands(): Map<string, ISubCommand>;
91
98
  private _addToOutput;
92
99
  addFlags(flags: readonly IFlag[]): this;
93
100
  addFlag(flag: IFlag): this;
@@ -100,7 +107,7 @@ export declare class ArgParser {
100
107
  * @param handler - The function to execute.
101
108
  * @returns The ArgParser instance for chaining.
102
109
  */
103
- setHandler(handler: (ctx: HandlerContext) => void): this;
110
+ setHandler(handler: (ctx: IHandlerContext<any, any>) => THandlerReturn | Promise<THandlerReturn>): this;
104
111
  printAll(filePath?: string): void;
105
112
  parse(processArgs: string[], options?: IParseOptions): TParsedArgsWithRouting<any>;
106
113
  /**
@@ -115,4 +122,4 @@ export declare class ArgParser {
115
122
  getLastParseResult(): TParsedArgs<ProcessedFlag[]>;
116
123
  }
117
124
  export {};
118
- //# sourceMappingURL=ArgParser.d.ts.map
125
+ //# sourceMappingURL=ArgParserBase.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ArgParserBase.d.ts","sourceRoot":"","sources":["../../src/ArgParserBase.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,KAAK,EACL,eAAe,EACf,WAAW,EACX,aAAa,EACb,WAAW,EACZ,MAAM,SAAS,CAAC;AAEjB,qBAAa,cAAe,SAAQ,KAAK;IAI9B,QAAQ,EAAE,MAAM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-1,4 +1,4 @@
1
- import { IFlag, ProcessedFlag } from "./types";
1
+ import type { IFlag, ProcessedFlag } from "./types";
2
2
  export declare class FlagManager {
3
3
  #private;
4
4
  constructor(options?: {
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FlagManager.d.ts","sourceRoot":"","sources":["../../src/FlagManager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAEpD,qBAAa,WAAW;;gBAKpB,OAAO,GAAE;QAAE,sBAAsB,CAAC,EAAE,OAAO,CAAA;KAAO,EAClD,YAAY,GAAE,SAAS,KAAK,EAAO;IAMrC,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,KAAK,GAAG,aAAa;IAwC5C,OAAO,CAAC,IAAI,EAAE,KAAK,GAAG,IAAI;IAoB1B,+BAA+B,CAAC,aAAa,EAAE,aAAa,GAAG,IAAI;IAQnE,QAAQ,CAAC,KAAK,EAAE,SAAS,KAAK,EAAE,GAAG,IAAI;IAOvC,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI9B,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS;IAIhD,IAAI,KAAK,IAAI,aAAa,EAAE,CAE3B;IAED,IAAI,SAAS,IAAI,MAAM,EAAE,CAExB;CACF"}
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+ import { ArgParser } from "./ArgParser";
3
+ declare const fuzzyTestCli: ArgParser<void>;
4
+ export { fuzzyTestCli };
5
+ //# sourceMappingURL=fuzzy-test-cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fuzzy-test-cli.d.ts","sourceRoot":"","sources":["../../src/fuzzy-test-cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAgBxC,QAAA,MAAM,YAAY,iBAmEhB,CAAC;AAkPH,OAAO,EAAE,YAAY,EAAE,CAAC"}
@@ -0,0 +1,101 @@
1
+ import type { ArgParserBase } from "./ArgParserBase";
2
+ export interface FuzzyTestOptions {
3
+ /** Maximum depth for command path exploration */
4
+ maxDepth?: number;
5
+ /** Number of random test cases to generate per command path */
6
+ randomTestCases?: number;
7
+ /** Include performance timing in results */
8
+ includePerformance?: boolean;
9
+ /** Test invalid combinations to verify error handling */
10
+ testErrorCases?: boolean;
11
+ /** Verbose output for debugging */
12
+ verbose?: boolean;
13
+ }
14
+ export interface TestResult {
15
+ commandPath: string[];
16
+ args: string[];
17
+ success: boolean;
18
+ error?: string;
19
+ executionTime?: number;
20
+ parsedResult?: any;
21
+ }
22
+ export interface FuzzyTestReport {
23
+ totalTests: number;
24
+ successfulTests: number;
25
+ failedTests: number;
26
+ commandPaths: string[][];
27
+ results: TestResult[];
28
+ summary: {
29
+ coverageByPath: Record<string, {
30
+ total: number;
31
+ passed: number;
32
+ }>;
33
+ errorTypes: Record<string, number>;
34
+ };
35
+ }
36
+ export declare class ArgParserFuzzyTester {
37
+ private parser;
38
+ private options;
39
+ constructor(parser: ArgParserBase, options?: FuzzyTestOptions);
40
+ /**
41
+ * Run comprehensive fuzzy testing on the ArgParser instance
42
+ */
43
+ runFuzzyTest(): Promise<FuzzyTestReport>;
44
+ /**
45
+ * Discover all possible command paths in the parser
46
+ */
47
+ private discoverCommandPaths;
48
+ /**
49
+ * Recursively discover subcommand paths
50
+ */
51
+ private discoverSubCommandPaths;
52
+ /**
53
+ * Get subcommands from a parser instance
54
+ */
55
+ private getSubCommands;
56
+ /**
57
+ * Get flags from a parser instance
58
+ */
59
+ private getFlags;
60
+ /**
61
+ * Test a specific command path with various flag combinations
62
+ */
63
+ private testCommandPath;
64
+ /**
65
+ * Get the parser instance for a specific command path
66
+ */
67
+ private getParserForPath;
68
+ /**
69
+ * Generate valid flag combinations for testing
70
+ */
71
+ private generateValidFlagCombinations;
72
+ /**
73
+ * Generate random flag combination
74
+ */
75
+ private generateRandomFlagCombination;
76
+ /**
77
+ * Generate error test cases
78
+ */
79
+ private generateErrorCases;
80
+ /**
81
+ * Generate arguments for a specific flag
82
+ */
83
+ private generateFlagArgs;
84
+ /**
85
+ * Generate values for a flag based on its type and constraints
86
+ */
87
+ private generateFlagValues;
88
+ /**
89
+ * Generate a single value for a flag
90
+ */
91
+ private generateSingleFlagValue;
92
+ /**
93
+ * Execute a single test case
94
+ */
95
+ private executeTest;
96
+ /**
97
+ * Generate comprehensive test report
98
+ */
99
+ private generateReport;
100
+ }
101
+ //# sourceMappingURL=fuzzy-tester.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fuzzy-tester.d.ts","sourceRoot":"","sources":["../../src/fuzzy-tester.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGrD,MAAM,WAAW,gBAAgB;IAC/B,iDAAiD;IACjD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,+DAA+D;IAC/D,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,4CAA4C;IAC5C,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,yDAAyD;IACzD,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,mCAAmC;IACnC,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,EAAE,EAAE,CAAC;IACzB,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB,OAAO,EAAE;QACP,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;QAClE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KACpC,CAAC;CACH;AAED,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,OAAO,CAA6B;gBAEhC,MAAM,EAAE,aAAa,EAAE,OAAO,GAAE,gBAAqB;IAWjE;;OAEG;IACG,YAAY,IAAI,OAAO,CAAC,eAAe,CAAC;IAiB9C;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAY5B;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAmB/B;;OAEG;IACH,OAAO,CAAC,cAAc;IAItB;;OAEG;IACH,OAAO,CAAC,QAAQ;IAIhB;;OAEG;YACW,eAAe;IAsC7B;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAexB;;OAEG;IACH,OAAO,CAAC,6BAA6B;IAqDrC;;OAEG;IACH,OAAO,CAAC,6BAA6B;IAerC;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAoB1B;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAsBxB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAa1B;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAsC/B;;OAEG;YACW,WAAW;IA0CzB;;OAEG;IACH,OAAO,CAAC,cAAc;CAuCvB"}
@@ -0,0 +1,7 @@
1
+ export { ArgParserBase, ArgParserError } from "./ArgParserBase";
2
+ export { ArgParser, type McpTransportConfig, type McpSubCommandOptions } from "./ArgParser";
3
+ export { zodFlagSchema, type IFlagCore, type IFlag, type ProcessedFlagCore, type ProcessedFlag, type TParsedArgsTypeFromFlagDef, type FlagsArray, type ResolveType, type ExtractFlagType, type TParsedArgs, type IHandlerContext, type MainHandler, type ISubCommand, type ArgParserInstance, } from "./types";
4
+ export { generateMcpToolsFromArgParser, type IMcpToolStructure, type GenerateMcpToolsOptions, type IParseExecutionResult, } from "./mcp-integration";
5
+ export { ArgParserFuzzyTester } from "./fuzzy-tester";
6
+ export type { FuzzyTestOptions, TestResult, FuzzyTestReport } from "./fuzzy-tester";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,EACL,SAAS,EACT,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EAC1B,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,aAAa,EACb,KAAK,SAAS,EACd,KAAK,KAAK,EACV,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,0BAA0B,EAC/B,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,iBAAiB,GACvB,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,6BAA6B,EAC7B,KAAK,iBAAiB,EACtB,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,GAC3B,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,YAAY,EAAE,gBAAgB,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,31 @@
1
+ import type { ZodTypeAny } from "zod";
2
+ import { ArgParserBase } from "./ArgParserBase";
3
+ import type { ProcessedFlag, TParsedArgs } from "./";
4
+ export interface IMcpToolStructure {
5
+ name: string;
6
+ description?: string;
7
+ inputSchema: ZodTypeAny;
8
+ outputSchema?: ZodTypeAny;
9
+ execute: (args: any) => Promise<any>;
10
+ }
11
+ export interface GenerateMcpToolsOptions {
12
+ outputSchemaMap?: Record<string, ZodTypeAny>;
13
+ defaultOutputSchema?: ZodTypeAny;
14
+ generateToolName?: (commandPath: string[], appName?: string) => string;
15
+ includeSubCommands?: boolean;
16
+ toolNamePrefix?: string;
17
+ toolNameSuffix?: string;
18
+ }
19
+ interface ISpecialParseResultProps {
20
+ $commandChain?: string[];
21
+ $error?: {
22
+ type: string;
23
+ message: string;
24
+ details?: any;
25
+ };
26
+ handlerResponse?: any;
27
+ }
28
+ export type IParseExecutionResult = TParsedArgs<ProcessedFlag[]> & ISpecialParseResultProps;
29
+ export declare function generateMcpToolsFromArgParser(rootParser: ArgParserBase, options?: GenerateMcpToolsOptions): IMcpToolStructure[];
30
+ export {};
31
+ //# sourceMappingURL=mcp-integration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-integration.d.ts","sourceRoot":"","sources":["../../src/mcp-integration.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAe,UAAU,EAAE,MAAM,KAAK,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAA0B,aAAa,EAAE,WAAW,EAAE,MAAM,IAAI,CAAC;AAK7E,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,UAAU,CAAC;IACxB,YAAY,CAAC,EAAE,UAAU,CAAC;IAC1B,OAAO,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;CACtC;AAqID,MAAM,WAAW,uBAAuB;IACtC,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAC7C,mBAAmB,CAAC,EAAE,UAAU,CAAC;IACjC,gBAAgB,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;IACvE,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,UAAU,wBAAwB;IAChC,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,MAAM,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,GAAG,CAAA;KAAE,CAAC;IAC1D,eAAe,CAAC,EAAE,GAAG,CAAC;CACvB;AACD,MAAM,MAAM,qBAAqB,GAAG,WAAW,CAAC,aAAa,EAAE,CAAC,GAC9D,wBAAwB,CAAC;AAE3B,wBAAgB,6BAA6B,CAC3C,UAAU,EAAE,aAAa,EACzB,OAAO,CAAC,EAAE,uBAAuB,GAChC,iBAAiB,EAAE,CAmerB"}
@@ -0,0 +1,165 @@
1
+ import { z } from "zod";
2
+ export type ArgParserInstance = any;
3
+ export declare const zodFlagSchema: z.ZodEffects<z.ZodObject<{
4
+ name: z.ZodString;
5
+ allowLigature: z.ZodDefault<z.ZodBoolean>;
6
+ allowMultiple: z.ZodDefault<z.ZodBoolean>;
7
+ description: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
8
+ options: z.ZodArray<z.ZodString, "many">;
9
+ defaultValue: z.ZodOptional<z.ZodAny>;
10
+ type: z.ZodDefault<z.ZodUnion<[z.ZodEffects<z.ZodAny, any, any>, z.ZodEffects<z.ZodAny, any, any>, z.ZodEffects<z.ZodAny, any, any>, z.ZodEffects<z.ZodAny, any, any>, z.ZodEffects<z.ZodAny, any, any>, z.ZodFunction<z.ZodTuple<[z.ZodString], z.ZodUnknown>, z.ZodAny>, z.ZodEffects<z.ZodString, string, string>]>>;
11
+ mandatory: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodFunction<z.ZodTuple<[z.ZodAny], z.ZodUnknown>, z.ZodBoolean>]>>;
12
+ flagOnly: z.ZodDefault<z.ZodBoolean>;
13
+ validate: z.ZodOptional<z.ZodFunction<z.ZodTuple<[z.ZodOptional<z.ZodAny>, z.ZodOptional<z.ZodAny>], z.ZodUnknown>, z.ZodUnion<[z.ZodBoolean, z.ZodString, z.ZodVoid, z.ZodPromise<z.ZodUnion<[z.ZodBoolean, z.ZodString, z.ZodVoid]>>]>>>;
14
+ enum: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>;
15
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
16
+ name: z.ZodString;
17
+ allowLigature: z.ZodDefault<z.ZodBoolean>;
18
+ allowMultiple: z.ZodDefault<z.ZodBoolean>;
19
+ description: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
20
+ options: z.ZodArray<z.ZodString, "many">;
21
+ defaultValue: z.ZodOptional<z.ZodAny>;
22
+ type: z.ZodDefault<z.ZodUnion<[z.ZodEffects<z.ZodAny, any, any>, z.ZodEffects<z.ZodAny, any, any>, z.ZodEffects<z.ZodAny, any, any>, z.ZodEffects<z.ZodAny, any, any>, z.ZodEffects<z.ZodAny, any, any>, z.ZodFunction<z.ZodTuple<[z.ZodString], z.ZodUnknown>, z.ZodAny>, z.ZodEffects<z.ZodString, string, string>]>>;
23
+ mandatory: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodFunction<z.ZodTuple<[z.ZodAny], z.ZodUnknown>, z.ZodBoolean>]>>;
24
+ flagOnly: z.ZodDefault<z.ZodBoolean>;
25
+ validate: z.ZodOptional<z.ZodFunction<z.ZodTuple<[z.ZodOptional<z.ZodAny>, z.ZodOptional<z.ZodAny>], z.ZodUnknown>, z.ZodUnion<[z.ZodBoolean, z.ZodString, z.ZodVoid, z.ZodPromise<z.ZodUnion<[z.ZodBoolean, z.ZodString, z.ZodVoid]>>]>>>;
26
+ enum: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>;
27
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
28
+ name: z.ZodString;
29
+ allowLigature: z.ZodDefault<z.ZodBoolean>;
30
+ allowMultiple: z.ZodDefault<z.ZodBoolean>;
31
+ description: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
32
+ options: z.ZodArray<z.ZodString, "many">;
33
+ defaultValue: z.ZodOptional<z.ZodAny>;
34
+ type: z.ZodDefault<z.ZodUnion<[z.ZodEffects<z.ZodAny, any, any>, z.ZodEffects<z.ZodAny, any, any>, z.ZodEffects<z.ZodAny, any, any>, z.ZodEffects<z.ZodAny, any, any>, z.ZodEffects<z.ZodAny, any, any>, z.ZodFunction<z.ZodTuple<[z.ZodString], z.ZodUnknown>, z.ZodAny>, z.ZodEffects<z.ZodString, string, string>]>>;
35
+ mandatory: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodFunction<z.ZodTuple<[z.ZodAny], z.ZodUnknown>, z.ZodBoolean>]>>;
36
+ flagOnly: z.ZodDefault<z.ZodBoolean>;
37
+ validate: z.ZodOptional<z.ZodFunction<z.ZodTuple<[z.ZodOptional<z.ZodAny>, z.ZodOptional<z.ZodAny>], z.ZodUnknown>, z.ZodUnion<[z.ZodBoolean, z.ZodString, z.ZodVoid, z.ZodPromise<z.ZodUnion<[z.ZodBoolean, z.ZodString, z.ZodVoid]>>]>>>;
38
+ enum: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>;
39
+ }, z.ZodTypeAny, "passthrough">>, {
40
+ [key: string]: any;
41
+ }, z.objectInputType<{
42
+ name: z.ZodString;
43
+ allowLigature: z.ZodDefault<z.ZodBoolean>;
44
+ allowMultiple: z.ZodDefault<z.ZodBoolean>;
45
+ description: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>;
46
+ options: z.ZodArray<z.ZodString, "many">;
47
+ defaultValue: z.ZodOptional<z.ZodAny>;
48
+ type: z.ZodDefault<z.ZodUnion<[z.ZodEffects<z.ZodAny, any, any>, z.ZodEffects<z.ZodAny, any, any>, z.ZodEffects<z.ZodAny, any, any>, z.ZodEffects<z.ZodAny, any, any>, z.ZodEffects<z.ZodAny, any, any>, z.ZodFunction<z.ZodTuple<[z.ZodString], z.ZodUnknown>, z.ZodAny>, z.ZodEffects<z.ZodString, string, string>]>>;
49
+ mandatory: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodFunction<z.ZodTuple<[z.ZodAny], z.ZodUnknown>, z.ZodBoolean>]>>;
50
+ flagOnly: z.ZodDefault<z.ZodBoolean>;
51
+ validate: z.ZodOptional<z.ZodFunction<z.ZodTuple<[z.ZodOptional<z.ZodAny>, z.ZodOptional<z.ZodAny>], z.ZodUnknown>, z.ZodUnion<[z.ZodBoolean, z.ZodString, z.ZodVoid, z.ZodPromise<z.ZodUnion<[z.ZodBoolean, z.ZodString, z.ZodVoid]>>]>>>;
52
+ enum: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>;
53
+ }, z.ZodTypeAny, "passthrough">>;
54
+ /**
55
+ * The raw input type for defining a flag, before Zod processing (aliases, defaults).
56
+ */
57
+ export type IFlagCore = z.input<typeof zodFlagSchema>;
58
+ /**
59
+ * The type of the `type` property in a ProcessedFlagCore object.
60
+ * This represents all valid forms the `type` property can take after Zod processing.
61
+ */
62
+ export type TParsedArgsTypeFromFlagDef = StringConstructor | NumberConstructor | BooleanConstructor | ArrayConstructor | ObjectConstructor | ((value: string) => any) | "string" | "number" | "boolean" | "array" | "object";
63
+ /**
64
+ * The core type of a flag after Zod processing (defaults applied, aliases resolved),
65
+ * but before some properties are made more specific (like `type` constructor to actual type).
66
+ * This type is output by `zodFlagSchema.parse()`.
67
+ */
68
+ export type ProcessedFlagCore = Omit<z.output<typeof zodFlagSchema>, "type"> & {
69
+ type: TParsedArgsTypeFromFlagDef;
70
+ };
71
+ /**
72
+ * The user-facing type for defining a flag. It includes aliases like `default` and `required`.
73
+ * The `handler` property is removed as handlers are typically associated with commands/subcommands, not individual flags.
74
+ */
75
+ export type IFlag = IFlagCore & {
76
+ /** @alias defaultValue */
77
+ default?: any;
78
+ /** @alias mandatory */
79
+ required?: boolean | ((parsedArgs: TParsedArgs<any>) => boolean);
80
+ };
81
+ /**
82
+ * A more refined type for a flag after it has been fully processed by ArgParser,
83
+ * particularly its `type` property and validation/enum/mandatory functions.
84
+ * This is the type that ArgParser would internally work with for parsing and type extraction.
85
+ */
86
+ export type ProcessedFlag = Omit<ProcessedFlagCore, "validate" | "enum" | "mandatory"> & {
87
+ validate?: (value: any, parsedArgs?: TParsedArgs<ProcessedFlag[]>) => boolean | string | void | Promise<boolean | string | void>;
88
+ enum?: any[];
89
+ mandatory?: boolean | ((parsedArgs: TParsedArgs<ProcessedFlag[]>) => boolean);
90
+ };
91
+ /**
92
+ * Resolves the TypeScript type from a flag's `type` definition.
93
+ */
94
+ export type ResolveType<T extends TParsedArgsTypeFromFlagDef> = T extends StringConstructor ? string : T extends NumberConstructor ? number : T extends BooleanConstructor ? boolean : T extends ArrayConstructor ? any[] : T extends ObjectConstructor ? Record<string, any> : T extends "string" ? string : T extends "number" ? number : T extends "boolean" ? boolean : T extends "array" ? any[] : T extends "object" ? Record<string, any> : T extends (value: string) => infer R ? R : any;
95
+ /**
96
+ * Extracts the final TypeScript type for a flag's value based on its definition,
97
+ * considering `flagOnly` and `allowMultiple` properties.
98
+ */
99
+ export type ExtractFlagType<TFlag extends ProcessedFlag> = TFlag["flagOnly"] extends true ? TFlag["allowMultiple"] extends true ? boolean[] : boolean : TFlag["allowMultiple"] extends true ? Array<ResolveType<TFlag["type"]>> : ResolveType<TFlag["type"]>;
100
+ /**
101
+ * Represents the structured object of parsed arguments.
102
+ * Keys are flag names, and values are their parsed and typed values.
103
+ * `TFlags` should be the array of `ProcessedFlag` definitions for the specific command.
104
+ */
105
+ export type TParsedArgs<TFlags extends readonly ProcessedFlag[]> = {
106
+ [K in TFlags[number]["name"]]: ExtractFlagType<Extract<TFlags[number], {
107
+ name: K;
108
+ }>>;
109
+ };
110
+ /**
111
+ * Generic context object passed to command handlers.
112
+ * @template TCurrentCommandArgs Shape of `args` for the current command, derived from its flags.
113
+ * @template TParentCommandArgs Shape of `parentArgs` from the parent command, if any.
114
+ */
115
+ export type IHandlerContext<TCurrentCommandArgs extends Record<string, any> = Record<string, any>, TParentCommandArgs extends Record<string, any> = Record<string, any>> = {
116
+ /** Parsed arguments specific to the current command. */
117
+ args: TCurrentCommandArgs;
118
+ /** Parsed arguments from the parent command, if this is a subcommand. */
119
+ parentArgs?: TParentCommandArgs;
120
+ /** The sequence of command names that led to this handler. */
121
+ commandChain: string[];
122
+ /** The `ArgParser` instance that invoked this handler (could be a subcommand's parser). */
123
+ parser: ArgParserInstance;
124
+ /** The parent `ArgParser` instance, if this is a subcommand handler. */
125
+ parentParser?: ArgParserInstance;
126
+ /** Optional: The root `ArgParser` instance of the CLI. */
127
+ /** Indicates if the handler is being called from MCP mode (true) or CLI mode (false). */
128
+ isMcp?: boolean;
129
+ };
130
+ /**
131
+ * Generic type for the collection of processed flags that an ArgParser instance manages.
132
+ */
133
+ export type FlagsArray = readonly ProcessedFlag[];
134
+ /**
135
+ * Defines a subcommand within an ArgParser setup.
136
+ * @template TSubCommandFlags Flags defined specifically FOR this subcommand.
137
+ * @template TParentCommandFlags Flags defined for the PARENT of this subcommand.
138
+ * @template THandlerReturn The expected return type of the subcommand's handler.
139
+ */
140
+ export interface ISubCommand<TSubCommandFlags extends FlagsArray = FlagsArray, TParentCommandFlags extends FlagsArray = FlagsArray, THandlerReturn = any> {
141
+ name: string;
142
+ description?: string;
143
+ /** The ArgParser instance for this subcommand, typed with its own flags. */
144
+ parser: ArgParserInstance;
145
+ /** Handler function for this subcommand. */
146
+ handler?: (ctx: IHandlerContext<TParsedArgs<TSubCommandFlags>, TParsedArgs<TParentCommandFlags>>) => THandlerReturn | Promise<THandlerReturn>;
147
+ /** Internal flag to identify MCP subcommands for proper exclusion from tool generation */
148
+ isMcp?: boolean;
149
+ /** MCP server information for DXT generation */
150
+ mcpServerInfo?: {
151
+ name: string;
152
+ version: string;
153
+ description?: string;
154
+ };
155
+ /** MCP tool generation options for DXT generation */
156
+ mcpToolOptions?: any;
157
+ }
158
+ /**
159
+ * Type for the main handler of an ArgParser instance (root command or a command defined by an ArgParser).
160
+ * @template TParserFlags Flags defined for this ArgParser instance.
161
+ * @template TParentParserFlags Flags of the parent parser, if this parser is used as a subcommand.
162
+ * @template THandlerReturn The expected return type of the handler.
163
+ */
164
+ export type MainHandler<TParserFlags extends FlagsArray = FlagsArray, TParentParserFlags extends FlagsArray = FlagsArray, THandlerReturn = any> = (ctx: IHandlerContext<TParsedArgs<TParserFlags>, TParsedArgs<TParentParserFlags>>) => THandlerReturn | Promise<THandlerReturn>;
165
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,MAAM,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAEpC,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gCAwHtB,CAAC;AAEL;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAEtD;;;GAGG;AACH,MAAM,MAAM,0BAA0B,GAClC,iBAAiB,GACjB,iBAAiB,GACjB,kBAAkB,GAClB,gBAAgB,GAChB,iBAAiB,GACjB,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,GAAG,CAAC,GACxB,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,OAAO,GACP,QAAQ,CAAC;AAEb;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,aAAa,CAAC,EAAE,MAAM,CAAC,GAAG;IAC7E,IAAI,EAAE,0BAA0B,CAAC;CAClC,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,KAAK,GAAG,SAAS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