Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions apps/sandbox-container/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
"dev": "concurrently \"tsx container/index.ts\" \"wrangler dev --var \"ENVIRONMENT:dev\"\"",
"build": "docker build .",
"start": "wrangler dev",
"start:container": "tsx container/index.ts"
"start:container": "tsx container/index.ts",
"postinstall": "mkdir -p workdir"
},
"dependencies": {
"@cloudflare/workers-oauth-provider": "0.0.2",
"@cloudflare/workers-types": "^4.20250320.0",
"@hono/node-server": "^1.13.8",
"@hono/zod-validator": "^0.4.3",
Expand All @@ -26,7 +28,8 @@
"partyserver": "^0.0.65",
"tsx": "^4.19.3",
"workers-mcp": "0.1.0-3",
"zod": "^3.24.2"
"zod": "^3.24.2",
"@repo/mcp-common": "workspace:*"
},
"devDependencies": {
"concurrently": "^9.1.2",
Expand Down
39 changes: 28 additions & 11 deletions apps/sandbox-container/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Hono } from 'hono'
import { Octokit } from 'octokit'
import OAuthProvider, {
AuthRequest,
OAuthHelpers,
} from 'workers-mcp/vendor/workers-oauth-provider/oauth-provider.js'
import OAuthProvider from '@cloudflare/workers-oauth-provider'

import {
AccountSchema,
CloudflareAuthHandler,
handleTokenExchangeCallback,
UserSchema,
} from '@repo/mcp-common/src/cloudflare-oauth-handler'

import { ContainerManager } from './containerManager'
import { ContainerMcpAgent } from './containerMcp'
Expand All @@ -16,9 +18,24 @@ export type Env = {
ENVIRONMENT: 'dev' | 'prod'
}

// TODO: add user specific props
export type Props = {}

const app = new Hono<{ Bindings: Env }>()
// Context from the auth process, encrypted & stored in the auth token
// and provided to the DurableMCP as this.props
export type Props = {
accessToken: string
user: UserSchema['result']
accounts: AccountSchema['result']
}

export default ContainerMcpAgent.mount('/sse', { binding: 'CONTAINER_MCP_AGENT' })
export default new OAuthProvider({
apiRoute: '/workers/sandbox/sse',
// @ts-ignore
apiHandler: ContainerMcpAgent.mount('/workers/sandbox/sse', { binding: 'CONTAINER_MCP_AGENT' }),
// @ts-ignore
defaultHandler: CloudflareAuthHandler,
authorizeEndpoint: '/oauth/authorize',
tokenEndpoint: '/token',
tokenExchangeCallback: handleTokenExchangeCallback,
// Cloudflare access token TTL
accessTokenTTL: 3600,
clientRegistrationEndpoint: '/register',
})
9 changes: 9 additions & 0 deletions apps/sandbox-container/wrangler.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,14 @@
],
"observability": {
"enabled": true
},
"kv_namespaces": [
{
"binding": "OAUTH_KV",
"id": "DEV_KV"
}
],
"dev": {
"port": 8976
}
}
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.