Skip to content

Commit 2effbb1

Browse files
Saranya-jenaHarness
authored andcommitted
chore: [ML-1466]: Add harness context in the ask_ai_devops_agent tool from harness_context (#231)
* eb819c chore: [ML-1466]: Add harness context in the ask_ai_devops_agent tool from harness_context
1 parent 9a92adc commit 2effbb1

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

pkg/harness/tools/intelligence.go

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,37 @@ func AIDevOpsAgentTool(config *config.Config, client *client.IntelligenceService
186186
return mcp.NewToolResultError(err.Error()), nil
187187
}
188188

189+
harnessContextRaw, err := OptionalParam[map[string]interface{}](request, "harness_context")
190+
if err != nil {
191+
return mcp.NewToolResultError(err.Error()), nil
192+
}
193+
189194
// Try to fetch scope parameters (account_id, org_id, project_id) if provided
190195
scope, err := common.FetchScope(config, request, false)
191196
if err != nil {
192197
return mcp.NewToolResultError(err.Error()), nil
193198
}
194199

200+
// Create harness context from scope
201+
harnessContext := &dto.HarnessContext{
202+
AccountID: scope.AccountID,
203+
OrgID: scope.OrgID,
204+
ProjectID: scope.ProjectID,
205+
}
206+
207+
// Override with values from request if provided
208+
if harnessContextRaw != nil {
209+
if accountID, ok := harnessContextRaw["account_id"].(string); ok && accountID != "" {
210+
harnessContext.AccountID = accountID
211+
}
212+
if orgID, ok := harnessContextRaw["org_id"].(string); ok && orgID != "" {
213+
harnessContext.OrgID = orgID
214+
}
215+
if projectID, ok := harnessContextRaw["project_id"].(string); ok && projectID != "" {
216+
harnessContext.ProjectID = projectID
217+
}
218+
}
219+
195220
// Process context items
196221
var contextItems []dto.ContextItem
197222
for _, ctxRaw := range contextRaw {
@@ -213,13 +238,6 @@ func AIDevOpsAgentTool(config *config.Config, client *client.IntelligenceService
213238
interactionID = uuid.New().String()
214239
}
215240

216-
// Create harness context from scope
217-
harnessContext := &dto.HarnessContext{
218-
AccountID: scope.AccountID,
219-
OrgID: scope.OrgID,
220-
ProjectID: scope.ProjectID,
221-
}
222-
223241
// Create AI DevOps request
224242
aiRequest := &dto.ServiceChatParameters{
225243
BaseRequestParameters: dto.BaseRequestParameters{

0 commit comments

Comments
 (0)