11package io .seequick .mcp .tool ;
22
3+ import com .fasterxml .jackson .core .type .TypeReference ;
4+ import com .fasterxml .jackson .databind .ObjectMapper ;
35import io .fabric8 .kubernetes .client .KubernetesClient ;
46import io .modelcontextprotocol .server .McpServerFeatures ;
5- import io .modelcontextprotocol .server .McpSyncServerExchange ;
67import io .modelcontextprotocol .spec .McpSchema .CallToolResult ;
8+ import io .modelcontextprotocol .spec .McpSchema .JsonSchema ;
79import io .modelcontextprotocol .spec .McpSchema .TextContent ;
810import io .modelcontextprotocol .spec .McpSchema .Tool ;
911
1517 */
1618public abstract class AbstractStrimziTool implements StrimziTool {
1719
20+ private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper ();
21+
1822 protected final KubernetesClient kubernetesClient ;
1923
2024 protected AbstractStrimziTool (KubernetesClient kubernetesClient ) {
@@ -34,17 +38,50 @@ protected AbstractStrimziTool(KubernetesClient kubernetesClient) {
3438 /**
3539 * Returns the JSON schema for the tool's input parameters.
3640 */
37- protected abstract String getInputSchema ();
41+ protected abstract JsonSchema getInputSchema ();
3842
3943 /**
4044 * Executes the tool with the given arguments.
4145 */
4246 protected abstract CallToolResult execute (Map <String , Object > args );
4347
48+ /**
49+ * Parses a JSON schema string into a JsonSchema object.
50+ */
51+ @ SuppressWarnings ("unchecked" )
52+ protected static JsonSchema parseSchema (String jsonSchema ) {
53+ try {
54+ Map <String , Object > schemaMap = OBJECT_MAPPER .readValue (
55+ jsonSchema , new TypeReference <>() {});
56+
57+ String type = (String ) schemaMap .get ("type" );
58+ Map <String , Object > properties = (Map <String , Object >) schemaMap .get ("properties" );
59+ List <String > required = (List <String >) schemaMap .get ("required" );
60+ Boolean additionalProperties = schemaMap .get ("additionalProperties" ) instanceof Boolean b ? b : null ;
61+ Map <String , Object > defs = (Map <String , Object >) schemaMap .get ("$defs" );
62+ Map <String , Object > definitions = (Map <String , Object >) schemaMap .get ("definitions" );
63+
64+ return new JsonSchema (
65+ type ,
66+ properties ,
67+ required ,
68+ additionalProperties ,
69+ defs ,
70+ definitions
71+ );
72+ } catch (Exception e ) {
73+ throw new RuntimeException ("Failed to parse JSON schema: " + e .getMessage (), e );
74+ }
75+ }
76+
4477 @ Override
4578 public McpServerFeatures .SyncToolSpecification getSpecification () {
4679 return new McpServerFeatures .SyncToolSpecification (
47- new Tool (getName (), getDescription (), getInputSchema ()),
80+ Tool .builder ()
81+ .name (getName ())
82+ .description (getDescription ())
83+ .inputSchema (getInputSchema ())
84+ .build (),
4885 (exchange , args ) -> execute (args )
4986 );
5087 }
0 commit comments