Skip to content

feat: Add JSON output format option to key tools #9

@patrickfreyer

Description

@patrickfreyer

Summary

Add a format parameter to key tools to enable structured JSON output alongside human-readable text.

Motivation

Current tools return formatted strings - great for display but hard to process programmatically. JSON output enables:

  • Chaining tool results
  • Integration with other systems
  • Custom formatting by consumers

Proposed Changes

Add format: Literal["text", "json"] = "text" to these tools:

  • get_recent_emails
  • search_emails
  • search_all_accounts
  • get_inbox_overview
  • get_unread_count (already returns dict, standardize)
  • list_accounts (already returns list, standardize)

Example

@mcp.tool()
def get_recent_emails(
    account: str,
    count: int = 10,
    format: Literal["text", "json"] = "text"
) -> str | List[Dict]:
    """Get recent emails.
    
    Args:
        format: Output format
            - "text": Human-readable formatted string (default)
            - "json": Structured list of email dictionaries
    """
    # ... implementation
    
    if format == "json":
        return json.dumps(emails, indent=2)
    else:
        return format_emails_as_text(emails)

JSON Schema for Emails

{
  "subject": "string",
  "sender": "string", 
  "date": "ISO8601 string",
  "is_read": boolean,
  "mailbox": "string",
  "account": "string",
  "preview": "string (optional)"
}

Priority

MEDIUM - Enables programmatic use

Labels

enhancement, priority-medium, api-design

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions