Skip to content

vMCP: render -32042 on Legacy sessions that declared URL-mode elicitation #7023

Closed

Description

@tgrunnagle

Summary

A Legacy (2025-11-25) vMCP session whose client declared elicitation.url at initialize receives a URL elicitation answer as JSON-RPC -32042 URLElicitationRequiredError, with the elicitations in error.data.elicitations. Before this slice every Legacy session receives the fallback, because vMCP cannot read the client's declared capabilities. This slice reads them through a toolhive-core accessor and switches declaring sessions to -32042.

The smallest proof: a go-sdk 2025-11-25 client that declares elicitation: {url: {}} calls a tool whose BackendClient decorator returns the answer, and receives a *jsonrpc.Error with code -32042 whose data lists the elicitation with its elicitationId.

Sub-issue of #6970. Lands after #7022, and after the toolhive-core release that exposes declared client capabilities (stacklok/toolhive-core#447).

Governing decisions

  • MCP 2025-11-25 client/elicitation § URL Elicitation Required Error: the error "MUST include a list of elicitations", each "MUST be URL mode elicitations and have an elicitationId property". "Servers MUST NOT send elicitation requests with modes that are not supported by the client", and an elicitation capability of {} means form only.
  • go-sdk v1.8 internal/jsonrpc2/messages.go toWireError: a *jsonrpc.Error returned unwrapped from a raw tool handler reaches the wire with its code and data. A wrapped one keeps the code and drops the data. mcpcompat's wrapToolHandler passes the handler error through unchanged. So every Legacy handler returns the bare error.
  • .claude/rules/vmcp-anti-patterns.md Implement secret injection #5: SDK session details stay behind the adapter. vMCP reads capabilities through the mcpcompat accessor, never from go-sdk internals.
  • vMCP: answer tools/call with a URL-mode elicitation (Modern and fallback) #7022 defines vmcp.URLElicitationRequiredError, the fixed fallback, and the in-process-only boundary. This slice changes only which Legacy sessions skip the fallback. Grounded in docs/arch/10-virtual-mcp-architecture.md § Answering a call with a URL elicitation, which vMCP: answer tools/call with a URL-mode elicitation (Modern and fallback) #7022 adds.

Vocabulary

Scenario 1. A declaring Legacy client receives -32042

Grounded in docs/arch/10-virtual-mcp-architecture.md § Answering a call with a URL elicitation.

Work:

  • Bump github.com/stacklok/toolhive-core to the tagged release carrying the accessor.
  • pkg/vmcp/server: the shared Legacy render helper reads the declared capabilities. When known is true and elicitation.url is present, it returns a bare *jsonrpc.Error with code -32042, message URL elicitation required, and data.elicitations as [{mode: "url", elicitationId, url, message}].
  • serve_optimizer.go: the optimizer call_tool handler wraps inner errors with %w before conversion.ErrorToToolResult, which drops the error data. It returns a -32042 *jsonrpc.Error from the inner call unwrapped.
  • Rewrite the conversion.ErrorToToolResult doc comment, which says tool handlers "cannot reliably carry custom JSON-RPC codes". A bare *jsonrpc.Error can. Coded domain errors keep the isError shape by choice.

Acceptance:

  • AC1.1: A go-sdk 2025-11-25 client that declared elicitation: {url: {}} receives -32042 with every elicitation in data.elicitations, in order, each carrying its elicitationId.
    • verify: AT: pkg/vmcp/server integration, TestIntegration_Legacy_URLElicitation_Required drives a real go-sdk client with a test BackendClient decorator
  • AC1.2: Through the optimizer call_tool meta-tool, the same client receives the same -32042 with the same data.
    • verify: AT: pkg/vmcp/server integration, TestIntegration_Legacy_URLElicitation_RequiredViaOptimizer
  • AC1.3: An error that both wraps ErrAuthorizationFailed and carries the answer renders as the deny tool result.
    • verify: Unit: TestLegacyRender_DenialOutranksURLElicitation, no AT because branch ordering

Scenario 2. Non-declaring and unknown sessions keep the fallback

Grounded in the MCP 2025-11-25 capability rule above and .claude/rules/vmcp-anti-patterns.md #5: vMCP trusts only what the accessor reports as known.

Acceptance:

  • AC2.1: A client that declared elicitation: {}, only form, or no elicitation, or that negotiated a revision older than 2025-11-25, receives the fallback and no -32042.
    • verify: AT: pkg/vmcp/server integration, TestIntegration_Legacy_URLElicitation_UndeclaredFallsBack
  • AC2.2: A session whose declared capabilities are unknown, such as a rehydrated session, receives the fallback. vMCP sends URL mode only when the accessor reports the capabilities as known.
    • verify: Unit: TestLegacyRender_UnknownCapabilitiesFallBack, no AT because rehydration needs a second pod

Out of scope

Item Defer to Why
Persisting declared capabilities across pods Unscheduled toolhive-core follow-up Unknown capabilities fall back safely
notifications/elicitation/complete Unscheduled follow-up Needs out-of-band delivery to one session across pods
Modern rendering, the domain type, the fallback content #7022 Lands before this

Documentation impact

  • docs/arch/10-virtual-mcp-architecture.md: the URL elicitation render table gains the Legacy -32042 row and the unknown-capabilities caveat for rehydrated sessions.
    • verify: inspection: table matches the shipped behaviour
  • pkg/vmcp/conversion/errors.go: doc comment rewritten as above.
    • verify: inspection: comment states the current reason for the isError shape

Delivery shape

One PR, and the second of two sub-issues of #6970. Lands after #7022 and after the toolhive-core release with the capability accessor.

Closes AC1.1 to AC2.2. Does not change Modern rendering, the domain type, or the fallback content, which #7022 owns.

Risks and open questions

Definition of done

  1. Every checkbox above is checked, and every verify: test exists and is green.
  2. task build, task test, task test-integration, and task lint-fix pass with no diff.
  3. go.mod pins a tagged toolhive-core release, not a pseudo-version.
  4. The PR body states the before and after for Legacy clients.

Activity

  1. added
    enhancement
    size/S
    vmcp
    on Nov 2, 2026
  2. added
    needs-triage
    on Nov 2, 2026
  3. tgrunnagle commented on Nov 5, 2026

    @tgrunnagle
    CollaboratorAuthor

    Blocked on stacklok/toolhive-core#467.

    toolhive-core v0.0.59 (#447) exposes DeclaredClientCapabilities(), which covers AC1.1–AC1.3, AC2.2, and the {} / form-only / no-elicitation part of AC2.1. The other part of AC2.1, falling back for a client that negotiated a revision older than 2025-11-25, needs the negotiated protocol version. A tool handler can't read it today:

    • The accessor returns capabilities only.
    • mcpcompat's wrapToolHandler doesn't pass MCP-Protocol-Version into CallToolRequest.Header.
    • go-sdk v1.8 keeps the negotiated version in session state with no exported getter.

    Reading the header through a context value would add vmcp-anti-patterns #1, so this waits for the accessor in toolhive-core#467. Once that ships, the Legacy render helper returns -32042 only when capabilities and version are both known, elicitation.url is declared, and the version is at least 2025-11-25. Every other session gets the fallback.

  4. added a commit that references this issue on Nov 14, 2026
    b9de592
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementneeds-triagesize/Svmcp

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions