Skip to content

Conversation

@sam-at-luther
Copy link

Summary

This PR adds server-wide JSON output format support to all MCP tools. Users can now configure the output format via the OUTPUT_FORMAT environment variable to receive structured JSON responses instead of formatted markdown/text.

Changes

  • ✅ Added OUTPUT_FORMAT environment variable (defaults to "markdown" for backward compatibility)
  • ✅ Updated all 15 tools to support JSON output when OUTPUT_FORMAT="json"
  • ✅ Added format_as_json() helper function with custom serializers for dates, decimals, and Oracle-specific types
  • ✅ Added comprehensive test coverage for JSON output format
  • ✅ Updated README with documentation for the new feature

Benefits

  • Programmatic Integration: JSON output makes it easier to integrate MCP server responses into automated workflows, APIs, or other programs
  • Structured Data: All tools now return consistent JSON structures that are easy to parse and process
  • Backward Compatible: Default behavior unchanged - markdown format is still the default

Example JSON Output

When OUTPUT_FORMAT="json":

  • run_sql_query returns: {"row_count": N, "columns": [...], "rows": [...]}
  • get_table_schema returns: {"table_name": "...", "columns": [...], "relationships": {...}}
  • get_table_constraints returns: {"table_name": "...", "constraints": [...]}
  • And similarly for all other tools

Testing

  • ✅ Added unit tests for JSON formatting with various data types
  • ✅ Added integration tests for JSON output with actual database queries
  • ✅ All existing tests pass (backward compatibility verified)

Documentation

  • ✅ Updated README with OUTPUT_FORMAT configuration examples
  • ✅ Added examples showing JSON output structure for different tools

- Add OUTPUT_FORMAT environment variable (markdown/json)
- Update all tools to support JSON output when OUTPUT_FORMAT=json
- Add format_as_json helper function with custom serializers for dates/decimals
- Add comprehensive tests for JSON output format
- Update README documentation for OUTPUT_FORMAT option

This change makes it easier to integrate MCP server output into
automated workflows, APIs, or other programs that need structured
data rather than formatted text. Backward compatible - defaults to
markdown format if OUTPUT_FORMAT is not set.
Copilot AI review requested due to automatic review settings November 3, 2025 16:32
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds server-wide JSON output format support to all MCP tools. Users can now configure the output format via the OUTPUT_FORMAT environment variable to receive structured JSON responses instead of formatted markdown/text.

  • Added OUTPUT_FORMAT environment variable with default value of "markdown" for backward compatibility
  • Updated all 15 tools to support JSON output format when OUTPUT_FORMAT="json"
  • Added comprehensive test coverage for JSON output format functionality

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/unit/test_json_output.py New unit tests for JSON formatting with dates, decimals, nested structures, and null values
tests/unit/test_formatter_output.py Added JSON output format tests for SQL query results and format_as_json helper
tests/integration/test_query_result_formatting.py Added integration tests for JSON output with actual database queries
main.py Updated all 15 tools to support JSON output format based on OUTPUT_FORMAT environment variable
db_context/schema/formatter.py Added format_as_json helper function and JSON serialization support to format_sql_query_result
README.md Updated documentation with OUTPUT_FORMAT configuration examples and JSON output structure

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant