Skip to content

Sent Headers in MCP sse server #5152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 of 2 tasks
04cfb1ed opened this issue Apr 14, 2025 · 2 comments · Fixed by #5493
Closed
1 of 2 tasks

Sent Headers in MCP sse server #5152

04cfb1ed opened this issue Apr 14, 2025 · 2 comments · Fixed by #5493
Assignees
Labels
area:configuration Relates to configuration options kind:enhancement Indicates a new feature request, imrovement, or extension

Comments

@04cfb1ed
Copy link
Contributor

Validations

  • I believe this is a way to improve. I'll try to join the Continue Discord for questions
  • I'm not able to find an open issue that requests the same enhancement

Problem

Hello, I'm trying to use an MCP sse server protected by authentication, but I found that the headers are not sent in the request

I did the change in a local environment, and I want to share with you, and if it's useful could be added in the code

Solution

Headers in interfaces
https://github.com/continuedev/continue/blob/main/core/index.d.ts#L1105-L1124

export interface StdioOptions {
  type: "stdio";
  command: string;
  args: string[];
  env?: Record<string, string>;
  headers?: HeadersInit;
}

export interface WebSocketOptions {
  type: "websocket";
  url: string;
  headers?: HeadersInit;
}

export interface SSEOptions {
  type: "sse";
  url: string;
  headers?: HeadersInit;
}

Send headers to mcp library
https://github.com/continuedev/continue/blob/main/core/context/mcp/index.ts#L170-L171

case "sse":
        console.log("HEADERS");
        console.log(options.transport.headers);
        return new SSEClientTransport(new URL(options.transport.url), {
          eventSourceInit: {
            fetch: (input, init) =>
              fetch(input, {
                ...init,
                headers: {
                  ...init?.headers,
                  ...(options.transport.headers as Record<string, string> | undefined),
                }
              }),
          },
          requestInit: { headers: options.transport.headers }
        });

These changes allow using a config like this (config.json)

"experimental": {
        "modelContextProtocolServers": [
            {
                "name": "hola",
                "transport": {
                    "type": "sse",
                    "url": "https://protected.example.org/sse",
                    "headers": {
                        "Authorization": "Bearer supertoken"
                    }
                }
            },
        ]
    }
@dosubot dosubot bot added area:configuration Relates to configuration options kind:enhancement Indicates a new feature request, imrovement, or extension labels Apr 14, 2025
@Patrick-Erichsen
Copy link
Collaborator

This would definitely be a welcome PR! Mind opening one? Your logic looks sound to me.

@04cfb1ed
Copy link
Contributor Author

04cfb1ed commented May 2, 2025

I opened the PR #5493 with the changes proposed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:configuration Relates to configuration options kind:enhancement Indicates a new feature request, imrovement, or extension
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants