Skip to content

Commit 49f2517

Browse files
committed
fix: preserve Unicode letters and numbers in MCP search tokens
1 parent da03d0d commit 49f2517

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

‎src/services/tools/Bm25Ranker.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export class Bm25Ranker implements Ranker {
8888
function tokenize(value: string): string[] {
8989
return value
9090
.toLowerCase()
91-
.split(/[\W_]+/)
91+
.split(/[^\p{L}\p{N}]+/u)
9292
.filter(Boolean)
9393
}
9494

‎src/services/tools/__tests__/Bm25Ranker.spec.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ describe("Bm25Ranker", () => {
5959
expect(new Bm25Ranker().rank("create issue", [nonMatching, matching], 10)).toEqual([matching])
6060
})
6161

62+
it("preserves Unicode letters and numbers in tokens", () => {
63+
const russian = tool("погода-сервер", "прогноз", "Прогноз погоды")
64+
const arabic = tool("أدوات", "مقياس", "يدعم ٣ بروتوكولات")
65+
66+
expect(new Bm25Ranker().rank("погода", [arabic, russian], 10)).toEqual([russian])
67+
expect(new Bm25Ranker().rank("٣", [russian, arabic], 10)).toEqual([arabic])
68+
})
69+
6270
it("handles tools with empty descriptions", () => {
6371
const item = tool("GitHub", "listRepos", "")
6472

0 commit comments

Comments
 (0)