@@ -48,6 +48,9 @@ class ServerSettings(BaseSettings):
48
48
github_auth_url : str = "https://github.com/login/oauth/authorize"
49
49
github_token_url : str = "https://github.com/login/oauth/access_token"
50
50
51
+ mcp_scope : str = "user"
52
+ github_scope : str = "read:user"
53
+
51
54
def __init__ (self , ** data ):
52
55
"""Initialize settings with values from environment variables.
53
56
@@ -100,7 +103,7 @@ async def authorize(
100
103
f"{ self .settings .github_auth_url } "
101
104
f"?client_id={ self .settings .github_client_id } "
102
105
f"&redirect_uri={ self .settings .github_callback_path } "
103
- f"&scope=user " # Only request user scope for minimal example
106
+ f"&scope={ self . settings . github_scope } " # Only request user scope for minimal example
104
107
f"&state={ state } "
105
108
)
106
109
@@ -141,7 +144,6 @@ async def handle_github_callback(self, code: str, state: str) -> str:
141
144
raise HTTPException (400 , data .get ("error_description" , data ["error" ]))
142
145
143
146
github_token = data ["access_token" ]
144
- scope = data .get ("scope" , "user" ).split ()
145
147
146
148
# Create MCP authorization code
147
149
new_code = f"mcp_{ secrets .token_hex (16 )} "
@@ -151,7 +153,7 @@ async def handle_github_callback(self, code: str, state: str) -> str:
151
153
redirect_uri = AnyHttpUrl (redirect_uri ),
152
154
redirect_uri_provided_explicitly = redirect_uri_provided_explicitly ,
153
155
expires_at = time .time () + 300 ,
154
- scopes = scope ,
156
+ scopes = [ self . settings . mcp_scope ] ,
155
157
code_challenge = code_challenge ,
156
158
)
157
159
self .auth_codes [new_code ] = auth_code
@@ -160,7 +162,7 @@ async def handle_github_callback(self, code: str, state: str) -> str:
160
162
self .tokens [github_token ] = AccessToken (
161
163
token = github_token ,
162
164
client_id = client_id ,
163
- scopes = scope ,
165
+ scopes = [ self . settings . github_scope ] ,
164
166
expires_at = None ,
165
167
)
166
168
@@ -260,10 +262,10 @@ def create_simple_mcp_server(settings: ServerSettings) -> FastMCP:
260
262
issuer_url = settings .server_url ,
261
263
client_registration_options = ClientRegistrationOptions (
262
264
enabled = True ,
263
- valid_scopes = ["user" ],
264
- default_scopes = ["user" ],
265
+ valid_scopes = [settings . mcp_scope ],
266
+ default_scopes = [settings . mcp_scope ],
265
267
),
266
- required_scopes = ["user" ],
268
+ required_scopes = [settings . mcp_scope ],
267
269
)
268
270
269
271
app = FastMCP (
0 commit comments