@@ -46,7 +46,9 @@ def load_scopes_config():
46
46
47
47
def map_cognito_groups_to_scopes (groups : List [str ]) -> List [str ]:
48
48
"""
49
- Map Cognito groups to MCP scopes using the same format as M2M resource server scopes.
49
+ Map Cognito groups to MCP scopes using scopes.yml configuration.
50
+
51
+ Uses the same scope format as M2M tokens for consistency.
50
52
51
53
Args:
52
54
groups: List of Cognito group names
@@ -56,34 +58,27 @@ def map_cognito_groups_to_scopes(groups: List[str]) -> List[str]:
56
58
"""
57
59
scopes = []
58
60
61
+ # Use group mappings from scopes.yml if available
62
+ group_mappings = SCOPES_CONFIG .get ('group_mappings' , {})
63
+
59
64
for group in groups :
60
- if group == 'mcp-admin' :
61
- # Admin gets unrestricted read and execute access
62
- scopes .append ('mcp-servers-unrestricted/read' )
63
- scopes .append ('mcp-servers-unrestricted/execute' )
64
- elif group == 'mcp-user' :
65
- # Regular users get restricted read access by default
66
- scopes .append ('mcp-servers-restricted/read' )
67
- elif group .startswith ('mcp-server-' ):
68
- # Server-specific groups grant access based on server permissions
69
- # For now, grant restricted execute access for specific servers
70
- # This allows access to the servers defined in the restricted scope
71
- scopes .append ('mcp-servers-restricted/execute' )
72
-
73
- # Note: The actual server access control is handled by the
74
- # validate_server_tool_access function which checks the scopes.yml
75
- # configuration. The group names are preserved in the 'groups' field
76
- # for potential future fine-grained access control.
65
+ if group in group_mappings :
66
+ # Use configured mapping
67
+ scopes .extend (group_mappings [group ])
68
+ else :
69
+ # Legacy fallback for backward compatibility
70
+ logger .debug (f"Group '{ group } ' not in group_mappings, using legacy mapping" )
71
+
72
+ if group == 'mcp-admin' :
73
+ scopes .extend (['mcp-servers-unrestricted/read' ,
74
+ 'mcp-servers-unrestricted/execute' ])
75
+ elif group == 'mcp-user' :
76
+ scopes .append ('mcp-servers-restricted/read' )
77
+ elif group .startswith ('mcp-server-' ):
78
+ scopes .append ('mcp-servers-restricted/execute' )
77
79
78
80
# Remove duplicates while preserving order
79
- seen = set ()
80
- unique_scopes = []
81
- for scope in scopes :
82
- if scope not in seen :
83
- seen .add (scope )
84
- unique_scopes .append (scope )
85
-
86
- return unique_scopes
81
+ return list (dict .fromkeys (scopes ))
87
82
88
83
def validate_session_cookie (cookie_value : str ) -> Dict [str , any ]:
89
84
"""
0 commit comments