-
Notifications
You must be signed in to change notification settings - Fork 49
Add server-wide JSON output format support #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add server-wide JSON output format support #25
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.
There was a problem hiding this 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_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
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