This repository was archived by the owner on May 16, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
This repository was archived by the owner on May 16, 2025. It is now read-only.
[BUG] Headers are not being sent as Authorization or "x-api-key" #65
Copy link
Copy link
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Bug Description
I am using Next.js version 13. The mcp-server and client are both running within the same application.
I have installed all the mentioned packages to allow sending custom headers (eventsource and extended-eventsource), but even so, the headers are not being sent.
Implementation:
// Create client and connect to server
const client = new MultiServerMCPClient({
// Global tool configuration options
// Whether to throw on errors if a tool fails to load (optional, default: true)
throwOnLoadError: true,
// Whether to prefix tool names with the server name (optional, default: true)
prefixToolNameWithServerName: true,
// Optional additional prefix for tool names (optional, default: "mcp")
additionalToolNamePrefix: "mcp",
// Server configuration
mcpServers: {
// adds a STDIO connection to a server named "math"
// math: {
// transport: "stdio",
// command: "npx",
// args: ["-y", "@modelcontextprotocol/server-math"],
// // Restart configuration for stdio transport
// restart: {
// enabled: true,
// maxAttempts: 3,
// delayMs: 1000,
// },
// },
// SSE transport example with reconnection configuration
saaspilot: {
transport: "sse",
url: `${req.headers.origin || "http://localhost:3000"}/api/mcp-server/sse`,
headers: {
"x-api-key": req.headers.authorization?.startsWith("Bearer ") ? req.headers.authorization : `Bearer ${req.headers.authorization}`,
},
useNodeEventSource: true,
reconnect: {
enabled: true,
maxAttempts: 5,
delayMs: 2000,
},
},
},
});
const tools = await client.getTools();
// Create an OpenAI model
const model = new ChatOpenAI({
modelName: "gpt-4o",
temperature: 0,
});
// Create the React agent
const agent = createReactAgent({
llm: model,
tools,
prompt: requestData.user_description
});Logs
▲ Next.js 13.5.11
- Local: http://localhost:3000
- Environments: .env
- Experiments (use at your own risk):
· instrumentationHook
✓ Ready in 2.2s
✓ Compiled /api/agents/v1/answers in 677ms (164 modules)
/api/v1/answers called!
@langchain/mcp-adapters:client INFO: Initializing connection to server "saaspilot"... +0ms
@langchain/mcp-adapters:client DEBUG: Creating SSE transport for server "saaspilot" with URL: http://localhost:3000/api/mcp-server/sse +0ms
@langchain/mcp-adapters:client DEBUG: Using custom headers for SSE transport to server "saaspilot" +0ms
@langchain/mcp-adapters:client DEBUG: Using Extended EventSource for server "saaspilot" +4ms
@langchain/mcp-adapters:client DEBUG: Setting headers for Extended EventSource: {"x-api-key":"Bearer saaspk-14dd717c*********************adf32ff"} +1ms
Headers received by my mcp-server:
✓ Compiled /api/mcp-server/sse in 84ms (177 modules)
{
host: 'localhost:3000',
connection: 'keep-alive',
accept: 'text/event-stream',
'accept-language': '*',
'sec-fetch-mode': 'cors',
'user-agent': 'node',
pragma: 'no-cache',
'cache-control': 'no-cache',
'accept-encoding': 'gzip, deflate',
'x-middleware-invoke': '',
'x-invoke-path': '/api/mcp-server/sse',
'x-invoke-query': '%7B%7D',
'x-forwarded-host': 'localhost:3000',
'x-forwarded-port': '3000',
'x-forwarded-proto': 'http',
'x-forwarded-for': '::ffff:127.0.0.1',
'x-invoke-output': '/api/mcp-server/sse'
}
Inspector screenshot where the mcp-server works 100%
raphaelblum, MichaelSchwaiger48 and avi1mizrahi
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
