@@ -32,31 +32,33 @@ func WithScope(config *config.Config, required bool) mcp.ToolOption {
32
32
}
33
33
34
34
// 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.
36
37
// If orgID and projectID are required fields, it will return an error if they are not present.
37
38
func fetchScope (config * config.Config , request mcp.CallToolRequest , required bool ) (dto.Scope , error ) {
38
- scope := dto.Scope {}
39
39
// account ID is always required
40
40
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 ,
42
48
}
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
48
49
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 != "" {
52
53
scope .OrgID = org
53
54
}
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 != "" {
57
57
scope .ProjectID = project
58
58
}
59
59
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.
60
62
if required {
61
63
if scope .OrgID == "" || scope .ProjectID == "" {
62
64
return scope , fmt .Errorf ("org ID and project ID are required" )
0 commit comments