Skip to content

feat(cmd): add CmdCommand for Unix-friendly automation and fix serialization#227

Merged
chrishayuk merged 2 commits intoIBM:mainfrom
axisrow:main
Mar 1, 2026
Merged

feat(cmd): add CmdCommand for Unix-friendly automation and fix serialization#227
chrishayuk merged 2 commits intoIBM:mainfrom
axisrow:main

Conversation

@axisrow
Copy link
Contributor

@axisrow axisrow commented Feb 28, 2026

Fixes #226

Summary

  • New cmd subcommand (mcp-cli cmd) for Unix-friendly, non-interactive automation and scripting
    • Supports direct tool execution (-t/--tool) with JSON arguments (--tool-args)
    • Supports LLM-driven prompt mode (-p/--prompt) with single-turn and multi-turn conversations
    • Pipe-friendly I/O (-i/-o), raw output mode (--raw), and composable with Unix tools
  • Fix ToolExecutionResult JSON serialization — extract unwrap_tool_result() + to_serializable() into shared mcp_cli.utils.serialization module to correctly handle MCP SDK wrapper types
  • Fix contradictory success banner — defer output.success("✅ Tool executed successfully") until after unwrap_tool_result() completes, preventing misleading output when inner result contains isError=true
  • Harden unwrap_tool_result — raise RuntimeError on max-depth exceeded (instead of silent break), stringify non-string error content

Files Changed

File Change
src/mcp_cli/commands/cmd/cmd.py New CmdCommand implementation
src/mcp_cli/commands/__init__.py Register cmd subcommand
src/mcp_cli/utils/serialization.py New shared serialization utilities
src/mcp_cli/commands/tools/execute_tool.py Use shared serialization, fix banner ordering
src/mcp_cli/main.py Minor import fix
tests/commands/cmd/test_cmd_command.py 391-line test suite for CmdCommand
tests/utils/test_serialization.py Tests for unwrap_tool_result and to_serializable
tests/commands/definitions/test_execute_tool_coverage.py Updated imports

Test plan

  • python -m pytest tests/ — 4163 passed, 0 failures
  • Manual CLI verification: mcp-cli cmd -t list_tables, mcp-cli cmd -t read_query --tool-args '...'
  • Verified providers, models, ping, servers, tools, theme, tokens commands work correctly

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

…ization

Add `mcp-cli cmd` subcommand for non-interactive automation:
- Direct tool execution (-t/--tool) with JSON args (--tool-args)
- LLM prompt mode (-p/--prompt) with single/multi-turn support
- Pipe-friendly I/O (-i/-o) and raw output (--raw)

Fix ToolExecutionResult serialization:
- Extract unwrap_tool_result() + to_serializable() into shared
  mcp_cli.utils.serialization module
- Defer success banner until after unwrap to prevent contradictory
  output when inner result contains isError=true
- Raise RuntimeError on max-depth exceeded instead of silent break

Fixes IBM#226

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@chrishayuk chrishayuk merged commit b38b0a4 into IBM:main Mar 1, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mcp-cli cmd fails with "Unknown command: cmd"

2 participants