It would be nice if we could configure custom headers, for example, we could pass OAuth access token like this:

spring.ai.mcp.client:
  sse:
    connections:
      server1:
        url: http://localhost:8080
        headers:
          Authorization: "Bearer ***"

I'd like to contribute if the proposal is accepted.

Comment From: Kehrlann

@quaff Access tokens have a limited TTL. Since they expire, I don't think they're a great candidate for configuration. I do see the point in having custom "default" headers, though.

Are you aware of the work that we've done in https://github.com/modelcontextprotocol/java-sdk/pull/388 ? We're integrating it in https://github.com/spring-projects/spring-ai/pull/3994, with the ultimate goal to provide OAuth2 integration. This opens a much broader field, where users can customize the entire MCP client HTTP request for HttpClient-based transport.

Comment From: quaff

@Kehrlann I think it's covered by #3994, thanks.

Comment From: quaff

Access tokens have a limited TTL. Since they expire, I don't think they're a great candidate for configuration.

We could create long live or never expired access token like GitHub Personal Access Token, https://github.com/github/github-mcp-server

{
  "servers": {
    "github": {
      "type": "http",
      "url": "https://api.githubcopilot.com/mcp/",
      "headers": {
        "Authorization": "Bearer ${input:github_mcp_pat}"
      }
    }
  },
  "inputs": [
    {
      "type": "promptString",
      "id": "github_mcp_pat",
      "description": "GitHub Personal Access Token",
      "password": true
    }
  ]
}

I do see the point in having custom "default" headers, though.

I think it's reasonable to configure custom headers.