forked from punkpeye/fastmcp
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathoauth-proxy-github.ts
More file actions
55 lines (48 loc) · 1.48 KB
/
Copy pathoauth-proxy-github.ts
File metadata and controls
55 lines (48 loc) · 1.48 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
/**
* Example FastMCP server with GitHub OAuth
*
* This example shows how to use GitHub as the OAuth provider
* with the simplified auth configuration.
*
* Run with: node dist/examples/oauth-proxy-github.js
*/
import { getAuthSession, GitHubProvider, requireAuth } from "../auth/index.js";
import { FastMCP } from "../FastMCP.js";
// Create FastMCP server with GitHub OAuth
const server = new FastMCP({
auth: new GitHubProvider({
baseUrl: "http://localhost:4201",
clientId: process.env.GITHUB_CLIENT_ID || "your-github-client-id",
clientSecret:
process.env.GITHUB_CLIENT_SECRET || "your-github-client-secret",
scopes: ["read:user", "user:email"],
}),
name: "GitHub OAuth Server",
version: "1.0.0",
});
server.addTool({
canAccess: requireAuth, // Only visible to authenticated users
description: "Get GitHub repositories for authenticated user",
execute: async (_, { session }) => {
const { accessToken } = getAuthSession(session);
return {
content: [
{
text: `Authenticated! Token starts with: ${accessToken.slice(0, 8)}...`,
type: "text" as const,
},
],
};
},
name: "get-repositories",
});
await server.start({
httpStream: { port: 4201 },
transportType: "httpStream",
});
console.log(`
🚀 GitHub OAuth Server is running on http://localhost:4201
OAuth Provider: GitHub
Callback URL: http://localhost:4201/oauth/callback
Make sure to configure this callback URL in your GitHub OAuth App settings.
`);