@alcyone-labs/arg-parser 2.4.2 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +100 -2
- package/dist/core/ArgParserBase.d.ts.map +1 -1
- package/dist/core/types.d.ts +4 -4
- package/dist/core/types.d.ts.map +1 -1
- package/dist/index.cjs +78 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.min.mjs +495 -440
- package/dist/index.min.mjs.map +1 -1
- package/dist/index.mjs +78 -6
- package/dist/index.mjs.map +1 -1
- package/dist/mcp/mcp-integration.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,6 +25,7 @@ A modern, type-safe command line argument parser with built-in MCP (Model Contex
|
|
|
25
25
|
- [Runtime Type Validation](#runtime-type-validation)
|
|
26
26
|
- [Automatic Type Processing](#automatic-type-processing)
|
|
27
27
|
- [Async Custom Parser Support](#async-custom-parser-support)
|
|
28
|
+
- [Zod Schema Flags (Structured JSON Validation)](#zod-schema-flags-structured-json-validation)
|
|
28
29
|
- [Type Conversion Examples](#type-conversion-examples)
|
|
29
30
|
- [Hierarchical CLIs (Sub-Commands)](#hierarchical-clis-sub-commands)
|
|
30
31
|
- [MCP Exposure Control](#mcp-exposure-control)
|
|
@@ -69,6 +70,9 @@ A modern, type-safe command line argument parser with built-in MCP (Model Contex
|
|
|
69
70
|
- [Typical Errors](#typical-errors)
|
|
70
71
|
- [System Flags & Configuration](#system-flags--configuration)
|
|
71
72
|
- [Changelog](#changelog)
|
|
73
|
+
- [v2.5.0](#v250)
|
|
74
|
+
- [v2.4.2](#v242)
|
|
75
|
+
- [v2.4.1](#v241)
|
|
72
76
|
- [v2.4.0](#v240)
|
|
73
77
|
- [v2.3.0](#v230)
|
|
74
78
|
- [v2.2.1](#v221)
|
|
@@ -102,6 +106,7 @@ A modern, type-safe command line argument parser with built-in MCP (Model Contex
|
|
|
102
106
|
- [Runtime Type Validation](#runtime-type-validation)
|
|
103
107
|
- [Automatic Type Processing](#automatic-type-processing)
|
|
104
108
|
- [Async Custom Parser Support](#async-custom-parser-support)
|
|
109
|
+
- [Zod Schema Flags (Structured JSON Validation)](#zod-schema-flags-structured-json-validation)
|
|
105
110
|
- [Type Conversion Examples](#type-conversion-examples)
|
|
106
111
|
- [Hierarchical CLIs (Sub-Commands)](#hierarchical-clis-sub-commands)
|
|
107
112
|
- [MCP Exposure Control](#mcp-exposure-control)
|
|
@@ -447,7 +452,7 @@ const cli = ArgParser.withMcp({
|
|
|
447
452
|
// parse() is async and works with both sync and async handlers
|
|
448
453
|
async function main() {
|
|
449
454
|
try {
|
|
450
|
-
// Option 1: Auto-detection
|
|
455
|
+
// Option 1: Auto-detection - convenient for simple scripts
|
|
451
456
|
const result = await cli.parse();
|
|
452
457
|
|
|
453
458
|
// Option 2: Explicit arguments - full control
|
|
@@ -604,7 +609,7 @@ Flags are defined using the `IFlag` interface within the `flags` array of a tool
|
|
|
604
609
|
interface IFlag {
|
|
605
610
|
name: string; // Internal name (e.g., 'verbose')
|
|
606
611
|
options: string[]; // Command-line options (e.g., ['--verbose', '-v'])
|
|
607
|
-
type: "string" | "number" | "boolean" | "array" | "object" | Function;
|
|
612
|
+
type: "string" | "number" | "boolean" | "array" | "object" | Function | ZodSchema;
|
|
608
613
|
description?: string; // Help text
|
|
609
614
|
mandatory?: boolean | ((args: any) => boolean); // Whether the flag is required
|
|
610
615
|
defaultValue?: any; // Default value if not provided
|
|
@@ -756,6 +761,79 @@ const result = await parser.parse(process.argv.slice(2));
|
|
|
756
761
|
// Async custom parser functions
|
|
757
762
|
--config "./settings.json" → parsed JSON from file (async)
|
|
758
763
|
--user-id "123" → user data from API (async)
|
|
764
|
+
|
|
765
|
+
// Zod schema validation (structured JSON)
|
|
766
|
+
--config '{"host":"localhost","port":5432}' → validated object
|
|
767
|
+
--deployment '{"env":"prod","region":"us-east-1"}' → validated object
|
|
768
|
+
```
|
|
769
|
+
|
|
770
|
+
#### Zod Schema Flags (Structured JSON Validation)
|
|
771
|
+
|
|
772
|
+
**Since v2.5.0** - You can now use Zod schemas as flag types for structured JSON input with automatic validation and proper MCP JSON Schema generation:
|
|
773
|
+
|
|
774
|
+
```typescript
|
|
775
|
+
import { z } from "zod";
|
|
776
|
+
|
|
777
|
+
const DatabaseConfigSchema = z.object({
|
|
778
|
+
host: z.string().describe("Database host address"),
|
|
779
|
+
port: z.number().min(1).max(65535).describe("Database port number"),
|
|
780
|
+
credentials: z.object({
|
|
781
|
+
username: z.string().describe("Database username"),
|
|
782
|
+
password: z.string().describe("Database password"),
|
|
783
|
+
}),
|
|
784
|
+
ssl: z.boolean().optional().describe("Enable SSL connection"),
|
|
785
|
+
});
|
|
786
|
+
|
|
787
|
+
const cli = ArgParser.withMcp({
|
|
788
|
+
appName: "Database CLI",
|
|
789
|
+
appCommandName: "db-cli",
|
|
790
|
+
}).addTool({
|
|
791
|
+
name: "connect",
|
|
792
|
+
description: "Connect to database with structured configuration",
|
|
793
|
+
flags: [
|
|
794
|
+
{
|
|
795
|
+
name: "config",
|
|
796
|
+
options: ["--config", "-c"],
|
|
797
|
+
type: DatabaseConfigSchema, // 🎉 Zod schema as type!
|
|
798
|
+
description: "Database configuration as JSON object",
|
|
799
|
+
mandatory: true,
|
|
800
|
+
},
|
|
801
|
+
],
|
|
802
|
+
handler: async (ctx) => {
|
|
803
|
+
// ctx.args.config is fully typed and validated!
|
|
804
|
+
const { host, port, credentials, ssl } = ctx.args.config;
|
|
805
|
+
console.log(`Connecting to ${host}:${port} as ${credentials.username}`);
|
|
806
|
+
return { success: true };
|
|
807
|
+
},
|
|
808
|
+
});
|
|
809
|
+
|
|
810
|
+
// CLI usage with JSON validation:
|
|
811
|
+
// db-cli connect --config '{"host":"localhost","port":5432,"credentials":{"username":"admin","password":"secret"},"ssl":true}'
|
|
812
|
+
|
|
813
|
+
// MCP usage: Generates proper JSON Schema for MCP clients
|
|
814
|
+
// db-cli --s-mcp-serve
|
|
815
|
+
```
|
|
816
|
+
|
|
817
|
+
**Example with Complex Nested Schema:**
|
|
818
|
+
|
|
819
|
+
```typescript
|
|
820
|
+
const DeploymentSchema = z.object({
|
|
821
|
+
environment: z.enum(["dev", "staging", "prod"]),
|
|
822
|
+
region: z.string(),
|
|
823
|
+
scaling: z.object({
|
|
824
|
+
minInstances: z.number().min(1),
|
|
825
|
+
maxInstances: z.number().min(1),
|
|
826
|
+
targetCpu: z.number().min(10).max(100),
|
|
827
|
+
}),
|
|
828
|
+
monitoring: z.object({
|
|
829
|
+
enabled: z.boolean(),
|
|
830
|
+
alertEmail: z.string().email().optional(),
|
|
831
|
+
metrics: z.array(z.string()),
|
|
832
|
+
}),
|
|
833
|
+
});
|
|
834
|
+
|
|
835
|
+
// This generates comprehensive JSON Schema for MCP clients
|
|
836
|
+
// while providing full validation and type safety for CLI usage
|
|
759
837
|
```
|
|
760
838
|
|
|
761
839
|
### Hierarchical CLIs (Sub-Commands)
|
|
@@ -1746,6 +1824,26 @@ ArgParser includes built-in `--s-*` flags for development, debugging, and config
|
|
|
1746
1824
|
|
|
1747
1825
|
## Changelog
|
|
1748
1826
|
|
|
1827
|
+
### v2.5.0
|
|
1828
|
+
|
|
1829
|
+
**Feat**
|
|
1830
|
+
|
|
1831
|
+
- **Zod Schema Flags**: You can now use Zod schemas as flag types for structured JSON input validation. This enables complex object validation with automatic JSON Schema generation for MCP clients while maintaining full type safety and CLI compatibility.
|
|
1832
|
+
- **Improved MCP Tool Documentation**: Zod schema descriptions automatically become MCP tool parameter documentation
|
|
1833
|
+
|
|
1834
|
+
### v2.4.2
|
|
1835
|
+
|
|
1836
|
+
**Fixes and Changes**
|
|
1837
|
+
|
|
1838
|
+
- add missing MCP lifecycle event documentation
|
|
1839
|
+
- fix the behavior of the withMcp() options.mcp.log that was not working as expected
|
|
1840
|
+
|
|
1841
|
+
### v2.4.1
|
|
1842
|
+
|
|
1843
|
+
**Fixes and Changes**
|
|
1844
|
+
|
|
1845
|
+
- switch to NPM version of @alcyone-labs/modelcontextprotocol-sdk to freeze the dependency and avoid side-effects
|
|
1846
|
+
|
|
1749
1847
|
### v2.4.0
|
|
1750
1848
|
|
|
1751
1849
|
**Feat**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArgParserBase.d.ts","sourceRoot":"","sources":["../../src/core/ArgParserBase.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,aAAa,EACb,uBAAuB,EACxB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACpB,MAAM,yBAAyB,CAAC;AAIjC,OAAO,KAAK,EACV,KAAK,EACL,eAAe,EACf,WAAW,EACX,WAAW,EACX,aAAa,EACb,WAAW,EACZ,MAAM,SAAS,CAAC;AAEjB,qBAAa,cAAe,SAAQ,KAAK;IAI9B,QAAQ,EAAE,MAAM,EAAE;IAHpB,YAAY,EAAE,MAAM,EAAE,CAAC;gBAE5B,OAAO,EAAE,MAAM,EACR,QAAQ,GAAE,MAAM,EAAO;CAMjC;AAED,MAAM,WAAW,gBAAgB,CAAC,cAAc,GAAG,GAAG;IACpD;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,WAAW,EAAE,CAAC;IAC5B,OAAO,CAAC,EAAE,CACR,GAAG,EAAE,eAAe,CAAC,GAAG,EAAE,GAAG,CAAC,KAC3B,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAE9C;;;;;OAKG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B;;;OAGG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,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G,IAAI;IAQnC;;OAEG;IACH,aAAa,IAAI,eAAe,EAAE;IAIlC;;OAEG;IACH,WAAW,CACT,QAAQ,EAAE,CAAC,KAAK,EAAE;QAChB,IAAI,EAAE,aAAa,CAAC;QACpB,MAAM,EAAE,MAAM,CAAC;QACf,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,KAAK,IAAI,GACT,IAAI;IAKP;;OAEG;IACH,YAAY,CACV,QAAQ,EAAE,CAAC,KAAK,EAAE;QAChB,IAAI,EAAE,aAAa,CAAC;QACpB,MAAM,EAAE,MAAM,CAAC;QACf,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,KAAK,IAAI,GACT,IAAI;IAKP;;OAEG;IACH,0BAA0B,IAAI,uBAAuB;IAIrD;;OAEG;IACH,sBAAsB,IAAI,mBAAmB;IAI7C;;OAEG;IACH,oBAAoB,IAAI,iBAAiB;CA6d1C"}
|
package/dist/core/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
1
|
+
import { z, type ZodTypeAny } from "zod";
|
|
2
2
|
export type ArgParserInstance = any;
|
|
3
3
|
export declare const zodFlagSchema: z.ZodPipe<z.ZodObject<{
|
|
4
4
|
name: z.ZodString;
|
|
@@ -7,7 +7,7 @@ export declare const zodFlagSchema: z.ZodPipe<z.ZodObject<{
|
|
|
7
7
|
description: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
8
8
|
options: z.ZodArray<z.ZodString>;
|
|
9
9
|
defaultValue: z.ZodOptional<z.ZodAny>;
|
|
10
|
-
type: z.ZodDefault<z.ZodUnion<readonly [z.ZodAny, z.ZodAny, z.ZodAny, z.ZodAny, z.ZodAny, z.ZodCustom<(value: string) => any | Promise<any>, (value: string) => any | Promise<any>>, z.ZodString]>>;
|
|
10
|
+
type: z.ZodDefault<z.ZodUnion<readonly [z.ZodAny, z.ZodAny, z.ZodAny, z.ZodAny, z.ZodAny, z.ZodCustom<(value: string) => any | Promise<any>, (value: string) => any | Promise<any>>, z.ZodCustom<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>, z.ZodString]>>;
|
|
11
11
|
mandatory: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodCustom<(value?: any, parsedArgs?: any) => boolean, (value?: any, parsedArgs?: any) => boolean>]>>;
|
|
12
12
|
flagOnly: z.ZodDefault<z.ZodBoolean>;
|
|
13
13
|
validate: z.ZodOptional<z.ZodCustom<(value?: any, parsedArgs?: any) => boolean | string | void | Promise<boolean | string | void>, (value?: any, parsedArgs?: any) => boolean | string | void | Promise<boolean | string | void>>>;
|
|
@@ -37,7 +37,7 @@ export type IFlagCore = z.input<typeof zodFlagSchema>;
|
|
|
37
37
|
* The type of the `type` property in a ProcessedFlagCore object.
|
|
38
38
|
* This represents all valid forms the `type` property can take after Zod processing.
|
|
39
39
|
*/
|
|
40
|
-
export type TParsedArgsTypeFromFlagDef = StringConstructor | NumberConstructor | BooleanConstructor | ArrayConstructor | ObjectConstructor | ((value: string) => any) | ((value: string) => Promise<any>) | "string" | "number" | "boolean" | "array" | "object";
|
|
40
|
+
export type TParsedArgsTypeFromFlagDef = StringConstructor | NumberConstructor | BooleanConstructor | ArrayConstructor | ObjectConstructor | ((value: string) => any) | ((value: string) => Promise<any>) | ZodTypeAny | "string" | "number" | "boolean" | "array" | "object";
|
|
41
41
|
/**
|
|
42
42
|
* The core type of a flag after Zod processing (defaults applied, aliases resolved),
|
|
43
43
|
* but before some properties are made more specific (like `type` constructor to actual type).
|
|
@@ -72,7 +72,7 @@ export type ProcessedFlag = Omit<ProcessedFlagCore, "validate" | "enum" | "manda
|
|
|
72
72
|
/**
|
|
73
73
|
* Resolves the TypeScript type from a flag's `type` definition.
|
|
74
74
|
*/
|
|
75
|
-
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;
|
|
75
|
+
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 ZodTypeAny ? z.infer<T> : 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;
|
|
76
76
|
/**
|
|
77
77
|
* Extracts the final TypeScript type for a flag's value based on its definition,
|
|
78
78
|
* considering `flagOnly` and `allowMultiple` properties.
|
package/dist/core/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,KAAK,UAAU,EAAE,MAAM,KAAK,CAAC;AAKzC,MAAM,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAEpC,eAAO,MAAM,aAAa;;;;;;;kHAmDD,MAAM,KAAK,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,UAA7B,MAAM,KAAK,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;qFA2B5B,GAAG,eAAe,GAAG,KAAK,OAAO,WAAjC,GAAG,eAAe,GAAG,KAAK,OAAO;;iDAkBzC,GAAG,eACE,GAAG,KACb,OAAO,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,OAAO,GAAG,MAAM,G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
1111
|
"Must be a custom parser function"
|
|
1112
1112
|
),
|
|
1113
1113
|
// Custom parser function (value: string) => any | Promise<any>
|
|
1114
|
+
zod.z.custom(
|
|
1115
|
+
(val) => val && typeof val === "object" && val._def,
|
|
1116
|
+
"Must be a Zod schema"
|
|
1117
|
+
),
|
|
1118
|
+
// Zod schema for structured JSON validation
|
|
1114
1119
|
zod.z.string().refine(
|
|
1115
1120
|
// String literal types
|
|
1116
1121
|
(value) => ["boolean", "string", "number", "array", "object"].includes(
|
|
@@ -1121,7 +1126,7 @@ const zodFlagSchema = zod.z.object({
|
|
|
1121
1126
|
}
|
|
1122
1127
|
)
|
|
1123
1128
|
]).default("string").describe(
|
|
1124
|
-
"Expected data type (constructor
|
|
1129
|
+
"Expected data type (constructor, string literal, custom parser function, or Zod schema). Defaults to 'string'."
|
|
1125
1130
|
),
|
|
1126
1131
|
mandatory: zod.z.union([
|
|
1127
1132
|
zod.z.boolean(),
|
|
@@ -1153,6 +1158,9 @@ const zodFlagSchema = zod.z.object({
|
|
|
1153
1158
|
return newObj;
|
|
1154
1159
|
});
|
|
1155
1160
|
function getJsonSchemaTypeFromFlag(flagType) {
|
|
1161
|
+
if (flagType && typeof flagType === "object" && flagType._def) {
|
|
1162
|
+
return "object";
|
|
1163
|
+
}
|
|
1156
1164
|
if (typeof flagType === "function") {
|
|
1157
1165
|
if (flagType === String) return "string";
|
|
1158
1166
|
if (flagType === Number) return "number";
|
|
@@ -3379,7 +3387,21 @@ const _ArgParserBase = class _ArgParserBase {
|
|
|
3379
3387
|
const result = flag["type"](value);
|
|
3380
3388
|
value = result && typeof result.then === "function" ? await result : result;
|
|
3381
3389
|
} else if (typeof flag["type"] === "object") {
|
|
3382
|
-
|
|
3390
|
+
if (flag["type"] && flag["type"]._def) {
|
|
3391
|
+
try {
|
|
3392
|
+
const parsedJson = typeof value === "string" ? JSON.parse(value) : value;
|
|
3393
|
+
value = flag["type"].parse(parsedJson);
|
|
3394
|
+
} catch (error) {
|
|
3395
|
+
if (error instanceof SyntaxError) {
|
|
3396
|
+
throw new Error(`Invalid JSON for flag '${flag["name"]}': ${error.message}`);
|
|
3397
|
+
} else {
|
|
3398
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
3399
|
+
throw new Error(`Validation failed for flag '${flag["name"]}': ${errorMessage}`);
|
|
3400
|
+
}
|
|
3401
|
+
}
|
|
3402
|
+
} else {
|
|
3403
|
+
value = new flag["type"](value);
|
|
3404
|
+
}
|
|
3383
3405
|
}
|
|
3384
3406
|
if (flag["enum"] && flag["enum"].length > 0) {
|
|
3385
3407
|
const allowedValues = flag["enum"].map((v) => typeof v === "string" ? `'${v}'` : v).join(", ");
|
|
@@ -3751,7 +3773,28 @@ ${cyan("Flags:")}
|
|
|
3751
3773
|
const descriptionLines = Array.isArray(flag["description"]) ? flag["description"] : [flag["description"]];
|
|
3752
3774
|
const metaLines = [];
|
|
3753
3775
|
let typeName = "unknown";
|
|
3754
|
-
|
|
3776
|
+
let typeDetails = [];
|
|
3777
|
+
if (flag["type"] && typeof flag["type"] === "object" && flag["type"]._def) {
|
|
3778
|
+
typeName = "JSON object";
|
|
3779
|
+
try {
|
|
3780
|
+
const zodSchema = flag["type"];
|
|
3781
|
+
const def = zodSchema._def;
|
|
3782
|
+
if (def.shape) {
|
|
3783
|
+
const shape = typeof def.shape === "function" ? def.shape() : def.shape;
|
|
3784
|
+
const properties2 = Object.keys(shape);
|
|
3785
|
+
if (properties2.length > 0) {
|
|
3786
|
+
if (properties2.length <= 4) {
|
|
3787
|
+
typeDetails.push(`Properties: ${properties2.join(", ")}`);
|
|
3788
|
+
} else {
|
|
3789
|
+
typeDetails.push(`Properties: ${properties2.slice(0, 4).join(", ")}, ... (${properties2.length} total)`);
|
|
3790
|
+
}
|
|
3791
|
+
}
|
|
3792
|
+
}
|
|
3793
|
+
typeDetails.push("Expected: JSON string");
|
|
3794
|
+
} catch (error) {
|
|
3795
|
+
typeDetails.push("Expected: JSON string");
|
|
3796
|
+
}
|
|
3797
|
+
} else if (typeof flag["type"] === "function") {
|
|
3755
3798
|
typeName = flag["type"].name || "custom function";
|
|
3756
3799
|
if (typeName === "Boolean") typeName = "boolean";
|
|
3757
3800
|
if (typeName === "String") typeName = "string";
|
|
@@ -3762,6 +3805,9 @@ ${cyan("Flags:")}
|
|
|
3762
3805
|
typeName = flag["type"];
|
|
3763
3806
|
}
|
|
3764
3807
|
metaLines.push(`Type: ${typeName}`);
|
|
3808
|
+
if (typeDetails.length > 0) {
|
|
3809
|
+
metaLines.push(...typeDetails);
|
|
3810
|
+
}
|
|
3765
3811
|
if (flag["flagOnly"]) {
|
|
3766
3812
|
metaLines.push("Flag only (no value expected)");
|
|
3767
3813
|
}
|
|
@@ -4514,7 +4560,9 @@ _buildRecursiveString_fn = function(parser, level, visited = /* @__PURE__ */ new
|
|
|
4514
4560
|
`${flagIndent} Description: ${Array.isArray(flag["description"]) ? flag["description"].join(" | ") : flag["description"]}`
|
|
4515
4561
|
);
|
|
4516
4562
|
let typeName = "unknown";
|
|
4517
|
-
if (typeof flag["type"] === "
|
|
4563
|
+
if (flag["type"] && typeof flag["type"] === "object" && flag["type"]._def) {
|
|
4564
|
+
typeName = "Zod schema";
|
|
4565
|
+
} else if (typeof flag["type"] === "function") {
|
|
4518
4566
|
typeName = flag["type"].name || "custom function";
|
|
4519
4567
|
} else if (typeof flag["type"] === "string") {
|
|
4520
4568
|
typeName = flag["type"];
|
|
@@ -4581,7 +4629,9 @@ _buildRecursiveJson_fn = function(parser, visited = /* @__PURE__ */ new Set()) {
|
|
|
4581
4629
|
config.flags = flags.map((flag) => {
|
|
4582
4630
|
var _a;
|
|
4583
4631
|
let typeName = "unknown";
|
|
4584
|
-
if (typeof flag["type"] === "
|
|
4632
|
+
if (flag["type"] && typeof flag["type"] === "object" && flag["type"]._def) {
|
|
4633
|
+
typeName = "Zod schema";
|
|
4634
|
+
} else if (typeof flag["type"] === "function") {
|
|
4585
4635
|
typeName = flag["type"].name || "custom function";
|
|
4586
4636
|
} else if (typeof flag["type"] === "string") {
|
|
4587
4637
|
typeName = flag["type"];
|
|
@@ -5004,6 +5054,25 @@ function createMcpErrorResponse(error) {
|
|
|
5004
5054
|
};
|
|
5005
5055
|
}
|
|
5006
5056
|
function convertFlagToJsonSchemaProperty(flag) {
|
|
5057
|
+
if (flag.type && typeof flag.type === "object" && flag.type._def) {
|
|
5058
|
+
const zodSchema = flag.type;
|
|
5059
|
+
try {
|
|
5060
|
+
const property2 = zod.z.toJSONSchema(zodSchema);
|
|
5061
|
+
if (flag.description) {
|
|
5062
|
+
property2.description = flag.description;
|
|
5063
|
+
}
|
|
5064
|
+
const isRequired2 = !!(flag.mandatory || flag.required);
|
|
5065
|
+
return { property: property2, isRequired: isRequired2 };
|
|
5066
|
+
} catch (error) {
|
|
5067
|
+
console.warn(`Failed to convert Zod schema to JSON Schema for flag '${flag.name}':`, error);
|
|
5068
|
+
const property2 = {
|
|
5069
|
+
type: "object",
|
|
5070
|
+
description: flag.description || `${flag.name} parameter (Zod schema)`
|
|
5071
|
+
};
|
|
5072
|
+
const isRequired2 = !!(flag.mandatory || flag.required);
|
|
5073
|
+
return { property: property2, isRequired: isRequired2 };
|
|
5074
|
+
}
|
|
5075
|
+
}
|
|
5007
5076
|
const property = {
|
|
5008
5077
|
type: getJsonSchemaTypeFromFlag(flag.type),
|
|
5009
5078
|
description: flag.description || `${flag.name} parameter`
|
|
@@ -5110,8 +5179,11 @@ function extractSimplifiedResponse(mcpResponse) {
|
|
|
5110
5179
|
};
|
|
5111
5180
|
}
|
|
5112
5181
|
function mapArgParserFlagToZodSchema(flag) {
|
|
5113
|
-
let zodSchema = zod.z.string();
|
|
5114
5182
|
const flagTypeOpt = flag["type"];
|
|
5183
|
+
if (flagTypeOpt && typeof flagTypeOpt === "object" && flagTypeOpt._def) {
|
|
5184
|
+
return flagTypeOpt;
|
|
5185
|
+
}
|
|
5186
|
+
let zodSchema = zod.z.string();
|
|
5115
5187
|
let typeName;
|
|
5116
5188
|
if (typeof flagTypeOpt === "function") {
|
|
5117
5189
|
typeName = flagTypeOpt.name.toLowerCase().replace("constructor", "");
|