Skip to content

Commit 4c1dc21

Browse files
committed
Setup auth-server to handle callbacks for sandbox-container and workers-bindings
1 parent a925043 commit 4c1dc21

File tree

14 files changed

+53
-36
lines changed

14 files changed

+53
-36
lines changed

apps/auth-server/wrangler.jsonc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
"staging": {
2121
"name": "mcp-cloudflare-auth-server-staging",
2222
"account_id": "8995c0f49cdcf57eb54d2c1e52b7d2f3",
23-
"routes": ["staging.mcp.cloudflare.com/oauth/callback"],
23+
"routes": ["staging.mcp.cloudflare.com/oauth/callback"]
2424
},
2525
"production": {
2626
"name": "mcp-cloudflare-auth-server-production",
2727
"account_id": "8995c0f49cdcf57eb54d2c1e52b7d2f3",
28-
"routes": ["mcp.cloudflare.com/oauth/callback"],
28+
"routes": ["mcp.cloudflare.com/oauth/callback"]
2929
}
3030
}
3131
}

apps/sandbox-container/container/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { Hono } from 'hono'
77
import { streamText } from 'hono/streaming'
88
import mime from 'mime'
99

10-
import { ExecParams, FilesWrite } from '../shared/schema.ts'
11-
import { get_file_name_from_path } from './fileUtils.ts'
10+
import { ExecParams, FilesWrite } from '../shared/schema'
11+
import { get_file_name_from_path } from './fileUtils'
1212

1313
import type { FileList } from '../shared/schema.ts'
1414

apps/sandbox-container/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"@hono/node-server": "^1.13.8",
2121
"@hono/zod-validator": "^0.4.3",
2222
"@modelcontextprotocol/sdk": "^1.7.0",
23+
"@repo/mcp-common": "workspace:*",
2324
"@types/node": "^22.13.10",
2425
"agents": "^0.0.42",
2526
"cron-schedule": "^5.0.4",
@@ -30,10 +31,10 @@
3031
"partyserver": "^0.0.65",
3132
"tsx": "^4.19.3",
3233
"workers-mcp": "0.1.0-3",
33-
"zod": "^3.24.2",
34-
"@repo/mcp-common": "workspace:*"
34+
"zod": "^3.24.2"
3535
},
3636
"devDependencies": {
37+
"@cloudflare/vitest-pool-workers": "0.8.14",
3738
"concurrently": "^9.1.2",
3839
"wrangler": "^4.9.1"
3940
}

apps/sandbox-container/server/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import OAuthProvider from '@cloudflare/workers-oauth-provider'
22
import { env } from 'cloudflare:workers'
33

44
import {
5-
CloudflareAuthHandler,
5+
createAuthHandlers,
66
handleTokenExchangeCallback,
77
} from '@repo/mcp-common/src/cloudflare-oauth-handler'
8+
import { getEnvironment } from '@repo/mcp-common/src/config'
89

