Repository navigation
Log backend tool errors at Debug and count them - #7300
Merged
Merged
Conversation
When a backend answers tools/call with isError, the vMCP backend client logged a WARN line carrying the text of the result's first content block. A caller can trigger that line on every call, and a tool's error text often repeats the call's arguments, such as a query the backend could not parse, an identifier, or a file name, so a failed call could write the caller's input into the vMCP logs at the default level. The vMCP log level setting can only switch debug on, so operators had no way to keep that text out. The line now logs at Debug with the same message and fields, as code mode does for a failed script. The backend telemetry decorator counts these results in a new toolhive_vmcp_backend_tool_errors counter with the attributes of toolhive_vmcp_backend_requests, once per call on both the Legacy and the Modern path, because toolhive_vmcp_backend_errors counts only calls that return a Go error. The client still receives the full result. toolResultFromMCP takes its logger as a parameter, so the test asserts on the line without swapping the process-wide slog default. Composite tool workflows still log a failed step's error text in their own lines, and this change leaves them as they are. Signed-off-by: Aleksandr Filippov <[email protected]>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7300 +/- ##
==========================================
+ Coverage 81.95% 82.00% +0.04%
==========================================
Files 922 922
Lines 93367 93376 +9
==========================================
+ Hits 76521 76575 +54
+ Misses 16841 16796 -45
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
ChrisJBurns
approved these changes
Nov 25, 2026
1 task
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
A tool's error text often repeats the call's input: a query the backend could not parse, an ID it could not find, a file name. When a backend answers
tools/callwithisError: true, the vMCP backend client logs that text at WARN, so a failed call can write the caller's input into the vMCP logs at the default level, and operators cannot drop it becauselogLevelaccepts onlydebug(pkg/vmcp/config/config.go:726). A caller can trigger the line on every call, sodocs/logging.md:22puts it at Debug with a counter where operators need a signal, as code mode does for a failed script withtoolhive_vmcp_script_executions{status}(#7275).toolResultFromMCPlogstool returned IsError=trueat Debug, with the same message and fields.toolhive_vmcp_backend_tool_errors.docs/operator/virtualmcpserver-observability.mddocuments the counter and the log line, and says that composite tool workflows still log the text. It anddocs/telemetry-migration-guide.mdsay thatmcp.client.operation.durationgets noerror.typefor anisErrorresult.Closes #7297
Type of change
Test plan
task test)task test-e2e)task lint-fix)TestToolResultFromMCP_LogsIsErrorOnlyAtDebugcovers a result with and without_metaand fails with main'sslog.Warnput back.TestTelemetryBackendClient_CallToolRecordsToolErrorscovers one and twoisErrorresults, a successful result, and a Go error, and checks each case'smcp.client.operation.durationpoint, where only the Go error setserror.type. It fails when the counter is skipped, doubled, or carries other attributes than the request counter, and when the duration point of anisErrorresult gainserror.typeor loses its attributes.Does this introduce a user-facing change?
Yes, for operators.
isErrorresult logsWARN tool returned IsError=truewithtool,backend,error(the first content block's text), andmetawhen the backend sent_meta. Outside the optimizer, no vMCP metric reads the flag.logLevel: debug(--debug) the backend client logs nothing for them, and a deployment without telemetry no longer sees these failures at the default level. With telemetry configured,toolhive_vmcp_backend_tool_errors(_totalin Prometheus) counts them per backend and tool.toolhive_vmcp_backend_errorsis unchanged.Special notes for reviewers
backendtelemetry, recorded with the attributestoolhive_vmcp_backend_requestsgets for the same call, as the errors counter and duration histogram are (pkg/vmcp/internal/backendtelemetry/backendtelemetry.go:238,:242,:254), so it adds no new label values. The decorator wraps the backend client once, incore.New(pkg/vmcp/core/core_vmcp.go:122), above both the Legacy and the Modern path, so each result counts once, composite workflow steps and code mode's inner calls included. It is a separate counter, not an attribute ontoolhive_vmcp_backend_errors, so existing series and alerts keep their meaning; the optimizer countsresult.IsErrorthe same way (pkg/vmcp/server/sessionmanager/factory.go:362-365,:484).error.type: the OTel MCP semantic conventions puterror.type=tool_erroronmcp.client.operation.durationand the client span for anisErrorresult. This PR sets neither, and the decorator's span status stays unset where code mode marks its inner span failed (pkg/vmcp/codemode/decorator.go:407). Setting them would change what an existing metric and existing traces report for these calls, which is a different change; OTEL: Add error.type and rpc.response.status_code for JSON-RPC errors #3765 tracks the same gap forpkg/telemetry/middleware.go. As recorded here, the histogram has no backend or tool attribute (backendtelemetry.go:232-235), so it could not say which tool failed. The docs now say thaterror.typeis not set for anisErrorresult.recordalso returns the call's metric attributes: the revision label is read before the call, and a call can reclassify it.CallTool(pkg/vmcp/session/internal/backend/mcp_session.go:364) is left alone because notools/callreaches it:server.Newroutes every call through the core (pkg/vmcp/server/server.go:590-593), and the one handler that calls a session'sCallToolis installed only in a branchsessionmanagerdocuments as unreachable (pkg/vmcp/server/sessionmanager/factory.go:182-186).pkg/vmcp/composer/workflow_engine.go:518-519) and wraps it into the step error (:520). The executor, the engine, and the workflow's caller each log that error at ERROR (pkg/vmcp/composer/dag_executor.go:138,workflow_engine.go:203, and for examplepkg/vmcp/core/core_calls.go:297), and the client gets it as the workflow's failure message. Taking the text out of those lines means separating the logged error from the returned one, which is a different change.toolResultFromMCPtakes the logger as a parameter. The test passes its own logger and never swaps the process-wide default, for the reasoncedarAdmissiongives for its injected logger (pkg/vmcp/core/admission.go:121-126).