11import dev.johnoreilly.climatetrace.data.ClimateTraceRepository
22import dev.johnoreilly.climatetrace.di.initKoin
33import io.ktor.server.cio.CIO
4- import io.ktor.server.engine.*
5- import io.ktor.utils.io.streams.*
6- import io.modelcontextprotocol.kotlin.sdk.*
7- import io.modelcontextprotocol.kotlin.sdk.server.*
4+ import io.ktor.server.engine.embeddedServer
5+ import io.ktor.utils.io.streams.asInput
6+ import io.modelcontextprotocol.kotlin.sdk.types.TextContent
7+ import io.modelcontextprotocol.kotlin.sdk.server.Server
8+ import io.modelcontextprotocol.kotlin.sdk.server.ServerOptions
9+ import io.modelcontextprotocol.kotlin.sdk.server.StdioServerTransport
10+ import io.modelcontextprotocol.kotlin.sdk.server.mcp
11+ import io.modelcontextprotocol.kotlin.sdk.types.CallToolResult
12+ import io.modelcontextprotocol.kotlin.sdk.types.Implementation
13+ import io.modelcontextprotocol.kotlin.sdk.types.ServerCapabilities
14+ import io.modelcontextprotocol.kotlin.sdk.types.ToolSchema
815import kotlinx.coroutines.Job
916import kotlinx.coroutines.runBlocking
1017import kotlinx.io.asSink
@@ -63,7 +70,7 @@ fun configureMcpServer(): Server {
6370 server.addTool(
6471 name = " get-country-asset-emissions" ,
6572 description = " Get sector emission information for the given countries" ,
66- inputSchema = Tool . Input (
73+ inputSchema = ToolSchema (
6774 properties = buildJsonObject {
6875 putJsonObject(" countryCodeList" ) {
6976 put(" type" , JsonPrimitive (" array" ))
@@ -75,7 +82,7 @@ fun configureMcpServer(): Server {
7582 required = listOf (" countryCodeList" )
7683 )
7784 ) { request ->
78- val countryCodeList = request.arguments[ " countryCodeList" ]
85+ val countryCodeList = request.arguments?.get( " countryCodeList" )
7986 if (countryCodeList == null ) {
8087 return @addTool CallToolResult (
8188 content = listOf (TextContent (" The 'countryCodeList' parameters are required." ))
@@ -96,7 +103,7 @@ fun configureMcpServer(): Server {
96103 server.addTool(
97104 name = " get-emissions" ,
98105 description = " Get total emission information for the given countries" ,
99- inputSchema = Tool . Input (
106+ inputSchema = ToolSchema (
100107 properties = buildJsonObject {
101108 putJsonObject(" countryCodeList" ) {
102109 put(" type" , JsonPrimitive (" array" ))
@@ -110,8 +117,8 @@ fun configureMcpServer(): Server {
110117 )
111118
112119 ) { request ->
113- val countryCodeList = request.arguments[ " countryCodeList" ]
114- val year = request.arguments[ " year" ]
120+ val countryCodeList = request.arguments?.get( " countryCodeList" )
121+ val year = request.arguments?.get( " year" )
115122 if (countryCodeList == null || year == null ) {
116123 return @addTool CallToolResult (
117124 content = listOf (TextContent (" The 'countryCodeList' and `year` parameters are required." ))
@@ -142,7 +149,7 @@ fun configureMcpServer(): Server {
142149 * a close event.
143150 */
144151fun `run mcp server using stdio` () {
145- ` val server = configureMcpServer()
152+ val server = configureMcpServer()
146153 val transport = StdioServerTransport (
147154 System .`in `.asInput(),
148155 System .out .asSink().buffered()
@@ -156,7 +163,7 @@ fun `run mcp server using stdio`() {
156163 }
157164 done.join()
158165 }
159- ` }
166+ }
160167
161168/* *
162169 * Launches an SSE (Server-Sent Events) MCP (Model Context Protocol) server on the specified port.
0 commit comments