910
import { ContainerManager } from './containerManager'
1011
import { ContainerMcpAgent } from './containerMcp'
@@ -32,7 +33,10 @@ export default new OAuthProvider({
3233
// @ts-ignore
3334
apiHandler: ContainerMcpAgent.mount('/workers/sandbox/sse', { binding: 'CONTAINER_MCP_AGENT' }),
3435
// @ts-ignore
35-
defaultHandler: CloudflareAuthHandler,
36+
defaultHandler: createAuthHandlers({
37+
serverPath: 'workers/containers',
38+
environment: getEnvironment(env.ENVIRONMENT),
39+
}),
3640
authorizeEndpoint: '/oauth/authorize',
3741
tokenEndpoint: '/token',
3842
tokenExchangeCallback: (options) =>
Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
11
{
2-
"compilerOptions": {
3-
"target": "ESNext",
4-
"lib": ["ESNext", "DOM"],
5-
"jsx": "react-jsx",
6-
"module": "ESNext",
7-
"moduleResolution": "bundler",
8-
"types": ["./worker-configuration.d.ts", "@cloudflare/workers-types/2023-07-01"],
9-
"noEmit": true,
10-
"esModuleInterop": true,
11-
"forceConsistentCasingInFileNames": true,
12-
"strict": true,
13-
"skipLibCheck": true
14-
},
15-
"include": ["server/**.ts", "shared/**.ts"]
2+
"extends": "@repo/typescript-config/workers.json"
163
}

apps/sandbox-container/worker-configuration.d.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
// Runtime types generated with [email protected] 2025-04-03
33
declare namespace Cloudflare {
44
interface Env {
5-
OAUTH_KV: KVNamespace
6-
CONTAINER_MCP_AGENT: DurableObjectNamespace<import('./server/index').ContainerMcpAgent>
7-
CONTAINER_MANAGER: DurableObjectNamespace<import('./server/index').ContainerManager>
8-
CLOUDFLARE_CLIENT_ID: string
9-
CLOUDFLARE_CLIENT_SECRET: string
5+
OAUTH_KV: KVNamespace;
6+
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
7+
CONTAINER_MCP_AGENT: DurableObjectNamespace<import("./server/index").ContainerMcpAgent>;
8+
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
9+
CONTAINER_MANAGER: DurableObjectNamespace<import("./server/index").ContainerManager>;
10+
CLOUDFLARE_CLIENT_ID: string;
11+
CLOUDFLARE_CLIENT_SECRET: string;
12+
ENVIRONMENT: string
1013
}
1114
}
1215
interface Env extends Cloudflare.Env {}

apps/sandbox-container/wrangler.jsonc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "node_modules/wrangler/config-schema.json",
3-
"name": "sandbox-container",
3+
"name": "sandbox-container-dev",
44
"main": "server/index.ts",
55
"compatibility_date": "2025-04-03",
66
"containers": [
@@ -41,5 +41,8 @@
4141
],
4242
"dev": {
4343
"port": 8976
44+
},
45+
"vars": {
46+
"ENVIRONMENT": "development"
4447
}
4548
}

apps/workers-bindings/src/index.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import { McpAgent } from 'agents/mcp'
44
import { env } from 'cloudflare:workers'
55

66
import {
7-
CloudflareAuthHandler,
7+
createAuthHandlers,
88
handleTokenExchangeCallback,
99
} from '@repo/mcp-common/src/cloudflare-oauth-handler'
10+
import { getEnvironment } from '@repo/mcp-common/src/config'
1011
import { registerAccountTools } from '@repo/mcp-common/src/tools/account'
1112
import { registerKVTools } from '@repo/mcp-common/src/tools/kv_namespace'
1213
import { registerWorkersTools } from '@repo/mcp-common/src/tools/worker'
@@ -66,11 +67,18 @@ export default new OAuthProvider({
6667
// @ts-ignore
6768
apiHandler: WorkersBindingsMCP.mount('/workers/bindings/sse'),
6869
// @ts-ignore
69-
defaultHandler: CloudflareAuthHandler,
70+
defaultHandler: createAuthHandlers({
71+
serverPath: 'workers/containers',
72+
environment: getEnvironment(env.ENVIRONMENT),
73+
}),
7074
authorizeEndpoint: '/oauth/authorize',
7175
tokenEndpoint: '/token',
7276
tokenExchangeCallback: (options) =>
73-
handleTokenExchangeCallback(options, env.CLOUDFLARE_CLIENT_ID, env.CLOUDFLARE_CLIENT_SECRET),
77+
handleTokenExchangeCallback(
78+
options,
79+
env.CLOUDFLARE_CLIENT_ID,
80+
env.CLOUDFLARE_CLIENT_SECRET
81+
),
7482
// Cloudflare access token TTL
7583
accessTokenTTL: 3600,
7684
clientRegistrationEndpoint: '/register',

apps/workers-bindings/vitest.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { defineWorkersConfig } from '@cloudflare/vitest-pool-workers/config'
22

3+
import type { Env } from './worker-configuration'
4+
35
export interface TestEnv extends Env {
46
CLOUDFLARE_MOCK_ACCOUNT_ID: string
57
CLOUDFLARE_MOCK_API_TOKEN: string

apps/workers-bindings/worker-configuration.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
// Generated by Wrangler by running `wrangler types` (hash: 83b65e4226fcf5092146edc626681982)
2+
23
// Runtime types generated with [email protected] 2025-03-10 nodejs_compat
34
declare namespace Cloudflare {
45
interface Env {
56
OAUTH_KV: KVNamespace;
67
CLOUDFLARE_CLIENT_ID: string;
78
CLOUDFLARE_CLIENT_SECRET: string;
9+
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
810
MCP_OBJECT: DurableObjectNamespace<import("./src/index").WorkersBindingsMCP>;
11+
ENVIRONMENT: string
912
}
1013
}
1114
interface Env extends Cloudflare.Env {}

0 commit comments

Comments
 (0)