@@ -3,13 +3,19 @@ package knowledge
33import (
44 "errors"
55 "fmt"
6+ "slices"
67 "strings"
78
89 dhclient "github.com/txn2/mcp-datahub/pkg/client"
910)
1011
11- // entityTypeDataset is the DataHub entity type string for datasets.
12- const entityTypeDataset = "dataset"
12+ const (
13+ // entityTypeDataset is the DataHub entity type string for datasets.
14+ entityTypeDataset = "dataset"
15+
16+ // opsSeparator is the delimiter used when joining supported operations in error messages.
17+ opsSeparator = ", "
18+ )
1319
1420// entityTypeFromURN extracts the entity type from a DataHub URN.
1521// For example, "urn:li:dataset:(...)" returns "dataset".
@@ -37,7 +43,7 @@ func supportedOpsForType(entityType string) []string {
3743 }
3844
3945 if descriptionSupportedTypes [entityType ] {
40- ops = append ([] string { "update_description" }, ops ... )
46+ ops = slices . Insert ( ops , 0 , "update_description" )
4147 }
4248
4349 if entityType == entityTypeDataset {
@@ -48,7 +54,7 @@ func supportedOpsForType(entityType string) []string {
4854}
4955
5056// descriptionSupportedTypes are entity types that support update_description.
51- // This matches the upstream mcp-datahub descriptionAspectMap.
57+ // Must stay in sync with the upstream mcp-datahub descriptionAspectMap.
5258var descriptionSupportedTypes = map [string ]bool {
5359 "dataset" : true ,
5460 "dashboard" : true ,
@@ -73,23 +79,32 @@ func validateEntityTypeForChange(urn string, c ApplyChange) error {
7379 // Column-level descriptions are dataset-only (schema metadata is a dataset concept).
7480 if c .ChangeType == string (actionUpdateDescription ) {
7581 if _ , isColumn := parseColumnTarget (c .Target ); isColumn {
76- if entityType != "dataset" {
82+ if entityType != entityTypeDataset {
7783 return fmt .Errorf (
7884 "column-level update_description is only supported for datasets, not %s entities. " +
7985 "Supported operations for %s: %s" ,
80- entityType , entityType , strings .Join (supportedOpsForType (entityType ), ", " ),
86+ entityType , entityType , strings .Join (supportedOpsForType (entityType ), opsSeparator ),
8187 )
8288 }
8389 return nil
8490 }
91+
92+ // Entity-level update_description is only supported for specific entity types.
93+ if ! descriptionSupportedTypes [entityType ] {
94+ return fmt .Errorf (
95+ "update_description is not supported for %s entities. " +
96+ "Supported operations for %s: %s" ,
97+ entityType , entityType , strings .Join (supportedOpsForType (entityType ), opsSeparator ),
98+ )
99+ }
85100 }
86101
87102 // Dataset-only operations.
88- if datasetOnlyOperations [actionType (c .ChangeType )] && entityType != "dataset" {
103+ if datasetOnlyOperations [actionType (c .ChangeType )] && entityType != entityTypeDataset {
89104 return fmt .Errorf (
90105 "%s is only supported for datasets, not %s entities. " +
91106 "Supported operations for %s: %s" ,
92- c .ChangeType , entityType , entityType , strings .Join (supportedOpsForType (entityType ), ", " ),
107+ c .ChangeType , entityType , entityType , strings .Join (supportedOpsForType (entityType ), opsSeparator ),
93108 )
94109 }
95110
@@ -114,8 +129,8 @@ func wrapUnsupportedEntityTypeError(err error, urn string) error {
114129
115130 return fmt .Errorf (
116131 "update_description is not supported for %s entities. " +
117- "Supported operations for %s: %s" ,
118- entityType , entityType , strings .Join (supportedOpsForType (entityType ), ", " ) ,
132+ "Supported operations for %s: %s: %w " ,
133+ entityType , entityType , strings .Join (supportedOpsForType (entityType ), opsSeparator ), err ,
119134 )
120135}
121136
0 commit comments