diff --git a/.gitignore b/.gitignore index ad51f7fa8c08..4078eeed4783 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,9 @@ out/ # Mac .DS_Store +# Quarkus +.quarkus/ + # Maven log/* target/ diff --git a/quarkus-modules/pom.xml b/quarkus-modules/pom.xml index c1cdc3332b26..4a5cb4f2c1a0 100644 --- a/quarkus-modules/pom.xml +++ b/quarkus-modules/pom.xml @@ -14,6 +14,7 @@ + consume-rest-api jfr quarkus @@ -21,19 +22,19 @@ quarkus-clientbasicauth quarkus-extension quarkus-elasticsearch - quarkus-jandex - quarkus-vs-springboot quarkus-funqy - quarkus-kogito - quarkus-testcontainers - consume-rest-api - quarkus-virtual-threads + quarkus-jandex + quarkus-kogito quarkus-langchain4j - - quarkus-websockets-next quarkus-management-interface + quarkus-mcp-langchain quarkus-panache + + quarkus-testcontainers + quarkus-virtual-threads + quarkus-vs-springboot + quarkus-websockets-next diff --git a/quarkus-modules/quarkus-kogito/pom.xml b/quarkus-modules/quarkus-kogito/pom.xml index 7efee76508fd..0bb306ae956f 100644 --- a/quarkus-modules/quarkus-kogito/pom.xml +++ b/quarkus-modules/quarkus-kogito/pom.xml @@ -175,6 +175,7 @@ 1.6.3 2.44.0.Alpha + 17 diff --git a/quarkus-modules/quarkus-mcp-langchain/pom.xml b/quarkus-modules/quarkus-mcp-langchain/pom.xml new file mode 100644 index 000000000000..d5f648e3c4ac --- /dev/null +++ b/quarkus-modules/quarkus-mcp-langchain/pom.xml @@ -0,0 +1,55 @@ + + + 4.0.0 + quarkus-mcp-langchain + quarkus-mcp-langchain + pom + + + com.baeldung + quarkus-modules + 1.0.0-SNAPSHOT + + + + quarkus-mcp-server + quarkus-mcp-client + + + + + + io.quarkus.platform + quarkus-bom + ${quarkus.platform.version} + pom + import + + + + + + + io.quarkus + quarkus-arc + + + io.quarkus + quarkus-junit5 + test + + + + + 17 + 3.14.0 + 3.22.3 + true + 3.5.2 + 1.0.0.CR2 + 5.12.2 + + + diff --git a/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-client/pom.xml b/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-client/pom.xml new file mode 100644 index 000000000000..5e81ab25e160 --- /dev/null +++ b/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-client/pom.xml @@ -0,0 +1,103 @@ + + + 4.0.0 + quarkus-mcp-client + quarkus-mcp-client + + + com.baeldung + quarkus-mcp-langchain + 1.0.0-SNAPSHOT + + + + + io.quarkiverse.langchain4j + quarkus-langchain4j-mcp + ${quarkus-langchain4j.version} + + + io.quarkiverse.langchain4j + quarkus-langchain4j-ollama + ${quarkus-langchain4j.version} + + + io.quarkus + quarkus-vertx-http + + + + + + + io.quarkus.platform + quarkus-maven-plugin + ${quarkus.platform.version} + true + + + + build + generate-code + generate-code-tests + native-image-agent + + + + + + maven-compiler-plugin + ${compiler-plugin.version} + + true + + + + maven-surefire-plugin + ${surefire-plugin.version} + + + org.jboss.logmanager.LogManager + ${maven.home} + + + + + maven-failsafe-plugin + ${surefire-plugin.version} + + + + integration-test + verify + + + + + + ${project.build.directory}/${project.build.finalName}-runner + org.jboss.logmanager.LogManager + ${maven.home} + + + + + + + + + native + + + native + + + + false + true + + + + diff --git a/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-client/src/main/docker/Dockerfile.jvm b/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-client/src/main/docker/Dockerfile.jvm new file mode 100644 index 000000000000..6bba3f702594 --- /dev/null +++ b/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-client/src/main/docker/Dockerfile.jvm @@ -0,0 +1,98 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode +# +# Before building the container image run: +# +# ./mvnw package +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.jvm -t quarkus/quarkus-mcp-client-jvm . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/quarkus-mcp-client-jvm +# +# If you want to include the debug port into your docker image +# you will have to expose the debug port (default 5005 being the default) like this : EXPOSE 8080 5005. +# Additionally you will have to set -e JAVA_DEBUG=true and -e JAVA_DEBUG_PORT=*:5005 +# when running the container +# +# Then run the container using : +# +# docker run -i --rm -p 8080:8080 quarkus/quarkus-mcp-client-jvm +# +# This image uses the `run-java.sh` script to run the application. +# This scripts computes the command line to execute your Java application, and +# includes memory/GC tuning. +# You can configure the behavior using the following environment properties: +# - JAVA_OPTS: JVM options passed to the `java` command (example: "-verbose:class") - Be aware that this will override +# the default JVM options, use `JAVA_OPTS_APPEND` to append options +# - JAVA_OPTS_APPEND: User specified Java options to be appended to generated options +# in JAVA_OPTS (example: "-Dsome.property=foo") +# - JAVA_MAX_MEM_RATIO: Is used when no `-Xmx` option is given in JAVA_OPTS. This is +# used to calculate a default maximal heap memory based on a containers restriction. +# If used in a container without any memory constraints for the container then this +# option has no effect. If there is a memory constraint then `-Xmx` is set to a ratio +# of the container available memory as set here. The default is `50` which means 50% +# of the available memory is used as an upper boundary. You can skip this mechanism by +# setting this value to `0` in which case no `-Xmx` option is added. +# - JAVA_INITIAL_MEM_RATIO: Is used when no `-Xms` option is given in JAVA_OPTS. This +# is used to calculate a default initial heap memory based on the maximum heap memory. +# If used in a container without any memory constraints for the container then this +# option has no effect. If there is a memory constraint then `-Xms` is set to a ratio +# of the `-Xmx` memory as set here. The default is `25` which means 25% of the `-Xmx` +# is used as the initial heap size. You can skip this mechanism by setting this value +# to `0` in which case no `-Xms` option is added (example: "25") +# - JAVA_MAX_INITIAL_MEM: Is used when no `-Xms` option is given in JAVA_OPTS. +# This is used to calculate the maximum value of the initial heap memory. If used in +# a container without any memory constraints for the container then this option has +# no effect. If there is a memory constraint then `-Xms` is limited to the value set +# here. The default is 4096MB which means the calculated value of `-Xms` never will +# be greater than 4096MB. The value of this variable is expressed in MB (example: "4096") +# - JAVA_DIAGNOSTICS: Set this to get some diagnostics information to standard output +# when things are happening. This option, if set to true, will set +# `-XX:+UnlockDiagnosticVMOptions`. Disabled by default (example: "true"). +# - JAVA_DEBUG: If set remote debugging will be switched on. Disabled by default (example: +# true"). +# - JAVA_DEBUG_PORT: Port used for remote debugging. Defaults to 5005 (example: "8787"). +# - CONTAINER_CORE_LIMIT: A calculated core limit as described in +# https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt. (example: "2") +# - CONTAINER_MAX_MEMORY: Memory limit given to the container (example: "1024"). +# - GC_MIN_HEAP_FREE_RATIO: Minimum percentage of heap free after GC to avoid expansion. +# (example: "20") +# - GC_MAX_HEAP_FREE_RATIO: Maximum percentage of heap free after GC to avoid shrinking. +# (example: "40") +# - GC_TIME_RATIO: Specifies the ratio of the time spent outside the garbage collection. +# (example: "4") +# - GC_ADAPTIVE_SIZE_POLICY_WEIGHT: The weighting given to the current GC time versus +# previous GC times. (example: "90") +# - GC_METASPACE_SIZE: The initial metaspace size. (example: "20") +# - GC_MAX_METASPACE_SIZE: The maximum metaspace size. (example: "100") +# - GC_CONTAINER_OPTIONS: Specify Java GC to use. The value of this variable should +# contain the necessary JRE command-line options to specify the required GC, which +# will override the default of `-XX:+UseParallelGC` (example: -XX:+UseG1GC). +# - HTTPS_PROXY: The location of the https proxy. (example: "myuser@127.0.0.1:8080") +# - HTTP_PROXY: The location of the http proxy. (example: "myuser@127.0.0.1:8080") +# - NO_PROXY: A comma separated lists of hosts, IP addresses or domains that can be +# accessed directly. (example: "foo.example.com,bar.example.com") +# +### +FROM registry.access.redhat.com/ubi9/openjdk-21:1.21 + +ENV LANGUAGE='en_US:en' + + +# We make four distinct layers so if there are application changes the library layers can be re-used +COPY --chown=185 target/quarkus-app/lib/ /deployments/lib/ +COPY --chown=185 target/quarkus-app/*.jar /deployments/ +COPY --chown=185 target/quarkus-app/app/ /deployments/app/ +COPY --chown=185 target/quarkus-app/quarkus/ /deployments/quarkus/ + +EXPOSE 8080 +USER 185 +ENV JAVA_OPTS_APPEND="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" +ENV JAVA_APP_JAR="/deployments/quarkus-run.jar" + +ENTRYPOINT [ "/opt/jboss/container/java/run/run-java.sh" ] + diff --git a/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-client/src/main/docker/Dockerfile.legacy-jar b/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-client/src/main/docker/Dockerfile.legacy-jar new file mode 100644 index 000000000000..e8ff6711b59e --- /dev/null +++ b/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-client/src/main/docker/Dockerfile.legacy-jar @@ -0,0 +1,94 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode +# +# Before building the container image run: +# +# ./mvnw package -Dquarkus.package.jar.type=legacy-jar +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.legacy-jar -t quarkus/quarkus-mcp-client-legacy-jar . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/quarkus-mcp-client-legacy-jar +# +# If you want to include the debug port into your docker image +# you will have to expose the debug port (default 5005 being the default) like this : EXPOSE 8080 5005. +# Additionally you will have to set -e JAVA_DEBUG=true and -e JAVA_DEBUG_PORT=*:5005 +# when running the container +# +# Then run the container using : +# +# docker run -i --rm -p 8080:8080 quarkus/quarkus-mcp-client-legacy-jar +# +# This image uses the `run-java.sh` script to run the application. +# This scripts computes the command line to execute your Java application, and +# includes memory/GC tuning. +# You can configure the behavior using the following environment properties: +# - JAVA_OPTS: JVM options passed to the `java` command (example: "-verbose:class") - Be aware that this will override +# the default JVM options, use `JAVA_OPTS_APPEND` to append options +# - JAVA_OPTS_APPEND: User specified Java options to be appended to generated options +# in JAVA_OPTS (example: "-Dsome.property=foo") +# - JAVA_MAX_MEM_RATIO: Is used when no `-Xmx` option is given in JAVA_OPTS. This is +# used to calculate a default maximal heap memory based on a containers restriction. +# If used in a container without any memory constraints for the container then this +# option has no effect. If there is a memory constraint then `-Xmx` is set to a ratio +# of the container available memory as set here. The default is `50` which means 50% +# of the available memory is used as an upper boundary. You can skip this mechanism by +# setting this value to `0` in which case no `-Xmx` option is added. +# - JAVA_INITIAL_MEM_RATIO: Is used when no `-Xms` option is given in JAVA_OPTS. This +# is used to calculate a default initial heap memory based on the maximum heap memory. +# If used in a container without any memory constraints for the container then this +# option has no effect. If there is a memory constraint then `-Xms` is set to a ratio +# of the `-Xmx` memory as set here. The default is `25` which means 25% of the `-Xmx` +# is used as the initial heap size. You can skip this mechanism by setting this value +# to `0` in which case no `-Xms` option is added (example: "25") +# - JAVA_MAX_INITIAL_MEM: Is used when no `-Xms` option is given in JAVA_OPTS. +# This is used to calculate the maximum value of the initial heap memory. If used in +# a container without any memory constraints for the container then this option has +# no effect. If there is a memory constraint then `-Xms` is limited to the value set +# here. The default is 4096MB which means the calculated value of `-Xms` never will +# be greater than 4096MB. The value of this variable is expressed in MB (example: "4096") +# - JAVA_DIAGNOSTICS: Set this to get some diagnostics information to standard output +# when things are happening. This option, if set to true, will set +# `-XX:+UnlockDiagnosticVMOptions`. Disabled by default (example: "true"). +# - JAVA_DEBUG: If set remote debugging will be switched on. Disabled by default (example: +# true"). +# - JAVA_DEBUG_PORT: Port used for remote debugging. Defaults to 5005 (example: "8787"). +# - CONTAINER_CORE_LIMIT: A calculated core limit as described in +# https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt. (example: "2") +# - CONTAINER_MAX_MEMORY: Memory limit given to the container (example: "1024"). +# - GC_MIN_HEAP_FREE_RATIO: Minimum percentage of heap free after GC to avoid expansion. +# (example: "20") +# - GC_MAX_HEAP_FREE_RATIO: Maximum percentage of heap free after GC to avoid shrinking. +# (example: "40") +# - GC_TIME_RATIO: Specifies the ratio of the time spent outside the garbage collection. +# (example: "4") +# - GC_ADAPTIVE_SIZE_POLICY_WEIGHT: The weighting given to the current GC time versus +# previous GC times. (example: "90") +# - GC_METASPACE_SIZE: The initial metaspace size. (example: "20") +# - GC_MAX_METASPACE_SIZE: The maximum metaspace size. (example: "100") +# - GC_CONTAINER_OPTIONS: Specify Java GC to use. The value of this variable should +# contain the necessary JRE command-line options to specify the required GC, which +# will override the default of `-XX:+UseParallelGC` (example: -XX:+UseG1GC). +# - HTTPS_PROXY: The location of the https proxy. (example: "myuser@127.0.0.1:8080") +# - HTTP_PROXY: The location of the http proxy. (example: "myuser@127.0.0.1:8080") +# - NO_PROXY: A comma separated lists of hosts, IP addresses or domains that can be +# accessed directly. (example: "foo.example.com,bar.example.com") +# +### +FROM registry.access.redhat.com/ubi9/openjdk-21:1.21 + +ENV LANGUAGE='en_US:en' + + +COPY target/lib/* /deployments/lib/ +COPY target/*-runner.jar /deployments/quarkus-run.jar + +EXPOSE 8080 +USER 185 +ENV JAVA_OPTS_APPEND="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" +ENV JAVA_APP_JAR="/deployments/quarkus-run.jar" + +ENTRYPOINT [ "/opt/jboss/container/java/run/run-java.sh" ] diff --git a/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-client/src/main/docker/Dockerfile.native b/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-client/src/main/docker/Dockerfile.native new file mode 100644 index 000000000000..c463d3e35cc4 --- /dev/null +++ b/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-client/src/main/docker/Dockerfile.native @@ -0,0 +1,29 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode. +# +# Before building the container image run: +# +# ./mvnw package -Dnative +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.native -t quarkus/quarkus-mcp-client . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/quarkus-mcp-client +# +# The ` registry.access.redhat.com/ubi8/ubi-minimal:8.10` base image is based on UBI 9. +# To use UBI 8, switch to `quay.io/ubi8/ubi-minimal:8.10`. +### +FROM registry.access.redhat.com/ubi8/ubi-minimal:8.10 +WORKDIR /work/ +RUN chown 1001 /work \ + && chmod "g+rwX" /work \ + && chown 1001:root /work +COPY --chown=1001:root --chmod=0755 target/*-runner /work/application + +EXPOSE 8080 +USER 1001 + +ENTRYPOINT ["./application", "-Dquarkus.http.host=0.0.0.0"] diff --git a/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-client/src/main/docker/Dockerfile.native-micro b/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-client/src/main/docker/Dockerfile.native-micro new file mode 100644 index 000000000000..e96e01e9d335 --- /dev/null +++ b/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-client/src/main/docker/Dockerfile.native-micro @@ -0,0 +1,32 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode. +# It uses a micro base image, tuned for Quarkus native executables. +# It reduces the size of the resulting container image. +# Check https://quarkus.io/guides/quarkus-runtime-base-image for further information about this image. +# +# Before building the container image run: +# +# ./mvnw package -Dnative +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.native-micro -t quarkus/quarkus-mcp-client . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/quarkus-mcp-client +# +# The `quay.io/quarkus/quarkus-micro-image:2.0` base image is based on UBI 9. +# To use UBI 8, switch to `quay.io/quarkus/quarkus-micro-image:2.0`. +### +FROM quay.io/quarkus/quarkus-micro-image:2.0 +WORKDIR /work/ +RUN chown 1001 /work \ + && chmod "g+rwX" /work \ + && chown 1001:root /work +COPY --chown=1001:root --chmod=0755 target/*-runner /work/application + +EXPOSE 8080 +USER 1001 + +ENTRYPOINT ["./application", "-Dquarkus.http.host=0.0.0.0"] diff --git a/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-client/src/main/java/com/baeldung/quarkus/mcp/client/McpClientAI.java b/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-client/src/main/java/com/baeldung/quarkus/mcp/client/McpClientAI.java new file mode 100644 index 000000000000..8d2b90fe1f9d --- /dev/null +++ b/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-client/src/main/java/com/baeldung/quarkus/mcp/client/McpClientAI.java @@ -0,0 +1,28 @@ +package com.baeldung.quarkus.mcp.client; + +import dev.langchain4j.service.SystemMessage; +import dev.langchain4j.service.UserMessage; +import io.quarkiverse.langchain4j.RegisterAiService; +import io.quarkiverse.langchain4j.mcp.runtime.McpToolBox; +import jakarta.enterprise.context.SessionScoped; + + +@RegisterAiService +@SessionScoped +public interface McpClientAI { + + @SystemMessage(""" + You are a knowledgeable and helpful assistant powered by Mistral. + You can answer user questions and provide clear, concise, and accurate information. + You also have access to a set of tools via an MCP server. + + When using a tool, always convert the tool's response into a natural, human-readable answer. + If the user's question is unclear, politely ask for clarification. + If the question does not require tool usage, answer it directly using your own knowledge. + + Always communicate in a friendly and professional manner, and ensure your responses are easy to understand. + """ + ) + @McpToolBox("default") + String chat(@UserMessage String question); +} \ No newline at end of file diff --git a/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-client/src/main/resources/application.properties b/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-client/src/main/resources/application.properties new file mode 100644 index 000000000000..a7d1570af7cd --- /dev/null +++ b/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-client/src/main/resources/application.properties @@ -0,0 +1,7 @@ +quarkus.langchain4j.timeout=180s +quarkus.langchain4j.chat-model.provider=ollama +quarkus.langchain4j.ollama.chat-model.model-id=mistral +quarkus.langchain4j.ollama.base-url=http://localhost:11434 + +quarkus.langchain4j.mcp.default.transport-type=http +quarkus.langchain4j.mcp.default.url=http://localhost:9000/mcp/sse diff --git a/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-server/pom.xml b/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-server/pom.xml new file mode 100644 index 000000000000..14bb89abd000 --- /dev/null +++ b/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-server/pom.xml @@ -0,0 +1,98 @@ + + + 4.0.0 + quarkus-mcp-server + quarkus-mcp-server + + + com.baeldung + quarkus-mcp-langchain + 1.0.0-SNAPSHOT + + + + + io.quarkiverse.mcp + quarkus-mcp-server-sse + 1.1.1 + + + io.quarkus + quarkus-qute + + + + + + + io.quarkus.platform + quarkus-maven-plugin + ${quarkus.platform.version} + true + + + + build + generate-code + generate-code-tests + native-image-agent + + + + + + maven-compiler-plugin + ${compiler-plugin.version} + + true + + + + maven-surefire-plugin + ${surefire-plugin.version} + + + org.jboss.logmanager.LogManager + ${maven.home} + + + + + maven-failsafe-plugin + ${surefire-plugin.version} + + + + integration-test + verify + + + + + + ${project.build.directory}/${project.build.finalName}-runner + org.jboss.logmanager.LogManager + ${maven.home} + + + + + + + + + native + + + native + + + + false + true + + + + diff --git a/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-server/src/main/docker/Dockerfile.jvm b/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-server/src/main/docker/Dockerfile.jvm new file mode 100644 index 000000000000..198c1aa4d43e --- /dev/null +++ b/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-server/src/main/docker/Dockerfile.jvm @@ -0,0 +1,98 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode +# +# Before building the container image run: +# +# ./mvnw package +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.jvm -t quarkus/quarkus-mcp-server-jvm . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/quarkus-mcp-server-jvm +# +# If you want to include the debug port into your docker image +# you will have to expose the debug port (default 5005 being the default) like this : EXPOSE 8080 5005. +# Additionally you will have to set -e JAVA_DEBUG=true and -e JAVA_DEBUG_PORT=*:5005 +# when running the container +# +# Then run the container using : +# +# docker run -i --rm -p 8080:8080 quarkus/quarkus-mcp-server-jvm +# +# This image uses the `run-java.sh` script to run the application. +# This scripts computes the command line to execute your Java application, and +# includes memory/GC tuning. +# You can configure the behavior using the following environment properties: +# - JAVA_OPTS: JVM options passed to the `java` command (example: "-verbose:class") - Be aware that this will override +# the default JVM options, use `JAVA_OPTS_APPEND` to append options +# - JAVA_OPTS_APPEND: User specified Java options to be appended to generated options +# in JAVA_OPTS (example: "-Dsome.property=foo") +# - JAVA_MAX_MEM_RATIO: Is used when no `-Xmx` option is given in JAVA_OPTS. This is +# used to calculate a default maximal heap memory based on a containers restriction. +# If used in a container without any memory constraints for the container then this +# option has no effect. If there is a memory constraint then `-Xmx` is set to a ratio +# of the container available memory as set here. The default is `50` which means 50% +# of the available memory is used as an upper boundary. You can skip this mechanism by +# setting this value to `0` in which case no `-Xmx` option is added. +# - JAVA_INITIAL_MEM_RATIO: Is used when no `-Xms` option is given in JAVA_OPTS. This +# is used to calculate a default initial heap memory based on the maximum heap memory. +# If used in a container without any memory constraints for the container then this +# option has no effect. If there is a memory constraint then `-Xms` is set to a ratio +# of the `-Xmx` memory as set here. The default is `25` which means 25% of the `-Xmx` +# is used as the initial heap size. You can skip this mechanism by setting this value +# to `0` in which case no `-Xms` option is added (example: "25") +# - JAVA_MAX_INITIAL_MEM: Is used when no `-Xms` option is given in JAVA_OPTS. +# This is used to calculate the maximum value of the initial heap memory. If used in +# a container without any memory constraints for the container then this option has +# no effect. If there is a memory constraint then `-Xms` is limited to the value set +# here. The default is 4096MB which means the calculated value of `-Xms` never will +# be greater than 4096MB. The value of this variable is expressed in MB (example: "4096") +# - JAVA_DIAGNOSTICS: Set this to get some diagnostics information to standard output +# when things are happening. This option, if set to true, will set +# `-XX:+UnlockDiagnosticVMOptions`. Disabled by default (example: "true"). +# - JAVA_DEBUG: If set remote debugging will be switched on. Disabled by default (example: +# true"). +# - JAVA_DEBUG_PORT: Port used for remote debugging. Defaults to 5005 (example: "8787"). +# - CONTAINER_CORE_LIMIT: A calculated core limit as described in +# https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt. (example: "2") +# - CONTAINER_MAX_MEMORY: Memory limit given to the container (example: "1024"). +# - GC_MIN_HEAP_FREE_RATIO: Minimum percentage of heap free after GC to avoid expansion. +# (example: "20") +# - GC_MAX_HEAP_FREE_RATIO: Maximum percentage of heap free after GC to avoid shrinking. +# (example: "40") +# - GC_TIME_RATIO: Specifies the ratio of the time spent outside the garbage collection. +# (example: "4") +# - GC_ADAPTIVE_SIZE_POLICY_WEIGHT: The weighting given to the current GC time versus +# previous GC times. (example: "90") +# - GC_METASPACE_SIZE: The initial metaspace size. (example: "20") +# - GC_MAX_METASPACE_SIZE: The maximum metaspace size. (example: "100") +# - GC_CONTAINER_OPTIONS: Specify Java GC to use. The value of this variable should +# contain the necessary JRE command-line options to specify the required GC, which +# will override the default of `-XX:+UseParallelGC` (example: -XX:+UseG1GC). +# - HTTPS_PROXY: The location of the https proxy. (example: "myuser@127.0.0.1:8080") +# - HTTP_PROXY: The location of the http proxy. (example: "myuser@127.0.0.1:8080") +# - NO_PROXY: A comma separated lists of hosts, IP addresses or domains that can be +# accessed directly. (example: "foo.example.com,bar.example.com") +# +### +FROM registry.access.redhat.com/ubi9/openjdk-21:1.21 + +ENV LANGUAGE='en_US:en' + + +# We make four distinct layers so if there are application changes the library layers can be re-used +COPY --chown=185 target/quarkus-app/lib/ /deployments/lib/ +COPY --chown=185 target/quarkus-app/*.jar /deployments/ +COPY --chown=185 target/quarkus-app/app/ /deployments/app/ +COPY --chown=185 target/quarkus-app/quarkus/ /deployments/quarkus/ + +EXPOSE 8080 +USER 185 +ENV JAVA_OPTS_APPEND="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" +ENV JAVA_APP_JAR="/deployments/quarkus-run.jar" + +ENTRYPOINT [ "/opt/jboss/container/java/run/run-java.sh" ] + diff --git a/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-server/src/main/docker/Dockerfile.legacy-jar b/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-server/src/main/docker/Dockerfile.legacy-jar new file mode 100644 index 000000000000..d4fff916099c --- /dev/null +++ b/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-server/src/main/docker/Dockerfile.legacy-jar @@ -0,0 +1,94 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode +# +# Before building the container image run: +# +# ./mvnw package -Dquarkus.package.jar.type=legacy-jar +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.legacy-jar -t quarkus/quarkus-mcp-server-legacy-jar . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/quarkus-mcp-server-legacy-jar +# +# If you want to include the debug port into your docker image +# you will have to expose the debug port (default 5005 being the default) like this : EXPOSE 8080 5005. +# Additionally you will have to set -e JAVA_DEBUG=true and -e JAVA_DEBUG_PORT=*:5005 +# when running the container +# +# Then run the container using : +# +# docker run -i --rm -p 8080:8080 quarkus/quarkus-mcp-server-legacy-jar +# +# This image uses the `run-java.sh` script to run the application. +# This scripts computes the command line to execute your Java application, and +# includes memory/GC tuning. +# You can configure the behavior using the following environment properties: +# - JAVA_OPTS: JVM options passed to the `java` command (example: "-verbose:class") - Be aware that this will override +# the default JVM options, use `JAVA_OPTS_APPEND` to append options +# - JAVA_OPTS_APPEND: User specified Java options to be appended to generated options +# in JAVA_OPTS (example: "-Dsome.property=foo") +# - JAVA_MAX_MEM_RATIO: Is used when no `-Xmx` option is given in JAVA_OPTS. This is +# used to calculate a default maximal heap memory based on a containers restriction. +# If used in a container without any memory constraints for the container then this +# option has no effect. If there is a memory constraint then `-Xmx` is set to a ratio +# of the container available memory as set here. The default is `50` which means 50% +# of the available memory is used as an upper boundary. You can skip this mechanism by +# setting this value to `0` in which case no `-Xmx` option is added. +# - JAVA_INITIAL_MEM_RATIO: Is used when no `-Xms` option is given in JAVA_OPTS. This +# is used to calculate a default initial heap memory based on the maximum heap memory. +# If used in a container without any memory constraints for the container then this +# option has no effect. If there is a memory constraint then `-Xms` is set to a ratio +# of the `-Xmx` memory as set here. The default is `25` which means 25% of the `-Xmx` +# is used as the initial heap size. You can skip this mechanism by setting this value +# to `0` in which case no `-Xms` option is added (example: "25") +# - JAVA_MAX_INITIAL_MEM: Is used when no `-Xms` option is given in JAVA_OPTS. +# This is used to calculate the maximum value of the initial heap memory. If used in +# a container without any memory constraints for the container then this option has +# no effect. If there is a memory constraint then `-Xms` is limited to the value set +# here. The default is 4096MB which means the calculated value of `-Xms` never will +# be greater than 4096MB. The value of this variable is expressed in MB (example: "4096") +# - JAVA_DIAGNOSTICS: Set this to get some diagnostics information to standard output +# when things are happening. This option, if set to true, will set +# `-XX:+UnlockDiagnosticVMOptions`. Disabled by default (example: "true"). +# - JAVA_DEBUG: If set remote debugging will be switched on. Disabled by default (example: +# true"). +# - JAVA_DEBUG_PORT: Port used for remote debugging. Defaults to 5005 (example: "8787"). +# - CONTAINER_CORE_LIMIT: A calculated core limit as described in +# https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt. (example: "2") +# - CONTAINER_MAX_MEMORY: Memory limit given to the container (example: "1024"). +# - GC_MIN_HEAP_FREE_RATIO: Minimum percentage of heap free after GC to avoid expansion. +# (example: "20") +# - GC_MAX_HEAP_FREE_RATIO: Maximum percentage of heap free after GC to avoid shrinking. +# (example: "40") +# - GC_TIME_RATIO: Specifies the ratio of the time spent outside the garbage collection. +# (example: "4") +# - GC_ADAPTIVE_SIZE_POLICY_WEIGHT: The weighting given to the current GC time versus +# previous GC times. (example: "90") +# - GC_METASPACE_SIZE: The initial metaspace size. (example: "20") +# - GC_MAX_METASPACE_SIZE: The maximum metaspace size. (example: "100") +# - GC_CONTAINER_OPTIONS: Specify Java GC to use. The value of this variable should +# contain the necessary JRE command-line options to specify the required GC, which +# will override the default of `-XX:+UseParallelGC` (example: -XX:+UseG1GC). +# - HTTPS_PROXY: The location of the https proxy. (example: "myuser@127.0.0.1:8080") +# - HTTP_PROXY: The location of the http proxy. (example: "myuser@127.0.0.1:8080") +# - NO_PROXY: A comma separated lists of hosts, IP addresses or domains that can be +# accessed directly. (example: "foo.example.com,bar.example.com") +# +### +FROM registry.access.redhat.com/ubi9/openjdk-21:1.21 + +ENV LANGUAGE='en_US:en' + + +COPY target/lib/* /deployments/lib/ +COPY target/*-runner.jar /deployments/quarkus-run.jar + +EXPOSE 8080 +USER 185 +ENV JAVA_OPTS_APPEND="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" +ENV JAVA_APP_JAR="/deployments/quarkus-run.jar" + +ENTRYPOINT [ "/opt/jboss/container/java/run/run-java.sh" ] diff --git a/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-server/src/main/docker/Dockerfile.native b/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-server/src/main/docker/Dockerfile.native new file mode 100644 index 000000000000..f2df21d8aba8 --- /dev/null +++ b/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-server/src/main/docker/Dockerfile.native @@ -0,0 +1,29 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode. +# +# Before building the container image run: +# +# ./mvnw package -Dnative +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.native -t quarkus/quarkus-mcp-server . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/quarkus-mcp-server +# +# The ` registry.access.redhat.com/ubi8/ubi-minimal:8.10` base image is based on UBI 9. +# To use UBI 8, switch to `quay.io/ubi8/ubi-minimal:8.10`. +### +FROM registry.access.redhat.com/ubi8/ubi-minimal:8.10 +WORKDIR /work/ +RUN chown 1001 /work \ + && chmod "g+rwX" /work \ + && chown 1001:root /work +COPY --chown=1001:root --chmod=0755 target/*-runner /work/application + +EXPOSE 8080 +USER 1001 + +ENTRYPOINT ["./application", "-Dquarkus.http.host=0.0.0.0"] diff --git a/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-server/src/main/docker/Dockerfile.native-micro b/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-server/src/main/docker/Dockerfile.native-micro new file mode 100644 index 000000000000..ddbe8db6ddf0 --- /dev/null +++ b/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-server/src/main/docker/Dockerfile.native-micro @@ -0,0 +1,32 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode. +# It uses a micro base image, tuned for Quarkus native executables. +# It reduces the size of the resulting container image. +# Check https://quarkus.io/guides/quarkus-runtime-base-image for further information about this image. +# +# Before building the container image run: +# +# ./mvnw package -Dnative +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.native-micro -t quarkus/quarkus-mcp-server . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/quarkus-mcp-server +# +# The `quay.io/quarkus/quarkus-micro-image:2.0` base image is based on UBI 9. +# To use UBI 8, switch to `quay.io/quarkus/quarkus-micro-image:2.0`. +### +FROM quay.io/quarkus/quarkus-micro-image:2.0 +WORKDIR /work/ +RUN chown 1001 /work \ + && chmod "g+rwX" /work \ + && chown 1001:root /work +COPY --chown=1001:root --chmod=0755 target/*-runner /work/application + +EXPOSE 8080 +USER 1001 + +ENTRYPOINT ["./application", "-Dquarkus.http.host=0.0.0.0"] diff --git a/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-server/src/main/java/com/baeldung/quarkus/mcp/ToolBox.java b/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-server/src/main/java/com/baeldung/quarkus/mcp/ToolBox.java new file mode 100644 index 000000000000..d37719ed5370 --- /dev/null +++ b/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-server/src/main/java/com/baeldung/quarkus/mcp/ToolBox.java @@ -0,0 +1,50 @@ +package com.baeldung.quarkus.mcp; + +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Locale; + +import io.quarkiverse.mcp.server.Tool; +import io.quarkiverse.mcp.server.ToolArg; + +public class ToolBox { + + @Tool(description = "Get the current time in a specific timezone.") + public String getTimeInTimezone( + @ToolArg(description = "Timezone ID (e.g., America/Los_Angeles)") String timezoneId) { + try { + ZoneId zoneId = ZoneId.of(timezoneId); + ZonedDateTime zonedDateTime = ZonedDateTime.now(zoneId); + DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDateTime(java.time.format.FormatStyle.FULL) + .withLocale(Locale.getDefault()); + return zonedDateTime.format(formatter); + } catch (Exception e) { + return "Invalid timezone ID: " + timezoneId + ". Please provide a valid IANA timezone ID."; + } + } + + @Tool(description = "Provides JVM system information such as available processors, free memory, total memory, and max memory.") + public String getJVMInfo() { + StringBuilder systemInfo = new StringBuilder(); + + // Get available processors + int availableProcessors = Runtime.getRuntime().availableProcessors(); + systemInfo.append("Available processors (cores): ").append(availableProcessors).append("\n"); + + // Get free memory + long freeMemory = Runtime.getRuntime().freeMemory(); + systemInfo.append("Free memory (bytes): ").append(freeMemory).append("\n"); + + // Get total memory + long totalMemory = Runtime.getRuntime().totalMemory(); + systemInfo.append("Total memory (bytes): ").append(totalMemory).append("\n"); + + // Get max memory + long maxMemory = Runtime.getRuntime().maxMemory(); + systemInfo.append("Max memory (bytes): ").append(maxMemory).append("\n"); + return systemInfo.toString(); + } + + +} \ No newline at end of file diff --git a/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-server/src/main/resources/application.properties b/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-server/src/main/resources/application.properties new file mode 100644 index 000000000000..4690a13c8da0 --- /dev/null +++ b/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-server/src/main/resources/application.properties @@ -0,0 +1,2 @@ +quarkus.package.jar.type=uber-jar +quarkus.http.port=9000 \ No newline at end of file diff --git a/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-server/src/test/java/com/baeldung/quarkus/mcp/ToolBoxUnitTest.java b/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-server/src/test/java/com/baeldung/quarkus/mcp/ToolBoxUnitTest.java new file mode 100644 index 000000000000..49b7b6ed9663 --- /dev/null +++ b/quarkus-modules/quarkus-mcp-langchain/quarkus-mcp-server/src/test/java/com/baeldung/quarkus/mcp/ToolBoxUnitTest.java @@ -0,0 +1,35 @@ +package com.baeldung.quarkus.mcp; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +public class ToolBoxUnitTest { + + private final ToolBox toolBox = new ToolBox(); + + @Test + void givenValidTimezone_whenGetTimeInTimezone_thenContainsFormattedDate() { + String timezoneId = "America/Los_Angeles"; + String result = toolBox.getTimeInTimezone(timezoneId); + // Should contain the timezone's display name or a recognizable part of the formatted date + assertTrue(result.contains("Pacific") || result.contains("Los Angeles") || result.contains(", 20"), + "Result should contain formatted date for the timezone"); + } + + @Test + void givenInvalidTimezone_whenGetTimeInTimezone_thenReturnsInvalidTimezoneMessage() { + String timezoneId = "Invalid/Timezone"; + String result = toolBox.getTimeInTimezone(timezoneId); + assertTrue(result.startsWith("Invalid timezone ID")); + } + + @Test + void givenJVM_whenGetSystemInfo_thenContainsExpectedFields() { + String result = toolBox.getJVMInfo(); + assertTrue(result.contains("Available processors")); + assertTrue(result.contains("Free memory")); + assertTrue(result.contains("Total memory")); + assertTrue(result.contains("Max memory")); + } +}