How to use separate RestClient for model call and tool calls? #5309
Replies: 1 comment
-
|
Follow up. I just needed to use a McpSyncHttpClientRequestCustomizer. Note, by adding a @component annotation it just autowided into the McpClient's RestClient and Boom, problem solved. @Component
public class FooMcpSyncHttpCLientRequestCustomizer implements McpSyncHttpClientRequestCustomizer {
@Override
public void customize(
HttpRequest.Builder builder,
String method,
URI endpoint,
String body,
McpTransportContext context) {
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
if (requestAttributes instanceof ServletRequestAttributes servletRequestAttributes) {
var httpRequest = servletRequestAttributes.getRequest();
var authHeader = httpRequest.getHeader(HttpHeaders.AUTHORIZATION);
builder.header(HttpHeaders.AUTHORIZATION, authHeader);
}
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I need to use separate RestClient(s). One for the Model calls and another one for MCP Tool calls. Is there a way to configure the tool manager to have it's own RestClient?
Background:
We use
management.tracing.baggage.remote-fields=Authorizationto propagate Authorization header for calls to other services. Works great. However, OpenAI calls fail because the RestClient replaces the OpenAI apiKey in the Authorization header with the header from the request.I can create the OpenAiApi bean and use default RestClient.Builder(), but then MCP tool calls fail b/c the services being called require an auth token.
Beta Was this translation helpful? Give feedback.
All reactions