Skip to content

feat(agent): add source_filter to list_citations so the assistant can isolate owned/competitor citations #297

Closed

Description

@gkhngyk

Problem

When a user asks the in-product AI assistant something like "which of our URLs did the LLMs cite in brand X today?", the agent returns a generic, mixed report instead of isolating the brand's own cited URLs.

The list_citations tool already classifies every citation by source — web/src/lib/mcp/data.ts:listCitationsFor() loads brand_domains + competitors and tags each result with category: 'you' | 'competitor' | 'news' | 'review' | 'social' | 'forum' | .... But the tool exposes no parameter to filter on that classification, so top_domains / top_urls come back with news sites, social, competitors, and the brand's own domains all mixed together. The model has no clean way to answer an "owned-only" question.

Root cause

list_citations accepts date_from, date_to, model, region, topic_id, limit — but nothing to scope by source category. The filtering logic itself already exists in the UI layer: getCitationsOverview() in web/src/lib/actions/citations.ts supports ownOnly / excludeOwnDomain / competitorOnly. It was simply never surfaced to the agent / MCP tools.

Proposed change

Add a source_filter parameter to list_citations:

  • owned — only citations whose domain matches one of the brand's brand_domains
  • competitor — only citations matching a tracked competitor domain
  • external — everything that is neither owned nor competitor (news, review, social, forum, etc.)
  • all — current behaviour (default, backward compatible)

Apply the filter inside listCitationsFor() using the category it already computes — no new query or classification logic needed. Recompute totals, source_type_breakdown, top_domains, top_urls over the filtered set.

Files to touch

  • web/src/lib/agent/tools.ts — add source_filter to the list_citations tool schema + description
  • web/src/lib/mcp/server.ts — mirror the param on the MCP list_citations tool
  • web/src/lib/mcp/data.ts — listCitationsFor() filters on the existing category before aggregation

How to test

  1. Ask the assistant: "Which of our own URLs did AI engines cite for brand X this week?" → tool is called with source_filter: "owned" and the response lists only owned-domain URLs.
  2. source_filter: "competitor" returns only competitor-domain citations.
  3. Omitting source_filter (or all) reproduces today's output exactly (no regression).
  4. A brand with no owned citations in the window returns empty top_urls rather than a generic list.

Activity

  1. added
    enhancement
    on Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions