@alcyone-labs/arg-parser 2.0.0 → 2.1.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 (46) hide show
  1. package/README.md +371 -5
  2. package/dist/index.cjs +3362 -2603
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.min.mjs +7569 -6957
  5. package/dist/index.min.mjs.map +1 -1
  6. package/dist/index.mjs +3362 -2603
  7. package/dist/index.mjs.map +1 -1
  8. package/package.json +8 -4
  9. package/dist/src/config/ConfigurationManager.d.ts +0 -74
  10. package/dist/src/config/ConfigurationManager.d.ts.map +0 -1
  11. package/dist/src/config/plugins/ConfigPlugin.d.ts +0 -60
  12. package/dist/src/config/plugins/ConfigPlugin.d.ts.map +0 -1
  13. package/dist/src/config/plugins/ConfigPluginRegistry.d.ts +0 -72
  14. package/dist/src/config/plugins/ConfigPluginRegistry.d.ts.map +0 -1
  15. package/dist/src/config/plugins/TomlConfigPlugin.d.ts +0 -30
  16. package/dist/src/config/plugins/TomlConfigPlugin.d.ts.map +0 -1
  17. package/dist/src/config/plugins/YamlConfigPlugin.d.ts +0 -29
  18. package/dist/src/config/plugins/YamlConfigPlugin.d.ts.map +0 -1
  19. package/dist/src/config/plugins/index.d.ts +0 -5
  20. package/dist/src/config/plugins/index.d.ts.map +0 -1
  21. package/dist/src/core/ArgParser.d.ts +0 -332
  22. package/dist/src/core/ArgParser.d.ts.map +0 -1
  23. package/dist/src/core/ArgParserBase.d.ts +0 -206
  24. package/dist/src/core/ArgParserBase.d.ts.map +0 -1
  25. package/dist/src/core/FlagManager.d.ts +0 -16
  26. package/dist/src/core/FlagManager.d.ts.map +0 -1
  27. package/dist/src/core/types.d.ts +0 -194
  28. package/dist/src/core/types.d.ts.map +0 -1
  29. package/dist/src/dxt/DxtGenerator.d.ts +0 -115
  30. package/dist/src/dxt/DxtGenerator.d.ts.map +0 -1
  31. package/dist/src/index.d.ts +0 -11
  32. package/dist/src/index.d.ts.map +0 -1
  33. package/dist/src/mcp/ArgParserMcp.d.ts +0 -21
  34. package/dist/src/mcp/ArgParserMcp.d.ts.map +0 -1
  35. package/dist/src/mcp/mcp-integration.d.ts +0 -83
  36. package/dist/src/mcp/mcp-integration.d.ts.map +0 -1
  37. package/dist/src/mcp/mcp-notifications.d.ts +0 -138
  38. package/dist/src/mcp/mcp-notifications.d.ts.map +0 -1
  39. package/dist/src/mcp/mcp-prompts.d.ts +0 -132
  40. package/dist/src/mcp/mcp-prompts.d.ts.map +0 -1
  41. package/dist/src/mcp/mcp-resources.d.ts +0 -133
  42. package/dist/src/mcp/mcp-resources.d.ts.map +0 -1
  43. package/dist/src/testing/fuzzy-test-cli.d.ts +0 -5
  44. package/dist/src/testing/fuzzy-test-cli.d.ts.map +0 -1
  45. package/dist/src/testing/fuzzy-tester.d.ts +0 -101
  46. package/dist/src/testing/fuzzy-tester.d.ts.map +0 -1
