Skip to content

feat(mcp): update formatters for rich search results#75

Merged
prosdev merged 1 commit intomainfrom
feat/70-update-mcp-formatters
Nov 27, 2025
Merged

feat(mcp): update formatters for rich search results#75
prosdev merged 1 commit intomainfrom
feat/70-update-mcp-formatters

Conversation

@prosdev
Copy link
Copy Markdown
Collaborator

@prosdev prosdev commented Nov 27, 2025

Summary

Implements #70 - Fourth sub-issue of Epic #66 (Richer Search Results)

Changes

packages/mcp-server/src/formatters/types.ts

  • Added includeSnippets?: boolean
  • Added includeImports?: boolean
  • Added maxSnippetLines?: number

packages/mcp-server/src/formatters/compact-formatter.ts

  • Snippets/imports off by default (token efficient)
  • Added formatHeader(), truncateSnippet(), indentText() helpers
  • Max 5 imports shown with "..." truncation
  • Updated estimateTokens() for new content

packages/mcp-server/src/formatters/verbose-formatter.ts

  • Snippets/imports on by default (full context)
  • Shows location with line range (e.g., file.ts:45-67)
  • Added same helper methods
  • Updated estimateTokens() for new content

packages/mcp-server/src/formatters/__tests__/formatters.test.ts

  • Added 17 new tests for snippet/import formatting

Example Output

Compact (with options enabled)

1. [85%] function: handleAuth (src/auth/handler.ts:45)
   export async function handleAuth(req: Request) {
     const token = extractToken(req);
     // ... 15 more lines
   }
   Imports: ./service, ../utils/jwt, express

Verbose (default)

1. [Score: 85.0%] function: handleAuth
  Location: src/auth/handler.ts:45-67
  Signature: async handleAuth(req: Request): Promise<Response>
  Imports: ./service, ../utils/jwt, express
  Metadata: language: typescript, exported: true, lines: 23
  Code:
    export async function handleAuth(req: Request) {
      const token = extractToken(req);
      // ... 15 more lines
    }

Testing

  • ✅ 1282 tests passing (17 new)
  • ✅ TypeScript compiles without errors
  • ✅ Biome linting passes

Related Issues

Implements #70 - Richer Search Results (sub-issue 4/5)

Changes:
- Add FormatterOptions: includeSnippets, includeImports, maxSnippetLines
- Update CompactFormatter:
  - Add optional snippet rendering (off by default)
  - Add optional imports rendering (off by default, max 5 shown)
  - Add truncateSnippet and indentText helpers
  - Update token estimation for new content
- Update VerboseFormatter:
  - Add snippet rendering (on by default)
  - Add imports rendering (on by default)
  - Show location with line range (start-end)
  - Update token estimation for new content

Features:
- Compact: snippets/imports off by default (token efficient)
- Verbose: snippets/imports on by default (full context)
- Configurable maxSnippetLines (default: 10 compact, 20 verbose)
- Long snippets truncated with '// ... N more lines'
- Long import lists truncated with '...' (compact only)

Testing:
- 17 new tests for snippet/import formatting
- All 1282 tests passing

Closes #70
@prosdev prosdev merged commit 7d72817 into main Nov 27, 2025
1 check passed
@prosdev prosdev mentioned this pull request Nov 27, 2025
5 tasks
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.

Update MCP formatters for rich search results

1 participant