Documentation
¶
Overview ¶
Package filter provides keyword relevance scoring for MCP item filtering.
Design goals:
- Precise: word-boundary tokenization, not substring matching ("go" does NOT match "google" or "cargo")
- Relevant: weighted scoring — name > tags > description; stem + prefix matching
- Reproducible: stable sort (score desc, then original order for ties)
- Efficient: stateless pure functions, no allocations beyond the sort slice
Scoring pipeline:
- Tokenize + stopword-filter query and all fields
- Match each query token per field via exact → stem → prefix
- Coverage bonus: +10% per additional matched query term (beyond first)
- Co-occurrence bonus: +30% per field where 2+ query terms match
- Phrase adjacency bonus: +25%/+15%/+10% per adjacent pair in name/tags/desc
- Short-tag exact bonus: raw tag string match for short tags ("go", "ci"…)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Score ¶
Score computes a relevance score for name/description/tags against query.
The scoring pipeline:
- Tokenize + stopword-filter query and all fields
- Match each query token per field via exact → stem → prefix
- Coverage bonus: +10% per additional matched query term (beyond first)
- Co-occurrence bonus: +30% per field where 2+ query terms match together
- Phrase adjacency bonus: +25%/+15%/+10% when adjacent query terms appear adjacent in name/tags/desc ("code review" → "code-review" +25%)
- Short-tag bonus: raw tag == raw query word gives +8 (enables "go", "ci")
- Name precision bonus: +20% when ≥75% of name tokens are covered by query (rewards "jwt-auth" over "jwt-auth-middleware-guide" for query "jwt auth")
Returns 0 if no query term matches (item excluded). Returns 1 if query is empty or reduces to all stopwords (pass-through).
func SortByScore ¶
SortByScore filters and sorts items by relevance to query.
- Items scoring 0 are excluded when query is non-empty.
- Items are sorted by score descending.
- Equal-score items keep their original relative order (stable, reproducible).
- If query is empty, all items are returned in original order unchanged.
func Tokenize ¶
Tokenize splits s into lowercase alphanumeric tokens on non-alphanumeric boundaries. Single-character tokens and stopwords are discarded.
Examples:
"JWT Authentication" → ["jwt", "authentication"] "how to use mcp-skills" → ["mcp", "skills"] (stopwords filtered) "mcp-instructions" → ["mcp", "instructions"] "**/*.go" → ["go"]
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.