Skip to content

Reduce search discovery round trips: batch entity detail, inline call shapes, related operations, package maintain pointer - #769

Merged
cursor[bot] merged 3 commits into
mainfrom
cursor/search-discovery-friction-fixes-f618
Jul 16, 2026
Merged

cursor[bot] merged 3 commits into
mainfrom
cursor/search-discovery-friction-fixes-f618

Conversation

@kentcdodds

@kentcdodds kentcdodds commented Jul 16, 2026 •

Copy link
Copy Markdown
Member

Summary

Cuts the MCP search “entity ladder” that showed up in real agent transcripts (query → 1–2 entity: detail calls per new API surface, plus rediscovery of package-maintenance capabilities mid-task).

  • Batch entity detail — entity accepts string | string[] (1–10). Single-string behavior unchanged. Arrays resolve each ref independently; markdown joins with ---; structured content is an array of detail or { entityRef, error }. All-fail → isError: true. Batch structured payload is size-bounded (overflow entries become per-ref errors).
  • Inline call shapes (query mode) — After rerank, the top 3 capability hits get a compact accessor + whitespace-collapsed inputTypeDefinition (~500 char cap). Rendered as one indented list line; present on slim structured matches (with truncation flag). Guidance prefers calling via the accessor only when the inlined shape is complete.
  • Related operations — For openapi / mcp-server / remote-connector capability detail only, list up to 20 sibling ops from the same provider (create/poll pairs without a second entity lookup). Builtins intentionally skipped.
  • Package ## Maintain pointer — ~2 lines after Summary: git lane (package_get_git_remote → … → package_publish_external_push) and tool-only alternative; structured maintain.{gitLane,publish}.

Token discipline

  • Inline shapes: top 3 capabilities only, collapsed whitespace, 500-char type cap.
  • Related ops: synthesized providers only, cap 20, one-line each (no type defs).
  • Maintain: pointer only (~30–50 tokens), not a tutorial.
  • Common builtin / single-entity paths stay lean.

Test plan

  • search-format.node.test.ts — inline shapes, truncation flag, related ops present/absent, Maintain section
  • search.node.test.ts — top-3 inline attach, truncation → detail-first guidance, complete shape → direct call guidance
  • search-handler.node.test.ts — batch success / partial failure / all-failure; single-entity shape unchanged
  • npm run typecheck
  • format + lint on changed files
  • Pre-push Playwright E2E (18 passed)
  • CI Validate on ready PR
  • CodeRabbit feedback addressed (truncation guidance, markdown safety, batch structured budget, docs wording)
System recap — extends existing primitives (medium risk)

Mode: recap · Base: main @ 71930296 · Head: 4b6eff1b

Classification: extends — changes the MCP search tool contract and response shapes (batch entity, inlined call shapes, related ops, package Maintain) without adding primitives.

Primitives touched

Primitive Group Impact
mcp-server surfaces extends — search input/output contract and formatting
capability-registry assistant composes — reads specs for call shapes and sibling ops
saved-packages assistant composes — package detail Maintain pointer only

System map

Query and entity detail enrichment stay inside the MCP search tool; registry specs supply call shapes and related synthesized-provider operations, while package detail only adds a maintenance pointer.

Legend: green = composes (wiring only) · amber = extended by this PR · red = new primitive · gray = context (unchanged, included only when an edge crosses it).

flowchart LR
	mcpServer["mcp-server<br/>MCP endpoint"]:::extended
	capabilityRegistry["capability-registry<br/>Capability registry"]:::touched
	savedPackages["saved-packages<br/>Saved packages"]:::touched
	mcpServer -->|"batch entity + top-3 inline shapes"| capabilityRegistry
	mcpServer -->|"package Maintain snippets"| savedPackages
	classDef touched fill:#1a7f37,color:#fff
	classDef extended fill:#9a6700,color:#fff
	classDef added fill:#cf222e,color:#fff
	classDef untouched fill:#57606a,color:#fff
Loading

Change flow

sequenceDiagram
	participant Agent
	participant Search as search tool
	participant Registry as capability-registry
	Agent->>Search: query
	Search->>Registry: specs for top capability hits
	Search-->>Agent: ranked list + top-3 inline call shapes
	Agent->>Search: entity array (related ops)
	Search->>Registry: resolve each ref + siblings
	Search-->>Agent: joined detail / per-ref errors
Loading

Before / after

Surface Before After
entity input string only string | string[] (1–10)
Query capability hit name + one-line + entity ref optional indented compact call shape (top 3)
Synthesized capability detail execute + types only + Related operations (same provider)
Package detail Summary → App/Exports… Summary → Maintain → App/Exports…

Invariants

Per-user isolation unchanged: package/secret/value/integration entity paths remain userId-scoped; batch mode only parallelizes the same resolvers.

Open in Web Open in Cursor 

Summary by CodeRabbit

  • New Features

    • Search results now show compact call shapes and input details for the top capability matches, including truncation for lengthy definitions.
    • Entity details support looking up multiple references at once, with individual success or error results.
    • Capability details now include related operations from the same provider.
    • Package details now include maintenance commands and guidance.
  • Documentation

    • Updated search documentation with batch lookup behavior, expanded examples, related operations, and package maintenance guidance.

Batch entity detail (up to 10 refs), inline top capability call shapes,
surface related synthesized-provider operations, and add a package Maintain
pointer so agents need fewer search round trips.
Document batch entity lookup and inlined call shapes, and add colocated
coverage for batch success/partial/all-fail, top-3 inline shapes, related
operations, and package Maintain pointers.
@coderabbitai

coderabbitai Bot commented Jul 16, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The MCP search tool now inlines compact capability call shapes, exposes related provider operations and package maintenance commands, supports batched entity detail lookups, and documents the resulting markdown and structured response formats.

Changes

Search enrichment and batching

Layer / File(s) Summary
Capability match and detail formatting
packages/worker/src/mcp/tools/search-format.ts, packages/worker/src/mcp/tools/search-format.node.test.ts
Capability matches include compact input definitions and detail hints; entity details expose related operations, while package details include Maintain commands in markdown and structured output.
Capability search enrichment
packages/worker/src/mcp/tools/search.ts, packages/worker/src/mcp/tools/search.node.test.ts
Top capability matches receive bounded inline call shapes, guidance references them, and capability details collect related operations from the same synthesized provider.
Batched entity detail resolution
packages/worker/src/mcp/tools/search.ts, packages/worker/src/mcp/tools/search-handler.node.test.ts
entity accepts a single reference or an array of 1–10 references, resolves arrays concurrently, preserves per-entity errors, and reports an overall error only when all lookups fail.
Search usage documentation
docs/use/search.md
Documentation covers inline call shapes, batched entity detail requests, related operations, and package maintenance output.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant search
  participant resolveEntityDetail
  participant formatEntityDetailMarkdown
  Client->>search: Submit entity refs
  search->>resolveEntityDetail: Resolve refs concurrently
  resolveEntityDetail-->>search: Return details or per-ref errors
  search->>formatEntityDetailMarkdown: Format successful details
  formatEntityDetailMarkdown-->>Client: Return markdown and structured results
Loading

Possibly related PRs

  • kentcdodds/kody#242: Extends the same search formatting pipeline with structured entity and package metadata.
  • kentcdodds/kody#279: Updates capability type-definition generation used by the inline call-shape formatting.
  • kentcdodds/kody#628: Changes the same capability search and formatting path for execution accessors and provenance.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main search-tool changes: batched entity detail, inline call shapes, related operations, and package maintain pointers.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cursor/search-discovery-friction-fixes-f618

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@kody-bot
kody-bot marked this pull request as ready for review July 16, 2026 21:30
@github-actions

github-actions Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

🔎 Preview deployed: https://kody-pr-769.kody-a99.workers.dev

Worker: kody-pr-769
D1: kody-pr-769-db
KV: kody-pr-769-oauth-kv

