forked from quarkiverse/quarkus-mcp-servers
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request quarkiverse#11 from maxandersen/shared
add shared to handle sse/stdio and cli parsing/config
- Loading branch information
Showing
17 changed files
with
232 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 9 additions & 14 deletions
23
filesystem/src/main/java/io/quarkus/mcp/servers/filesystem/Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,21 @@ | ||
package io.quarkus.mcp.servers.filesystem; | ||
|
||
import io.quarkus.mcp.servers.shared.SharedApplication; | ||
import io.quarkus.runtime.Quarkus; | ||
import io.quarkus.runtime.annotations.QuarkusMain; | ||
|
||
/** | ||
* 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; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>io.quarkus.mcp.servers</groupId> | ||
<artifactId>mcp-server-shared</artifactId> | ||
|
||
<parent> | ||
<groupId>io.quarkiverse.mcp.servers</groupId> | ||
<artifactId>mcp-servers-parent</artifactId> | ||
<version>999-SNAPSHOT</version> | ||
</parent> | ||
|
||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>io.smallrye</groupId> | ||
<artifactId>jandex-maven-plugin</artifactId> | ||
<version>3.2.3</version> | ||
<executions> | ||
<execution> | ||
<id>make-index</id> | ||
<goals> | ||
<goal>jandex</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
83 changes: 83 additions & 0 deletions
83
shared/src/main/java/io/quarkus/mcp/servers/shared/McpCliConfigSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> setupConfigSource(String[] args) { | ||
List<String> 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<String, String> 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<String> getPropertyNames() { | ||
return configuration.keySet(); | ||
} | ||
|
||
@Override | ||
public String getValue(final String propertyName) { | ||
return configuration.get(propertyName); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return McpCliConfigSource.class.getSimpleName(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
shared/src/main/java/io/quarkus/mcp/servers/shared/SharedApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<List<String>, Void> onArgsProcessed) { | ||
onArgsProcessed.apply(McpCliConfigSource.setupConfigSource(args)); | ||
|
||
Quarkus.run(null, | ||
(exitCode, exception) -> { | ||
if(exception != null) { | ||
exception.printStackTrace(); | ||
} | ||
System.exit(exitCode); | ||
}, | ||
args); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
shared/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.quarkus.mcp.servers.shared.McpCliConfigSource |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |