nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] MCP websocket transport silently drops the configured `headers`, so Authorization is never sent

Open addyCooks opened this issue 1 week ago • 1 comments

Description

A websocket MCP server config can include headers, but the transport is created with new WebSocketClientTransport(url) and the headers are never used. The server receives the connection with no Authorization header and nothing tells the user.

Environment

  • OS: Windows 11 Home 10.0.26300
  • Node version: v22.22.3
  • Nanocoder version: 1.32.0 (built from main at eb7dee57)
  • Provider: Not provider-specific
  • Model: Not model-specific

Steps to Reproduce

  1. Start a WebSocket server (for example with the ws package) that records req.headers.authorization on each connection.
  2. Create the transport: TransportFactory.createTransport({name: 'ws', transport: 'websocket', url: 'ws://127.0.0.1:<port>', headers: {Authorization: 'Bearer secret-token'}}).
  3. Call await transport.start() and look at what the server recorded.

Expected Behavior

The server receives Authorization: Bearer secret-token. If headers cannot be sent, the config is rejected with a clear message.

Actual Behavior

The server records undefined. The headers are ignored with no warning.

Logs/Screenshots

recorded authorization header: [ undefined ]   (expected [ 'Bearer secret-token' ])

Additional Context

  • [x] I have searched existing issues to ensure this is not a duplicate
  • [x] I can reproduce this issue consistently
  • [x] This issue occurs with the latest version of nanocoder (main)

Suggested fix:

  • source/mcp/transport-factory.ts:144-162 (createWebSocketTransport): the SDK's WebSocketClientTransport takes only a URL. Wrap it (or pass a WebSocket factory) so the ws client is created with {headers}.
  • At minimum, throw or warn when server.headers is set for a websocket server (config type at source/types/config.ts around line 558).
  • Add a test with a local ws server like the steps above.

addyCooks avatar Nov 23 '26 07:11 addyCooks

Hi! Picking this up—I have a fix and regression tests ready that forward configured headers over the ws client transport (loaded lazily in start() so startup module count stays unchanged) and preserve websocket headers in the Custom MCP wizard. Opening a PR shortly.

Valexander7 avatar Nov 23 '26 10:11 Valexander7