You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
McpSchema.Tool should expose outputSchema via public accessor instead of requiring reflection #783
When building CallToolResult for tools that declare an outputSchema, the SDK 0.17.2 requires structuredContent to be included in the response. However, there is no clean public API to check whether a McpSchema.Tool has an outputSchema set.
Currently, we are forced to use Java reflection to access the outputSchema field: Object outputSchema = null; try { java.lang.reflect.Field field = tool.getClass().getDeclaredField("outputSchema"); field.setAccessible(true); outputSchema = field.get(tool); } catch (Exception e) { // No outputSchema field or access failed }
This approach is:
Fragile — breaks if the field is renamed or the class structure changes Incompatible with module system — setAccessible(true) may fail under strict Java module rules (Java 17+) Not idiomatic — McpSchema.Tool is a record, so it should already have an outputSchema() accessor
Expected Behavior:
McpSchema.Tool should expose a public outputSchema() method (or it already does as a record accessor, but it returns Map<String, Object> which may be null). The SDK should clearly document:
How to check if a tool has an outputSchema
Whether structuredContent is mandatory when outputSchema is present
Provide a utility or builder pattern that auto-handles the structured vs text content decision
Suggested Fix:
If Tool is a record, simply use tool.outputSchema() — document this clearly. If it's not exposed, add a public getter.
This appears to be resolved as of PR #302 (feat(client): add client tool output schema validation and caching). The Tool record now includes outputSchema as a field:
Thanks for the update! We've implemented this change in our codebase.
Replaced all reflection-based outputSchema access with the direct
tool.outputSchema() accessor method. Works great with SDK 0.18.1+ -
much cleaner approach than reflection. Appreciate the guidance!
You can close the ticket now.
Activity
rameshreddy-adutla commentedon Mar 4, 2026
This appears to be resolved as of PR #302 (
feat(client): add client tool output schema validation and caching). TheToolrecord now includesoutputSchemaas a field:Since
Toolis a Java record, the public accessortool.outputSchema()is automatically available — no reflection needed.Could this issue be closed?
sivakothuri commentedon Mar 5, 2026
tzolov commentedon Aug 17, 2026
Tool is a record in v2 — outputSchema() accessor exists. Fixed;