Skip to content

fix(mcp): look up a signal, prompt, citation, opportunity, draft or report by what the person names - #2461

Merged
gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:fix/mcp-lookups-by-name
Nov 16, 2026
Merged

gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:fix/mcp-lookups-by-name

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Stacked on #2460. Until it lands, this diff also shows its commits. This PR's own change is commit 0014eb75f. The owner approved this follow-up on 16 Nov.

Summary

#2460 gave Chat's reads direct lookups: a signal by its code, a prompt by its words, a cited domain or page by its address, and an opportunity, draft or report by its title. The MCP server, which Claude, ChatGPT and other clients use, still couldn't do this:

  • A client asked "what is S-07?", "how does the 'skip a month' prompt do?" or "is example.com cited?" could only page a list. That meant 50 signals, 100 prompts or the top 50 domains.
  • Anything past that page looked missing. The client could say it doesn't exist, or answer with the closest ones instead.

This PR gives the matching MCP tools the same lookups, through Chat's reads: the same query, rows and note, with no second query. It follows #2452 (codes on list_actions).

Changes

MCP tool New inputs Chat's read it calls List inputs a lookup ignores
list_signals codes ("S-07", "S 7", "s7", "#7", "7"), ids lookUpSignalsFor status, kind, limit
list_prompts search (words of the text, any order and case), ids, offset lookUpPromptsFor topic_id, is_active, limit
get_prompt_performance prompt_ids lookUpPromptPerformanceFor topic_id, sort_by, order, limit
list_citations domains (with subdomains, top pages and citing prompts), urls (scheme, www. and a trailing slash aside) lookUpCitationsFor source_filter, limit
list_content_opportunities search (title words), ids, offset lookUpOpportunitiesFor status, impact, type, limit
list_content_drafts search (title words), ids, offset lookUpDraftsFor status
list_reports search (title words), ids, offset lookUpReportsFor limit
  • Output. With a lookup input, a tool returns Chat's { note, <rows>, not_found } instead of its list:
    • signals, prompts, opportunities, drafts or reports; domains, urls and period for citations; prompts and no_results for performance.
    • A search also returns total, offset and next_offset.
    • Without a lookup input, every tool reads exactly as before.
    • The rows are Chat's compact rows (for signals: code, title, where, actions), not the plain list's full rows, as fix(mcp): look up an action by its code, and never answer with "the closest" ones #2452 chose for actions.
  • Up to 10 per read. Each code, id, domain or address list takes up to 10 (LOOKUP_MAX). A search takes up to 200 characters.
  • Paging. A search returns 50 at a time. offset takes the result's next_offset and applies only to a search, since these lists don't page today.
  • What it reads.
    • Signals: every status and date.
    • Prompts: every topic, active and paused.
    • Opportunities and drafts: every status, archived included (an archived draft is marked).
    • Citations: every source type over the same window, model, region and topic.
    • Performance: never cut by limit. A tracked prompt with no answers in the window goes in no_results.
  • Scoping. The same as each tool today.
    • brandAllowed checks the key's or app's organization and brand access.
    • Each read filters by brand_id and inner-joins the brand's organization.
    • An id or code of another brand or workspace comes back as not found.
    • Ids are checked as UUIDs, codes become numbers, and words reach a filter only as escaped ilike patterns (fix(chat): look up any listed item by its code, id, words or address #2460).
  • Descriptions. Each tool's description now says:
    • Read what the person names first.
    • Which list inputs a lookup ignores.
    • Say "not found" plainly, with where it looked, and never offer the closest.
    • Never say an item doesn't exist because a page of the list didn't show it.
  • Id inputs. get_report's report_id, get_content_draft's draft_id and get_content_opportunity's opportunity_id now say that one named by its title gets its id from the list's search.
  • REST unchanged. The routes under /api/mcp/* (signals, prompts, prompt-performance, citations, content-opportunities, content-drafts) share the list reads but don't take these inputs. A lookup returns a different shape (note, Chat's rows, not_found), which wouldn't match those routes' rows. This is the same reasoning as fix(mcp): look up an action by its code, and never answer with "the closest" ones #2452.
  • Docs, Help and skill.
    • The MCP guide's rows for the seven tools mention the new inputs.
    • Help gets one example line in "Use Ansvisor in AI assistants with MCP" › "What you can ask" (now 140 words). approved-articles.json is regenerated.
    • The coach skill (skills/ansvisor-aeo-coach/SKILL.md) lists each tool's inputs, so it now names the new ones. It also gets one pitfall: "Don't call something missing because a list didn't show it."

How to test

From an MCP client, such as Claude with the Ansvisor connector, on a brand with plenty of data:

  1. Ask "What is signal S-07?" on a brand with more than 50 signals.
    • Claude calls list_signals with codes: ["S-07"] and names the signal by its title and code, resolved ones too.
  2. Ask "What is S-99999?". Claude says this brand has no signal with that code, and lists no other signals.
  3. Ask about an older or paused prompt by a few of its words, e.g. "How does the 'skip a month' prompt do this month?".
    • Claude finds it with list_prompts' search.
    • It then reads its figures with get_prompt_performance's prompt_ids.
    • When the prompt had no answers in the window, Claude says so and that it is still tracked.
  4. Ask "Is example.com cited?" for a domain outside the top 50.
    • list_citations with domains returns it with its subdomains, top pages and the prompts citing it.
    • For a domain that isn't cited, Claude says so for the window and offers no other domains.
  5. Ask about an archived opportunity, an archived draft and an old report by their titles. Each is found with search, and an archived draft is marked archived.
  6. Ask for something with a title no item has. Claude tries fewer words once, then says "not found" plainly.
  7. Use a key whose person doesn't have the brand shared. The answer is "Brand not found".

Checks

  • npx tsc --noEmit -p .: passes.
  • Vitest on src/lib/mcp, src/app/api/mcp, src/lib/chat, src/lib/help, src/i18n, use-server-exports and subscription-guard-coverage: 270 files, 3,701 tests pass (1 skipped). This includes the MCP/Chat parity test (mcp-parity.test.ts) and server.test.ts.
  • New tests (lookups.test.ts, 15) call each tool through an MCP client and cover:
    • the MCP result equal to Chat's read for the same input;
    • a match past the first page of the tool's list;
    • not_found with its note;
    • another brand of the workspace, or another workspace, never read;
    • a brand of another workspace, a brand not shared with the key, and a key with no organization: "Brand not found", with nothing but brands read;
    • limit and the list's filters not cutting a lookup;
    • a search paged by offset;
    • the descriptions, input limits and the get tools' id lines.
  • brand-scope.test.ts: 7 new rows, one per tool, each a lookup on a brand not shared with a Selected-brands key. Each answers "Brand not found", reads only brands and calls no function.
  • ESLint and Prettier are clean on the changed TypeScript files.
  • Merges cleanly on main (git merge-tree).
  • No migration, new dependency, lockfile change or new server action. server.ts isn't a 'use server' file, and its new helpers aren't exported.

Generated by Claude Code

…report by what the person names

Chat answered "what is X?" from the first page of a list, so an item past it
read as missing. Each list read now takes a direct lookup:

- list_signals: codes ("S-07", "S 7", "s7", "#7", "7") and ids, every status and date
- list_prompts: search (words of the text, any order and case) and ids, every topic and state
- get_prompt_performance: prompt_ids, whatever the topic; tracked prompts with no answers in no_results
- list_citations: domains (with subdomains, top pages and citing prompts) and urls (scheme, www and trailing slash aside), every source type
- list_content_opportunities, list_drafts, get_reports: search (title words) and ids, archived included

Each returns what it found and not_found, with a note to say "not found"
plainly and never offer the closest. A lookup is never cut by limit
(NAMED_ROWS). Every read keeps brandAllowed, the brand_id filter and the
organization join; words reach the filter only as escaped ilike patterns.
Shared helpers in lib/mcp/lookup.ts; MCP tool shapes unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
…eport by what the person names

An MCP client asked "what is S-07?", "how does the 'skip a month' prompt
do?" or "is example.com cited?" could only page a list (50 signals, 100
prompts, the top 50 domains, ...), so an item past the page looked missing
and the client could answer with the closest ones instead. Chat got direct
lookups in ansvisor#2460; the MCP tools now read them the same way, through Chat's
reads: the same query, rows and note, no second query.

- list_signals: `codes` ("S-07", "S 7", "s7", "#7", "7") and `ids`, every
  status and date (lookUpSignalsFor). status, kind and limit don't apply.
- list_prompts: `search` (words of the text, any order and case) and `ids`,
  every topic and state (lookUpPromptsFor). topic_id, is_active and limit
  don't apply.
- get_prompt_performance: `prompt_ids`, whatever the topic, never cut by
  limit; tracked prompts with no answers in no_results
  (lookUpPromptPerformanceFor). topic_id, sort_by, order and limit don't
  apply.
- list_citations: `domains` (with subdomains, top pages and citing
  prompts) and `urls` (scheme, www and trailing slash aside), every source
  type (lookUpCitationsFor). source_filter and limit don't apply.
- list_content_opportunities, list_content_drafts, list_reports: `search`
  (title words) and `ids`, archived included where the list has it
  (lookUpOpportunitiesFor, lookUpDraftsFor, lookUpReportsFor). Their
  filters and limit don't apply.
- A search pages 50 at a time: `offset` on those four tools takes the
  result's next_offset and applies to a search only.
- Each returns { note, <rows>, not_found } in place of the list. Without a
  lookup input every tool reads exactly as before.
- Scope as before: brandAllowed (organization and brand access), the
  brand_id filter and an inner join on the brand's organization. An id or
  code of another brand or workspace is not found; ids are checked as
  UUIDs, codes become numbers, words reach a filter only as escaped ilike
  patterns (ansvisor#2460).
- Descriptions: read what the person names first; which list inputs a
  lookup ignores; "not found" plainly, never the closest; never say an
  item doesn't exist because a page didn't show it. get_report,
  get_content_draft and get_content_opportunity say where a named one's
  id comes from.
- The REST mirrors (/api/mcp/*) are unchanged.
- Docs: the MCP guide's rows. Help: one example line in the MCP article's
  "What you can ask". The coach skill names the new inputs where it lists
  each tool's inputs, and a pitfall for "missing because a list didn't
  show it".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
@mintlify

mintlify Bot commented Nov 16, 2026

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 0014eb7.

Approve preview

gkhngyk
gkhngyk previously approved these changes Nov 16, 2026

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@cihan-gyk
cihan-gyk dismissed gkhngyk’s stale review November 16, 2026 20:34

The merge-base changed after approval.

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@gkhngyk
gkhngyk merged commit 0044e8f into ansvisor:main Nov 16, 2026
14 checks passed
cihan-gyk pushed a commit to cihan-gyk/ansvisor that referenced this pull request Nov 16, 2026
Brings in ansvisor#2449, ansvisor#2450, ansvisor#2457, ansvisor#2460 and ansvisor#2461 (Chat and MCP lookups by
code, id, words, domain or address; never give up on data it could read).

Conflicts, resolved as the union of both sides:
- agent-eval.ts: the scenario keeps askedSignals/askedDomains and checks;
  QUESTION_SCENARIOS holds action-by-code, signal-by-code,
  citation-by-domain and the three ai-revenue questions; every run gets
  "never gives up on data it could read" and then its scenario's checks.
- agent-eval-data.ts: EvalWorkspace is default, action_backlog,
  long_lists and conversions_off; both sides' imports.
- agent-eval.test.ts: both sides' imports.
- brand-scope.test.ts: the AI-revenue reads and the lookups.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9
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.

3 participants