feat(cmd): add CmdCommand for Unix-friendly automation and fix serialization#227
Merged
chrishayuk merged 2 commits intoIBM:mainfrom Mar 1, 2026
Merged
feat(cmd): add CmdCommand for Unix-friendly automation and fix serialization#227chrishayuk merged 2 commits intoIBM:mainfrom
chrishayuk merged 2 commits intoIBM:mainfrom
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #226
Summary
cmdsubcommand (mcp-cli cmd) for Unix-friendly, non-interactive automation and scripting-t/--tool) with JSON arguments (--tool-args)-p/--prompt) with single-turn and multi-turn conversations-i/-o), raw output mode (--raw), and composable with Unix toolsunwrap_tool_result()+to_serializable()into sharedmcp_cli.utils.serializationmodule to correctly handle MCP SDK wrapper typesoutput.success("✅ Tool executed successfully")until afterunwrap_tool_result()completes, preventing misleading output when inner result containsisError=trueunwrap_tool_result— raiseRuntimeErroron max-depth exceeded (instead of silent break), stringify non-string error contentFiles Changed
src/mcp_cli/commands/cmd/cmd.pysrc/mcp_cli/commands/__init__.pysrc/mcp_cli/utils/serialization.pysrc/mcp_cli/commands/tools/execute_tool.pysrc/mcp_cli/main.pytests/commands/cmd/test_cmd_command.pytests/utils/test_serialization.pytests/commands/definitions/test_execute_tool_coverage.pyTest plan
python -m pytest tests/— 4163 passed, 0 failuresmcp-cli cmd -t list_tables,mcp-cli cmd -t read_query --tool-args '...'providers,models,ping,servers,tools,theme,tokenscommands work correctly🤖 Generated with Claude Code
Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com