feat: add --result-format CLI arg for compact query results (csv)#171
Open
Finndersen wants to merge 1 commit intoSnowflake-Labs:mainfrom
Open
feat: add --result-format CLI arg for compact query results (csv)#171Finndersen wants to merge 1 commit intoSnowflake-Labs:mainfrom
Finndersen wants to merge 1 commit intoSnowflake-Labs:mainfrom
Conversation
Adds a --result-format option (json/csv) to reduce token usage for large result sets. CSV format writes column names once in a header row rather than repeating them for every row. - Add --result-format arg to parse_arguments() with SNOWFLAKE_MCP_RESULT_FORMAT env var fallback - Store result_format on SnowflakeService and pass through from create_lifespan - Add results_to_csv() utility in utils.py; inline the format conditional at each of the three query return points (execute_query, fetch_results, run_query) - Update AnalystResponse.results type to accept str for CSV-formatted embedded results - Add tests for results_to_csv(), SnowflakeService.result_format, and CLI arg parsing - Document --result-format in README
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
--result-formatCLI argument (choices:json,csv) that controls how SQL query results are returned to the LLMSNOWFLAKE_MCP_RESULT_FORMATas well as the CLI flagMotivation
Query results are returned as
list[dict], where column names repeat for every row. For large result sets this can be wasteful with LLM tokens. CSV format can significantly reduce result size with no new dependencies (uses Python stdlibcsvmodule).Changes
server.py: Add--result-formatarg toparse_arguments(); storeresult_formatonSnowflakeService; pass through fromcreate_lifespanutils.py: Addresults_to_csv()utility; apply format atexecute_query()andSnowflakeResponse.fetch_results(); updateAnalystResponse.resultstype tostr | dict | listto accommodate CSV-formatted embedded resultsquery_manager/tools.py: Apply format atrun_query()README.md: Document the new option with usage example and caveatstests/test_result_format.py: Tests forresults_to_csv(),SnowflakeService.result_format, and CLI arg parsingCaveats
jsonso existing behaviour is unchangedTest plan
pytest mcp_server_snowflake/tests/— all tests pass--result-format csvand run a SQL query — verify CSV string with header row is returned