diff --git a/filesystem/pom.xml b/filesystem/pom.xml index a396c33..6834c48 100644 --- a/filesystem/pom.xml +++ b/filesystem/pom.xml @@ -27,6 +27,10 @@ + io.quarkus.mcp.servers + mcp-server-shared + ${version} + io.quarkus quarkus-jackson diff --git a/filesystem/src/main/java/io/quarkus/mcp/servers/filesystem/Application.java b/filesystem/src/main/java/io/quarkus/mcp/servers/filesystem/Application.java index 6737ea2..9d4e136 100644 --- a/filesystem/src/main/java/io/quarkus/mcp/servers/filesystem/Application.java +++ b/filesystem/src/main/java/io/quarkus/mcp/servers/filesystem/Application.java @@ -1,5 +1,6 @@ package io.quarkus.mcp.servers.filesystem; +import io.quarkus.mcp.servers.shared.SharedApplication; import io.quarkus.runtime.Quarkus; import io.quarkus.runtime.annotations.QuarkusMain; @@ -7,20 +8,14 @@ * This is the main entry point for the filesystem server. * It will start the server and set the fileserver.paths property based on arguments if present. */ -@QuarkusMain -class Application { +@QuarkusMain(name="filesystem") +public class Application { public static void main(String[] args) { - if(args.length > 0) { - System.setProperty("fileserver.paths", String.join(",", args)); - } - - Quarkus.run(null, - (exitCode, exception) -> { - if(exception != null) { - exception.printStackTrace(); - } - System.exit(exitCode); - }, - args); + SharedApplication.main(args, (remainingArgs) -> { + if(remainingArgs.size() > 0) { + System.setProperty("fileserver.paths", String.join(",", remainingArgs)); + } + return null; + }); } } diff --git a/filesystem/src/main/resources/application.properties b/filesystem/src/main/resources/application.properties index f2dd760..331831b 100644 --- a/filesystem/src/main/resources/application.properties +++ b/filesystem/src/main/resources/application.properties @@ -1,5 +1,2 @@ -quarkus.package.jar.type=uber-jar -quarkus.package.jar.add-runner-suffix=false -quarkus.mcp.server.traffic-logging.enabled=true -quarkus.mcp.server.traffic-logging.text-limit=50 +quarkus.package.main-class=filesystem diff --git a/jdbc/pom.xml b/jdbc/pom.xml index f987da1..f5085f1 100644 --- a/jdbc/pom.xml +++ b/jdbc/pom.xml @@ -27,6 +27,10 @@ + io.quarkus.mcp.servers + mcp-server-shared + ${version} + io.quarkus quarkus-jackson diff --git a/jdbc/src/main/resources/application.properties b/jdbc/src/main/resources/application.properties index 5056d9d..4580421 100644 --- a/jdbc/src/main/resources/application.properties +++ b/jdbc/src/main/resources/application.properties @@ -1,9 +1,3 @@ -quarkus.package.jar.type=uber-jar -quarkus.package.jar.add-runner-suffix=false -#quarkus.log.level=DEBUG #disable db devservices as we are using direct connection %dev.quarkus.datasource.devservices.enabled=false - - -#quarkus.log.console.stderr=true diff --git a/jfx/pom.xml b/jfx/pom.xml index a126012..31c0717 100644 --- a/jfx/pom.xml +++ b/jfx/pom.xml @@ -30,6 +30,10 @@ + io.quarkus.mcp.servers + mcp-server-shared + ${version} + io.quarkus quarkus-jackson diff --git a/jfx/src/main/resources/application.properties b/jfx/src/main/resources/application.properties index 2366a09..8b13789 100644 --- a/jfx/src/main/resources/application.properties +++ b/jfx/src/main/resources/application.properties @@ -1,5 +1 @@ -quarkus.package.jar.type=uber-jar -quarkus.package.jar.add-runner-suffix=false -#quarkus.log.level=DEBUG -#quarkus.log.console.stderr=true diff --git a/kubernetes/README.md b/kubernetes/README.md index c8e6d68..1cc3036 100644 --- a/kubernetes/README.md +++ b/kubernetes/README.md @@ -58,3 +58,37 @@ Example for MacOS arm64 (M1, M2, etc.): ``` You can of course also rename the executable to something else, like `mcp-server-kubernetes` if you want. + +## How to build/test + +```bash +mvn clean install +``` + +There are profiles to add right JDBC driver to the build for easy testing. + +i.e. `h2`, `postgresql`, `sqlite` etc. + +Examples: + +h2 on an empty in-memory database: + +```bash +mvn quarkus:dev -Dh2 +``` + +postgresql with a pre-configured database running in a container: + +```bash +podman run -p 5432:5432 -d sakiladb/postgres:latest +mvn quarkus:dev -Dpostgresql +``` + +sqlite with a pre-configured database running in a container +using `./test.db` as the database file: + +```bash +mvn quarkus:dev -Dsqlite -Djdbc.url=jdbc:sqlite:./test.db +``` + + diff --git a/kubernetes/pom.xml b/kubernetes/pom.xml index b235d9f..5757d2f 100644 --- a/kubernetes/pom.xml +++ b/kubernetes/pom.xml @@ -28,6 +28,11 @@ + + io.quarkus.mcp.servers + mcp-server-shared + ${version} + io.quarkus quarkus-kubernetes-client diff --git a/kubernetes/src/main/resources/application.properties b/kubernetes/src/main/resources/application.properties index c7324ba..3682d81 100644 --- a/kubernetes/src/main/resources/application.properties +++ b/kubernetes/src/main/resources/application.properties @@ -1,10 +1,3 @@ -quarkus.package.jar.type=uber-jar -quarkus.package.jar.add-runner-suffix=false - -# Logging -#quarkus.log.level=DEBUG -#quarkus.log.console.stderr=true - %test.quarkus.kubernetes-client.devservices.enabled=true %test.quarkus.kubernetes-client.devservices.override-kubeconfig=true %test.quarkus.kubernetes-client.devservices.flavor=api-only diff --git a/pom.xml b/pom.xml index c65bf09..2e044b0 100644 --- a/pom.xml +++ b/pom.xml @@ -10,6 +10,7 @@ pom + shared jdbc filesystem jfx @@ -53,9 +54,23 @@ ${assertj.version} test + + + + + io.quarkiverse.mcp + quarkus-mcp-server-stdio + ${mcp.server.version} + + + io.quarkiverse.mcp + quarkus-mcp-server-sse + ${mcp.server.version} + + diff --git a/shared/README.md b/shared/README.md new file mode 100644 index 0000000..bc39956 --- /dev/null +++ b/shared/README.md @@ -0,0 +1,5 @@ +# Shared Model Context Protocol Server module + +This Model Context Protocol(MCP) server enables Large Language Models (LLMs) to make drawings using JavaFX primities. + +This module is to share common code between the different MCP server modules. diff --git a/shared/pom.xml b/shared/pom.xml new file mode 100644 index 0000000..d9a9640 --- /dev/null +++ b/shared/pom.xml @@ -0,0 +1,34 @@ + + + 4.0.0 + io.quarkus.mcp.servers + mcp-server-shared + + + io.quarkiverse.mcp.servers + mcp-servers-parent + 999-SNAPSHOT + + + + + + + io.smallrye + jandex-maven-plugin + 3.2.3 + + + make-index + + jandex + + + + + + + + \ No newline at end of file diff --git a/shared/src/main/java/io/quarkus/mcp/servers/shared/McpCliConfigSource.java b/shared/src/main/java/io/quarkus/mcp/servers/shared/McpCliConfigSource.java new file mode 100644 index 0000000..256a303 --- /dev/null +++ b/shared/src/main/java/io/quarkus/mcp/servers/shared/McpCliConfigSource.java @@ -0,0 +1,83 @@ +package io.quarkus.mcp.servers.shared; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.eclipse.microprofile.config.spi.ConfigSource; + +/** + * A shared config source for MCP CLI's + * Will treat any argument starting with -- or -D as a key/value pair. + * + */ +public class McpCliConfigSource implements ConfigSource { + + static List setupConfigSource(String[] args) { + List remainingArgs = new ArrayList<>(); + for (String arg : args) { + if (arg.startsWith("--") || arg.startsWith("-D")) { + String[] parts = arg.substring(2).split("="); + if (parts.length == 2) { + // System.out.println("Setting " + parts[0] + " to " + parts[1]); + McpCliConfigSource.put(parts[0], parts[1]); + } else { + McpCliConfigSource.put(parts[0], "true"); + } + + if(parts[0].equals("debug")) { + put("quarkus.mcp.server.client-logging.default-level", "DEBUG"); + put("quarkus.mcp.server.traffic-logging.enabled", "true"); + put("quarkus.log.category.\"io.quarkus.mcp.servers\".level", "DEBUG"); + } + } else { + remainingArgs.add(arg); + } + } + + boolean sse = Boolean.parseBoolean(configuration.get("sse")); + + if(sse) { + put("quarkus.http.host-enabled", "true"); + put("quarkus.mcp.server.stdio.enabled", "false"); + + } else { + put("quarkus.http.host-enabled", "false"); + put("quarkus.mcp.server.stdio.enabled", "true"); + } + + return remainingArgs; + } + + private static final Map configuration = new HashMap<>(); + + static { + // configuration.put("hass-server", "http://homeassistant.local:8123"); + } + + public static void put(String key, String value) { + configuration.put(key, value); + } + + @Override + public int getOrdinal() { + return 275; + } + + @Override + public Set getPropertyNames() { + return configuration.keySet(); + } + + @Override + public String getValue(final String propertyName) { + return configuration.get(propertyName); + } + + @Override + public String getName() { + return McpCliConfigSource.class.getSimpleName(); + } +} \ No newline at end of file diff --git a/shared/src/main/java/io/quarkus/mcp/servers/shared/SharedApplication.java b/shared/src/main/java/io/quarkus/mcp/servers/shared/SharedApplication.java new file mode 100644 index 0000000..43774b7 --- /dev/null +++ b/shared/src/main/java/io/quarkus/mcp/servers/shared/SharedApplication.java @@ -0,0 +1,28 @@ +package io.quarkus.mcp.servers.shared; + +import java.util.List; +import java.util.function.Function; + +import io.quarkus.runtime.Quarkus; +import io.quarkus.runtime.annotations.QuarkusMain; + +@QuarkusMain +public class SharedApplication { + + public static void main(String[] args) { + main(args, (remainingArgs) -> null); + } + + public static void main(String[] args, Function, Void> onArgsProcessed) { + onArgsProcessed.apply(McpCliConfigSource.setupConfigSource(args)); + + Quarkus.run(null, + (exitCode, exception) -> { + if(exception != null) { + exception.printStackTrace(); + } + System.exit(exitCode); + }, + args); + } +} diff --git a/shared/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource b/shared/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource new file mode 100644 index 0000000..a534893 --- /dev/null +++ b/shared/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource @@ -0,0 +1 @@ +io.quarkus.mcp.servers.shared.McpCliConfigSource diff --git a/shared/src/main/resources/application.properties b/shared/src/main/resources/application.properties new file mode 100644 index 0000000..6b9ebc7 --- /dev/null +++ b/shared/src/main/resources/application.properties @@ -0,0 +1,5 @@ +quarkus.package.jar.type=uber-jar +quarkus.package.jar.add-runner-suffix=false + +%dev.quarkus.mcp.server.stdio.enabled=false +%dev.quarkus.http.host-enabled=true \ No newline at end of file