Skip to content

Headers are modified automatically in SSE mode #342

@BitlyExchange

Description

@BitlyExchange

Describe the bug
When using the inspect to debug my MCP server of SSE type, I got modified Headers printed in my server:

Headers {
  host: 'localhost:8081',
  connection: 'keep-alive',
  accept: 'text/event-stream',
  'accept-language': '*',
  'sec-fetch-mode': 'cors',
  'user-agent': 'undici',
  pragma: 'no-cache',
  'cache-control': 'no-cache',
  'accept-encoding': 'gzip, deflate'
}

Cus I used auth in Header, so I cannot get correct headers to verify identity.

To Reproduce

  1. Start inspector:
npx @modelcontextprotocol/inspector node dist/index.js
  1. connect using SSE mode

Image

Expected behavior
A clear and concise description of what you expected to happen.

Logs
Original headers:

GET /sse?transportType=sse&url=http%3A%2F%2Flocalhost%3A8081%2Fsse HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate, br, zstd
Accept-Language: zh-CN,zh;q=0.9,en;q=0.8
Cache-Control: no-cache
Connection: keep-alive
Host: 127.0.0.1:6277
Origin: http://127.0.0.1:6274
Pragma: no-cache
Referer: http://127.0.0.1:6274/
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-site
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
ether-api-key: Bearer test
sec-ch-ua: "Chromium";v="134", "Not:A-Brand";v="24", "Google Chrome";v="134"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "macOS"

console log in MCP server:

Headers {
  host: 'localhost:8081',
  connection: 'keep-alive',
  accept: 'text/event-stream',
  'accept-language': '*',
  'sec-fetch-mode': 'cors',
  'user-agent': 'undici',
  pragma: 'no-cache',
  'cache-control': 'no-cache',
  'accept-encoding': 'gzip, deflate'
}

Additional context
I use FastMcp to develop my server. Code is like this:

const server = new FastMCP({
	name: "Bitly MCP Server",
	version: "0.1.0",
	authenticate: async (request) => {
		try {
			const privateKey = request.headers["ether-api-key"];
			console.log("Headers ", request.headers);
			const sdk = new BitlySDK({
				networkId: 84532,
				provider: DEFAULT_PROVIDER,
			})
			await sdk.setSigner(new Wallet(privateKey as string));

			return {
				sdk,
			}
		} catch (error) {
			console.error("ww: Error authenticating", error);
			const res = new ServerResponse({} as any);
			res.statusCode = 401;
			res.statusMessage = "Unauthorized";
			throw res;
		}
	},
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions