MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / handleSearch

Method handleSearch

src/mcp/tools.ts:3347–3381  ·  view source on GitHub ↗

* Handle codegraph_search

(args: Record<string, unknown>)

Source from the content-addressed store, hash-verified

3345 * Handle codegraph_search
3346 */
3347 private async handleSearch(args: Record<string, unknown>): Promise<ToolResult> {
3348 const query = this.validateString(args.query, 'query');
3349 if (typeof query !== 'string') return query;
3350
3351 const cg = this.getCodeGraph(args.projectPath as string | undefined);
3352 const rawKind = args.kind as string | undefined;
3353 // The schema enum says 'type' (what agents naturally reach for); the
3354 // NodeKind is 'type_alias'. Without the mapping, kind: "type" silently
3355 // matched nothing — a filter value we advertise must work.
3356 const kind = rawKind === 'type' ? 'type_alias' : rawKind;
3357 const rawLimit = Number(args.limit) || 10;
3358 const limit = clamp(rawLimit, 1, 100);
3359
3360 const results = cg.searchNodes(query, {
3361 limit,
3362 kinds: kind ? [kind as NodeKind] : undefined,
3363 });
3364
3365 if (results.length === 0) {
3366 return this.textResult(`No results found for "${query}"`);
3367 }
3368
3369 // Down-rank generated files within the FTS-returned set so a search
3370 // for "Send" surfaces the hand-written keeper before .pb.go stubs
3371 // that share the name. Stable: only reorders generated vs. not.
3372 const isGen = cg.generatedFilePredicate(results.map((r) => r.node.filePath));
3373 const ranked = [...results].sort((a, b) => {
3374 const aGen = isGen(a.node.filePath) ? 1 : 0;
3375 const bGen = isGen(b.node.filePath) ? 1 : 0;
3376 return aGen - bGen;
3377 });
3378
3379 const formatted = this.formatSearchResults(ranked);
3380 return this.answerResult(cg, this.truncateOutput(formatted), ranked.map(r => r.node.filePath));
3381 }
3382
3383 /**
3384 * Group symbol matches into DISTINCT DEFINITIONS — one group per

Callers 1

dispatchToolMethod · 0.95

Calls 11

validateStringMethod · 0.95
getCodeGraphMethod · 0.95
textResultMethod · 0.95
formatSearchResultsMethod · 0.95
answerResultMethod · 0.95
truncateOutputMethod · 0.95
clampFunction · 0.90
NumberInterface · 0.85
mapMethod · 0.80
searchNodesMethod · 0.65

Tested by

no test coverage detected