Skip to content

Conversation

@prosdev
Copy link
Collaborator

@prosdev prosdev commented Nov 24, 2025

Implements Issue #28 - First Adapter + Formatters (SearchAdapter)

Overview

Adds the first concrete MCP adapter: SearchAdapter with token-efficient formatters for semantic code search.

What's New

🎯 SearchAdapter

  • Exposes dev_search MCP tool for semantic code search
  • Integrates with RepositoryIndexer for vector search
  • Input validation: query, format, limit (1-50), scoreThreshold (0-1)
  • Structured error handling with error codes
  • Token estimation for cost awareness

📊 Formatters

  • CompactFormatter: Token-efficient summaries (~20 tokens/result)
    • Format: [score%] type: name (path:line)
    • Default mode for cost optimization
  • VerboseFormatter: Full details (~100+ tokens/result)
    • Includes signatures, metadata, line counts
    • Opt-in for detailed exploration
  • Token Estimation: ~4 chars/token heuristic
  • Empty result handling

✅ Comprehensive Tests (135 passing)

  • Formatters: 30 tests (formatting, tokens, edge cases)
  • Utils: 15 tests (estimation accuracy, truncation)
  • SearchAdapter: 25 tests (validation, execution, mocking)
  • Existing: 65 tests (registry, protocol, integration)

🔧 Test Restructuring

  • ✅ Moved ALL tests from tests/ to co-located __tests__/
  • ✅ Consistent with packages/core and packages/subagents
  • ✅ Simpler imports (../module vs ../../../src/module)
  • ✅ Works with root vitest.config.ts automatically

API

Tool: dev_search

{
  query: string;              // Natural language search
  format?: 'compact' | 'verbose';  // Default: 'compact'
  limit?: number;             // 1-50, default: 10
  scoreThreshold?: number;    // 0-1, default: 0
}

Response

{
  success: true;
  data: {
    query: string;
    format: 'compact' | 'verbose';
    resultCount: number;
    results: string;          // Formatted results
    tokenEstimate: number;    // Estimated token cost
  }
}

Benefits

  • 🎯 Token-efficient by default (compact mode)
  • 🔍 Semantic search over exact matching
  • 📈 Cost-aware (token estimation)
  • ✅ Extensible formatter framework
  • 🧪 Well-tested (100% coverage on utils)
  • 📁 Consistent monorepo structure

Testing

pnpm test -- mcp-server  # All 135 tests pass
pnpm build               # Clean build
pnpm typecheck           # No errors

Next Steps

  • Real MCP client testing (Claude Desktop, Cursor)
  • More adapters (GitHub, Explorer, Planner)
  • Performance benchmarking

Closes #28

Implements Issue #28 - First Adapter + Formatters

## Features

### Formatters
- **CompactFormatter**: Token-efficient summaries (score, type, name, path)
- **VerboseFormatter**: Full details with signatures and metadata
- **Token Estimation**: ~4 chars/token heuristic for GPT-4

### SearchAdapter
- Implements `dev_search` MCP tool
- Semantic code search via RepositoryIndexer
- Configurable format modes (compact/verbose)
- Input validation with structured errors
- Token-aware result formatting

### API
- Format modes: `compact` (default) | `verbose`
- Configurable limits: 1-50 results (default: 10)
- Score threshold: 0-1 (default: 0)
- Token budgets: 1K (compact) | 5K (verbose)

## Benefits
- ✅ Token-efficient by default (compact mode)
- ✅ Opt-in verbosity for detailed exploration
- ✅ Type-safe metadata access
- ✅ Structured error handling
- ✅ Extensible formatter framework

## Next Steps
- Add comprehensive tests (unit + integration)
- Test with real MCP clients
- Measure token estimation accuracy
Implements Issue #28 - First Adapter + Formatters (Tests)

## Test Coverage

### Formatters (30 tests)
- **formatters.test.ts**: CompactFormatter + VerboseFormatter
  - Single/multiple result formatting
  - Token estimation
  - Empty result handling
  - Signature inclusion/exclusion
  - maxResults option
- **utils.test.ts**: Token estimation utilities
  - Text/JSON token estimation
  - Truncation to token budgets
  - Whitespace normalization
  - Accuracy validation (~50% of actual)

### SearchAdapter (25 tests)
- Tool definition validation
- Query validation (empty, non-string)
- Format validation (compact/verbose/invalid)
- Limit validation (1-50 range)
- Score threshold validation (0-1 range)
- Search execution with mocked indexer
- Token estimation comparison
- Empty result handling

### Restructuring
- ✅ Moved ALL tests from `tests/` to co-located `__tests__/`
- ✅ Updated all import paths (simpler, cleaner)
- ✅ Consistent with `packages/core` and `packages/subagents`
- ✅ Works with root vitest.config.ts out of the box
- ✅ 135 total tests pass (7 test files)

## Benefits
- 🎯 Consistency across entire monorepo
- 📁 Tests co-located with source code
- 🔍 Easier discoverability
- 🚀 Simpler import paths
- ✅ Test discovery works automatically
@prosdev prosdev assigned prosdev and unassigned prosdev Nov 24, 2025
@prosdev prosdev merged commit 9533634 into main Nov 24, 2025
1 check passed
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.

First Adapter + Formatters (SearchAdapter)

1 participant