Skip to content

Support add custom http header in WebFluxSseClientTransport #161

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

Open
SunJiFengPlus opened this issue Apr 15, 2025 · 1 comment
Open

Support add custom http header in WebFluxSseClientTransport #161

SunJiFengPlus opened this issue Apr 15, 2025 · 1 comment

Comments

@SunJiFengPlus
Copy link

SunJiFengPlus commented Apr 15, 2025

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.

@SunJiFengPlus SunJiFengPlus changed the title Support mutate http header in WebFluxSseClientTransport Support add custom http header in WebFluxSseClientTransport Apr 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant