Skip to content

Commit 33b7906

Browse files
committed
Add version option
1 parent 8c1c481 commit 33b7906

File tree

5 files changed

+83
-32
lines changed

5 files changed

+83
-32
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ intellij-settings/
1313
**/*.actual
1414
**/generated/**
1515
jte-classes
16+
**/versions.properties

build.gradle.kts

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,19 @@ sourceSets {
3232
}
3333
}
3434

35+
val VERSION: String? by project
36+
37+
version = (VERSION ?: "LOCAL")
38+
39+
40+
val mainMcpDesktopClass = "org.http4k.mcp.Http4kMcpDesktop"
41+
3542
graalvmNative {
3643
toolchainDetection.set(true)
3744
binaries {
3845
named("main") {
3946
imageName.set("http4k-mcp-desktop")
40-
mainClass.set("org.http4k.mcp.Http4kMcpDesktop")
47+
mainClass.set(mainMcpDesktopClass)
4148
useFatJar.set(true)
4249
sharedLibrary.set(false)
4350

@@ -48,6 +55,20 @@ graalvmNative {
4855
}
4956

5057
tasks {
58+
59+
register("generateVersionProperties" ) {
60+
doLast {
61+
file("src/main/resources/version.properties").apply {
62+
parentFile.mkdirs()
63+
writeText("version=${project.version}")
64+
}
65+
}
66+
}
67+
68+
named("processResources") {
69+
dependsOn("generateVersionProperties")
70+
}
71+
5172
withType<KotlinJvmCompile>().configureEach {
5273
compilerOptions {
5374
allWarningsAsErrors = false
@@ -70,14 +91,19 @@ dependencies {
7091
implementation(platform("org.http4k:http4k-bom:$http4kVersion"))
7192

7293
implementation("dev.forkhandles:bunting4k:_")
94+
95+
runtimeOnly("org.slf4j:slf4j-nop:_")
96+
97+
implementation("com.jcabi:jcabi-manifests:_")
98+
7399
implementation(Http4k.securityOauth)
74100
implementation(Http4k.client.websocket)
75-
implementation(platform("org.http4k:http4k-realtime-core"))
101+
implementation(platform(Http4k.realtimeCore))
76102

77-
testImplementation(platform("org.junit:junit-bom:_"))
78-
testImplementation("org.junit.jupiter:junit-jupiter-api")
79-
testImplementation("org.junit.jupiter:junit-jupiter-engine")
80-
testImplementation("org.http4k:http4k-testing-hamkrest")
103+
testImplementation(platform(Testing.junit.bom))
104+
testImplementation(Testing.junit.jupiter.api)
105+
testImplementation(Testing.junit.jupiter.engine)
106+
testImplementation(Http4k.testing.hamkrest)
81107

82108
// testImplementation(project(":http4k-mcp-sdk"))
83109
testImplementation("org.http4k:http4k-server-helidon:_")

src/main/kotlin/org/http4k/mcp/Http4kMcpDesktop.kt

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,50 @@ import org.http4k.mcp.internal.pipeJsonRpcTraffic
1515
import org.http4k.mcp.internal.pipeSseTraffic
1616
import org.http4k.mcp.internal.pipeWebsocketTraffic
1717
import java.time.Clock
18+
import java.util.Properties
1819

1920
object Http4kMcpDesktop {
2021
@JvmStatic
2122
fun main(vararg args: String) = McpOptions(args.toList().toTypedArray())
2223
.use {
23-
val clock = Clock.systemUTC()
24+
when {
25+
version -> println("http4k MCP Desktop v${getVersion()}")
2426

25-
val security = McpClientSecurity.from(this, clock, JavaHttpClient())
26-
when (transport) {
27-
sse -> pipeSseTraffic(
28-
System.`in`.reader(),
29-
System.out.writer(),
30-
Request(GET, url),
31-
McpDesktopHttpClient(clock, security),
32-
if (reconnectDelay.isZero) Immediate else Delayed(reconnectDelay),
33-
)
27+
else -> {
28+
val clock = Clock.systemUTC()
3429

35-
jsonrpc -> pipeJsonRpcTraffic(
36-
System.`in`.reader(),
37-
System.out.writer(),
38-
Request(GET, url),
39-
McpDesktopHttpClient(clock, security),
40-
)
30+
val security = McpClientSecurity.from(this, clock, JavaHttpClient())
31+
when (transport) {
32+
sse -> pipeSseTraffic(
33+
System.`in`.reader(),
34+
System.out.writer(),
35+
Request(GET, url),
36+
McpDesktopHttpClient(clock, security),
37+
if (reconnectDelay.isZero) Immediate else Delayed(reconnectDelay),
38+
)
4139

42-
websocket -> pipeWebsocketTraffic(
43-
System.`in`.reader(),
44-
System.out.writer(),
45-
url,
46-
security,
47-
if (reconnectDelay.isZero) Immediate else Delayed(reconnectDelay),
48-
)
40+
jsonrpc -> pipeJsonRpcTraffic(
41+
System.`in`.reader(),
42+
System.out.writer(),
43+
Request(GET, url),
44+
McpDesktopHttpClient(clock, security),
45+
)
46+
47+
websocket -> pipeWebsocketTraffic(
48+
System.`in`.reader(),
49+
System.out.writer(),
50+
url,
51+
security,
52+
if (reconnectDelay.isZero) Immediate else Delayed(reconnectDelay),
53+
)
54+
}
55+
}
4956
}
5057
}
5158
}
5259

60+
private fun getVersion() = runCatching {
61+
Properties().apply {
62+
Http4kMcpDesktop::class.java.getResourceAsStream("/version.properties")?.use(::load)
63+
}.getProperty("version", "LOCAL")
64+
}.getOrDefault("-")

src/main/kotlin/org/http4k/mcp/McpOptions.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,17 @@ import java.time.Duration.ZERO
1313

1414
class McpOptions(args: Array<String>) :
1515
Bunting(
16-
args, "MCP proxy to pipe StdIO to a remote server. Command line options can be found at: https://github.com/http4k/mcp-desktop", "http4k-mcp-desktop",
16+
args,
17+
"MCP proxy to pipe StdIO to a remote server. Command line options can be found at: https://github.com/http4k/mcp-desktop",
18+
"http4k-mcp-desktop",
1719
config = InMemoryConfig()
1820
) {
1921

20-
val transport by option("MCP transport. Choose between 'jsonrpc' (non-streaming) and 'sse' (streaming)").map { valueOf(it) }
22+
val transport by option("MCP transport. Choose between 'jsonrpc' (non-streaming) and 'sse' (streaming)").map {
23+
valueOf(
24+
it
25+
)
26+
}
2127
.defaultsTo(sse)
2228

2329
val url by option("Base URL of the MCP server to connect to: eg. http://localhost:3001/sse")
@@ -36,7 +42,7 @@ class McpOptions(args: Array<String>) :
3642
.map { Credentials(it.substringBefore(":"), it.substringAfter(":")) }
3743
.secret()
3844

39-
val version by option().int().defaultsTo(0)
45+
val version by switch("Get the version information for the app")
4046

4147
val reconnectDelay by option("Reconnect delay (in seconds) in case of disconnection. Defaults to 0").int()
4248
.map { Duration.ofSeconds(it.toLong()) }

versions.properties

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
####
1010
#### NOTE: Some versions are filtered by the rejectVersionIf predicate. See the settings.gradle.kts file.
1111

12+
version.com.jcabi..jcabi-manifests=2.1.0
13+
1214
version.dev.forkhandles..bunting4k=2.22.2.1
1315

1416
## unused
@@ -23,3 +25,7 @@ plugin.de.fayard.buildSrcLibs=0.60.5
2325
version.http4k=6.1.0.1
2426

2527
version.junit=5.12.1
28+
29+
version.org.slf4j..slf4j-nop=2.0.17
30+
## # available=2.1.0-alpha0
31+
## # available=2.1.0-alpha1

0 commit comments

Comments
 (0)