Skip to content

feat(upstream): forward elicitation, sampling and roots to the calling client - #1977

Open
felipecrs wants to merge 7 commits into
smart-mcp-proxy:mainfrom
felipecrs:claude/upstream-capability-forward-issues-ed9989
Open

felipecrs wants to merge 7 commits into
smart-mcp-proxy:mainfrom
felipecrs:claude/upstream-capability-forward-issues-ed9989

Conversation

@felipecrs

@felipecrs felipecrs commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1964
Closes #1965
Closes #1966

Upstream servers can now ask the user, the client's model and the client's roots through mcpproxy, the way they could if the client connected to them directly.

What's new

  • Elicitation, sampling and roots are forwarded to the MCP client whose tool call caused the request, on every call surface (call_tool_*, direct names, /mcp/s/<server>, code_execution). URL-mode elicitation completions (notifications/elicitation/complete) reach the same client.
  • The user sees who is asking: elicitation messages start with [server].
  • Roots work outside a call too: a roots request with no calling client goes to the last client that called that server, and the server gets notifications/roots/list_changed when that client changes or reports new roots.
  • When nobody can be asked (REST/CLI calls, concurrent calls to one stdio server, a client without the capability) the server gets an immediate answer: elicitation decline, sampling an error, roots empty.
  • Opt-in per server: client_features: ["elicitation", "sampling", "roots"], none by default (a change reconnects the server). A server is offered only what it lists, and a quarantined one nothing. enable_client_features: false is a global kill switch (restart).
  • Audit: every request is a client_request activity row, readable by administrators only: server, method, what was asked (capped and scanned for sensitive data), outcome (forwarded/unanswered/failed) and the shape of the answer (action, field names and sizes, response size, root count), never its content.
  • Load: at most 4 requests of one upstream are answered at a time; the rest are shed with a decline or an error, and not recorded.

Docs: docs/features/client-requests.md.

Limits

  • Approvals must fit within call_tool_timeout. A prompt left open past it stays on the client's screen (mcp-go never withdraws it); answering it then does nothing.
  • mcp-go's client allows 30 s for a request an HTTP upstream sends on the call's own response stream.
  • Sampling has no [server] marker: clients show mcpproxy as the requester.

Tested by hand

Windows build of this branch, with Claude Code and VS Code as clients:

  • Elicitation: ssh-mcp's approval before rm -rf reached Claude Code; approve ran the command, decline and Esc refused it.
  • Two sessions at once on the same stdio server: the first got the prompt, the second was declined at once, and no prompt reached the wrong client.
  • Timeout: after 2 minutes the call failed and ssh-mcp denied the command; approving the stale prompt afterwards ran nothing.
  • Sampling: VS Code answered the everything server's sampling request; Claude Code (no sampling) got a clean refusal.
  • Roots reached the everything server, over stdio and streamable HTTP.
  • Forms: every field type of the everything server's elicitation form came back intact, over stdio, HTTP and code_execution.
  • Daily servers (tokensave, home-assistant, changedetection, context7) behaved as before.

The switches, the [server] marker, the audit rows, the in-flight limit and roots outside a call came after these runs and are covered by tests only.

@felipecrs
felipecrs marked this pull request as draft November 20, 2026 23:39
felipecrs added a commit to felipecrs/mcpproxy-go that referenced this pull request Nov 20, 2026
…he calling client

Upstreams were initialized with empty client capabilities and their
server-to-client requests were refused, so e.g. ssh-mcp's approval before
a destructive command always failed through mcpproxy.

mcpproxy now declares elicitation (form and URL), sampling and roots to
stdio and streamable-HTTP upstreams and forwards each request to the MCP
client whose tool call caused it. The client's session travels in the
call context; a request that carries no call (stdio, or the upstream's GET
stream) goes to the only call in flight to that server. When nobody can be
asked, elicitation is declined, sampling fails and roots/list is empty.

Closes smart-mcp-proxy#1964, closes smart-mcp-proxy#1965, part of smart-mcp-proxy#1966.
A URL-mode elicitation ends with the upstream's
notifications/elicitation/complete; the client waits for it. mcpproxy
dropped every upstream notification but list_changed, so a client that
accepted a URL elicitation waited forever.

Each upstream connection now remembers which client session a URL
elicitation went to (up to an hour, forgotten when not accepted) and
pushes the completion to that session only, also when it arrives on the
upstream's GET stream after the call has returned.
@felipecrs
felipecrs force-pushed the claude/upstream-capability-forward-issues-ed9989 branch from c17a2e7 to 72a842a Compare November 21, 2026 16:03
felipecrs added a commit to felipecrs/mcpproxy-go that referenced this pull request Nov 21, 2026
… calls for client features

