MCPcopy Create free account
hub / github.com/bytebase/bytebase / tableNameMatches

Function tableNameMatches

backend/api/mcp/tool_schema.go:503–518  ·  view source on GitHub ↗

tableNameMatches returns true if `name` is a plausible candidate for a typo of `missing`. A name matches if it contains the input as a (case-insensitive) substring, or if it shares a sufficiently long common prefix (useful for typos like "orderz" → "orders", "order_items").

(name, missing string)

Source from the content-addressed store, hash-verified

501// substring, or if it shares a sufficiently long common prefix (useful for typos
502// like "orderz" → "orders", "order_items").
503func tableNameMatches(name, missing string) bool {
504 n := strings.ToLower(name)
505 m := strings.ToLower(missing)
506 if m == "" {
507 return false
508 }
509 if strings.Contains(n, m) {
510 return true
511 }
512 // Require a shared prefix of at least 4 chars (or the full input if shorter).
513 prefixLen := min(4, len(m))
514 if len(n) < prefixLen {
515 return false
516 }
517 return n[:prefixLen] == m[:prefixLen]
518}
519
520// transformSchemas converts decoded metadata into the response shape for the
521// given include level. Applies sorting and per-schema truncation.

Callers 1

lookupTableCandidatesMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected