feat: add summary_only parameter to reduce response size#7
Open
ljadach wants to merge 3 commits into
Open
Conversation
…queries Adds an optional `summary_only` boolean parameter (default: False) to 7 query tools. When enabled, time-series arrays and non-essential metadata are stripped from responses while preserving all key metrics. Affected tools and estimated size reductions: - query_sleep_data: ~95% (strips per-minute movement, HR, stress, respiration) - query_health_summary: ~65-75% (skips duplicate stats, strips BB time-series) - query_heart_rate_data: ~90% (strips heartRateValues array) - query_activities: ~60-70% (strips userRoles, splitSummaries, profile data) - query_weight_data: strips device metadata (minor) - get_performance_metrics: strips HRV readings arrays - analyze_training_period: skips weekly trend computation Implementation approach: - Default behavior is unchanged (summary_only=False) - Filtering happens after API calls, before response building - Uses key-set stripping for predictable, maintainable filtering - Adds format_activity_summary() to ResponseBuilder for activity filtering Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ests Post-review cleanup: - Move _strip_keys to response_builder.py as shared strip_keys() function - Extract _HRV_DETAIL_KEYS constant in training.py (was inline set literal) - Extract _activity_formatter() helper in activities.py (was 5x ternary) - Add unit tests for strip_keys() and format_activity_summary() Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ering Found during live testing: - Sleep: wellnessEpochRespirationAveragesList was not in the blocklist (different key name from wellnessEpochRespirationDataDTOList) - Weight: API returns nested dailyWeightSummaries dict, not a flat list. Updated _summarize_weigh_ins to handle the nested structure. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
summary_onlyboolean parameter (default:False) to 7 query toolsMotivation
MCP tool responses contain large time-series arrays (per-minute sleep movement, heart rate readings, HRV data, etc.) that are rarely needed by LLM consumers. For routine health checks, these arrays account for 90%+ of response size while providing no additional value.
For example,
query_sleep_datareturns ~95K characters for a single night, but the essential metrics (sleep duration, scores, averages) fit in ~2K characters. This wastes context window budget and increases token costs significantly for daily/weekly health monitoring workflows.Changes
query_sleep_dataquery_health_summarystatscall, Body Battery time-seriesquery_heart_rate_dataheartRateValuestime-series arrayquery_activitiesuserRoles,splitSummaries, profile images, connectIQ dataquery_weight_dataget_performance_metricsanalyze_training_periodImplementation
strip_keys()utility inresponse_builder.pyfor consistent filteringformat_activity_summary()inResponseBuilderfor activity-specific field selectionstrip_keys()andformat_activity_summary()Usage
Test plan
ruff checkandruff formatpasssummary_only=False) is identical to pre-change behavior🤖 Generated with Claude Code