Skip to content

Expose structured MCP tool results for non-paged command return values #39

Description

@autocarl

Problem

MCP tool calls currently expose structured output primarily for paged Repl results.

For non-paged command handlers that return typed objects, Repl renders the result through the output pipeline and returns it as CallToolResult.Content text. Even when that text is JSON, the MCP tool does not generally advertise an outputSchema, and the call result does not generally populate StructuredContent.

That makes it harder for MCP clients and agents to distinguish:

  • human text fallback;
  • JSON-looking text;
  • actual structured tool result data with a declared schema.

Current behavior

  • McpSchemaGenerator.BuildOutputSchema(...) returns an output schema for paged results only.
  • McpToolAdapter.BuildToolResult(...) populates StructuredContent for paged result envelopes only.
  • Normal typed handler return values are exposed through text content.

Why this matters

Agents and MCP clients that understand outputSchema / StructuredContent should be able to consume typed Repl command results without parsing text fallbacks.

This is separate from MCP resources: resources now advertise the MIME type of the actual resource body. Tool calls need their own contract for typed return values.

Things to investigate

  • How Repl should infer or declare output schemas for non-paged handler return types.
  • Whether normal JSON-rendered command results should populate StructuredContent.
  • How to preserve a useful Content text fallback for clients that ignore structured content.
  • How Results.Success(...), Results.Error(...), void/no-output handlers, paged results, and custom output transformers should map to MCP tool result fields.
  • Whether this needs an explicit API, conventions, or documentation-only guidance first.

Related

Follow-up from #38, which fixed MCP resource MIME consistency but intentionally did not solve MCP tool return typing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions