Update sample project to use library version 0.3.0 (#47)
Co-authored-by: Leonid Stashevsky <e5l@users.noreply.github.com>
This commit is contained in:
parent
78ef0f9e2b
commit
164d276336
2 changed files with 15 additions and 11 deletions
|
|
@ -13,10 +13,8 @@ group = "org.example"
|
|||
version = "0.1.0"
|
||||
|
||||
dependencies {
|
||||
implementation("io.modelcontextprotocol:kotlin-sdk:0.2.0")
|
||||
implementation("io.modelcontextprotocol:kotlin-sdk:0.3.0")
|
||||
implementation("org.slf4j:slf4j-nop:2.0.9")
|
||||
|
||||
testImplementation(kotlin("test"))
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
|
|
|
|||
|
|
@ -22,6 +22,9 @@ import io.modelcontextprotocol.kotlin.sdk.server.StdioServerTransport
|
|||
import kotlinx.coroutines.CompletableDeferred
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.io.asSink
|
||||
import kotlinx.io.asSource
|
||||
import kotlinx.io.buffered
|
||||
|
||||
/**
|
||||
* Start sse-server mcp on port 3001.
|
||||
|
|
@ -35,9 +38,9 @@ fun main(args: Array<String>) {
|
|||
val command = args.firstOrNull() ?: "--sse-server-ktor"
|
||||
val port = args.getOrNull(1)?.toIntOrNull() ?: 3001
|
||||
when (command) {
|
||||
"--stdio" -> `run mcp server using stdio`()
|
||||
"--sse-server-ktor" -> `run sse mcp server using Ktor plugin`(port)
|
||||
"--sse-server" -> `run sse mcp server with plain configuration`(port)
|
||||
"--stdio" -> runMcpServerUsingStdio()
|
||||
"--sse-server-ktor" -> runSseMcpServerUsingKtorPlugin(port)
|
||||
"--sse-server" -> runSseMcpServerWithPlainConfiguration(port)
|
||||
else -> {
|
||||
System.err.println("Unknown command: $command")
|
||||
}
|
||||
|
|
@ -114,11 +117,14 @@ fun configureServer(): Server {
|
|||
return server
|
||||
}
|
||||
|
||||
fun `run mcp server using stdio`() {
|
||||
fun runMcpServerUsingStdio() {
|
||||
// Note: The server will handle listing prompts, tools, and resources automatically.
|
||||
// The handleListResourceTemplates will return empty as defined in the Server code.
|
||||
val server = configureServer()
|
||||
val transport = StdioServerTransport()
|
||||
val transport = StdioServerTransport(
|
||||
inputStream = System.`in`.asSource().buffered(),
|
||||
outputStream = System.out.asSink().buffered()
|
||||
)
|
||||
|
||||
runBlocking {
|
||||
server.connect(transport)
|
||||
|
|
@ -132,7 +138,7 @@ fun `run mcp server using stdio`() {
|
|||
}
|
||||
}
|
||||
|
||||
fun `run sse mcp server with plain configuration`(port: Int): Unit = runBlocking {
|
||||
fun runSseMcpServerWithPlainConfiguration(port: Int): Unit = runBlocking {
|
||||
val servers = ConcurrentMap<String, Server>()
|
||||
println("Starting sse server on port $port. ")
|
||||
println("Use inspector to connect to the http://localhost:$port/sse")
|
||||
|
|
@ -179,7 +185,7 @@ fun `run sse mcp server with plain configuration`(port: Int): Unit = runBlocking
|
|||
* @param port The port number on which the SSE MCP server will listen for client connections.
|
||||
* @return Unit This method does not return a value.
|
||||
*/
|
||||
fun `run sse mcp server using Ktor plugin`(port: Int): Unit = runBlocking {
|
||||
fun runSseMcpServerUsingKtorPlugin(port: Int): Unit = runBlocking {
|
||||
println("Starting sse server on port $port")
|
||||
println("Use inspector to connect to the http://localhost:$port/sse")
|
||||
|
||||
|
|
@ -187,5 +193,5 @@ fun `run sse mcp server using Ktor plugin`(port: Int): Unit = runBlocking {
|
|||
MCP {
|
||||
return@MCP configureServer()
|
||||
}
|
||||
}
|
||||
}.start(wait = true)
|
||||
}
|
||||
Loading…
Reference in a new issue