|
8 | 8 | import jakarta.enterprise.context.ApplicationScoped; |
9 | 9 |
|
10 | 10 | import org.jboss.jandex.AnnotationInstance; |
| 11 | +import org.jboss.jandex.ClassInfo; |
11 | 12 | import org.jboss.jandex.ClassType; |
12 | 13 | import org.jboss.jandex.DotName; |
| 14 | +import org.jboss.jandex.IndexView; |
13 | 15 |
|
14 | 16 | import dev.langchain4j.mcp.client.McpClient; |
15 | 17 | import dev.langchain4j.service.tool.ToolProvider; |
|
23 | 25 | import io.quarkus.deployment.annotations.BuildStep; |
24 | 26 | import io.quarkus.deployment.annotations.ExecutionTime; |
25 | 27 | import io.quarkus.deployment.annotations.Record; |
| 28 | +import io.quarkus.deployment.builditem.CombinedIndexBuildItem; |
| 29 | +import io.quarkus.deployment.builditem.IndexDependencyBuildItem; |
| 30 | +import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; |
26 | 31 |
|
27 | 32 | public class McpProcessor { |
28 | 33 |
|
@@ -75,4 +80,25 @@ public void registerMcpClients(McpBuildTimeConfiguration mcpBuildTimeConfigurati |
75 | 80 | } |
76 | 81 | } |
77 | 82 | } |
| 83 | + |
| 84 | + @BuildStep |
| 85 | + public void indexMcpClientDependency(BuildProducer<IndexDependencyBuildItem> index) { |
| 86 | + // this is needed for the 'reflectionRegistrations' build step to work |
| 87 | + index.produce(new IndexDependencyBuildItem("dev.langchain4j", "langchain4j-mcp")); |
| 88 | + } |
| 89 | + |
| 90 | + @BuildStep |
| 91 | + public void reflectionRegistrations(BuildProducer<ReflectiveClassBuildItem> reflectiveClass, |
| 92 | + CombinedIndexBuildItem indexBuildItem) { |
| 93 | + // register everything in the dev.langchain4j.mcp.client.protocol package |
| 94 | + String PROTOCOL_PACKAGE_PATTERN = "dev\\.langchain4j\\.mcp\\.client\\.protocol\\..+"; |
| 95 | + IndexView index = indexBuildItem.getIndex(); |
| 96 | + for (ClassInfo clazz : index.getKnownClasses()) { |
| 97 | + if (clazz.name().toString().matches(PROTOCOL_PACKAGE_PATTERN)) { |
| 98 | + reflectiveClass |
| 99 | + .produce(ReflectiveClassBuildItem.builder(clazz.name().toString()).fields(true).methods(true).build()); |
| 100 | + } |
| 101 | + } |
| 102 | + } |
| 103 | + |
78 | 104 | } |
0 commit comments