Skip to content

Commit b0827a7

Browse files
committed
give preference to orgID and projectID in MCP request
1 parent 9a85129 commit b0827a7

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

pkg/harness/scope.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,33 @@ func WithScope(config *config.Config, required bool) mcp.ToolOption {
3232
}
3333

3434
// fetchScope fetches the scope from the config and MCP request.
35-
// It looks in the config first and then in the request (if it was defined).
35+
// It looks in the config first and then in the request (if it was defined). The request is given preference
36+
// so anything passed by the user in the request will override the config.
3637
// If orgID and projectID are required fields, it will return an error if they are not present.
3738
func fetchScope(config *config.Config, request mcp.CallToolRequest, required bool) (dto.Scope, error) {
38-
scope := dto.Scope{}
3939
// account ID is always required
4040
if config.AccountID == "" {
41-
return scope, fmt.Errorf("account ID is required")
41+
return dto.Scope{}, fmt.Errorf("account ID is required")
42+
}
43+
44+
scope := dto.Scope{
45+
AccountID: config.AccountID,
46+
OrgID: config.OrgID,
47+
ProjectID: config.ProjectID,
4248
}
43-
scope.AccountID = config.AccountID
44-
// org ID and project ID may or may not be required for APIs. If they are required, we return an error
45-
// if not present.
46-
scope.OrgID = config.OrgID
47-
scope.ProjectID = config.ProjectID
4849

49-
if scope.OrgID == "" {
50-
// try to fetch it from the MCP request
51-
org, _ := OptionalParam[string](request, "org_id")
50+
// try to fetch it from the MCP request
51+
org, _ := OptionalParam[string](request, "org_id")
52+
if org != "" {
5253
scope.OrgID = org
5354
}
54-
if scope.ProjectID == "" {
55-
// try to fetch it from the MCP request
56-
project, _ := OptionalParam[string](request, "project_id")
55+
project, _ := OptionalParam[string](request, "project_id")
56+
if project != "" {
5757
scope.ProjectID = project
5858
}
5959

60+
// org ID and project ID may or may not be required for APIs. If they are required, we return an error
61+
// if not present.
6062
if required {
6163
if scope.OrgID == "" || scope.ProjectID == "" {
6264
return scope, fmt.Errorf("org ID and project ID are required")

0 commit comments

Comments
 (0)