Skip to content

Surface delegated credential errors in vMCP - #7353

Merged
jhrozek merged 3 commits into
stacklok:mainfrom
jhrozek:credential-read-3-delegated-errors
Nov 27, 2026
Merged

jhrozek merged 3 commits into
stacklok:mainfrom
jhrozek:credential-read-3-delegated-errors

Conversation

@jhrozek

@jhrozek jhrozek commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Summary

The delegated credential read (Part of "Ownership-checked credential read for delegated tokens, keyed by user and routed provider") needs a call that fails on the user's credential to look different from a backend failure. Clients should see "connect provider X" or a fixed "credential unavailable", not transport text, workflow wrapping or a Legacy-fallback retry. Today every such failure goes through the generic backend error classification, so it would come back as "backend unavailable: ..." or "authentication failed ...". Nothing produces these errors yet; the strategy that does lands next, and this PR prepares the call path so it renders correctly from the start.

  • New DelegatedAuthRequiredError (names the provider) and ErrDelegatedCredentialUnavailable in pkg/vmcp/auth/types, plus vmcp.DelegatedCredentialFailure, which returns the delegated error unless the chain also carries a denial or a URL elicitation answer.
  • The backend client returns these errors bare, without transport detail. dispatch does not fall back to Legacy or reclassify when the probe, the call, or a corrective re-probe fails on a credential.
  • tools/call on Legacy and Modern, including the Legacy optimizer's call_tool:
    • authorization required → isError result provider "X" requires upstream authorization
    • unavailable → JSON-RPC -32603 with the fixed message upstream credential unavailable
    • order: denial, then URL elicitation answer, then authorization required, then unavailable. The URL elicitation ranks above the plain message so the connect link from "vMCP: answer a call for an unconnected provider with a URL elicitation carrying the connect link" can't be hidden by it.
  • Composite tools return these errors to the renderers instead of flattening them into workflow text. forEach keeps the iteration error as a cause, and workflow steps don't retry them.
  • Legacy resources/read and prompts/get send -32603 for an unavailable credential, matching Modern (the SDK otherwise sends code 0).
  • An optional Modern list that fails on a credential still degrades, but its WARN names the credential failure.
  • Docs: docs/error-handling.md describes the responses and the limit below; docs/arch/10-virtual-mcp-architecture.md covers the probe exception and the renderer order.

Part of #6407

Type of change

  • New feature

Test plan

  • Unit tests (task test)
  • Linting (task lint-fix)
  • Manual testing (describe below)

Ran go test -race over ./pkg/vmcp/..., ./pkg/auth/upstreamtoken/... and ./pkg/authserver/... after rebasing on main. New tests cover each response through a real core and workflow engine and through both the Legacy and Modern handlers, the precedence chains through the client, the re-probe case, and the Legacy wire code for resources/prompts.

Does this introduce a user-facing change?

Not for delegated credentials yet, since nothing produces these errors. One small change is visible now: a composite tool whose forEach iteration times out used to answer Workflow execution failed: ... (logged at ERROR); it now answers Workflow execution timeout exceeded (logged at WARN), the same as a tool step that times out, because forEach now keeps the iteration error as a cause.

Special notes for reviewers

  • Known limit, recorded in the docs: the named errors only reach a client when listing worked and the later call's read failed. A backend whose credential fails during capability discovery is still dropped from the view, so its tools come back as not found. Changing that is "vMCP: keep a delegated session and route calls when the user has not connected a backend's provider" (vMCP: keep a delegated session and route calls when the user has not connected a backend's provider #7189); the open design question there is written up on that issue.
  • A composite chain that carries a URL elicitation answer or a denial together with a delegated error is still flattened into isError text, as composites did before. Only chains where the delegated error ranks highest are returned unflattened.
  • When a denial or URL elicitation is on the same chain as a delegated error, the client keeps the whole chain (unclassified) so the higher-ranked renderer can still see it. That text never reaches the client, but it can reach logs.
  • Health checks: per-user strategies skip auth on health-check contexts, so these errors can't reach categorizeError today. The producer must keep that, otherwise a bare delegated error would fall into the unhealthy default.

Keep per-user credential failures distinct from backend failures so
clients can tell when to authorize a provider without seeing transport
or workflow context. Nothing produces these errors yet; this prepares
the call path for the outgoing strategy that reads the delegated
credential.

