Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions mcp-agents/Github MCP Agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,13 @@ async def get_user_info(self, access_token: str) -> Optional[Dict]:
f"{self.api_base}/user",
headers={'Authorization': f'token {access_token}'}
)


# Initialize scopes to a safe default in case header is missing
scopes = scopes_response.headers.get('X-OAuth-Scopes', '') if scopes_response is not None else ''

# GitHub returns scopes in the X-OAuth-Scopes header
if 'X-OAuth-Scopes' in scopes_response.headers:
scopes = scopes_response.headers['X-OAuth-Scopes']
if scopes_response is not None and 'X-OAuth-Scopes' in scopes_response.headers:
scopes = scopes_response.headers.get('X-OAuth-Scopes', '')
user_info['token_scopes'] = scopes
print(f" Token scopes: {scopes}")

Expand Down Expand Up @@ -533,12 +536,15 @@ async def handle_chat_message(ctx: Context, sender: str, msg: ChatMessage):
headers={'Authorization': f'token {item.text}'}
)

# Initialize scopes to a safe default in case header is missing
scopes = scopes_response.headers.get('X-OAuth-Scopes', '') if scopes_response is not None else ''

# GitHub returns scopes in the X-OAuth-Scopes header
if 'X-OAuth-Scopes' in scopes_response.headers:
scopes = scopes_response.headers['X-OAuth-Scopes']
if scopes_response is not None and 'X-OAuth-Scopes' in scopes_response.headers:
scopes = scopes_response.headers.get('X-OAuth-Scopes', '')
user_info['token_scopes'] = scopes
ctx.logger.info(f"Token validated with required scopes")

if 'repo' not in scopes:
response_text = "❌ **Token Missing Permissions**\n\nYour token doesn't have 'repo' scope needed to create repositories.\n\nPlease create a new token at https://github.com/settings/tokens/new with these scopes:\n- ✅ repo\n- ✅ user:email\n- ✅ read:user"
else:
Expand Down