<@U4H0M349G> we are encountering an issue where ou...
# http4k
m
@dave we are encountering an issue where our MCP Tool Responses are not getting serialised correctly, specifically there are some value classes that keep on being serialised with the nested object. We are using structuredContent for our responses, so the lens we use for the schema is also used for populating the content, and as a matter of fact even the schema is broken. Seems that lots of inner working in the library are using a global McpJson and we can't figure out a way to add our own customisation to it. Is this a limitation or are we missing something? cc @Jack Bolles
d
does your custom JSON extend ConfigurableMcpJson ?
is it the schema being generated incorrectly or during the tool call?
m
both. We kind of fixed the schema generator as we "copied" the Tool.Output.auto and injected our own ConfigurableMcpJson, but when using the lens out of that output, somewhere down the line it's still uses the "McpJson" object.
ToolOutputLensBuilder.toLens
uses
McpJson.asJsonObject
d
Try this patch:
Copy code
Subject: [PATCH] use custom json
---
Index: pro/ai/mcp/core/src/main/kotlin/org/http4k/ai/mcp/model/ToolOutputLensBuilder.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
+UTF-8
===================================================================
diff --git a/pro/ai/mcp/core/src/main/kotlin/org/http4k/ai/mcp/model/ToolOutputLensBuilder.kt b/pro/ai/mcp/core/src/main/kotlin/org/http4k/ai/mcp/model/ToolOutputLensBuilder.kt
--- a/pro/ai/mcp/core/src/main/kotlin/org/http4k/ai/mcp/model/ToolOutputLensBuilder.kt	(revision d1ff863d678140d34916c3314b74b08a5cc03b96)
+++ b/pro/ai/mcp/core/src/main/kotlin/org/http4k/ai/mcp/model/ToolOutputLensBuilder.kt	(date 1773407021178)
@@ -8,6 +8,8 @@
 import org.http4k.ai.mcp.protocol.ProtocolVersion
 import org.http4k.ai.mcp.protocol.ProtocolVersion.Companion.DRAFT
 import org.http4k.ai.mcp.protocol.ProtocolVersion.Companion.LATEST_VERSION
+import org.http4k.ai.mcp.util.ConfigurableMcpJson
+import org.http4k.ai.mcp.util.McpJson
 import org.http4k.ai.mcp.util.McpJson.asFormatString
 import org.http4k.ai.mcp.util.McpJson.asJsonObject
 import org.http4k.ai.mcp.util.McpNodeType
@@ -16,6 +18,7 @@
 import org.http4k.lens.ParamMeta.ObjectParam
 
 class ToolOutputLensBuilderOUT : Any(
+    private val json: ConfigurableMcpJson,
     internal val get: LensGetOk, OUT,
     private val toSchema: McpCapabilityLensOk, *.() -> McpNodeType
 ) {
@@ -28,10 +31,10 @@
         { get("response")(it).first() },
         { value, target ->
             when (protocolCapability) {
-                DRAFT -> target.copy(structuredContent = asJsonObject(value), content = null)
+                DRAFT -> target.copy(structuredContent = json.asJsonObject(value), content = null)
                 else -> target.copy(
-                    structuredContent = asJsonObject(value),
-                    content = listOf(Content.Text(asFormatString(value)))
+                    structuredContent = json.asJsonObject(value),
+                    content = listOf(Content.Text(json.asFormatString(value)))
                 )
             }
         },
Index: pro/ai/mcp/core/src/main/kotlin/org/http4k/ai/mcp/util/ConfigurableMcpJson.kt
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
+UTF-8
===================================================================
diff --git a/pro/ai/mcp/core/src/main/kotlin/org/http4k/ai/mcp/util/ConfigurableMcpJson.kt b/pro/ai/mcp/core/src/main/kotlin/org/http4k/ai/mcp/util/ConfigurableMcpJson.kt
--- a/pro/ai/mcp/core/src/main/kotlin/org/http4k/ai/mcp/util/ConfigurableMcpJson.kt	(revision d1ff863d678140d34916c3314b74b08a5cc03b96)
+++ b/pro/ai/mcp/core/src/main/kotlin/org/http4k/ai/mcp/util/ConfigurableMcpJson.kt	(date 1773407021187)
@@ -109,7 +109,7 @@
         val autoJsonToJsonSchema = AutoJsonToJsonSchema(this@ConfigurableMcpJson)
         val jsonSchemaCollapser = JsonSchemaCollapser(this@ConfigurableMcpJson)
 
-        return ToolOutputLensBuilder(
+        return ToolOutputLensBuilder(this@ConfigurableMcpJson,
             LensGet { _, target -> listOf(convert(target.structuredContent!!)) },
             { jsonSchemaCollapser.collapseToNode(autoJsonToJsonSchema.toSchema(example)) }
         )
ie, create your own ToolOutputLensBuilder and pass your custom JSON in
(I'll apply the fixes when we've narrowed it all down 🙂 )
👍 1
m
Just tried, worked fine. Thank you.
d
wicked. it will be in the next release. thanks for the report 🙂
very nice 1