Description
Please do a quick search on GitHub issues first, the feature you are about to request might have already been requested.
Expected Behavior
I would like to add custom HTTP request headers to WebFluxSseClientTransport
like this, overload sendMessage
method
@Override
public Mono<Void> sendMessage(JSONRPCMessage message) {
return sendMessage(message, httpHeaders -> {});
}
public Mono<Void> sendMessage(JSONRPCMessage message, Consumer<HttpHeaders> mutateHeaders) {
// The messageEndpoint is the endpoint URI to send the messages
// It is provided by the server as part of the endpoint event
return messageEndpointSink.asMono().flatMap(messageEndpointUri -> {
if (isClosing) {
return Mono.empty();
}
try {
String jsonText = this.objectMapper.writeValueAsString(message);
return webClient.post()
.uri(messageEndpointUri)
.headers(mutateHeaders)
.contentType(MediaType.APPLICATION_JSON)
.bodyValue(jsonText)
.retrieve()
.toBodilessEntity()
.doOnSuccess(response -> {
logger.debug("Message sent successfully");
})
.doOnError(error -> {
if (!isClosing) {
logger.error("Error sending message: {}", error.getMessage());
}
});
}
catch (IOException e) {
if (!isClosing) {
return Mono.error(new RuntimeException("Failed to serialize message", e));
}
return Mono.empty();
}
}).then(); // TODO: Consider non-200-ok response
}
Current Behavior
Can't add custom header in WebFluxSseClientTransport
Context
If I can change the HTTP request header, I can do some extra processing on the server side like data permission checking. I briefly checked this article https://modelcontextprotocol.io/specification/2025-03-26/basic/authorization It doesn't seem to have been developed yet, so I don't know exactly how it will be used.
For common API Server to MCP Server conversion scenarios, the API Server already has its own authentication methods, and functional access control, data access control, for the current only missing the HTTP Header transfer.