- enable_client_features (global, default on, restart-gated like
  enable_prompts) and per-server client_features (reconnects the server)
  turn the forwarding off; a server with it off is offered no capability.
- Every relayed request is a client_request activity row (server, method,
  request, answer, outcome forwarded|unanswered|failed), scanned for
  sensitive data like prompt_get.
- Elicitation messages start with "[server] " so the user can tell who asks.
- roots/list with no calling client goes to the last client that called
  the server; the server is sent notifications/roots/list_changed when
  that client changes or reports new roots, and roots declare listChanged.
@felipecrs felipecrs changed the title feat(upstream): forward elicitation, sampling and roots requests to the calling client feat(upstream): forward elicitation, sampling and roots to the calling client Nov 21, 2026
felipecrs added a commit to felipecrs/mcpproxy-go that referenced this pull request Nov 21, 2026
…into claude/upstream-capability-forward-issues-ed9989
felipecrs added a commit to felipecrs/mcpproxy-go that referenced this pull request Nov 23, 2026
@Dumbris

Dumbris commented Nov 24, 2026

Copy link
Copy Markdown
Member

Thanks for this, @felipecrs. It is well structured: per-call routing, the capability and mode checks, the refusal for 2026-07-28 clients, and the client_request rows are all the right shape, and the hand tests are convincing. I read the diff against the merge-base and ran the touched packages under -race (all pass). A second model reviewed the relay code too, and I checked each of its findings.

Because mcpproxy puts untrusted upstream servers behind one client, I would like three things changed before this leaves draft. Everything else can be a follow-up.

1. Opt in per server instead of on by default. Today any server an agent happens to call can ask the user for a form or a URL (any host), ask the client's model something (includeContext/tools are passed through), and learn the user's workspace paths through roots. Clients that remember "always allow sampling" for mcpproxy would grant that for every upstream behind it. Suggestion: client_features: ["elicitation","sampling","roots"] per server (unset or empty means none), declare only the listed capabilities in Capabilities(), and keep enable_client_features as a global kill switch. A server you list for elicitation then does not get roots or sampling. Quarantined servers (they do connect for inspection) should be declared nothing.

2. Do not store what the user or the model answered. client_request rows keep the form answer, the sampling completion and the root URIs in clear, and the activity API shows them to any scoped token on the same server. arguments is also stored without a size cap, and a hostile server can write rows at will (a quarantined one too, since its decline is still recorded). Please store method, outcome, action, field names and sizes, root count; cap arguments; and make the type owner-or-admin visible like skill_access.

3. Cap the load. The GET-stream path starts one goroutine per request frame. Please add a per-upstream limit on in-flight relay requests (4 is plenty) and shed the rest with decline or error.

Smaller things, fine to defer: restrict URL elicitation to https:/localhost and show the host; the URL-completion map should be bounded and cleaned up by registration, not session; roots/list_changed is sent in the background while the new call dispatches; a log line when an SSE upstream gets no capabilities. Two things are inherent, so I would only document them: a stdio or GET-stream request is credited to the only call in flight, and a modern-protocol client gets a decline the upstream cannot tell from a user refusal.

Tests I would like with the changes: a quarantined server asks and is declined with no row, a scoped token cannot read relay content, two concurrent clients on one HTTP upstream are routed separately, and a GET-stream flood is shed. Progress forwarding (#1967) can follow once these gates exist. Happy to pair on any of it.

@Dumbris Dumbris 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.

Requesting changes per the review above (#1977 (comment)): opt-in per server, no stored answers/completions/roots, and a cap on in-flight relay requests before this leaves draft. The branch also conflicts with main now — a merge of main is enough, no rebase needed. Thanks for the work on this.

…rs out of the log

client_features lists what a server may use (none by default, none when quarantined); client_request rows keep only the shape of the answer and are administrator-only; at most 4 requests of one upstream are answered at a time.
@felipecrs

Copy link
Copy Markdown
Contributor Author

Thanks for the review! All three points and the requested tests are in via 019399e, and main is merged in. I left the smaller items for a follow-up, as you suggested.

@felipecrs
felipecrs marked this pull request as ready for review November 24, 2026 15:57
felipecrs added a commit to felipecrs/mcpproxy-go that referenced this pull request Nov 24, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants