Skip to content

Commit 45790cb

Browse files
authored
MCP: Also match against schema names (#3956)
## Changes `find_tables` does support filtering but right now it only filters table names and not schemas. Before: catalog: `samples` filter: `*taxi*` result: nothing After: catalog: `samples` filter: `*taxi*` result: samples.nyctaxi.trips Also contains a critical fix that prevented the find_tables command from working ## Why I noticed that claude did struggle to find the table and needed three round trips to find the right table ## Tests <!-- How have you tested the changes? --> <!-- If your PR needs to be included in the release notes for next release, add a separate entry in NEXT_CHANGELOG.md as part of your PR. -->
1 parent 0534e38 commit 45790cb

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

experimental/apps-mcp/lib/providers/databricks/databricks.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,9 @@ func (c *DatabricksRestClient) ListTables(ctx context.Context, request *ListTabl
635635
filterLower := strings.ToLower(*request.Filter)
636636
var filtered []TableInfoResponse
637637
for _, t := range tables {
638-
if strings.Contains(strings.ToLower(t.Name), filterLower) {
638+
// Match against both table name and schema name
639+
if strings.Contains(strings.ToLower(t.Name), filterLower) ||
640+
strings.Contains(strings.ToLower(t.SchemaName), filterLower) {
639641
filtered = append(filtered, t)
640642
}
641643
}
@@ -712,7 +714,8 @@ func (c *DatabricksRestClient) listTablesViaInformationSchema(ctx context.Contex
712714
pattern = "%" + pattern + "%"
713715
}
714716

715-
conditions = append(conditions, "table_name LIKE :pattern ESCAPE '\\\\'")
717+
// Match against both table name and schema name
718+
conditions = append(conditions, "(table_name LIKE :pattern ESCAPE '\\\\' OR table_schema LIKE :pattern ESCAPE '\\\\')")
716719
parameters = append(parameters, sql.StatementParameterListItem{
717720
Name: "pattern",
718721
Value: pattern,

experimental/apps-mcp/lib/providers/databricks/provider.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,18 @@ func (p *Provider) RegisterTools(server *mcpsdk.Server) error {
112112
mcpsdk.AddTool(server,
113113
&mcpsdk.Tool{
114114
Name: "databricks_find_tables",
115-
Description: "Find tables in Databricks Unity Catalog. Supports searching within a specific catalog and schema, across all schemas in a catalog, or across all catalogs. Supports wildcard patterns (* for multiple characters, ? for single character) in table name filtering.",
115+
Description: "Find tables in Databricks Unity Catalog. Supports searching within a specific catalog and schema, across all schemas in a catalog, or across all catalogs. Supports wildcard patterns (* for multiple characters, ? for single character) in table name and schema name filtering.",
116116
},
117117
session.WrapToolHandler(p.session, func(ctx context.Context, req *mcpsdk.CallToolRequest, args FindTablesInput) (*mcpsdk.CallToolResult, any, error) {
118-
log.Debugf(ctx, "databricks_find_tables called: catalog=%s, schema=%s", *args.CatalogName, *args.SchemaName)
118+
catalogName := "<all>"
119+
if args.CatalogName != nil {
120+
catalogName = *args.CatalogName
121+
}
122+
schemaName := "<all>"
123+
if args.SchemaName != nil {
124+
schemaName = *args.SchemaName
125+
}
126+
log.Debugf(ctx, "databricks_find_tables called: catalog=%s, schema=%s", catalogName, schemaName)
119127

120128
client, err := NewDatabricksRestClient(ctx, p.config)
121129
if err != nil {

0 commit comments

Comments
 (0)