Skip to content

Unable To Pass Custom Headers #78

@a-s-g93

Description

@a-s-g93

I would like to pass custom headers, which seems possible according to the documentation. When I test this in Claude Desktop I get the following error with this configuration.

This is on a Macbook M1 and using mcp-proxy v0.8.0.

It appears that customer headers are illegal.

httpx.LocalProtocolError: Illegal header name b'x-username: testuser'

Configuration

{
  "mcpServers": {
    "mcp-server": {
     "command": "/Users/user/.local/bin/mcp-proxy",
      "args": [
        "http://localhost:8000/mcp",
        "--headers",
        "x-username: testuser",
        "--transport",
        "sse"
      ]
    }
  }
}

Error

2025-06-06T17:59:18.190Z [mcp-server] [info] Initializing server...
2025-06-06T17:59:18.231Z [mcp-server] [info] Server started and connected successfully
2025-06-06T17:59:18.232Z [mcp-server] [info] Message from client: {"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"claude-ai","version":"0.1.0"}},"jsonrpc":"2.0","id":0}
  + Exception Group Traceback (most recent call last):
  |   File "/Users/user/.local/bin/mcp-proxy", line 10, in <module>
  |     sys.exit(main())
  |              ^^^^^^
  |   File "/Users/user/.local/share/uv/tools/mcp-proxy/lib/python3.12/site-packages/mcp_proxy/__main__.py", line 351, in main
  |     _handle_sse_client_mode(args_parsed, logger)
  |   File "/Users/user/.local/share/uv/tools/mcp-proxy/lib/python3.12/site-packages/mcp_proxy/__main__.py", line 221, in _handle_sse_client_mode
  |     asyncio.run(run_sse_client(args_parsed.command_or_url, headers=headers))
  |   File "/Users/user/.local/share/uv/python/cpython-3.12.7-macos-aarch64-none/lib/python3.12/asyncio/runners.py", line 194, in run
  |     return runner.run(main)
  |            ^^^^^^^^^^^^^^^^
  |   File "/Users/user/.local/share/uv/python/cpython-3.12.7-macos-aarch64-none/lib/python3.12/asyncio/runners.py", line 118, in run
  |     return self._loop.run_until_complete(task)
  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |   File "/Users/user/.local/share/uv/python/cpython-3.12.7-macos-aarch64-none/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete
  |     return future.result()
  |            ^^^^^^^^^^^^^^^
  |   File "/Users/user/.local/share/uv/tools/mcp-proxy/lib/python3.12/site-packages/mcp_proxy/sse_client.py", line 20, in run_sse_client
  |     async with sse_client(url=url, headers=headers) as streams, ClientSession(*streams) as session:
  |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |   File "/Users/user/.local/share/uv/python/cpython-3.12.7-macos-aarch64-none/lib/python3.12/contextlib.py", line 210, in __aenter__
  |     return await anext(self.gen)
  |            ^^^^^^^^^^^^^^^^^^^^^
  |   File "/Users/user/.local/share/uv/tools/mcp-proxy/lib/python3.12/site-packages/mcp/client/sse.py", line 54, in sse_client
  |     async with anyio.create_task_group() as tg:
  |                ^^^^^^^^^^^^^^^^^^^^^^^^^
  |   File "/Users/user/.local/share/uv/tools/mcp-proxy/lib/python3.12/site-packages/anyio/_backends/_asyncio.py", line 772, in __aexit__
  |     raise BaseExceptionGroup(
  | ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
  +-+---------------- 1 ----------------
    | Traceback (most recent call last):
    |   File "/Users/user/.local/share/uv/tools/mcp-proxy/lib/python3.12/site-packages/httpx/_transports/default.py", line 101, in map_httpcore_exceptions
    |     yield
    |   File "/Users/user/.local/share/uv/tools/mcp-proxy/lib/python3.12/site-packages/httpx/_transports/default.py", line 394, in handle_async_request
    |     resp = await self._pool.handle_async_request(req)
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "/Users/user/.local/share/uv/tools/mcp-proxy/lib/python3.12/site-packages/httpcore/_async/connection_pool.py", line 256, in handle_async_request
    |     raise exc from None
    |   File "/Users/user/.local/share/uv/tools/mcp-proxy/lib/python3.12/site-packages/httpcore/_async/connection_pool.py", line 236, in handle_async_request
    |     response = await connection.handle_async_request(
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "/Users/user/.local/share/uv/tools/mcp-proxy/lib/python3.12/site-packages/httpcore/_async/connection.py", line 103, in handle_async_request
    |     return await self._connection.handle_async_request(request)
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "/Users/user/.local/share/uv/tools/mcp-proxy/lib/python3.12/site-packages/httpcore/_async/http11.py", line 136, in handle_async_request
    |     raise exc
    |   File "/Users/user/.local/share/uv/tools/mcp-proxy/lib/python3.12/site-packages/httpcore/_async/http11.py", line 86, in handle_async_request
    |     await self._send_request_headers(**kwargs)
    |   File "/Users/user/.local/share/uv/tools/mcp-proxy/lib/python3.12/site-packages/httpcore/_async/http11.py", line 144, in _send_request_headers
    |     with map_exceptions({h11.LocalProtocolError: LocalProtocolError}):
    |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "/Users/user/.local/share/uv/python/cpython-3.12.7-macos-aarch64-none/lib/python3.12/contextlib.py", line 158, in __exit__
    |     self.gen.throw(value)
    |   File "/Users/user/.local/share/uv/tools/mcp-proxy/lib/python3.12/site-packages/httpcore/_exceptions.py", line 14, in map_exceptions
    |     raise to_exc(exc) from exc
    | httpcore.LocalProtocolError: Illegal header name b'x-username: testuser'
    | 
    | The above exception was the direct cause of the following exception:
    | 
    | Traceback (most recent call last):
    |   File "/Users/user/.local/share/uv/tools/mcp-proxy/lib/python3.12/site-packages/mcp/client/sse.py", line 58, in sse_client
    |     async with aconnect_sse(
    |                ^^^^^^^^^^^^^
    |   File "/Users/user/.local/share/uv/python/cpython-3.12.7-macos-aarch64-none/lib/python3.12/contextlib.py", line 210, in __aenter__
    |     return await anext(self.gen)
    |            ^^^^^^^^^^^^^^^^^^^^^
    |   File "/Users/user/.local/share/uv/tools/mcp-proxy/lib/python3.12/site-packages/httpx_sse/_api.py", line 69, in aconnect_sse
    |     async with client.stream(method, url, headers=headers, **kwargs) as response:
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "/Users/user/.local/share/uv/python/cpython-3.12.7-macos-aarch64-none/lib/python3.12/contextlib.py", line 210, in __aenter__
    |     return await anext(self.gen)
    |            ^^^^^^^^^^^^^^^^^^^^^
    |   File "/Users/user/.local/share/uv/tools/mcp-proxy/lib/python3.12/site-packages/httpx/_client.py", line 1583, in stream
    |     response = await self.send(
    |                ^^^^^^^^^^^^^^^^
    |   File "/Users/user/.local/share/uv/tools/mcp-proxy/lib/python3.12/site-packages/httpx/_client.py", line 1629, in send
    |     response = await self._send_handling_auth(
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "/Users/user/.local/share/uv/tools/mcp-proxy/lib/python3.12/site-packages/httpx/_client.py", line 1657, in _send_handling_auth
    |     response = await self._send_handling_redirects(
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "/Users/user/.local/share/uv/tools/mcp-proxy/lib/python3.12/site-packages/httpx/_client.py", line 1694, in _send_handling_redirects
    |     response = await self._send_single_request(request)
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "/Users/user/.local/share/uv/tools/mcp-proxy/lib/python3.12/site-packages/httpx/_client.py", line 1730, in _send_single_request
    |     response = await transport.handle_async_request(request)
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "/Users/user/.local/share/uv/tools/mcp-proxy/lib/python3.12/site-packages/httpx/_transports/default.py", line 393, in handle_async_request
    |     with map_httpcore_exceptions():
    |          ^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "/Users/user/.local/share/uv/python/cpython-3.12.7-macos-aarch64-none/lib/python3.12/contextlib.py", line 158, in __exit__
    |     self.gen.throw(value)
    |   File "/Users/user/.local/share/uv/tools/mcp-proxy/lib/python3.12/site-packages/httpx/_transports/default.py", line 118, in map_httpcore_exceptions
    |     raise mapped_exc(message) from exc
    | httpx.LocalProtocolError: Illegal header name b'x-username: testuser'
    +------------------------------------
2025-06-06T17:59:18.643Z [mcp-server] [info] Server transport closed
2025-06-06T17:59:18.643Z [mcp-server] [info] Client transport closed
2025-06-06T17:59:18.643Z [mcp-server] [info] Server transport closed unexpectedly, this is likely due to the process exiting early. If you are developing this MCP server you can add output to stderr (i.e. `console.error('...')` in JavaScript, `print('...', file=sys.stderr)` in python) and it will appear in this log.
2025-06-06T17:59:18.643Z [mcp-server] [error] Server disconnected. For troubleshooting guidance, please visit our [debugging documentation](https://modelcontextprotocol.io/docs/tools/debugging) {"context":"connection"}
2025-06-06T17:59:18.644Z [mcp-server] [info] Client transport closed

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions