File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -96,7 +96,16 @@ export function scoreLexical(
9696) : number {
9797 const name = fields . name . toLowerCase ( ) ;
9898 const blob = fields . blob . toLowerCase ( ) ;
99- let matched = name . includes ( rawQuery ) ? 1 : 0 ;
99+ // The whole-query bonus lifts a one-word query buried inside a longer name
100+ // token ("granola" in mygranolahoard) above a description hit. A word that
101+ // is already a name token, exact or folded, was scored by the token pass;
102+ // a second point for it would cut its folded matches at the score ratio.
103+ const single = new Set ( queryTokens ) . size === 1 ? queryTokens [ 0 ] : undefined ;
104+ const nameHit =
105+ single !== undefined &&
106+ ( fields . nameTokens . includes ( single ) ||
107+ fields . foldedNameTokens . includes ( foldPlural ( single ) ) ) ;
108+ let matched = ! nameHit && name . includes ( rawQuery ) ? 1 : 0 ;
100109 let total = matched ;
101110 // A model repeats a word because its sentence needs it ("release ID or
102111 // release slug"), not to weight it; counting each copy multiplies the
Original file line number Diff line number Diff line change @@ -529,6 +529,18 @@ describe("createToolIndex", () => {
529529 }
530530 } ) ;
531531
532+ test ( "a one-word plural query keeps the tools named for its singular" , ( ) => {
533+ const nameOnlyIndex = createToolIndex ( ( ) => [
534+ mcpDef ( "mcp__linear__list_issues" , "" ) ,
535+ mcpDef ( "mcp__linear__get_issue" , "" ) ,
536+ mcpDef ( "mcp__linear__save_issue" , "" ) ,
537+ ] ) ;
538+ const ranked = nameOnlyIndex . search ( "issues" , 20 ) ;
539+ expect ( ranked [ 0 ] ) . toBe ( "mcp__linear__list_issues" ) ;
540+ expect ( ranked ) . toContain ( "mcp__linear__get_issue" ) ;
541+ expect ( ranked ) . toContain ( "mcp__linear__save_issue" ) ;
542+ } ) ;
543+
532544 test ( "a malformed input schema still scores on name and description" , ( ) => {
533545 const malformedIndex = createToolIndex ( ( ) => [
534546 {
You can’t perform that action at this time.
0 commit comments