MCP - quarkus.langchain4j.mcp."client-name".transport-type - Fixed at BuildTime #1875
-
|
Hey, we are trying to use several mcp Servers in one Ai Service. @McpToolBox
String useAllMcpServers(@UserMessage String userMessage);Now we have the issue that the property: quarkus.langchain4j.mcp."client-name".transport-type (see: https://docs.quarkiverse.io/quarkus-langchain4j/dev/mcp.html#quarkus-langchain4j-mcp_section_quarkus-langchain4j-mcp) Is there a chance that this property must not be set at build and dynamicly detect the mcp servers, so that we only need one Build(Image) and the mcp server can be configured dynamic. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 15 replies
-
|
cc @jmartisk |
Beta Was this translation helpful? Give feedback.
-
|
I think that we could make the If you need to create MCP clients dynamically at runtime, you can certainly do that (by using the builder of |
Beta Was this translation helpful? Give feedback.
-
|
@jmartisk @ApplicationScoped
public class GecMcpToolsProvider implements ToolProvider {
@Inject
Vertx vertx;
private static CopyOnWriteArrayList<McpClient> mcpClients = new CopyOnWriteArrayList<>();
public void onStart(@Observes StartupEvent ev) {
QuarkusHttpMcpTransport t = new QuarkusHttpMcpTransport.Builder()
.sseUrl("http://localhost:8811/oncite-mcp/mcp/sse")
.mcpClientName("MyMCPClient")
.logRequests(true)
.logResponses(true)
.build();
// QuarkusStreamableHttpMcpTransport t = new QuarkusStreamableHttpMcpTransport.Builder()
// .url("https://oncite-dps-dev.apps.st.gcp.alm.oncite.io/oncite-mcp/mcp")
// .httpClient(vertx.createHttpClient())
// .logRequests(true)
// .logResponses(true)
// .build();
McpClient mcpClient = new DefaultMcpClient.Builder()
.key("MyMCPClient")
.transport(t)
.build();
//TODO add more clients
mcpClients.add(mcpClient);
}
public void onFinish(@Observes ShutdownEvent ev) {
for (McpClient mcpClient : mcpClients) {
try {
mcpClient.close();
} catch (Exception e) {
throw new RuntimeException("Failed to close MCP Client", e);
}
}
}
@Override
public ToolProviderResult provideTools(ToolProviderRequest request) {
ToolProviderResult.Builder builder = ToolProviderResult.builder();
for (McpClient mcpClient : mcpClients) {
var defaultToolExecutor = new McpToolExecutor(mcpClient);
try {
mcpClient.listTools().stream()
.forEach(toolSpecification -> {
builder.add(toolSpecification, defaultToolExecutor);
});
} catch (Exception e) {
throw new RuntimeException("Failed to retrieve tools from MCP server", e);
}
}
return builder.build();
}
}@RegisterAiService(maxSequentialToolInvocations = 50,
toolProviderSupplier = GecMcpToolsProviderSupplier.class)
@ApplicationScoped
public interface GecAiService {My local started mcp server is getting called. But the result is the Toolname not the Result of the Tool Call. Any Hint??? |
Beta Was this translation helpful? Give feedback.
-
|
@jmartisk I finally get all working @ApplicationScoped
public class GecMcpToolsProviderSupplier implements Supplier<ToolProvider> {
private static CopyOnWriteArrayList<McpClient> mcpClients = new CopyOnWriteArrayList<>();
@Inject
Vertx vertx;
@Inject
MCPConfig mcpConfig;
@Override
public ToolProvider get() {
for (Map.Entry<String, String> entry : mcpConfig.url().entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
QuarkusStreamableHttpMcpTransport t = new QuarkusStreamableHttpMcpTransport.Builder()
.url(value)
.httpClient(vertx.createHttpClient())
.logRequests(mcpConfig.logrequests())
.logResponses(mcpConfig.logresponses())
.mcpClientAuthProvider(new OidcMcpAuthProvider())
.build();
McpClient mcpClient = new DefaultMcpClient.Builder()
.key(key)
.transport(t)
.cacheToolList(mcpConfig.cachetoollist())
.clientName(key)
.build();
mcpClients.add(mcpClient);
}
return McpToolProvider.builder().mcpClients(mcpClients).build();
}
public void onShutdown(@Observes ShutdownEvent aShutdownEvent) {
for (McpClient mcpClient : mcpClients) {
try {
mcpClient.close();
} catch (Exception ex) {
Log.error("GecMcpToolsProviderSupplier.onShutdown", ex);
}
}
}
}Thats all what to do. As soon as my PR is merged and released, we will use the ToolProvider from above. Thx for your help. |
Beta Was this translation helpful? Give feedback.
-
|
@geoand When is the next release planned? |
Beta Was this translation helpful? Give feedback.
@jmartisk I finally get all working