Skip to content

feat(mcp-server-supabase): add level filter and per-lint findings cap to get_advisors - #574

Closed
francis-codex wants to merge 1 commit into
supabase:mainfrom
francis-codex:fix/advisors-level-limit
Closed

francis-codex wants to merge 1 commit into
supabase:mainfrom
francis-codex:fix/advisors-level-limit

Conversation

@francis-codex

@francis-codex francis-codex commented Nov 18, 2026 •

Copy link
Copy Markdown

What kind of change does this PR introduce?

Feature: two optional inputs on get_advisors.

What is the current behavior?

Closes #124.

#390 grouped repeated lints, which fixed the "same lint 300 times" case. Projects with many distinct findings still get oversized responses, because each group carries its full findings list. The agent has no way to ask for less, so it either truncates client-side or gives up on the tool.

What is the new behavior?

Implements the shape @Brian-1812 proposed in #124:

  • level (ERROR | WARN | INFO): keeps only lints at that level. Applied before grouping, so count reflects the filtered set.
  • max_findings_per_lint (int >= 1): caps the findings listed under each grouped lint. count keeps the true total and findings_omitted is added only when something was cut.

The cap is per lint instead of one global limit. A global cap applied in order lets one noisy lint (e.g. 200 unused_index) fill the budget and hide an ERROR lint further down. Per lint, every lint type stays visible and the response size is bounded by lint types × cap.

With neither input set the output is byte-identical to today. Unknown response shapes still pass through untouched.

How to Review

  1. Result shaping

    • packages/mcp-server-supabase/src/tools/debugging-tools.ts
    • groupAdvisorsResult now takes options: filter, then groupAdvisorLints, then capFindings. The schema changes are on getAdvisorsInputSchema, and the legacy schema inherits them through .extend.
  2. Tests

    • packages/mcp-server-supabase/src/server.debugging.test.ts
    • The new case covers a level filter that drops a WARN lint, a group capped from 3 to 2 with findings_omitted: 1, and a group under the cap that gets no findings_omitted key.

Review questions

  • Is max_findings_per_lint the right name, or would you rather keep limit from the issue thread?
  • Should findings_omitted always be present (as 0) for a stable shape, or only when non-zero as here?
  • Both inputs apply to all three advisor types (security, performance, health) since they share the lints shape. Any type where you'd rather not expose them?

Verification

pnpm --filter @supabase/mcp-server-supabase test:unit --run
 Test Files  35 passed (35)
      Tests  930 passed (930)

pnpm --filter @supabase/mcp-server-supabase exec tsc --noEmit   # clean
pnpm format:check                                               # Checked 141 files, no fixes

No eval added. Happy to add one if you'd like the size reduction measured on a seeded project.

Additional context

@Brian-1812 offered to take this on 11 Nov. I've used his proposed API and credited it here. If you already have a branch, I'm glad to close this in favour of yours.

… to get_advisors

Projects with many distinct findings still produce oversized get_advisors
responses after supabase#390 grouped repeated lints, because every group carries
its full findings list. Add two optional inputs:

- level: keep only ERROR, WARN or INFO lints (applied before grouping)
- max_findings_per_lint: cap the findings listed under each lint; count
  keeps the true total and findings_omitted reports what was cut

The cap is per lint rather than global so a long tail of one lint cannot
crowd every other lint out of the response. Default output is unchanged.

Refs supabase#124
@francis-codex
francis-codex requested a review from a team as a code owner November 18, 2026 09:43
@Brian-1812

Brian-1812 commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the credit, go ahead.

@francis-codex

Copy link
Copy Markdown
Author

thanks brian, appreciate it. will ping you if the review turns up anything on the cap.

@francis-codex

Copy link
Copy Markdown
Author

