@@ -82,19 +82,15 @@ async def register_client(self, client_info: OAuthClientInformationFull):
82
82
"""Register a new OAuth client."""
83
83
self .clients [client_info .client_id ] = client_info
84
84
85
- async def authorize (
86
- self , client : OAuthClientInformationFull , params : AuthorizationParams
87
- ) -> str :
85
+ async def authorize (self , client : OAuthClientInformationFull , params : AuthorizationParams ) -> str :
88
86
"""Generate an authorization URL for GitHub OAuth flow."""
89
87
state = params .state or secrets .token_hex (16 )
90
88
91
89
# Store the state mapping
92
90
self .state_mapping [state ] = {
93
91
"redirect_uri" : str (params .redirect_uri ),
94
92
"code_challenge" : params .code_challenge ,
95
- "redirect_uri_provided_explicitly" : str (
96
- params .redirect_uri_provided_explicitly
97
- ),
93
+ "redirect_uri_provided_explicitly" : str (params .redirect_uri_provided_explicitly ),
98
94
"client_id" : client .client_id ,
99
95
}
100
96
@@ -117,9 +113,7 @@ async def handle_github_callback(self, code: str, state: str) -> str:
117
113
118
114
redirect_uri = state_data ["redirect_uri" ]
119
115
code_challenge = state_data ["code_challenge" ]
120
- redirect_uri_provided_explicitly = (
121
- state_data ["redirect_uri_provided_explicitly" ] == "True"
122
- )
116
+ redirect_uri_provided_explicitly = state_data ["redirect_uri_provided_explicitly" ] == "True"
123
117
client_id = state_data ["client_id" ]
124
118
125
119
# Exchange code for token with GitHub
@@ -200,8 +194,7 @@ async def exchange_authorization_code(
200
194
for token , data in self .tokens .items ()
201
195
# see https://github.blog/engineering/platform-security/behind-githubs-new-authentication-token-formats/
202
196
# which you get depends on your GH app setup.
203
- if (token .startswith ("ghu_" ) or token .startswith ("gho_" ))
204
- and data .client_id == client .client_id
197
+ if (token .startswith ("ghu_" ) or token .startswith ("gho_" )) and data .client_id == client .client_id
205
198
),
206
199
None ,
207
200
)
@@ -232,9 +225,7 @@ async def load_access_token(self, token: str) -> AccessToken | None:
232
225
233
226
return access_token
234
227
235
- async def load_refresh_token (
236
- self , client : OAuthClientInformationFull , refresh_token : str
237
- ) -> RefreshToken | None :
228
+ async def load_refresh_token (self , client : OAuthClientInformationFull , refresh_token : str ) -> RefreshToken | None :
238
229
"""Load a refresh token - not supported."""
239
230
return None
240
231
@@ -247,9 +238,7 @@ async def exchange_refresh_token(
247
238
"""Exchange refresh token"""
248
239
raise NotImplementedError ("Not supported" )
249
240
250
- async def revoke_token (
251
- self , token : str , token_type_hint : str | None = None
252
- ) -> None :
241
+ async def revoke_token (self , token : str , token_type_hint : str | None = None ) -> None :
253
242
"""Revoke a token."""
254
243
if token in self .tokens :
255
244
del self .tokens [token ]
@@ -335,9 +324,7 @@ async def get_user_profile() -> dict[str, Any]:
335
324
)
336
325
337
326
if response .status_code != 200 :
338
- raise ValueError (
339
- f"GitHub API error: { response .status_code } - { response .text } "
340
- )
327
+ raise ValueError (f"GitHub API error: { response .status_code } - { response .text } " )
341
328
342
329
return response .json ()
343
330
@@ -361,9 +348,7 @@ def main(port: int, host: str, transport: Literal["sse", "streamable-http"]) ->
361
348
# No hardcoded credentials - all from environment variables
362
349
settings = ServerSettings (host = host , port = port )
363
350
except ValueError as e :
364
- logger .error (
365
- "Failed to load settings. Make sure environment variables are set:"
366
- )
351
+ logger .error ("Failed to load settings. Make sure environment variables are set:" )
367
352
logger .error (" MCP_GITHUB_GITHUB_CLIENT_ID=<your-client-id>" )
368
353
logger .error (" MCP_GITHUB_GITHUB_CLIENT_SECRET=<your-client-secret>" )
369
354
logger .error (f"Error: { e } " )
0 commit comments