Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ class ClimateTraceRepository(
return countries
}

suspend fun fetchCountryEmissionsInfo(countryCodeList: List<String>, year: String) = api.fetchCountryEmissionsInfo(countryCodeList, year)
suspend fun fetchCountryEmissionsInfo(countryCode: String, year: String) = api.fetchCountryEmissionsInfo(listOf(countryCode), year)
suspend fun fetchCountryEmissionsInfo(countryCodeList: List<String>, year: String) = api.fetchCountryEmissionsInfo(countryCodeList, year)

suspend fun fetchCountryAssetEmissionsInfo(countryCode: String) = api.fetchCountryAssetEmissionsInfo(countryCode)
suspend fun fetchCountryAssetEmissionsInfo(countryCodeList: List<String>) = api.fetchCountryAssetEmissionsInfo(countryCodeList)
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ class ClimateTraceApi(
// TODO need to implement paging on top of this
suspend fun fetchAssets() = client.get("$baseUrl/assets").body<AssetsResult>()

suspend fun fetchCountryAssets(countryCode: String) = client.get("$baseUrl/assets?countries=$countryCode").body<AssetsResult>()
//suspend fun fetchCountryEmissionsInfo(countryCode: String, year: String) = client.get("$baseUrl/country/emissions?since=$year&to=$year&countries=$countryCode").body<List<CountryEmissionsInfo>>()

suspend fun fetchCountryEmissionsInfo(countryCodeList: List<String>, year: String): List<CountryEmissionsInfo> {
return client.get("$baseUrl/country/emissions") {
Expand All @@ -86,6 +84,13 @@ class ClimateTraceApi(
}.body<List<CountryEmissionsInfo>>()
}

suspend fun fetchCountryAssetEmissionsInfo(countryCodeList: List<String>): Map<String, List<CountryAssetEmissionsInfo>> {
return client.get("$baseUrl/assets/emissions") {
url {
parameters.append("countries", countryCodeList.joinToString(","))
}
}.body<Map<String, List<CountryAssetEmissionsInfo>>>()
}

suspend fun fetchCountryAssetEmissionsInfo(countryCode: String) = client.get("$baseUrl/assets/emissions?countries=$countryCode").body<Map<String, List<CountryAssetEmissionsInfo>>>()[countryCode] ?: emptyList()
}
Binary file not shown.
37 changes: 36 additions & 1 deletion mcp-server/src/main/kotlin/server.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,44 @@ fun configureServer(): Server {
)
}


server.addTool(
name = "get-country-asset-emissions",
description = "Get sector emission information for the given countries",
inputSchema = Tool.Input(
properties = buildJsonObject {
putJsonObject("countryCodeList") {
put("type", JsonPrimitive("array"))
putJsonObject("items") {
put("type", JsonPrimitive("string"))
}
}
},
required = listOf("countryCodeList")
)
) { request ->
val countryCodeList = request.arguments["countryCodeList"]
if (countryCodeList == null) {
return@addTool CallToolResult(
content = listOf(TextContent("The 'countryCodeList' parameters are required."))
)
}

val countryAssetEmissionInfo = climateTraceRepository.fetchCountryAssetEmissionsInfo(
countryCodeList = countryCodeList
.jsonArray
.map { it.jsonPrimitive.content }
)
CallToolResult(
content = countryAssetEmissionInfo.map { TextContent("${it.key}, ${it.value}") }
)
}



server.addTool(
name = "get-emissions",
description = "List emission info for a particular country",
description = "Get total emission information for the given countries",
inputSchema = Tool.Input(
properties = buildJsonObject {
putJsonObject("countryCodeList") {
Expand Down