fix: support valid JSON value in tool structured content output (#551)
- Change CallToolResult.structuredContent type from Map<String,Object> to Object to support both objects and arrays - Update JsonSchemaValidator to validate any Object type, not just Maps - Add test cases for array-type structured output validation - Fix type casting in existing tests to handle the more generic Object type - Deprecate CallToolResult constructors in favor of builder pattern - Update server implementations to use CallToolResult builder This allows tools to return arrays as structured content, not just objects, which is required by the MCP specification for tools with array-type output schemas. It is realated to MPC spec fix: https://github.com/modelcontextprotocol/modelcontextprotocol/issues/834 Fixes #550 BREAKING CHANGE! Migration Guide: ---------------- 1. If you're accessing CallToolResult.structuredContent(): - Add explicit casting when you know it's a Map: Before: result.structuredContent().get("key") After: ((Map<String,Object>) result.structuredContent()).get("key") - Or check the type first: if (result.structuredContent() instanceof Map) { Map<String,Object> map = (Map<String,Object>) result.structuredContent(); // use map } else if (result.structuredContent() instanceof List) { List<?> list = (List<?>) result.structuredContent(); // use list } 2. If you're creating CallToolResult instances: - Switch to using the builder pattern: Before: new CallToolResult(content, isError, structuredContent) After: CallToolResult.builder() .content(content) .isError(isError) .structuredContent(structuredContent) .build() 3. If you're implementing JsonSchemaValidator: - Update your validate() method signature: Before: validate(Map<String,Object> schema, Map<String,Object> structuredContent) After: validate(Map<String,Object> schema, Object structuredContent) Signed-off-by:Christian Tzolov <christian.tzolov@broadcom.com>
Loading
Please sign in to comment