Fix: keep MCP diagnostics observations within the model context budget#377
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR reduces MCP diagnostics payload size so diagnostics-first harnesses can record baselines and inspect reports without overflowing model context.
Changes:
- Adds a configurable cap for diagnostics included in
get_diagnosticsobservation envelopes. - Changes
diagnostics_baselineto store diagnostics server-side without echoing the full file list. - Adds tests for baseline payload shape, truncation, source summaries, and structured next actions.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
ai-code-mcp-server.el |
Implements capped diagnostics envelopes and compact baseline responses. |
test/test_ai-code-mcp-server.el |
Adds ERT coverage for the new diagnostics response behavior. |
Make the truncation note context-aware: delta reports only point to per-file uri narrowing (the caller already filters with since=baseline), while current reports frame since=baseline as a way to focus on newly introduced diagnostics rather than to page through omitted ones. Restrict ai-code-mcp-diagnostics-max-report-diagnostics to a non-negative integer (natnum) so a negative cap can no longer silently hide every diagnostic while still reporting status as issues.
Owner
Author
|
feedbacks have been addressed. |
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
The
diagnostics_baselineMCP tool was returning the full project diagnostics list in its response. On a checkdoc-heavy Elisp project that payload reached ~245 KB and could not fit in the model context, which broke the diagnostics-first TDD harness (the harness callsdiagnostics_baselinebefore editing). Since the baseline is meant to be recorded server-side, echoing every diagnostic back into the model context contradicted its own design. This PR makes the diagnostics observations context-safe and a bit more actionable.What changed
diagnostics_baselineno longer echoes the diagnostics list. The baseline is already stored server-side in the identity-count table, so the response now carries onlystatus, asummary(with the count), and a structurednext_actionsstep. The payload drops from ~245 KB to a constant ~120 B regardless of project size.get_diagnosticsreports are bounded. The shared observation envelope now capsfilesandnext_actionsat a new defcustomai-code-mcp-diagnostics-max-report-diagnostics(default 200). Thesummaryalways reports the true totals and notes when the list was truncated, so the project-wide path cannot overflow the context either.summarygains aTop sources:breakdown (which checkers dominate), and the structurednext_actionstells the agent exactly how to verify — edit, then callget_diagnosticswithsince="baseline"untilstatusisclean.Verification
next_actions. The fulltest_ai-code-mcp-server.elsuite passes (38/38) and the module byte-compiles with no warnings.baselinethenregressionwhen a new diagnostic appears, thencleanonce it is fixed.