Skip to content

Commit 2fd4db5

Browse files
authored
Merge branch 'main' into feature/auth-tfe
2 parents 36eb20d + 0caacaf commit 2fd4db5

File tree

3 files changed

+46
-6
lines changed

3 files changed

+46
-6
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ cmd/terraform-mcp-server/terraform-mcp-server/terraform-mcp-server
33
cmd/mcpcurl/mcpcurl
44
*.log
55
.vscode/
6-
dist/
6+
dist/
7+
bin/*

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ all: build
2323
ARCH = $(shell A=$$(uname -m); [ $$A = x86_64 ] && A=amd64; echo $$A)
2424
OS = $(shell uname | tr [[:upper:]] [[:lower:]])
2525
build:
26-
CGO_ENABLED=0 GOARCH=$(ARCH) GOOS=$(OS) $(GO) build $(LDFLAGS) -o $(BINARY_NAME) ./cmd/terraform-mcp-server
26+
CGO_ENABLED=0 GOARCH=$(ARCH) GOOS=$(OS) $(GO) build $(LDFLAGS) -o bin/$(BINARY_NAME) ./cmd/terraform-mcp-server
2727

2828
crt-build:
2929
@mkdir -p $(TARGET_DIR)

pkg/tools/resolve_provider_doc_id.go

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func resolveProviderDocIDHandler(ctx context.Context, request mcp.CallToolReques
116116

117117
var builder strings.Builder
118118
builder.WriteString(fmt.Sprintf("Available Documentation (top matches) for %s in Terraform provider %s/%s version: %s\n\n", providerDetail.ProviderDataType, providerDetail.ProviderNamespace, providerDetail.ProviderName, providerDetail.ProviderVersion))
119-
builder.WriteString("Each result includes:\n- providerDocID: tfprovider-compatible identifier\n- Title: Service or resource name\n- Category: Type of document\n")
119+
builder.WriteString("Each result includes:\n- providerDocID: tfprovider-compatible identifier\n- Title: Service or resource name\n- Category: Type of document\n- Description: Brief summary of the document\n")
120120
builder.WriteString("For best results, select libraries based on the service_slug match and category of information requested.\n\n---\n\n")
121121

122122
contentAvailable := false
@@ -126,7 +126,11 @@ func resolveProviderDocIDHandler(ctx context.Context, request mcp.CallToolReques
126126
cs_pn, err_pn := utils.ContainsSlug(fmt.Sprintf("%s_%s", providerDetail.ProviderName, doc.Slug), serviceSlug)
127127
if (cs || cs_pn) && err == nil && err_pn == nil {
128128
contentAvailable = true
129-
builder.WriteString(fmt.Sprintf("- providerDocID: %s\n- Title: %s\n- Category: %s\n---\n", doc.ID, doc.Title, doc.Category))
129+
descriptionSnippet, err := getContentSnippet(registryClient, doc.ID, logger)
130+
if err != nil {
131+
logger.Warnf("Error fetching content snippet for provider doc ID: %s: %v", doc.ID, err)
132+
}
133+
builder.WriteString(fmt.Sprintf("- providerDocID: %s\n- Title: %s\n- Category: %s\n- Description: %s\n---\n", doc.ID, doc.Title, doc.Category, descriptionSnippet))
130134
}
131135
}
132136
}
@@ -218,11 +222,46 @@ func get_provider_docsV2(registryClient *http.Client, providerDetail client.Prov
218222

219223
var builder strings.Builder
220224
builder.WriteString(fmt.Sprintf("Available Documentation (top matches) for %s in Terraform provider %s/%s version: %s\n\n", providerDetail.ProviderDataType, providerDetail.ProviderNamespace, providerDetail.ProviderName, providerDetail.ProviderVersion))
221-
builder.WriteString("Each result includes:\n- providerDocID: tfprovider-compatible identifier\n- Title: Service or resource name\n- Category: Type of document\n")
225+
builder.WriteString("Each result includes:\n- providerDocID: tfprovider-compatible identifier\n- Title: Service or resource name\n- Category: Type of document\n- Description: Brief summary of the document\n")
222226
builder.WriteString("For best results, select libraries based on the service_slug match and category of information requested.\n\n---\n\n")
223227
for _, doc := range docs {
224-
builder.WriteString(fmt.Sprintf("- providerDocID: %s\n- Title: %s\n- Category: %s\n---\n", doc.ID, doc.Attributes.Title, doc.Attributes.Category))
228+
descriptionSnippet, err := getContentSnippet(registryClient, doc.ID, logger)
229+
if err != nil {
230+
logger.Warnf("Error fetching content snippet for provider doc ID: %s: %v", doc.ID, err)
231+
}
232+
builder.WriteString(fmt.Sprintf("- providerDocID: %s\n- Title: %s\n- Category: %s\n- Description: %s\n---\n", doc.ID, doc.Attributes.Title, doc.Attributes.Category, descriptionSnippet))
225233
}
226234

227235
return builder.String(), nil
228236
}
237+
238+
func getContentSnippet(registryClient *http.Client, docID string, logger *log.Logger) (string, error) {
239+
docContent, err := client.SendRegistryCall(registryClient, "GET", fmt.Sprintf("provider-docs/%s", docID), logger, "v2")
240+
if err != nil {
241+
return "", utils.LogAndReturnError(logger, fmt.Sprintf("error fetching provider-docs/%s within getContentSnippet", docID), err)
242+
}
243+
var docDescription client.ProviderResourceDetails
244+
if err := json.Unmarshal(docContent, &docDescription); err != nil {
245+
return "", utils.LogAndReturnError(logger, fmt.Sprintf("error unmarshalling provider-docs/%s within getContentSnippet", docID), err)
246+
}
247+
248+
content := docDescription.Data.Attributes.Content
249+
// Try to extract description from markdown content
250+
desc := ""
251+
if start := strings.Index(content, "description: |-"); start != -1 {
252+
if end := strings.Index(content[start:], "\n---"); end != -1 {
253+
substring := content[start+len("description: |-") : start+end]
254+
trimmed := strings.TrimSpace(substring)
255+
desc = strings.ReplaceAll(trimmed, "\n", " ")
256+
} else {
257+
substring := content[start+len("description: |-"):]
258+
trimmed := strings.TrimSpace(substring)
259+
desc = strings.ReplaceAll(trimmed, "\n", " ")
260+
}
261+
}
262+
263+
if len(desc) > 300 {
264+
return desc[:300] + "...", nil
265+
}
266+
return desc, nil
267+
}

0 commit comments

Comments
 (0)