|
1 | | -import { Hono } from 'hono' |
2 | | -import { Octokit } from 'octokit' |
3 | | -import OAuthProvider, { |
4 | | - AuthRequest, |
5 | | - OAuthHelpers, |
6 | | -} from 'workers-mcp/vendor/workers-oauth-provider/oauth-provider.js' |
| 1 | +import OAuthProvider from '@cloudflare/workers-oauth-provider'; |
| 2 | +import { |
| 3 | + AccountSchema, |
| 4 | + CloudflareAuthHandler, |
| 5 | + handleTokenExchangeCallback, |
| 6 | + UserSchema, |
| 7 | +} from '@repo/mcp-common/src/cloudflare-oauth-handler'; |
7 | 8 |
|
8 | | -import { ContainerManager } from './containerManager' |
9 | | -import { ContainerMcpAgent } from './containerMcp' |
| 9 | +import { ContainerManager } from './containerManager'; |
| 10 | +import { ContainerMcpAgent } from './containerMcp'; |
10 | 11 |
|
11 | | -export { ContainerManager, ContainerMcpAgent } |
| 12 | +export { ContainerManager, ContainerMcpAgent }; |
12 | 13 |
|
13 | 14 | export type Env = { |
14 | 15 | CONTAINER_MCP_AGENT: DurableObjectNamespace<ContainerMcpAgent> |
15 | 16 | CONTAINER_MANAGER: DurableObjectNamespace<ContainerManager> |
16 | 17 | ENVIRONMENT: 'dev' | 'prod' |
17 | 18 | } |
18 | 19 |
|
19 | | -// TODO: add user specific props |
20 | | -export type Props = {} |
21 | | - |
22 | | -const app = new Hono<{ Bindings: Env }>() |
| 20 | +// Context from the auth process, encrypted & stored in the auth token |
| 21 | +// and provided to the DurableMCP as this.props |
| 22 | +export type Props = { |
| 23 | + accessToken: string |
| 24 | + user: UserSchema['result'] |
| 25 | + accounts: AccountSchema['result'] |
| 26 | +} |
23 | 27 |
|
24 | | -export default ContainerMcpAgent.mount('/sse', { binding: 'CONTAINER_MCP_AGENT' }) |
| 28 | +export default new OAuthProvider({ |
| 29 | + apiRoute: '/workers/sandbox/sse', |
| 30 | + // @ts-ignore |
| 31 | + apiHandler: ContainerMcpAgent.mount('/workers/sandbox/sse', { binding: 'CONTAINER_MCP_AGENT' }), |
| 32 | + // @ts-ignore |
| 33 | + defaultHandler: CloudflareAuthHandler, |
| 34 | + authorizeEndpoint: '/oauth/authorize', |
| 35 | + tokenEndpoint: '/token', |
| 36 | + tokenExchangeCallback: handleTokenExchangeCallback, |
| 37 | + // Cloudflare access token TTL |
| 38 | + accessTokenTTL: 3600, |
| 39 | + clientRegistrationEndpoint: '/register', |
| 40 | +}) |
0 commit comments