Add server-wide JSON output format support#25
Open
sam-at-luther wants to merge 8 commits intodanielmeppiel:mainfrom
Open
Add server-wide JSON output format support#25sam-at-luther wants to merge 8 commits intodanielmeppiel:mainfrom
sam-at-luther wants to merge 8 commits intodanielmeppiel:mainfrom
Conversation
- 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.
Contributor
There was a problem hiding this comment.
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_FORMATenvironment 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.
…ing for empty query results - Remove redundant 'matching_tables = limited_tables' assignment in search_tables_schema - Fix JSON formatting for empty query results with messages in run_sql_query - Ensure all empty result cases return JSON format when OUTPUT_FORMAT=json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds server-wide JSON output format support to all MCP tools. Users can now configure the output format via the
OUTPUT_FORMATenvironment variable to receive structured JSON responses instead of formatted markdown/text.Changes
OUTPUT_FORMATenvironment variable (defaults to"markdown"for backward compatibility)OUTPUT_FORMAT="json"format_as_json()helper function with custom serializers for dates, decimals, and Oracle-specific typesBenefits
Example JSON Output
When
OUTPUT_FORMAT="json":run_sql_queryreturns:{"row_count": N, "columns": [...], "rows": [...]}get_table_schemareturns:{"table_name": "...", "columns": [...], "relationships": {...}}get_table_constraintsreturns:{"table_name": "...", "constraints": [...]}Testing
Documentation
OUTPUT_FORMATconfiguration examples