forked from mcp-use/mcp-use
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoauth_preregistered.py
More file actions
71 lines (56 loc) · 1.77 KB
/
oauth_preregistered.py
File metadata and controls
71 lines (56 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""
Test OAuth with Pre-registered credentials using GitHub.
SETUP REQUIRED:
1. Go to https://github.com/settings/developers
2. Click "New OAuth App"
3. Fill in:
- Application name: mcp-use-test
- Homepage URL: http://localhost
- Authorization callback URL: http://127.0.0.1:8080/callback
4. Click "Register application"
5. Copy the Client ID
6. Click "Generate a new client secret" and copy it
7. Create a .env file with:
GITHUB_CLIENT_ID=your_client_id
GITHUB_CLIENT_SECRET=your_client_secret
"""
import asyncio
import os
from dotenv import load_dotenv
from mcp_use import MCPClient
load_dotenv()
client_id = os.getenv("GITHUB_CLIENT_ID")
client_secret = os.getenv("GITHUB_CLIENT_SECRET")
if not client_id or not client_secret:
print("Missing GITHUB_CLIENT_ID or GITHUB_CLIENT_SECRET in .env file")
print("See docstring at top of file for setup instructions")
exit(1)
config = {
"mcpServers": {
"github": {
"url": "https://api.githubcopilot.com/mcp",
"auth": {
"client_id": client_id,
"client_secret": client_secret,
"scope": "read:user",
"callback_port": 8080,
},
}
}
}
async def main():
client = MCPClient(config=config)
try:
session = await client.create_session("github")
print("Connected to GitHub MCP server!")
# List available tools
tools = await session.connector.list_tools()
print(f"\nAvailable tools ({len(tools)}):")
for tool in tools[:5]: # Show first 5
print(f" - {tool.name}")
if len(tools) > 5:
print(f" ... and {len(tools) - 5} more")
finally:
await client.close_all_sessions()
if __name__ == "__main__":
asyncio.run(main())