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

Function matchDatabases

backend/api/mcp/tool_resolve.go:131–163  ·  view source on GitHub ↗

matchDatabases applies tiered matching (exact > case-insensitive > substring) and returns the resolved result, an ambiguous result, or a not-found error.

(databases []databaseEntry, database, instance, project string)

Source from the content-addressed store, hash-verified

129// matchDatabases applies tiered matching (exact > case-insensitive > substring) and
130// returns the resolved result, an ambiguous result, or a not-found error.
131func matchDatabases(databases []databaseEntry, database, instance, project string) (*resolvedDatabase, error) {
132 matches := matchExact(databases, database)
133 if len(matches) == 0 {
134 matches = matchCaseInsensitive(databases, database)
135 }
136 if len(matches) == 0 {
137 matches = matchSubstring(databases, database)
138 }
139
140 if len(matches) == 0 {
141 suggestion := "check the database name or use search_api to list available databases"
142 if instance != "" || project != "" {
143 suggestion = "try without instance/project filters, or use search_api to list available databases"
144 }
145 return nil, &toolError{
146 Code: "DATABASE_NOT_FOUND",
147 Message: fmt.Sprintf("no database matching %q", database),
148 Suggestion: suggestion,
149 }
150 }
151
152 if len(matches) > 1 {
153 return buildAmbiguousResult(matches), nil
154 }
155
156 db := matches[0]
157 return &resolvedDatabase{
158 resourceName: db.Name,
159 dataSourceID: selectDataSource(db.InstanceResource.DataSources),
160 engine: db.InstanceResource.Engine,
161 project: db.Project,
162 }, nil
163}
164
165// buildAmbiguousResult constructs a resolvedDatabase with multiple candidates.
166func buildAmbiguousResult(matches []databaseEntry) *resolvedDatabase {

Callers 3

resolveDatabaseMethod · 0.85

Calls 5

matchExactFunction · 0.85
matchCaseInsensitiveFunction · 0.85
matchSubstringFunction · 0.85
buildAmbiguousResultFunction · 0.85
selectDataSourceFunction · 0.85

Tested by 2