Skip to content

Fix: keep MCP diagnostics observations within the model context budget#377

Merged
tninja merged 4 commits into
mainfrom
kang_feat_11
May 31, 2026
Merged

Fix: keep MCP diagnostics observations within the model context budget#377
tninja merged 4 commits into
mainfrom
kang_feat_11

Conversation

@tninja
Copy link
Copy Markdown
Owner

@tninja tninja commented May 31, 2026

Summary

The diagnostics_baseline MCP 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 calls diagnostics_baseline before 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_baseline no longer echoes the diagnostics list. The baseline is already stored server-side in the identity-count table, so the response now carries only status, a summary (with the count), and a structured next_actions step. The payload drops from ~245 KB to a constant ~120 B regardless of project size.
  • get_diagnostics reports are bounded. The shared observation envelope now caps files and next_actions at a new defcustom ai-code-mcp-diagnostics-max-report-diagnostics (default 200). The summary always reports the true totals and notes when the list was truncated, so the project-wide path cannot overflow the context either.
  • More signal, less bulk. The baseline summary gains a Top sources: breakdown (which checkers dominate), and the structured next_actions tells the agent exactly how to verify — edit, then call get_diagnostics with since="baseline" until status is clean.

Verification

  • New ERT tests cover each behavior: the baseline response omits the list, the envelope truncates large reports, the summary names top sources, and the baseline response carries next_actions. The full test_ai-code-mcp-server.el suite passes (38/38) and the module byte-compiles with no warnings.
  • Verified live in Emacs: the baseline payload is constant (~120 B vs ~245 KB before), and the end-to-end harness loop converges correctly — baseline then regression when a new diagnostic appears, then clean once it is fixed.

Copy link
Copy Markdown
Contributor

Copilot AI left a 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 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_diagnostics observation envelopes.
  • Changes diagnostics_baseline to 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.

Comment thread ai-code-mcp-server.el Outdated
Comment thread ai-code-mcp-server.el Outdated
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.
@tninja
Copy link
Copy Markdown
Owner Author

tninja commented May 31, 2026

feedbacks have been addressed.

@tninja tninja merged commit 7911176 into main May 31, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants