Skip to content

MCPServerEntry response headers get swallowed by VirtualMCPServer #6743

Open

Description

@JeremiasRy

Hi!

In a setup where we have VirtualMCPServer and MCPServerEntry's, response headers sent by the upstream server seem to be swallowed by the VirtualMCPServer.

Example tool that throws:

mcpRouter.all('/mcp', async (ctx, _) => {
  const body = ctx.request.body;
  const isToolCall =
    typeof body === 'object' && body !== null && 'method' in body && body.method === 'tools/call';
  if (isToolCall) {
    ctx.status = 403;
    ctx.set(
      'WWW-Authenticate',
      'Bearer error="insufficient_scope", error_description="mcp header experiment", scope="mcp.write"',
    );
    ctx.body = {
      error: 'insufficient_scope',
      error_description: 'mcp header experiment',
    };
    return;
  }
  // SNIP
});

When calling straight to the server responds as such:

HTTP/2 403
server: nginx
date: Wed, 16 Sep 2026 08:41:31 GMT
content-type: application/json; charset=utf-8
content-length: 74
vary: Accept-Encoding
www-authenticate: Bearer error="insufficient_scope", error_description="mcp header experiment", scope="mcp.write" <-- BINGO!
strict-transport-security: max-age=31622400; includeSubDomains
access-control-allow-credentials: true
access-control-allow-methods: OPTIONS
access-control-allow-headers: accept, content-type
access-control-expose-headers: x-request-id, content-disposition

But going through the VirtualMCPServer our header gets swallowed:

HTTP/2 403
server: nginx
date: Wed, 16 Sep 2026 08:42:24 GMT
content-type: application/json
content-length: 94
vary: Accept-Encoding
strict-transport-security: max-age=31622400; includeSubDomains
access-control-allow-credentials: true
access-control-allow-methods: OPTIONS
access-control-allow-headers: accept, content-type
access-control-expose-headers: x-request-id, content-disposition

I couldn't find any configuration options to allow for passthrough response headers, only passthrough request headers. Could this be something that could be added to the project? I'm also willing to contribute if this ranks low in your current priorities.

Thanks!