package/README.md CHANGED
@@ -23,15 +23,32 @@ A modern, type-safe command line argument parser with built-in MCP (Model Contex
23
23
  - [MCP Exposure Control](#mcp-exposure-control)
24
24
  - [Flag Inheritance (`inheritParentFlags`)](#flag-inheritance-inheritparentflags)
25
25
  - [MCP & Claude Desktop Integration](#mcp--claude-desktop-integration)
26
+ - [Output Schema Support](#output-schema-support)
27
+ - [Basic Usage](#basic-usage)
28
+ - [Predefined Schema Patterns](#predefined-schema-patterns)
29
+ - [Custom Zod Schemas](#custom-zod-schemas)
30
+ - [MCP Version Compatibility](#mcp-version-compatibility)
31
+ - [Automatic Error Handling](#automatic-error-handling)
32
+ - [Writing Effective MCP Tool Descriptions](#writing-effective-mcp-tool-descriptions)
33
+ - [Best Practices for Tool Descriptions](#best-practices-for-tool-descriptions)
34
+ - [Complete Example: Well-Documented Tool](#complete-example-well-documented-tool)
35
+ - [Parameter Description Guidelines](#parameter-description-guidelines)
36
+ - [Common Pitfalls to Avoid](#common-pitfalls-to-avoid)
26
37
  - [Automatic MCP Server Mode (`--s-mcp-serve`)](#automatic-mcp-server-mode---s-mcp-serve)
27
38
  - [MCP Transports](#mcp-transports)
28
39
  - [Automatic Console Safety](#automatic-console-safety)
29
40
  - [Generating DXT Packages (`--s-build-dxt`)](#generating-dxt-packages---s-build-dxt)
30
41
  - [Logo Configuration](#logo-configuration)
42
+ - [Supported Logo Sources](#supported-logo-sources)
31
43
  - [How DXT Generation Works](#how-dxt-generation-works)
32
44
  - [System Flags & Configuration](#system-flags--configuration)
33
45
  - [Changelog](#changelog)
46
+ - [v2.0.0](#v200)
47
+ - [v1.3.0](#v130)
48
+ - [v1.2.0](#v120)
49
+ - [v1.1.0](#v110)
34
50
  - [Backlog](#backlog)
51
+ - [(known) Bugs / DX improvement points](#known-bugs--dx-improvement-points)
35
52
 
36
53
  ## Features Overview
37
54
 
@@ -62,6 +79,7 @@ pnpm add @alcyone-labs/arg-parser
62
79
  The modern way to build with ArgParser is using the `.addTool()` method. It creates a single, self-contained unit that works as both a CLI subcommand and an MCP tool.
63
80
 
64
81
  ```typescript
82
+ import { z } from "zod";
65
83
  import { ArgParser } from "@alcyone-labs/arg-parser";
66
84
 
67
85
  // Use ArgParser.withMcp to enable MCP and DXT features
@@ -93,6 +111,13 @@ const cli = ArgParser.withMcp({
93
111
  description: "Greeting style",
94
112
  },
95
113
  ],
114
+ // Optional: Define output schema for MCP clients (Claude Desktop, etc.)
115
+ // This only affects MCP mode - CLI mode works the same regardless
116
+ outputSchema: {
117
+ success: z.boolean().describe("Whether the greeting was successful"),
118
+ greeting: z.string().describe("The formatted greeting message"),
119
+ name: z.string().describe("The name that was greeted"),
120
+ },
96
121
  handler: async (ctx) => {
97
122
  // Use console.log freely - it's automatically safe in MCP mode!
98
123
  console.log(`Greeting ${ctx.args.name} in a ${ctx.args.style} style...`);
@@ -368,6 +393,7 @@ cli.addTool({
368
393
  - **Simpler Logic**: No more manual MCP mode detection or response formatting.
369
394
  - **Automatic Schemas**: Flags are automatically converted into the `input_schema` for MCP tools.
370
395
  - **Automatic Console Safety**: `console.log` is automatically redirected in MCP mode.
396
+ - **Optional Output Schemas**: Add `outputSchema` only if you want structured responses for MCP clients - CLI mode works perfectly without them.
371
397
 
372
398
  ---
373
399
 
@@ -395,12 +421,81 @@ interface IFlag {
395
421
 
396
422
  ### Type Handling and Validation
397
423
 
398
- ArgParser automatically handles type conversion and validation:
424
+ ArgParser provides **strong typing** for flag definitions with comprehensive validation at both compile-time and runtime. The `type` property accepts multiple formats and ensures type safety throughout your application.
425
+
426
+ #### Supported Type Formats
427
+
428
+ You can define flag types using either **constructor functions** or **string literals**:
429
+
430
+ ```typescript
431
+ const parser = new ArgParser({ /* ... */ }).addFlags([
432
+ // Constructor functions (recommended for TypeScript)
433
+ { name: "count", options: ["--count"], type: Number },
434
+ { name: "enabled", options: ["--enabled"], type: Boolean, flagOnly: true },
435
+ { name: "files", options: ["--files"], type: Array, allowMultiple: true },
436
+
437
+ // String literals (case-insensitive)
438
+ { name: "name", options: ["--name"], type: "string" },
439
+ { name: "port", options: ["--port"], type: "number" },
440
+ { name: "verbose", options: ["-v"], type: "boolean", flagOnly: true },
441
+ { name: "tags", options: ["--tags"], type: "array", allowMultiple: true },
442
+ { name: "config", options: ["--config"], type: "object" },
443
+
444
+ // Custom parser functions
445
+ {
446
+ name: "date",
447
+ options: ["--date"],
448
+ type: (value: string) => new Date(value)
449
+ }
450
+ ]);
451
+ ```
452
+
453
+ #### Runtime Type Validation
399
454
 
400
- - **String flags**: `--name value` or `--name="quoted value"`
401
- - **Number flags**: `--count 42` (automatically parsed)
402
- - **Boolean flags**: `--verbose` (presence implies `true`)
403
- - **Array flags**: `--tags tag1,tag2,tag3` or multiple `--tag value1 --tag value2` (requires `allowMultiple: true`)
455
+ The type system validates flag definitions at runtime and throws descriptive errors for invalid configurations:
456
+
457
+ ```typescript
458
+ // Valid - these work
459
+ { name: "count", options: ["--count"], type: Number }
460
+ { name: "count", options: ["--count"], type: "number" }
461
+ { name: "count", options: ["--count"], type: "NUMBER" } // case-insensitive
462
+
463
+ // ❌ Invalid - these throw ZodError
464
+ { name: "count", options: ["--count"], type: "invalid-type" }
465
+ { name: "count", options: ["--count"], type: 42 } // primitive instead of constructor
466
+ { name: "count", options: ["--count"], type: null }
467
+ ```
468
+
469
+ #### Automatic Type Processing
470
+
471
+ - **String literals** are automatically converted to constructor functions internally
472
+ - **Constructor functions** are preserved as-is
473
+ - **Custom parser functions** allow complex transformations
474
+ - **undefined** falls back to the default `"string"` type
475
+
476
+ #### Type Conversion Examples
477
+
478
+ ```typescript
479
+ // String flags
480
+ --name value → "value"
481
+ --name="quoted value" → "quoted value"
482
+
483
+ // Number flags
484
+ --count 42 → 42
485
+ --port=8080 → 8080
486
+
487
+ // Boolean flags (flagOnly: true)
488
+ --verbose → true
489
+ (no flag) → false
490
+
491
+ // Array flags (allowMultiple: true)
492
+ --tags tag1,tag2,tag3 → ["tag1", "tag2", "tag3"]
493
+ --file file1.txt --file file2.txt → ["file1.txt", "file2.txt"]
494
+
495
+ // Custom parser functions
496
+ --date "2023-01-01" → Date object
497
+ --json '{"key":"val"}' → parsed JSON object
498
+ ```
404
499
 
405
500
  ### Hierarchical CLIs (Sub-Commands)
406
501
 
@@ -468,6 +563,266 @@ parentParser.addSubCommand({ name: "deploy", parser: childParser });
468
563
 
469
564
  ## MCP & Claude Desktop Integration
470
565
 
566
+ ### Output Schema Support
567
+
568
+ Output schemas are **completely optional** and **only affect MCP mode** (Claude Desktop, MCP clients). They have **zero impact** on CLI usage - your CLI will work exactly the same with or without them.
569
+
570
+ **When do I need output schemas?**
571
+
572
+ - ❌ **CLI-only usage**: Never needed - skip this section entirely
573
+ - ✅ **MCP integration**: Optional but recommended for better structured responses
574
+ - ✅ **Claude Desktop**: Helpful for Claude to understand your tool's output format
575
+
576
+ **Key Points:**
577
+
578
+ - ✅ **CLI works perfectly without them**: Your command-line interface is unaffected
579
+ - ✅ **MCP-only feature**: Only used when running with `--s-mcp-serve`
580
+ - ✅ **Version-aware**: Automatically included only for compatible MCP clients (v2025-06-18+)
581
+ - ✅ **Flexible**: Use predefined patterns or custom Zod schemas
582
+
583
+ #### Basic Usage
584
+
585
+ ```typescript
586
+ import { z } from "zod";
587
+
588
+ .addTool({
589
+ name: "process-file",
590
+ description: "Process a file",
591
+ flags: [
592
+ { name: "path", options: ["--path"], type: "string", mandatory: true }
593
+ ],
594
+ // Optional: Only needed if you want structured MCP responses
595
+ // CLI mode works exactly the same whether this is present or not
596
+ outputSchema: {
597
+ success: z.boolean().describe("Whether processing succeeded"),
598
+ filePath: z.string().describe("Path to the processed file"),
599
+ size: z.number().describe("File size in bytes"),
600
+ lastModified: z.string().describe("Last modification timestamp")
601
+ },
602
+ handler: async (ctx) => {
603
+ // Your logic here - same code for both CLI and MCP
604
+ // The outputSchema doesn't change how this function works
605
+ return {
606
+ success: true,
607
+ filePath: ctx.args.path,
608
+ size: 1024,
609
+ lastModified: new Date().toISOString()
610
+ };
611
+ }
612
+ })
613
+
614
+ // CLI usage (outputSchema ignored): mycli process-file --path /my/file.txt
615
+ // MCP usage (outputSchema provides structure): mycli --s-mcp-serve
616
+ ```
617
+
618
+ #### Predefined Schema Patterns
619
+
620
+ For common use cases, use predefined patterns:
621
+
622
+ ```typescript
623
+ // For simple success/error responses
624
+ outputSchema: "successError";
625
+
626
+ // For operations that return data
627
+ outputSchema: "successWithData";
628
+
629
+ // For file operations
630
+ outputSchema: "fileOperation";
631
+
632
+ // For process execution
633
+ outputSchema: "processExecution";
634
+
635
+ // For list operations
636
+ outputSchema: "list";
637
+ ```
638
+
639
+ #### Custom Zod Schemas
640
+
641
+ For complex data structures:
642
+
643
+ ```typescript
644
+ outputSchema: z.object({
645
+ analysis: z.object({
646
+ summary: z.string(),
647
+ wordCount: z.number(),
648
+ sentiment: z.enum(["positive", "negative", "neutral"]),
649
+ }),
650
+ metadata: z.object({
651
+ timestamp: z.string(),
652
+ processingTime: z.number(),
653
+ }),
654
+ });
655
+ ```
656
+
657
+ #### MCP Version Compatibility
658
+
659
+ Output schemas are automatically handled based on MCP client version:
660
+
661
+ - **MCP v2025-06-18+**: Full output schema support with `structuredContent`
662
+ - **Earlier versions**: Schemas ignored, standard JSON text response only
663
+
664
+ To explicitly set the MCP version for testing:
665
+
666
+ ```typescript
667
+ const cli = ArgParser.withMcp({
668
+ // ... your config
669
+ }).setMcpProtocolVersion("2025-06-18"); // Enable output schema support
670
+ ```
671
+
672
+ **Important**:
673
+
674
+ - **CLI users**: You can ignore MCP versions entirely - they don't affect command-line usage
675
+ - **MCP users**: ArgParser handles version detection automatically based on client capabilities
676
+
677
+ #### Automatic Error Handling
678
+
679
+ ArgParser automatically handles errors differently based on execution context, so your handlers can simply throw errors without worrying about CLI vs MCP mode:
680
+
681
+ ```typescript
682
+ const cli = ArgParser.withMcp({
683
+ // ... config
684
+ }).addTool({
685
+ name: "process-data",
686
+ handler: async (ctx) => {
687
+ // Simply throw errors - ArgParser handles the rest automatically
688
+ if (!ctx.args.apiKey) {
689
+ throw new Error("API key is required");
690
+ }
691
+
692
+ // Do your work and return results
693
+ return { success: true, data: processedData };
694
+ },
695
+ });
696
+ ```
697
+
698
+ **How it works:**
699
+
700
+ - **CLI mode**: Thrown errors cause the process to exit with error code 1
701
+ - **MCP mode**: Thrown errors are automatically converted to structured MCP error responses
702
+ - **No manual checks needed**: Handlers don't need to check `ctx.isMcp` or handle different response formats
703
+
704
+ ### Writing Effective MCP Tool Descriptions
705
+
706
+ **Why descriptions matter**: When your tools are exposed to Claude Desktop or other MCP clients, the `description` field is the primary way LLMs understand what your tool does and when to use it. A well-written description significantly improves tool selection accuracy and user experience.
707
+
708
+ #### Best Practices for Tool Descriptions
709
+
710
+ **1. Start with the action** - Begin with a clear verb describing what the tool does:
711
+
712
+ ```typescript
713
+ // ✅ Good: Action-first, specific
714
+ description: "Analyzes text files and returns detailed statistics including word count, character count, and sentiment analysis";
715
+
716
+ // ❌ Avoid: Vague or noun-heavy
717
+ description: "File analysis tool";
718
+ ```
719
+
720
+ **2. Include context and use cases** - Explain when and why to use the tool:
721
+
722
+ ```typescript
723
+ // ✅ Good: Provides context
724
+ description: "Converts image files between formats (PNG, JPEG, WebP). Use this when you need to change image format, resize images, or optimize file sizes. Supports batch processing of multiple files.";
725
+
726
+ // ❌ Avoid: No context
727
+ description: "Converts images";
728
+ ```
729
+
730
+ **3. Mention key parameters and constraints** - Reference important inputs and limitations:
731
+
732
+ ```typescript
733
+ // ✅ Good: Mentions key parameters and constraints
734
+ description: "Searches through project files using regex patterns. Specify the search pattern and optionally filter by file type. Supports JavaScript, TypeScript, Python, and text files up to 10MB.";
735
+
736
+ // ❌ Avoid: No parameter guidance
737
+ description: "Searches files";
738
+ ```
739
+
740
+ **4. Be specific about outputs** - Describe what the tool returns:
741
+
742
+ ```typescript
743
+ // ✅ Good: Clear output description
744
+ description: "Analyzes code complexity and returns metrics including cyclomatic complexity, lines of code, and maintainability index. Results include detailed breakdown by function and overall file scores.";
745
+
746
+ // ❌ Avoid: Unclear output
747
+ description: "Analyzes code";
748
+ ```
749
+
750
+ #### Complete Example: Well-Documented Tool
751
+
752
+ ```typescript
753
+ .addTool({
754
+ name: "analyze-repository",
755
+ description: "Analyzes a Git repository and generates comprehensive statistics including commit history, contributor activity, code quality metrics, and dependency analysis. Use this to understand project health, identify bottlenecks, or prepare reports. Supports Git repositories up to 1GB with history up to 5 years.",
756
+ flags: [
757
+ {
758
+ name: "path",
759
+ description: "Path to the Git repository root directory",
760
+ options: ["--path", "-p"],
761
+ type: "string",
762
+ mandatory: true,
763
+ },
764
+ {
765
+ name: "include-dependencies",
766
+ description: "Include analysis of package.json dependencies and security vulnerabilities",
767
+ options: ["--include-dependencies", "-d"],
768
+ type: "boolean",
769
+ flagOnly: true,
770
+ },
771
+ {
772
+ name: "output-format",
773
+ description: "Output format for the analysis report",
774
+ options: ["--output-format", "-f"],
775
+ type: "string",
776
+ choices: ["json", "markdown", "html"],
777
+ defaultValue: "json",
778
+ }
779
+ ],
780
+ handler: async (ctx) => {
781
+ // Implementation here
782
+ }
783
+ })
784
+ ```
785
+
786
+ #### Parameter Description Guidelines
787
+
788
+ Each flag should have a clear, concise description:
789
+
790
+ ```typescript
791
+ // ✅ Good parameter descriptions
792
+ {
793
+ name: "timeout",
794
+ description: "Maximum execution time in seconds (default: 30, max: 300)",
795
+ options: ["--timeout", "-t"],
796
+ type: "number",
797
+ }
798
+
799
+ {
800
+ name: "verbose",
801
+ description: "Enable detailed logging output including debug information",
802
+ options: ["--verbose", "-v"],
803
+ type: "boolean",
804
+ flagOnly: true,
805
+ }
806
+
807
+ {
808
+ name: "format",
809
+ description: "Output format for results (json: structured data, csv: spreadsheet-friendly, pretty: human-readable)",
810
+ options: ["--format"],
811
+ type: "string",
812
+ choices: ["json", "csv", "pretty"],
813
+ }
814
+ ```
815
+
816
+ #### Common Pitfalls to Avoid
817
+
818
+ - **Don't be overly technical**: Avoid jargon that doesn't help with tool selection
819
+ - **Don't repeat the tool name**: The name is already visible, focus on functionality
820
+ - **Don't use generic terms**: "Process data" or "handle files" are too vague
821
+ - **Don't forget constraints**: Mention important limitations or requirements
822
+ - **Don't ignore parameter descriptions**: Each flag should have a helpful description
823
+
824
+ **Remember**: A good description helps the LLM choose the right tool for the task and use it correctly. Invest time in writing clear, comprehensive descriptions - it directly impacts the user experience in Claude Desktop and other MCP clients.
825
+
471
826
  ### Automatic MCP Server Mode (`--s-mcp-serve`)
472
827
 
473
828
  You don't need to write any server logic. Run your application with the `--s-mcp-serve` flag, and ArgParser will automatically start a compliant MCP server, exposing all tools defined with `.addTool()` and subcommands created with `.addSubCommand()` (unless `includeSubCommands: false` is set).
@@ -620,6 +975,17 @@ ArgParser includes built-in `--s-*` flags for development, debugging, and config
620
975
 
621
976
  ## Changelog
622
977
 
978
+ ### v2.1.0
979
+
980
+ **Feat**
981
+
982
+ - IFlag function-based `type` handling must now define the type it returns, this unlocks nice features such as providing nicer Intellisense, `output schemas` support and makes it easier to upgrade to Zod V4
983
+ - Add support for MCP output_schema field for clients that support it, CLI isn't impacted by it, this helps a lot the interactivity, self-documentation, and improves the API guarantees
984
+
985
+ **Fixes and changes**
986
+ - Fix missing missing types
987
+ - Improved MCP version compliance
988
+
623
989
  ### v2.0.0
624
990
 
625
991
  - **Unified Tool Architecture**: Introduced `.addTool()` to define CLI subcommands and MCP tools in a single declaration.