@gregnr ready for review when you have a moment. this adds an optional level filter and a per-lint max_findings_per_lint cap to get_advisors, so projects with many distinct findings stay under client token limits (#124, which #390's grouping doesn't fully cover). both params are optional, so default output is unchanged. 930/930 unit tests pass, tsc + biome clean. happy to adjust the cap default or naming if you'd rather shape it differently.

@barryroodt

Copy link
Copy Markdown
Contributor

Thanks for picking this up, and for crediting Brian's proposal! The change itself looks good. We're holding it for now because #546 adds get_issues and plans to deprecate get_advisors, so we need to decide where a filter + cap should live. I'll follow up here once that's settled.

@Brian-1812

Brian-1812 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

hey, what if keep the filter and cap only in get_issues and leave get_advisors as it is. #546 already has both: severity as a minimum level, and up to 20 findings per issue with affected_count for the total.

New inputs on get_advisors wouldn't reach anyone that get_issues doesn't. Once #546 ships, a client that re-reads tools/list also sees get_issues, and the frozen ChatGPT snapshot sees neither.

The cost of that choice is that get_advisors stays uncapped until it is removed. And in get_issues the cap is per issue, so the total still grows with the number of issues: on a synthetic project shaped like the Mockamaster capture (11 issues, 547 findings), the default call came out at 65-85k characters. About a quarter of that is the same docs_url repeated on every finding.
If you want, I can move that link up to the issue level instead of repeating it on every finding, and add a size test on get_issues before it goes into a ChatGPT submission, while its output schema can still change.

@francis-codex

Copy link
Copy Markdown
Author

@barryroodt agree with brian, the cap belongs in get_issues. happy to close this once #546 lands so there's one place to maintain. to help #546 along, i'll take the eval mattrossman asked for in supabase/evals: a large-project scenario (Mockamaster-shaped, 500+ findings) that has to pass with get_issues and stay under a set output size, run through the #514 local-repo flow. @Brian-1812 that pairs with your docs_url move and size test, so we don't overlap

francis-codex added a commit to francis-codex/evals that referenced this pull request Nov 25, 2026
…on eval

Adds 10 Supabase database linter checks to platform-lite (security:
policy_exists_rls_disabled, rls_enabled_no_policy, security_definer_view,
function_search_path_mutable, materialized_view_in_api; performance:
unindexed_foreign_keys, auth_rls_initplan, no_primary_key,
multiple_permissive_policies, duplicate_index). The performance advisor
now returns real lints instead of an empty list. rls_disabled_in_public
remediation is now the docs URL, matching the hosted API.

New regression eval investigate-database-001-large-advisor-backlog seeds
a Mockamaster-shaped project: 547 findings in 11 issues, 8 at warning or
worse, and 3 critical issues that all trace to public.payments having RLS
disabled. It checks get_issues was called, its output stayed under 100k
chars without harness truncation, and the agent ranked enabling RLS on
public.payments first.

The experiment pins supabase/mcp at a0137116 (supabase#546 head) so it runs
without a local MCP checkout. Drop the pin once get_issues ships.

Refs supabase/mcp#546, supabase/mcp#574
@francis-codex

Copy link
Copy Markdown
Author

updated supabase/evals#552 so it matches mockamaster and runs without a local mcp checkout.

once docs_url moves to issue level, the default size here should drop. i'll re-measure then.

@barryroodt

Copy link
Copy Markdown
Contributor

Agreed, @Brian-1812. I'm closing this PR and keeping the filter + cap in get_issues only.

#546 has merged and we're releasing it today. Its get_issues tool takes a severity input for the minimum level, and each issue includes up to 20 findings with affected_count for the total. We're planning to deprecate get_advisors, and any client that would see new inputs there will already have get_issues.

Thanks for the clean change, @francis-codex! I had no concerns with the code.

Brian, I got similar numbers on #546. Dropping the per-finding docs_url cut the output by about 21%, so I'd welcome a follow-up PR from you that removes it from the findings and adds the size test.

@barryroodt barryroodt closed this Nov 25, 2026
barryroodt pushed a commit that referenced this pull request Nov 26, 2026
## What kind of change does this PR introduce?

Bug fix (response size). Follow-up to #546, as @barryroodt asked on #574
([comment](#574 (comment))).
Refs #124.

## What is the current behavior?

Every finding in `get_issues` repeats its issue's `docs_url`. In
splinter, each lint has one fixed remediation link, so these copies add
no data for splinter lints. On a project the size of the Mockamaster
capture in #546 (547 findings in 11 issues), the copies are about 22% of
the default response.

## What is the new behavior?

Findings no longer carry `docs_url`. The issue keeps its `docs_url`, so
every finding still reaches the link through its issue. Nothing else in
the output changes.

| Call | Before | After | Saved (chars / tokens) |
|---|---:|---:|---:|
| default | 62,296 chars, 15,225 tokens | 48,243 chars, 11,614 tokens |
22.6% / 23.7% |
| `severity: warning` | 43,789 chars, 10,533 tokens | 34,836 chars,
8,252 tokens | 20.4% / 21.7% |

I ran the real splinter SQL in PGlite on the supabase/evals#552 seed and
fed the lints to the real `get_issues` on `main`. Splinter also flags 41
unused indexes there, because a fresh database has no index scans. I
left those out to match 547 findings in 11 issues. With them, the
default call goes from 69,279 to 53,346 chars (23.0%). Tokens are OpenAI
`o200k_base`; I did not count Claude tokens. In every call I ran, each
removed link was equal to its issue's link, and the rest of the output
is byte-identical.

There is exactly one way this change can lose data: two findings of the
same lint with different docs links, where the second link is now gone.
I checked splinter at
[`cc529aa9`](https://github.com/supabase/splinter/blob/cc529aa9d3eeffd2e64576c7591e60b22abd205c/splinter.sql):
each of its 31 lints has one constant remediation, so this can't happen
there. I can't see the platform-only and health lints, though: can you
confirm that none of them gives two findings of one lint different
links?

## How to Review

1. **Output contract**
   - `packages/mcp-server-supabase/src/issues.ts`
- `docs_url` leaves the finding schema and the finding object. The
issue-level `docs_url` does not change. `get_issues` uses this schema as
its output schema, so `tools/list` changes too.

2. **Tests**
- `packages/mcp-server-supabase/src/server.debugging.test.ts`: a new
size test calls `get_issues` through the server harness on 547 findings
in 11 issues. The default response must stay under
`LARGE_PROJECT_ISSUES_BUDGET` (48,000 chars).
- `packages/mcp-server-supabase/src/issues.test.ts`: one #546 test gave
two findings of one issue different links. It now checks the issue's
link, and that a finding has no `docs_url`.

**Review questions**

- [ ] Is 48,000 chars a good budget? It is about 10% above today's
43,493 for this fixture, so it catches growth early. It is well under
the 25,000-token limit from #124.
- [ ] If a platform-only or health lint can give different links
(question above), should I keep `docs_url` on a finding only when it
differs from the issue's link?
- [ ] Should this land before the release in #586? Then no published
version has `docs_url` on findings.
- [ ] Do the tests check output, not implementation details?

## Verification

- With `main`'s `issues.ts`, the new size test fails with `expected
56866 to be less than 48000`. On this branch it passes at 43,493.
- `pnpm format:check`, `tsc --noEmit`, and `vitest run --project unit`:
1028/1028 passed.

## Additional context

This changes the `get_issues` output schema: `issues[].affected[]` no
longer has `docs_url`. So it is best merged before that schema goes into
a ChatGPT submission. If #586 merges first, the field is in a published
release. Then I will mark the commit as breaking, as CONTRIBUTING asks
for a contract step.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

get_advisors tool returns responses exceeding token limits without pagination support

3 participants