Skip to content

Fix exit code for call subcommand when tool execution fails #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Jun 5, 2025

The call subcommand was not returning proper exit codes when encountering execution errors (such as calling unknown tools). This made it impossible to use the tool effectively in CI pipelines and validation scripts.

Problem

Before this fix:

$ mcpt call unknown npx -y @modelcontextprotocol/server-filesystem ~
Error: Unknown tool: unknown
$ echo $?
0

The command would print the error message but exit with code 0, making it difficult to detect failures in automated environments.

Solution

Added proper error handling to check for execution errors (execErr) after calling MCP client methods and exit with code 1 when errors occur.

After this fix:

$ mcpt call unknown npx -y @modelcontextprotocol/server-filesystem ~
Error: Unknown tool: unknown
$ echo $?
1

Now the command correctly exits with code 1 for execution errors while maintaining code 0 for successful operations.

Changes Made

  • Added 4 lines in cmd/mcptools/commands/call.go to check for execution errors and exit with code 1
  • Added test case to verify error handling behavior
  • All existing tests continue to pass
  • Verified with integration testing

This enables proper use of mcptools in CI pipelines and validation workflows where non-zero exit codes are essential for detecting failures.

Fixes #53.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] Exit code for call subcommand Fix exit code for call subcommand when tool execution fails Jun 5, 2025
@Copilot Copilot AI requested a review from f June 5, 2025 23:21
Copilot finished work on behalf of f June 5, 2025 23:21
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.

Exit code for call subcommand
2 participants