Skip to content

Commit d32b905

Browse files
authored
Show/remove $schema (#24)
1 parent 6420be7 commit d32b905

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

core/src/main/scala/chimp/McpHandler.scala

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,27 @@ import sttp.tapir.docs.apispec.schema.TapirSchemaToJsonSchema
1919
* The server name (for protocol reporting).
2020
* @param version
2121
* The server version (for protocol reporting).
22+
* @param showJsonSchemaMetadata
23+
* Whether to include JSON Schema metadata (such as $schema) in the tool input schemas. Some agents do not recognize it, so it can be
24+
* disabled.
2225
*/
23-
class McpHandler[F[_]](tools: List[ServerTool[?, F]], name: String = "Chimp MCP server", version: String = "1.0.0"):
26+
class McpHandler[F[_]](
27+
tools: List[ServerTool[?, F]],
28+
name: String = "Chimp MCP server",
29+
version: String = "1.0.0",
30+
showJsonSchemaMetadata: Boolean = true
31+
):
2432
private val logger = LoggerFactory.getLogger(classOf[McpHandler[_]])
2533
private val ProtocolVersion = "2025-03-26"
2634
private val toolsByName = tools.map(t => t.name -> t).toMap
2735

2836
/** Converts a ServerTool to its protocol definition. */
2937
private def toolToDefinition(tool: ServerTool[?, F]): ToolDefinition =
30-
val jsonSchema = TapirSchemaToJsonSchema(tool.inputSchema, markOptionsAsNullable = true)
38+
val jsonSchema =
39+
val base = TapirSchemaToJsonSchema(tool.inputSchema, markOptionsAsNullable = true)
40+
if showJsonSchemaMetadata then base
41+
else base.copy($schema = None)
42+
3143
val json = jsonSchema.asJson
3244
ToolDefinition(
3345
name = tool.name,

core/src/main/scala/chimp/mcpEndpoint.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,14 @@ private val logger = LoggerFactory.getLogger(classOf[McpHandler[_]])
2121
* @tparam F
2222
* The effect type. Might be `Identity` for a endpoints with synchronous logic.
2323
*/
24-
def mcpEndpoint[F[_]](tools: List[ServerTool[?, F]], path: List[String]): ServerEndpoint[Any, F] =
25-
val mcpHandler = new McpHandler(tools)
24+
def mcpEndpoint[F[_]](
25+
tools: List[ServerTool[?, F]],
26+
path: List[String],
27+
name: String = "Chimp MCP server",
28+
version: String = "1.0.0",
29+
showJsonSchemaMetadata: Boolean = true
30+
): ServerEndpoint[Any, F] =
31+
val mcpHandler = new McpHandler(tools, name, version, showJsonSchemaMetadata)
2632
val e = infallibleEndpoint.post
2733
.in(path.foldLeft(emptyInput)((inputSoFar, pathComponent) => inputSoFar / pathComponent))
2834
.in(extractFromRequest(_.headers))

0 commit comments

Comments
 (0)