feat: add --cli mode for direct tool invocation #63

Merged
goern merged 0 commits from refs/pull/63/head into main 2026-02-06 09:29:07 +00:00
goern commented 2026-02-06 09:26:53 +00:00 (Migrated from codeberg.org)

Summary

  • Add global --cli flag that bypasses the MCP server and invokes any of the 46 registered tools directly from the command line
  • Support --cli list (grouped by domain), --cli <tool> --args '{json}', --cli <tool> --help, stdin pipe, and --output=json|text
  • Enables use of forgejo-mcp as a Claude Code skill, in shell scripts, and CI/CD pipelines — partially implements the forgejo-cli vision

Changes

  • cmd/cli.go (new): RunCLI() entry point, cliList(), cliHelp(), cliExec(), stdin reader, domain-grouping via per-domain registration tracking
  • cmd/cmd.go: Early --cli detection in init(), CLI branch in Execute(), extracted initConfig() for shared URL/token resolution
  • operation/operation.go: Exported per-domain registration functions (RegisterUserTool, RegisterRepoTool, etc.) for domain tracking
  • README.md: New "CLI Mode" section with usage examples

Usage

forgejo-mcp --cli list                                    # List tools grouped by domain
forgejo-mcp --cli list --output=json                      # JSON tool listing
forgejo-mcp --cli get_my_user_info --args '{}'            # Invoke tool
forgejo-mcp --cli create_issue --help                     # Show parameters
echo '{"owner":"x","repo":"y"}' | forgejo-mcp --cli list_repo_issues  # Stdin pipe

Test plan

  • --cli list shows all 46 tools grouped by domain
  • --cli list --output=json emits valid JSON array
  • --cli <tool> --args '{}' invokes handler and returns JSON
  • --cli <tool> --help prints parameter schema
  • Stdin pipe works as alternative to --args
  • Unknown tool / invalid JSON produce stderr errors with non-zero exit
  • --output=text and --output=json work for both list and execution
  • MCP server mode (no --cli) is unaffected
## Summary - Add global `--cli` flag that bypasses the MCP server and invokes any of the 46 registered tools directly from the command line - Support `--cli list` (grouped by domain), `--cli <tool> --args '{json}'`, `--cli <tool> --help`, stdin pipe, and `--output=json|text` - Enables use of forgejo-mcp as a Claude Code skill, in shell scripts, and CI/CD pipelines — partially implements the [forgejo-cli](https://codeberg.org/forgejo-contrib/forgejo-cli) vision ## Changes - **`cmd/cli.go`** (new): `RunCLI()` entry point, `cliList()`, `cliHelp()`, `cliExec()`, stdin reader, domain-grouping via per-domain registration tracking - **`cmd/cmd.go`**: Early `--cli` detection in `init()`, CLI branch in `Execute()`, extracted `initConfig()` for shared URL/token resolution - **`operation/operation.go`**: Exported per-domain registration functions (`RegisterUserTool`, `RegisterRepoTool`, etc.) for domain tracking - **`README.md`**: New "CLI Mode" section with usage examples ## Usage ```bash forgejo-mcp --cli list # List tools grouped by domain forgejo-mcp --cli list --output=json # JSON tool listing forgejo-mcp --cli get_my_user_info --args '{}' # Invoke tool forgejo-mcp --cli create_issue --help # Show parameters echo '{"owner":"x","repo":"y"}' | forgejo-mcp --cli list_repo_issues # Stdin pipe ``` ## Test plan - [x] `--cli list` shows all 46 tools grouped by domain - [x] `--cli list --output=json` emits valid JSON array - [x] `--cli <tool> --args '{}'` invokes handler and returns JSON - [x] `--cli <tool> --help` prints parameter schema - [x] Stdin pipe works as alternative to `--args` - [x] Unknown tool / invalid JSON produce stderr errors with non-zero exit - [x] `--output=text` and `--output=json` work for both list and execution - [x] MCP server mode (no `--cli`) is unaffected
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
agentic-forges/forgejo-mcp!63
No description provided.