fastapi_mcp icon indicating copy to clipboard operation
fastapi_mcp copied to clipboard

Feature Request: Add Structured Content Support

Open Edison-A-N opened this issue 8 months ago • 1 comments

Is your feature request related to a problem? Please describe. Currently, the FastAPI MCP server converts JSON responses to formatted text strings. This limits the ability to provide structured data that can be easily consumed by MCP clients.

Describe the solution you'd like Add support for returning StructuredContent when API responses are valid JSON. This would involve:

  1. Enhanced Return Type: Modify _execute_api_tool to return StructuredContent for JSON responses
  2. Configuration Option: Add prefer_structured_content: bool = False parameter to control behavior. Defaults to False for backwards compatibility.
  3. Backward Compatibility: Preserve existing text content behavior when disabled

Describe alternatives you've considered

  • Always return structured content (might break existing clients)
  • Separate method for structured content (adds complexity)
  • Content negotiation (overly complex for this use case)

Additional context Current implementation converts JSON to formatted text strings. This change would allow MCP clients to receive properly typed structured data instead of text, while maintaining backward compatibility through a configuration option.

Key Benefits The main advantage is that StructuredContent supports outputSchema, which enables LLMs to understand tool output schemas and create tool chains for single-step execution of multiple tools in sequence.

Edison-A-N avatar Aug 13 '25 09:08 Edison-A-N

i think this is important feature

Zarqu0n avatar Sep 22 '25 11:09 Zarqu0n