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

Method lookupTableCandidates

backend/api/mcp/tool_schema.go:479–497  ·  view source on GitHub ↗

lookupTableCandidates issues a second GetDatabaseMetadata call (no table filter) to build a list of candidate table names for a TABLE_NOT_FOUND error. Bounded by schemaCandidateFetchLimit per schema on the wire and schemaCandidateResultCap on the returned slice.

(ctx context.Context, resourceName, schemaFilter, missing string)

Source from the content-addressed store, hash-verified

477// Bounded by schemaCandidateFetchLimit per schema on the wire and
478// schemaCandidateResultCap on the returned slice.
479func (s *Server) lookupTableCandidates(ctx context.Context, resourceName, schemaFilter, missing string) []string {
480 filter := buildMetadataFilter(schemaFilter, "")
481 metadata, err := s.fetchMetadata(ctx, resourceName, filter, int32(schemaCandidateFetchLimit))
482 if err != nil || metadata == nil {
483 return nil
484 }
485 var candidates []string
486 for _, schema := range metadata.Schemas {
487 for _, t := range schema.Tables {
488 if tableNameMatches(t.Name, missing) {
489 candidates = append(candidates, t.Name)
490 if len(candidates) >= schemaCandidateResultCap {
491 return candidates
492 }
493 }
494 }
495 }
496 return candidates
497}
498
499// tableNameMatches returns true if `name` is a plausible candidate for a typo of
500// `missing`. A name matches if it contains the input as a (case-insensitive)

Callers 1

renderTableResultMethod · 0.95

Calls 3

fetchMetadataMethod · 0.95
buildMetadataFilterFunction · 0.85
tableNameMatchesFunction · 0.85

Tested by

no test coverage detected