{"id":48935239,"url":"https://github.com/ilia3546/swift-argument-parser-mcp","last_synced_at":"2026-04-20T14:01:30.204Z","repository":{"id":351503687,"uuid":"1210436009","full_name":"ilia3546/swift-argument-parser-mcp","owner":"ilia3546","description":" A Swift library that turns any ArgumentParser CLI into an MCP server, letting AI agents call your commands as tools.","archived":false,"fork":false,"pushed_at":"2026-04-15T22:27:27.000Z","size":38,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-17T11:38:38.247Z","etag":null,"topics":["ai-tools","argument-parser","claude","cli","llm","macos","mcp","model-context-protocol","swift","swift-package-manager"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ilia3546.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-14T12:17:14.000Z","updated_at":"2026-04-16T10:55:09.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/ilia3546/swift-argument-parser-mcp","commit_stats":null,"previous_names":["ilia3546/swift-argument-parser-mcp"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/ilia3546/swift-argument-parser-mcp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ilia3546%2Fswift-argument-parser-mcp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ilia3546%2Fswift-argument-parser-mcp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ilia3546%2Fswift-argument-parser-mcp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ilia3546%2Fswift-argument-parser-mcp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ilia3546","download_url":"https://codeload.github.com/ilia3546/swift-argument-parser-mcp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ilia3546%2Fswift-argument-parser-mcp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31967993,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T00:39:45.007Z","status":"online","status_checked_at":"2026-04-18T02:00:07.018Z","response_time":103,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai-tools","argument-parser","claude","cli","llm","macos","mcp","model-context-protocol","swift","swift-package-manager"],"created_at":"2026-04-17T11:30:53.133Z","updated_at":"2026-04-18T12:00:57.129Z","avatar_url":"https://github.com/ilia3546.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Swift Argument Parser MCP\n\n**Turn any Swift CLI into an MCP server in minutes.**\n\nArgumentParserMCP lets AI agents call your [Swift Argument Parser][sap] commands\nas tools via the [Model Context Protocol][mcp].\nAdd one conformance, register your commands, and your CLI is ready for Claude, Cursor, and other MCP clients.\n\n[sap]: https://github.com/apple/swift-argument-parser\n[mcp]: https://modelcontextprotocol.io\n\n## Usage\n\nStart with a regular Argument Parser command and conform it to `MCPCommand`:\n\n```swift\nimport ArgumentParser\nimport ArgumentParserMCP\n\nstruct RepeatPhrase: ParsableCommand, MCPCommand {\n\n    static let configuration = CommandConfiguration(\n        abstract: \"Repeat a phrase multiple times.\"\n    )\n\n    @Flag(help: \"Include a counter with each repetition.\")\n    var includeCounter = false\n\n    @Option(name: .shortAndLong, help: \"How many times to repeat 'phrase'.\")\n    var count: Int? = nil\n\n    @Argument(help: \"The phrase to repeat.\")\n    var phrase: String\n\n    mutating func run() throws {\n        let repeatCount = count ?? 2\n        for i in 1...repeatCount {\n            if includeCounter {\n                print(\"\\(i): \\(phrase)\")\n            } else {\n                print(phrase)\n            }\n        }\n    }\n}\n```\n\nThen add a subcommand that starts the MCP server:\n\n```swift\nimport ArgumentParser\nimport ArgumentParserMCP\n\nstruct MCP: AsyncParsableCommand {\n\n    static let configuration = CommandConfiguration(\n        abstract: \"MCP Server for AI agents\"\n    )\n\n    mutating func run() async throws {\n        let server = MCPServer(\n            name: \"my-cli\",\n            version: \"1.0.0\",\n            commands: [RepeatPhrase.self]\n        )\n        try await server.start()\n    }\n}\n```\n\nRegister both subcommands in your root command:\n\n```swift\n@main\nstruct MyCLI: AsyncParsableCommand {\n\n    static let configuration = CommandConfiguration(\n        subcommands: [\n            RepeatPhrase.self,\n            MCP.self,\n        ]\n    )\n}\n```\n\nThat's it. Your CLI now speaks MCP over stdio when invoked with the `mcp` subcommand:\n\n```\n$ my-cli mcp\n```\n\nThe library automatically introspects your CLI via `--experimental-dump-help`,\ngenerates JSON Schema for every registered command,\nand dispatches tool calls back to the same binary as subprocesses.\n\n## How It Works\n\n```\nAI Agent ──stdio──\u003e my-cli mcp (MCPServer)\n                       |\n                       |── tools/list  -\u003e tool definitions from --experimental-dump-help\n                       |\n                       └── tools/call  -\u003e my-cli repeat-phrase --count 3 \"hello\"\n                                          captures stdout, returns as text\n```\n\n1. On startup, `MCPServer` runs the current executable with `--experimental-dump-help`\n   to discover the full command tree and argument metadata.\n2. For each registered `MCPCommand`, it builds an MCP tool with a JSON Schema `inputSchema`\n   derived from the command's arguments, options, and flags.\n3. When an agent calls a tool, the server converts JSON arguments back to CLI arguments\n   and invokes the appropriate subcommand as a child process.\n\n## Customization\n\n### Custom Tool Descriptions\n\nBy default, the MCP tool description is built from `CommandConfiguration.abstract` and `.discussion`.\nOverride `mcpDescription` for a custom one:\n\n```swift\nextension RepeatPhrase: MCPCommand {\n\n    static var mcpDescription: String {\n        \"Repeats a given phrase N times. Useful for testing and demonstrations.\"\n    }\n}\n```\n\n### Argument Interceptor\n\nUse `transformArguments` to add, remove, or modify CLI arguments before execution on a per-command basis:\n\n```swift\nextension Deploy: MCPCommand {\n\n    static func transformArguments(_ arguments: [String]) -\u003e [String] {\n        arguments + [\"--non-interactive\"]\n    }\n}\n```\n\n### Global Arguments\n\nPass arguments that should be appended to every command invocation:\n\n```swift\nlet server = MCPServer(\n    name: \"my-cli\",\n    version: \"1.0.0\",\n    commands: [Deploy.self, Status.self],\n    globalArguments: [\"--verbose\"]\n)\n```\n\n## Adding `ArgumentParserMCP` as a Dependency\n\nTo use the `ArgumentParserMCP` library in a SwiftPM project,\nadd it to the dependencies for your package and your CLI target:\n\n```swift\nlet package = Package(\n    // name, platforms, products, etc.\n    dependencies: [\n        .package(url: \"https://github.com/apple/swift-argument-parser\", from: \"1.0.0\"),\n        .package(url: \"https://github.com/ilia3546/swift-argument-parser-mcp\", from: \"1.0.0\"),\n    ],\n    targets: [\n        .executableTarget(name: \"\u003ccommand-line-tool\u003e\", dependencies: [\n            .product(name: \"ArgumentParser\", package: \"swift-argument-parser\"),\n            .product(name: \"ArgumentParserMCP\", package: \"swift-argument-parser-mcp\"),\n        ]),\n    ]\n)\n```\n\n### Connecting to an MCP Client\n\nAdd your CLI to the client's MCP configuration. For example, in Claude Code (`settings.json`):\n\n```json\n{\n  \"mcpServers\": {\n    \"my-cli\": {\n      \"command\": \"/path/to/my-cli\",\n      \"args\": [\"mcp\"]\n    }\n  }\n}\n```\n\n## Documentation\n\nAPI documentation is generated automatically from source and hosted by Swift Package Index:\n\n- [ArgumentParserMCP documentation][docs]\n\n[docs]: https://swiftpackageindex.com/ilia3546/swift-argument-parser-mcp/documentation/argumentparsermcp\n\n## Requirements\n\n- Swift 6.0+\n- macOS 13+\n\n## License\n\nThis library is released under the Apache 2.0 license. See [LICENSE](LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Filia3546%2Fswift-argument-parser-mcp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Filia3546%2Fswift-argument-parser-mcp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Filia3546%2Fswift-argument-parser-mcp/lists"}