Skip to content

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

Closed

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.

Activity

  1. rameshreddy-adutla commented on Mar 4, 2026

    @rameshreddy-adutla
    Contributor

    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:

    public record Tool(
        @JsonProperty("name") String name,
        @JsonProperty("title") String title,
        @JsonProperty("description") String description,
        @JsonProperty("inputSchema") JsonSchema inputSchema,
        @JsonProperty("outputSchema") Map<String, Object> outputSchema,
        @JsonProperty("annotations") ToolAnnotations annotations,
        @JsonProperty("_meta") Map<String, Object> meta)

    Since Tool is a Java record, the public accessor tool.outputSchema() is automatically available — no reflection needed.

    Could this issue be closed?

  2. sivakothuri commented on Mar 5, 2026

    @sivakothuri
    Author
  3. tzolov commented on Aug 17, 2026

    @tzolov
    Contributor

    Tool is a record in v2 — outputSchema() accessor exists. Fixed;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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