Mocks:

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/use/search.md`:
- Around line 50-54: Revise the search documentation around the entity lookup
guidance so capability entities are the only ones described as providing execute
call shapes and input/output definitions. Describe values, integrations,
packages, and secrets as detail lookups, while preserving the existing
"{id}:{type}" entity format and capability metadata examples.

In `@packages/worker/src/mcp/tools/search-format.ts`:
- Around line 930-935: The Markdown output at
packages/worker/src/mcp/tools/search-format.ts:930-935 must use
formatMarkdownInlineCode for the externally supplied operation name, HTTP
method/path, and entityRef instead of literal backticks; preserve the existing
description escaping. At packages/worker/src/mcp/tools/search.ts:2395-2402,
apply formatMarkdownInlineCode to entry.entityRef and escape the one-line error
message with the existing Markdown safety helper.
- Line 125: Preserve truncation metadata and prevent incomplete call
recommendations: in packages/worker/src/mcp/tools/search-format.ts:125-125 add
inputTypeDefinitionTruncated?: boolean to the slim capability contract, and at
760-762 propagate it with the definition; in
packages/worker/src/mcp/tools/search.ts:409-413 route truncated direct matches
to entity-detail guidance before execution; update
packages/worker/src/mcp/tools/search-format.node.test.ts:941-944 to assert the
flag, and packages/worker/src/mcp/tools/search.node.test.ts:1199-1205 to rank a
truncated capability first and verify detail-first guidance.

In `@packages/worker/src/mcp/tools/search.ts`:
- Around line 2406-2408: Bound the aggregate payload built by structuredResults
in the batch search flow around formatEntityDetailMarkdown, not just the
markdown text. Track the cumulative structured-result size and, once the budget
is exceeded, replace additional entries with per-reference errors directing
callers to individual lookup; apply the same behavior to the corresponding path
around the later structuredResults push.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6cd56380-6e3b-4ada-b8a1-596b9d70b196

📥 Commits

Reviewing files that changed from the base of the PR and between 7193029 and a74ed71.

📒 Files selected for processing (6)
  • docs/use/search.md
  • packages/worker/src/mcp/tools/search-format.node.test.ts
  • packages/worker/src/mcp/tools/search-format.ts
  • packages/worker/src/mcp/tools/search-handler.node.test.ts
  • packages/worker/src/mcp/tools/search.node.test.ts
  • packages/worker/src/mcp/tools/search.ts

Comment thread docs/use/search.md Outdated
Comment thread packages/worker/src/mcp/tools/search-format.ts
Comment on lines +930 to +935
const openApiSuffix =
related.method && related.path
? ` — \`${related.method.toUpperCase()} ${related.path}\``
: ''
lines.push(
`- \`${related.name}\`${openApiSuffix} — ${escapeMarkdownText(formatOneLineSentence(related.description))} Entity: \`${related.entityRef}\``,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Render externally supplied values with the Markdown safety helpers.

Literal backticks allow provider paths or caller-supplied entity references to break or spoof the generated Markdown.

  • packages/worker/src/mcp/tools/search-format.ts#L930-L935: use formatMarkdownInlineCode for operation names, HTTP method/path, and entity references.
  • packages/worker/src/mcp/tools/search.ts#L2395-L2402: safely format entry.entityRef and escape the one-line error message.
📍 Affects 2 files
  • packages/worker/src/mcp/tools/search-format.ts#L930-L935 (this comment)
  • packages/worker/src/mcp/tools/search.ts#L2395-L2402
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/worker/src/mcp/tools/search-format.ts` around lines 930 - 935, The
Markdown output at packages/worker/src/mcp/tools/search-format.ts:930-935 must
use formatMarkdownInlineCode for the externally supplied operation name, HTTP
method/path, and entityRef instead of literal backticks; preserve the existing
description escaping. At packages/worker/src/mcp/tools/search.ts:2395-2402,
apply formatMarkdownInlineCode to entry.entityRef and escape the one-line error
message with the existing Markdown safety helper.

Comment thread packages/worker/src/mcp/tools/search.ts
Propagate truncation flags and avoid recommending truncated call shapes,
escape batch/related-ops markdown safely, bound batch structured payload
size, and clarify capability-only call-shape docs.
@cursor
cursor Bot merged commit cfc4e44 into main Jul 16, 2026
5 checks passed
@cursor
cursor Bot deleted the cursor/search-discovery-friction-fixes-f618 branch July 16, 2026 21:47
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