Skip to content

Commit 1e10f9f

Browse files
authored
fix: default context documents to visible and published (#122) (#123)
Documents created via UpsertContextDocument and datahub_create were invisible in the DataHub UI because GlobalContext defaulted to false (Go zero value) and Status was empty (server default: UNPUBLISHED). Changes: - context_documents.go: set GlobalContext: true in createContextDocument - write_create.go: default Status to "PUBLISHED" when not provided, default GlobalContext to true (use *bool to allow explicit false override) Closes #122
1 parent 7a406a8 commit 1e10f9f

File tree

4 files changed

+68
-6
lines changed

4 files changed

+68
-6
lines changed

pkg/client/context_documents.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,13 @@ func (c *Client) UpsertContextDocument(
154154
func (c *Client) createContextDocument(
155155
ctx context.Context, entityURN string, doc types.ContextDocumentInput,
156156
) (*types.ContextDocument, error) {
157-
// GlobalContext defaults to false (zero value), which is intentional:
158-
// context documents are entity-scoped and should not appear in global search.
159-
// CreateDocument always sends the settings block, so false is explicit on the wire.
160157
input := types.CreateDocumentInput{
161158
Title: doc.Title,
162159
Content: doc.Content,
163160
SubType: doc.Category,
164161
RelatedAssetURNs: []string{entityURN},
165162
Status: "PUBLISHED",
163+
GlobalContext: true,
166164
}
167165

168166
urn, err := c.CreateDocument(ctx, input)

pkg/client/context_documents_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ func TestUpsertContextDocument_Create(t *testing.T) {
180180
if len(assets) != 1 {
181181
t.Errorf("relatedAssets len = %d, want 1", len(assets))
182182
}
183+
settings, _ := input["settings"].(map[string]any)
184+
if settings["showInGlobalContext"] != true {
185+
t.Errorf("showInGlobalContext = %v, want true", settings["showInGlobalContext"])
186+
}
183187
_, _ = w.Write([]byte(`{"data": {"createDocument": "urn:li:document:new-1"}}`))
184188

185189
case strings.Contains(req.Query, "getDocument"):

pkg/tools/write_create.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type CreateInput struct {
3838
Status string `json:"status,omitempty" jsonschema_description:"Publication status: PUBLISHED or UNPUBLISHED (document only)"`
3939
SubType string `json:"sub_type,omitempty" jsonschema_description:"Document sub-type (document only)"`
4040
RelatedAssets []string `json:"related_assets,omitempty" jsonschema_description:"Related asset URNs (document only)"`
41-
GlobalContext bool `json:"global_context,omitempty" jsonschema_description:"Show in global search (document only)"`
41+
GlobalContext *bool `json:"global_context,omitempty" jsonschema_description:"Show in global search (document only, default: true)"`
4242

4343
// Structured property fields
4444
QualifiedName string `json:"qualified_name,omitempty" jsonschema_description:"Fully qualified name (structured_property)"`
@@ -167,13 +167,24 @@ func (t *Toolkit) handleCreateDocument(ctx context.Context, c DataHubClient, inp
167167
if input.Name == "" {
168168
return "", errRequired("name")
169169
}
170+
171+
status := input.Status
172+
if status == "" {
173+
status = "PUBLISHED"
174+
}
175+
176+
globalContext := true
177+
if input.GlobalContext != nil {
178+
globalContext = *input.GlobalContext
179+
}
180+
170181
return c.CreateDocument(ctx, types.CreateDocumentInput{
171182
Title: input.Name,
172183
Content: input.Description,
173-
Status: input.Status,
184+
Status: status,
174185
SubType: input.SubType,
175186
RelatedAssetURNs: input.RelatedAssets,
176-
GlobalContext: input.GlobalContext,
187+
GlobalContext: globalContext,
177188
})
178189
}
179190

pkg/tools/write_create_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package tools
33
import (
44
"context"
55
"testing"
6+
7+
"github.com/txn2/mcp-datahub/pkg/types"
68
)
79

810
func TestHandleCreate_RequiresWhat(t *testing.T) {
@@ -67,6 +69,53 @@ func TestHandleCreate_AllTypes(t *testing.T) {
6769
}
6870
}
6971

72+
func TestHandleCreateDocument_Defaults(t *testing.T) {
73+
mock := &mockClient{}
74+
mock.createDocumentFunc = func(_ context.Context, input types.CreateDocumentInput) (string, error) {
75+
if input.Status != "PUBLISHED" {
76+
t.Errorf("Status = %q, want PUBLISHED", input.Status)
77+
}
78+
if !input.GlobalContext {
79+
t.Error("GlobalContext = false, want true")
80+
}
81+
return "urn:li:document:test", nil
82+
}
83+
84+
toolkit := NewToolkit(mock, Config{WriteEnabled: true})
85+
result, _, _ := toolkit.handleCreate(context.Background(), nil, CreateInput{
86+
What: "document",
87+
Name: "Test Doc",
88+
})
89+
if result.IsError {
90+
t.Errorf("unexpected error: %v", result)
91+
}
92+
}
93+
94+
func TestHandleCreateDocument_ExplicitOverrides(t *testing.T) {
95+
mock := &mockClient{}
96+
mock.createDocumentFunc = func(_ context.Context, input types.CreateDocumentInput) (string, error) {
97+
if input.Status != "UNPUBLISHED" {
98+
t.Errorf("Status = %q, want UNPUBLISHED", input.Status)
99+
}
100+
if input.GlobalContext {
101+
t.Error("GlobalContext = true, want false")
102+
}
103+
return "urn:li:document:test", nil
104+
}
105+
106+
toolkit := NewToolkit(mock, Config{WriteEnabled: true})
107+
gcFalse := false
108+
result, _, _ := toolkit.handleCreate(context.Background(), nil, CreateInput{
109+
What: "document",
110+
Name: "Draft Doc",
111+
Status: "UNPUBLISHED",
112+
GlobalContext: &gcFalse,
113+
})
114+
if result.IsError {
115+
t.Errorf("unexpected error: %v", result)
116+
}
117+
}
118+
70119
func TestHandleCreate_InvalidWhat(t *testing.T) {
71120
toolkit := NewToolkit(&mockClient{}, Config{WriteEnabled: true})
72121
result, _, _ := toolkit.handleCreate(context.Background(), nil, CreateInput{What: "invalid"})

0 commit comments

Comments
 (0)