I'm looking to integrate an MCP server that I've b...
# koog-agentic-framework
j
I'm looking to integrate an MCP server that I've been successfully using. with Claude Desktop but getting....
Copy code
ai.koog.agents.mcp.McpToolRegistryProvider - Failed to parse descriptor parameters for tool: get-emissions
java.lang.IllegalArgumentException: Parameter countryCode must be a JSON object
The MCP server is developed using Kotlin MCP SDK and includes
Copy code
server.addTool(
        name = "get-emissions",
        description = "List emission info for a particular country",
        inputSchema = Tool.Input(
            properties = JsonObject(
                mapOf(
                    "countryCode" to JsonPrimitive("string"),
                    "year" to JsonPrimitive("date"),
                )
            ),
            required = listOf("countryCode", "year")
        )
d
It doesn't look to me like this is a valid JSON schema. But I may be wrong. I think each property here should be a valid JSON schema type definition. Something like
{ "type": "string" }
. So the whole thing should look like:
Copy code
properties = JsonObject(
  mapOf(
    "countryCode" to JsonObject(
      mapOf("type" to "string")
    ),
    "year" to JsonObject(
      mapOf("type" to "date")
    ),
  )
),
(the "required" part looks correct to me) It would appear that Claude can accept invalid schema definitions...
j
ok, thanks, I'll try that shortly
ok, this is what ended up working here
Copy code
properties = buildJsonObject {
    putJsonObject("countryCode") {
        put("type", JsonPrimitive("string"))
    }
    putJsonObject("year") {
        put("type", JsonPrimitive("string"))
    }
},
👍 1
(from another one of the Kotlin MCP SDK samples)
Thanks for the help
❤️ 1
d
If you want to be precise, you can do that for `year`:
Copy code
"date": {
  "type": "string",
  "format": "date"
}
Though it appears this is really not stable yet (https://json-schema.org/draft/2020-12/json-schema-validation#name-dates-times-and-duration)
j
yeah, I had used "date" before there but hadn't seemed to work here
but string seemed to work anyway (it just takes in a year)
d
@John O'Reilly also, if you are writing you MCP server in Kotlin, I really recommend you this: https://github.com/xemantic/xemantic-ai-tool-schema. (there is another similar library in the field but I can't remember its name, but that's something that should IMO be part of kotlinx-serialization...). You define your
@Serializable
classes and let it generate the schema... You can see an examples of its uses here https://github.com/ptitjes/konvo/blob/main/konvo-mcp-web-tools/src/commonMain/kotlin/io/github/ptitjes/konvo/mcp/web/utils/ServerOps.kt#L31, here https://github.com/ptitjes/konvo/blob/main/konvo-mcp-web-tools/src/commonMain/kotlin/io/github/ptitjes/konvo/mcp/web/utils/JsonSchemaOf.kt and here https://github.com/ptitjes/konvo/blob/main/konvo-mcp-web-tools/src/commonMain/kotlin/io/github/ptitjes/konvo/mcp/web/KonvoWebTools.kt#L31
j
thanks, will take a look at that
this is the one I'm currently using https://github.com/modelcontextprotocol/kotlin-sdk
d
@John O'Reilly I am using the same SDK. The library I pointed "just" does the kotlinx-serialization -> JSON schema glue. You can see in one of the three github excerpts how I use
jsonSchemaOf
to call the
Server.addTool
with a simple Kotlin method reference and reified type parameters. All the typing info is already contained in the KSerializer.
jsonSchemaOf
is using that to produce a JSON schema. Then I simply wrap the
Server.addTool
call in a
inline fun <reified I, reified O> Server.addJsonTool(name: String, description: String, crossinline handler: suspend (I) -> O)
.
👍 1
k
I ran into a similar issue and just did some reified types on data classes with kotlin serialization