tools/call renders an authorization requirement as an isError result
naming the provider, and an unavailable credential as a fixed JSON-RPC
internal error, on both Legacy and Modern and through the Legacy
optimizer's call_tool. A denial still wins, then a URL elicitation
answer, so a later connect link is never hidden by the plain message.
Composite tools return these errors to the renderers instead of
flattening them into workflow text, and forEach keeps the cause. Legacy
resources/read and prompts/get send -32603 for an unavailable credential,
matching Modern.

Workflow steps do not retry these errors, and dispatch does not fall back
to Legacy or re-probe when the probe or a corrective re-probe fails on a
credential. An optional Modern list that fails on a credential still
degrades, but its WARN names the credential failure. A backend whose
credential fails during discovery is still left out of the tool list;
the docs record that limit.

Co-authored-by: Mecatl <[email protected]>
@jhrozek
jhrozek requested a review from ChrisJBurns as a code owner November 27, 2026 13:07
@codecov

codecov Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.03922% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.68%. Comparing base (35c677f) to head (160756a).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
pkg/vmcp/composer/workflow_engine.go 75.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7353      +/-   ##
==========================================
+ Coverage   82.59%   82.68%   +0.08%     
==========================================
  Files         943      944       +1     
  Lines       96943    97034      +91     
==========================================
+ Hits        80074    80232     +158     
+ Misses      16864    16797      -67     
  Partials        5        5              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

rdimitrov
rdimitrov previously approved these changes Nov 27, 2026

@rdimitrov rdimitrov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed against Part C of #6407, #7188 and #7189.

The mapping matches the design. A missing connection or a rejected grant is a tool error that names the provider, never 401 or 403. A storage or transient failure is -32603 with a fixed message, and other tools keep working. The order (denial, then URL elicitation, then authorization required, then unavailable) leaves room for the connect link in #7188.

I checked the seams beyond the unit tests with a throwaway integration test. It ran a real vMCP server against two real streamable-HTTP backends. The second backend used an outgoing strategy that returns these errors on the call path. Results on 2025-11-25 and 2026-07-28:

  • A direct call, a one-step composite and a forEach composite all return exactly provider "github" requires upstream authorization (as isError) or -32603 upstream credential unavailable.
  • No backend URL, workload name, workflow text or strategy cause reaches the body. A plain strategy error, by contrast, still leaks all of these, so the producer must return these types.
  • The other backend's tool works throughout, and the failing backend recovers once its strategy succeeds.

go test -race ./pkg/vmcp/... passes.

One gap, non-blocking: code mode. execute_tool_script calls VMCP.CallTool directly (pkg/vmcp/codemode/decorator.go:444) and hands the error to the script, so neither renderer runs on that path. The script sees the bare text and the outer call answers with an ordinary tool result. The text is safe, so nothing needs fixing here. But docs/error-handling.md doesn't list this path, and the URL elicitation from #7188 can't reach a client through it. Worth a line in the doc, or a note on #7188.

The CRD reference generator scans pkg/vmcp/auth/types, and the new
DelegatedAuthRequiredError struct there adds an empty entry to the
generated page.

Co-authored-by: Mecatl <[email protected]>
A script's tool call goes to VMCP.CallTool directly, so neither tools/call
renderer runs on it: the script gets the error text and the outer call
answers with an ordinary tool result. Say so, and that a URL elicitation
cannot reach the client through a script.

Co-authored-by: Mecatl <[email protected]>
@jhrozek

jhrozek commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

@rdimitrov thanks for the integration run. Added a paragraph on code mode to the limitations in docs/error-handling.md: script tool calls skip both renderers, the script gets the plain text, and a URL elicitation can't reach the client through a script. Also regenerated the CRD reference docs, since the new struct in pkg/vmcp/auth/types adds an entry there; that push is what dismissed your review.

Agreed on the plain strategy errors leaking. The producer has to return these types, and I'll make sure that PR does and tests for it.

@jhrozek
jhrozek requested a review from rdimitrov November 27, 2026 13:42

@rdimitrov rdimitrov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approving. The two commits since my review only touch docs. The code-mode paragraph in docs/error-handling.md covers the gap I raised, and the regenerated crd-api.md entry is expected. The branch merges cleanly with main, including #7354, and no files overlap.

@jhrozek
jhrozek merged commit cfebc3d into stacklok:main Nov 27, 2026
44 checks passed
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.

3 participants