Skip to content

McpSchema.Tool should expose outputSchema via public accessor instead of requiring reflection #783

@sivakothuri

Description

@sivakothuri

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions