Add 'thv mcp call' for invoking MCP server tools#5389
Merged
Conversation
Listing tools via 'thv mcp list' showed what an MCP server exposes but not how it behaves. Adding 'thv mcp call' lets the user open a session, invoke a named tool, and inspect the result without leaving the CLI -- useful for ad-hoc debugging, registry verification, and shell pipelines. The subcommand accepts a positional tool name, server URL or workload name via --server, and JSON arguments via --args, --args-file, or stdin (--args-file -). Output is rendered in text by default or as the full CallToolResult in JSON. Tool-level errors exit non-zero by default; --ignore-tool-error inverts that for pipelines that want to inspect the result regardless. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5389 +/- ##
==========================================
- Coverage 68.84% 68.77% -0.08%
==========================================
Files 627 628 +1
Lines 63644 63658 +14
==========================================
- Hits 43816 43780 -36
- Misses 16574 16626 +52
+ Partials 3254 3252 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
rdimitrov
approved these changes
May 29, 2026
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.
Summary
thv mcp listshows what an MCP server exposes but not how it behaves. This adds a siblingthv mcp callsubcommand so an operator can open a session, invoke a named tool, and inspect the result without leaving the CLI — useful for ad-hoc debugging, registry verification, and shell pipelines.thv mcp call <tool-name>with--server(URL or workload name),--args '<json>',--args-file <path>(where-reads stdin),--ignore-tool-error,--format,--timeout,--transport.pkg/mcp/client.CallToolhandles theConnect → CallTool → Closelifecycle.StructuredContentpretty-printed);--format jsonemits the fullCallToolResult.CallToolResult.IsError=true) exit non-zero;--ignore-tool-errorflips that. Transport / protocol failures always exit non-zero.Contenttypes (TextContent,ImageContent,AudioContent,ResourceLink,EmbeddedResource).Type of change
Test plan
task test) — addedTestReadToolArgs,TestFormatBinaryContent,TestFormatContentResourceLinkcovering the JSON-args validation helper and content rendering.task lint-fix) — clean on touched files.Live testing against running MCP servers:
thv mcp call fetch --server fetch --args '{"url":"https://example.com"}'→ returns example.com content on stdout, exit 0.thv mcp call get_vulnerability --server osv --args '{"id":"GHSA-jq35-85cj-fj4p"}' --format json→ real OSV record (Docker/sys/devices/virtual/powercapadvisory, all references and affected ranges correct).thv mcp call query_vulnerability --server osv --args '{"package_name":"github.com/docker/docker","ecosystem":"Go","version":"24.0.0"}'→ live OSV query, structured JSON, exit 0.--args-file -), tool-error path (isError=true→ exit 1 with content on stdout andError:marker on stderr),--ignore-tool-error(same result, exit 0), non-object JSON rejection — all verified.Does this introduce a user-facing change?
Yes. A new
thv mcp callsubcommand is added for invoking MCP tools. CLI documentation is regenerated atdocs/cli/thv_mcp_call.mdand thetoolhive-cli-userskill is updated with the new command, examples, and flag reference.Implementation plan
Approved implementation plan
Surface:
Decisions agreed before implementation:
--tool).--argsand--args-filemutually exclusive. No flag → tool called with no arguments.IsError=true;--ignore-tool-erroroverrides.pkg/mcp/client(Connect + CallTool + Close), CLI stays thin.Contenttypes from the 2025-11-25 spec.Special notes for reviewers
ResourceLinkcontent type, stderr-redirect of tool output — were addressed. Mechanical fixes (dead-code pointer cases dropped, doc/code sync inCallTool, error-message style aligned tofailed to <verb>: %w) were also applied.pkg/mcp/client.CallToolhelper is intentionally kept as a thin wrapper for now. The existingthv mcp listsubcommands do the sameConnect → SDK call → Closeshape inline; the asymmetry is acknowledged. Reviewers flagged a judgement call here — either keep the helper or inline it for symmetry withlist. I'd like to revisit that decision when a third caller (e.g.mcp resource read,mcp prompt get) lands, since the right abstraction at that point is "scoped session", not "one-shot tool call". Open to inlining now if preferred.thv mcp listeither. Worth a follow-up that backfills both.🤖 Generated with Claude Code