Skip to content

Feature Request: Add Structured Content Support #219

@Edison-A-N

Description

@Edison-A-N

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions