@@ -48,6 +48,9 @@ class ServerSettings(BaseSettings):
4848 github_auth_url : str = "https://github.com/login/oauth/authorize"
4949 github_token_url : str = "https://github.com/login/oauth/access_token"
5050
51+ mcp_scope : str = "user"
52+ github_scope : str = "read:user"
53+
5154 def __init__ (self , ** data ):
5255 """Initialize settings with values from environment variables.
5356
@@ -100,7 +103,7 @@ async def authorize(
100103 f"{ self .settings .github_auth_url } "
101104 f"?client_id={ self .settings .github_client_id } "
102105 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
104107 f"&state={ state } "
105108 )
106109
@@ -141,7 +144,6 @@ async def handle_github_callback(self, code: str, state: str) -> str:
141144 raise HTTPException (400 , data .get ("error_description" , data ["error" ]))
142145
143146 github_token = data ["access_token" ]
144- scope = data .get ("scope" , "user" ).split ()
145147
146148 # Create MCP authorization code
147149 new_code = f"mcp_{ secrets .token_hex (16 )} "
@@ -151,7 +153,7 @@ async def handle_github_callback(self, code: str, state: str) -> str:
151153 redirect_uri = AnyHttpUrl (redirect_uri ),
152154 redirect_uri_provided_explicitly = redirect_uri_provided_explicitly ,
153155 expires_at = time .time () + 300 ,
154- scopes = scope ,
156+ scopes = [ self . settings . mcp_scope ] ,
155157 code_challenge = code_challenge ,
156158 )
157159 self .auth_codes [new_code ] = auth_code
@@ -160,7 +162,7 @@ async def handle_github_callback(self, code: str, state: str) -> str:
160162 self .tokens [github_token ] = AccessToken (
161163 token = github_token ,
162164 client_id = client_id ,
163- scopes = scope ,
165+ scopes = [ self . settings . github_scope ] ,
164166 expires_at = None ,
165167 )
166168
@@ -260,10 +262,10 @@ def create_simple_mcp_server(settings: ServerSettings) -> FastMCP:
260262 issuer_url = settings .server_url ,
261263 client_registration_options = ClientRegistrationOptions (
262264 enabled = True ,
263- valid_scopes = ["user" ],
264- default_scopes = ["user" ],
265+ valid_scopes = [settings . mcp_scope ],
266+ default_scopes = [settings . mcp_scope ],
265267 ),
266- required_scopes = ["user" ],
268+ required_scopes = [settings . mcp_scope ],
267269 )
268270
269271 app = FastMCP (
0 commit comments