Activity

  1. added
    kubernetes
    on Oct 2, 2026
  2. added
    needs-triage
    on Oct 2, 2026
  3. changed the title [-]McpServer response headers get swallowed by VMcpServer[/-] [+]MCPServerEntry response headers get swallowed by VirtualMCPServer[/+] on Oct 2, 2026
  4. Sanskarzz commented on Oct 4, 2026

    @Sanskarzz
    Collaborator

    Thanks for reporting this, @JeremiasRy , and for offering to contribute! Assigning this to you.

    The current vMCP code does lose upstream WWW-Authenticate scope challenges. This needs a bit of design around vMCP auth before implementation: incoming client authentication and outgoing backend authentication are separate, so we need to agree on how backend scope challenges should reach the client.

    Could you share your operator/vMCP version, redacted manifests and auth configuration, and the full downstream response body? That will help clarify the setup and the reported 403.

    Happy to work and address through the design with you before you start a PR.

    cc @jerm-dro @jhrozek as the vMCP owner, for input on the auth behavior and proposed approach.

  5. removed
    needs-triage
    on Oct 8, 2026
  6. dqk0902 commented on Nov 12, 2026

    @dqk0902

    Hi guys, @Sanskarzz, @jerm-dro , @jhrozek. The reason why we try this approach return insufficient_scope from upstream server is because we try to follow step-up scope challenge here. And this seems like the easiest way to support it

    However, as I can see toolhive has defined OAuthErrInsufficientScope but couldn’t find it used in the Cedar authorization-denial path. Do we have expected timeline to support step-up scope challenge in production for toolhive? 🤔

  7. Sanskarzz commented on Nov 12, 2026

    @Sanskarzz
    Collaborator

    Thanks for clarifying, @dqk0902—the step-up authorization use case makes sense.

    You’re right: OAuthErrInsufficientScope is currently defined but isn’t wired into an end-to-end step-up flow. Cedar denials also don’t identify which OAuth scopes would satisfy the request. A denial can reflect other policy restrictions, so returning insufficient_scope for every Cedar denial would be misleading.

    For backend scope challenges, we still need to define how the required scopes and authorization-server metadata map across vMCP’s incoming and outgoing authentication boundaries.

    I don’t have a confirmed production ETA to share yet. cc @reyortiz3 @jhrozek for input on the design and prioritization.

    Could you share the redacted auth configuration and clarify which authorization server issues mcp.write? That would help us agree on a concrete flow for contribution.

  8. Sanskarzz commented on Nov 12, 2026

    @Sanskarzz
    Collaborator

    @JeremiasRy, are you still interested in contributing to this? I’m happy to help move it forward by preparing a design proposal for vMCP scope challenges and step-up authorization.

    If you’re still interested, we can coordinate on the design and implementation. If you’re no longer available, I’m happy to take over.

  9. dqk0902 commented on Nov 12, 2026

    @dqk0902

    Thanks @Sanskarzz for replying, for the context

    We operate our own authorization server in the architechture. It issues the access tokens and OAuth scopes used to authenticate clients to our ToolHive gateway. mcp.write was just an example scope so we can test scope challenge flow.

    A denial can reflect other policy restrictions, so returning insufficient_scope for every Cedar denial would be misleading.

    I agree, we might not want to return insufficient_scope for every Cedar denial.

    Could VirtualMCPServer support an explicit configuration mapping tools to required scopes? When the incoming token lacks those scopes, vMCP could return a 403 with a WWW-Authenticate scope challenge. Requests with sufficient scopes would still undergo Cedar authorization, and other policy denials would remain ordinary denials.

  10. dqk0902 commented on Nov 16, 2026

    @dqk0902

    @Sanskarzz , Hi!
    Hope this information helpful for you guys. So for scope challenge, we as MCP Gateway/Server need to return MCP standard spec: 403 + WWW-authenticate + insufficient_scope, but this currently do not worked for Codex/ChatGPT.

    So you can see, we have different logic to trigger reauth from client when handle scope challenge. For example, cloudfare, they have to write this kind of identifying client logic to handle it (cloudfare code). But this is the mismatch from MCP Client side!

  11. ngocketit commented on Nov 16, 2026

    @ngocketit

    @JeremiasRy, are you still interested in contributing to this? I’m happy to help move it forward by preparing a design proposal for vMCP scope challenges and step-up authorization.

    If you’re still interested, we can coordinate on the design and implementation. If you’re no longer available, I’m happy to take over.

    @Sanskarzz Jeremias is currently on leave (we're in the same team) so it'd be great if you can reassign this. This is currently very critical to us as without this support, we won't be able to take advantage of the step-up scope challenge implementation as recommended in the MCP spec. Thanks a lot for your work on Toolhive!

  12. self-assigned this
    on Nov 16, 2026
  13. Sanskarzz commented on Nov 16, 2026

    @Sanskarzz
    Collaborator

    Thanks @ngocketit for confirming, and @dqk0902 for the additional detail. I’ve assigned myself and will take this forward.

    The external-AS clarification gives us a concrete initial direction: opt-in mappings from exposed tools to required scopes in the validated incoming token, returning a standard 403 + WWW-Authenticate scope challenge before execution. Cedar would remain authoritative, with ordinary policy denials retaining their existing behavior.

    The client compatibility distinction is useful. I propose standard HTTP behavior by default, with any OpenAI compatibility mode explicit and tested against named client versions.

  14. dqk0902 commented on Nov 16, 2026

    @dqk0902

    Really nice!! @Sanskarzz , I agree we should have default 403 + WWW-Authenticate, some small questions for the other mode:

    I propose standard HTTP behavior by default, with any OpenAI compatibility mode explicit and tested against named client versions.

    • Do you have plan to support this 🤔 Because, from my own experience, identify which clients is Codex/ChatGPT is not that easy and kinda hacky (in authorization server layer). If we can support this 200 + _meta mode in Toolhive layer that would be best, because at least I can see from the logs when MCP client do initialize, we saw "clientInfo":{"title":"Codex","version":"etc etc","name":"codex-mcp-client"}} which mean in toolhive layer, we can identify whether the client is Codex/ChatGPT and also the version
  15. Sanskarzz commented on Nov 17, 2026

    @Sanskarzz
    Collaborator

    @dqk0902 Thanks for the clarification! I’ve included an explicit responseMode: tool-result option for 200 + _meta, while keeping 403 + WWW-Authenticate as the default. Both modes enforce the same scope check before execution. I’ve kept selection in configuration because Modern stateless requests do not require initialization. Wire behavior is covered by tests; authentication UI still needs verification against specific client versions.

  16. dqk0902 commented on Nov 17, 2026

    @dqk0902

    Hi @Sanskarzz, Thanks! I have 1 small question for clarification with current approach

    I’ve included an explicit responseMode: tool-result option for 200 + _meta, while keeping 403 + WWW-Authenticate as the default.

    I have gone thru your PR here Am I understand correctly that toolhive will support default 403 + WWW-Authenticate to everybody and if we change the responseMode to tool-result option for 200 + _meta then it will switch the whole gateway to return 200 + _meta for everybody?

    I’ve kept selection in configuration because Modern stateless requests do not require initialization.

    As reading your PR, it means toolhive will have option to return 403 + WWW-Authenticateor 200 + _meta based on configuration? So for example, in our logic would have to identify who are Codex/ChatGPT and configure that to use 200 + _meta 🤔

  17. Sanskarzz commented on Nov 17, 2026

    @Sanskarzz
    Collaborator

    Thanks @dqk0902—you’re right that a gateway-wide toggle alone wouldn’t cover mixed clients on the same URL.

    For the transport follow-up, I propose an opt-in responseMode: auto. ToolHive would select the scope-challenge format per client: recognized, tested client profiles requiring tool-result authentication would receive 200 + _meta["mcp/www_authenticate"]; other clients would receive the standard 403 + WWW-Authenticate. Missing or unrecognized client information would fall back to HTTP 403.

    This would let supported clients share one gateway URL without external routing or client-detection logic in your authorization server. We would use initialization metadata for session-based clients and per-request metadata where available for stateless clients, while retaining explicit http and tool-result overrides.

    Both formats would enforce the same Cedar and scope checks before execution. PR #7170 remains the core-enforcement foundation; automatic response selection belongs in the next PR and will need verification against specific client versions.

  18. dqk0902 commented on Nov 18, 2026

    @dqk0902

    I propose an opt-in responseMode: auto. ToolHive would select the scope-challenge format per client: recognized, tested client profiles requiring tool-result authentication would receive 200 + _meta["mcp/www_authenticate"]; other clients would receive the standard 403 + WWW-Authenticate

    This is great, thanks @Sanskarzz !!! 🚀 Please let me know if you need anything from my side!

  19. Sanskarzz commented on Nov 19, 2026

    @Sanskarzz
    Collaborator

    Thanks @dqk0902! PR 2 is open: #7190. Could you share your exact Codex/ChatGPT/etc versions and redacted clientInfo showing the name and version sent during initialization? For stateless clients, the per-request client metadata would help.

    This will help verify the auto-mode profiles. Once PR 3 adds configuration support, could you also help test the consent prompt, scope upgrade, and successful retry?

  20. dqk0902 commented on Nov 19, 2026

    @dqk0902

    Hi @Sanskarzz , we have not testing with ChatGPT yet. The latest Codex version we can capture from our side is "version": "0.166.0-alpha.5.1". However, the latest Codex version in the internet, 0.170.0 release yesterday, seems does not fix this problem yet.

    Once PR 3 adds configuration support, could you also help test the consent prompt, scope upgrade, and successful retry?

    Yes, I think we can have testing in our dev env by bump toolhive version

  21. JeremiasRy commented on Dec 1, 2026

    @JeremiasRy
    Author

    Hi @Sanskarzz, really glad to see the progress in this issue! Much appreciated 🙏

    I wanted politely to ask that; what is the current status on the finishing PR on this trilogy? We are eager to put this to the test once it's available.

  22. Sanskarzz commented on Dec 2, 2026

    @Sanskarzz
    Collaborator

    Hi @JeremiasRy
    Thank you for bringing this to our attention. I have submitted the final pull request (#7446), and it is currently undergoing review. This issue will be resolved and closed upon merging.

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

Metadata

Metadata

Labels

kubernetes

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions