Skip to content

Commit 753c854

Browse files
committed
Add support for bearer auth with user API tokens
1 parent 8a2913f commit 753c854

File tree

11 files changed

+65
-32
lines changed

11 files changed

+65
-32
lines changed

apps/auditlogs/src/auditlogs.app.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
createAuthHandlers,
66
handleTokenExchangeCallback,
77
} from '@repo/mcp-common/src/cloudflare-oauth-handler'
8-
import { handleDevMode } from '@repo/mcp-common/src/dev-mode'
8+
import { handleApiTokenMode, isApiTokenRequest } from '@repo/mcp-common/src/dev-mode'
99
import { getUserDetails, UserDetails } from '@repo/mcp-common/src/durable-objects/user_details.do'
1010
import { getEnv } from '@repo/mcp-common/src/env'
1111
import { RequiredScopes } from '@repo/mcp-common/src/scopes'
@@ -95,8 +95,8 @@ const AuditlogScopes = {
9595

9696
export default {
9797
fetch: async (req: Request, env: Env, ctx: ExecutionContext) => {
98-
if (env.ENVIRONMENT === 'development' && env.DEV_DISABLE_OAUTH === 'true') {
99-
return await handleDevMode(AuditlogMCP, req, env, ctx)
98+
if (await isApiTokenRequest(req, env)) {
99+
return await handleApiTokenMode(AuditlogMCP, req, env, ctx)
100100
}
101101

102102
return new OAuthProvider({

apps/autorag/src/autorag.app.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
createAuthHandlers,
66
handleTokenExchangeCallback,
77
} from '@repo/mcp-common/src/cloudflare-oauth-handler'
8-
import { handleDevMode } from '@repo/mcp-common/src/dev-mode'
8+
import { handleApiTokenMode, isApiTokenRequest } from '@repo/mcp-common/src/dev-mode'
99
import { getUserDetails, UserDetails } from '@repo/mcp-common/src/durable-objects/user_details.do'
1010
import { getEnv } from '@repo/mcp-common/src/env'
1111
import { RequiredScopes } from '@repo/mcp-common/src/scopes'
@@ -95,8 +95,8 @@ const LogPushScopes = {
9595

9696
export default {
9797
fetch: async (req: Request, env: Env, ctx: ExecutionContext) => {
98-
if (env.ENVIRONMENT === 'development' && env.DEV_DISABLE_OAUTH === 'true') {
99-
return await handleDevMode(AutoRAGMCP, req, env, ctx)
98+
if (await isApiTokenRequest(req, env)) {
99+
return await handleApiTokenMode(AutoRAGMCP, req, env, ctx)
100100
}
101101

102102
return new OAuthProvider({

apps/cloudflare-one-casb/src/cf1-casb.app.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import {
55
createAuthHandlers,
66
handleTokenExchangeCallback,
77
} from '@repo/mcp-common/src/cloudflare-oauth-handler'
8-
import { handleDevMode } from '@repo/mcp-common/src/dev-mode'
98
import { getUserDetails, UserDetails } from '@repo/mcp-common/src/durable-objects/user_details.do'
9+
import { handleApiTokenMode, isApiTokenRequest } from '@repo/mcp-common/src/dev-mode'
1010
import { getEnv } from '@repo/mcp-common/src/env'
1111
import { RequiredScopes } from '@repo/mcp-common/src/scopes'
1212
import { CloudflareMCPServer } from '@repo/mcp-common/src/server'
@@ -93,8 +93,8 @@ const CloudflareOneCasbScopes = {
9393

9494
export default {
9595
fetch: async (req: Request, env: Env, ctx: ExecutionContext) => {
96-
if (env.ENVIRONMENT === 'development' && env.DEV_DISABLE_OAUTH === 'true') {
97-
return await handleDevMode(CASBMCP, req, env, ctx)
96+
if (await isApiTokenRequest(req, env)) {
97+
return await handleApiTokenMode(CASBMCP, req, env, ctx)
9898
}
9999

100100
return new OAuthProvider({

apps/dns-analytics/src/dns-analytics.app.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
createAuthHandlers,
66
handleTokenExchangeCallback,
77
} from '@repo/mcp-common/src/cloudflare-oauth-handler'
8-
import { handleDevMode } from '@repo/mcp-common/src/dev-mode'
8+
import { handleApiTokenMode, isApiTokenRequest } from '@repo/mcp-common/src/dev-mode'
99
import { getUserDetails, UserDetails } from '@repo/mcp-common/src/durable-objects/user_details.do'
1010
import { getEnv } from '@repo/mcp-common/src/env'
1111
import { RequiredScopes } from '@repo/mcp-common/src/scopes'
@@ -102,8 +102,8 @@ const AnalyticsScopes = {
102102

103103
export default {
104104
fetch: async (req: Request, env: Env, ctx: ExecutionContext) => {
105-
if (env.ENVIRONMENT === 'development' && env.DEV_DISABLE_OAUTH === 'true') {
106-
return await handleDevMode(DNSAnalyticsMCP, req, env, ctx)
105+
if (await isApiTokenRequest(req, env)) {
106+
return await handleApiTokenMode(DNSAnalyticsMCP, req, env, ctx)
107107
}
108108

109109
return new OAuthProvider({

apps/radar/src/radar.app.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
createAuthHandlers,
66
handleTokenExchangeCallback,
77
} from '@repo/mcp-common/src/cloudflare-oauth-handler'
8-
import { handleDevMode } from '@repo/mcp-common/src/dev-mode'
8+
import { handleApiTokenMode, isApiTokenRequest } from '@repo/mcp-common/src/dev-mode'
99
import { getUserDetails, UserDetails } from '@repo/mcp-common/src/durable-objects/user_details.do'
1010
import { getEnv } from '@repo/mcp-common/src/env'
1111
import { RequiredScopes } from '@repo/mcp-common/src/scopes'
@@ -98,8 +98,8 @@ const RadarScopes = {
9898

9999
export default {
100100
fetch: async (req: Request, env: Env, ctx: ExecutionContext) => {
101-
if (env.ENVIRONMENT === 'development' && env.DEV_DISABLE_OAUTH === 'true') {
102-
return await handleDevMode(RadarMCP, req, env, ctx)
101+
if (await isApiTokenRequest(req, env)) {
102+
return await handleApiTokenMode(RadarMCP, req, env, ctx)
103103
}
104104

105105
return new OAuthProvider({

apps/sandbox-container/container/sandbox.container.app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ app.delete('/files/contents/*', async (c) => {
137137
*/
138138
app.post('/exec', zValidator('json', ExecParams), (c) => {
139139
const execParams = c.req.valid('json')
140-
const proc = exec(execParams.args)
140+
const proc = exec(execParams.shell_command)
141141
return streamText(c, async (stream) => {
142142
return new Promise((resolve, reject) => {
143143
if (proc.stdout) {

apps/sandbox-container/server/sandbox.server.app.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
createAuthHandlers,
66
handleTokenExchangeCallback,
77
} from '@repo/mcp-common/src/cloudflare-oauth-handler'
8-
import { handleDevMode } from '@repo/mcp-common/src/dev-mode'
8+
import { handleApiTokenMode, isApiTokenRequest } from '@repo/mcp-common/src/dev-mode'
99
import { getEnv } from '@repo/mcp-common/src/env'
1010
import { RequiredScopes } from '@repo/mcp-common/src/scopes'
1111
import { MetricsTracker } from '@repo/mcp-observability'
@@ -39,11 +39,8 @@ const ContainerScopes = {
3939

4040
export default {
4141
fetch: async (req: Request, env: Env, ctx: ExecutionContext) => {
42-
if (
43-
(env.ENVIRONMENT === 'dev' || env.ENVIRONMENT === 'test') &&
44-
env.DEV_DISABLE_OAUTH === 'true'
45-
) {
46-
return await handleDevMode(ContainerMcpAgent, req, env, ctx)
42+
if (await isApiTokenRequest(req, env)) {
43+
return await handleApiTokenMode(ContainerMcpAgent, req, env, ctx)
4744
}
4845

4946
return new OAuthProvider({

apps/sandbox-container/shared/schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import z from 'zod'
22

33
export type ExecParams = z.infer<typeof ExecParams>
44
export const ExecParams = z.object({
5-
args: z.string(),
5+
shell_command: z.string(),
66
timeout: z.number().optional().describe('Timeout in milliseconds'),
77
streamStderr: z.boolean().default(true),
88
})

apps/workers-bindings/src/bindings.app.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
createAuthHandlers,
66
handleTokenExchangeCallback,
77
} from '@repo/mcp-common/src/cloudflare-oauth-handler'
8-
import { handleDevMode } from '@repo/mcp-common/src/dev-mode'
8+
import { handleApiTokenMode, isApiTokenRequest } from '@repo/mcp-common/src/dev-mode'
99
import { getUserDetails, UserDetails } from '@repo/mcp-common/src/durable-objects/user_details.do'
1010
import { getEnv } from '@repo/mcp-common/src/env'
1111
import { RequiredScopes } from '@repo/mcp-common/src/scopes'
@@ -108,11 +108,8 @@ const BindingsScopes = {
108108

109109
export default {
110110
fetch: async (req: Request, env: Env, ctx: ExecutionContext) => {
111-
if (
112-
(env.ENVIRONMENT === 'development' || env.ENVIRONMENT === 'test') &&
113-
env.DEV_DISABLE_OAUTH === 'true'
114-
) {
115-
return await handleDevMode(WorkersBindingsMCP, req, env, ctx)
111+
if (await isApiTokenRequest(req, env)) {
112+
return await handleApiTokenMode(WorkersBindingsMCP, req, env, ctx)
116113
}
117114

118115
return new OAuthProvider({

apps/workers-observability/src/workers-observability.app.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
createAuthHandlers,
66
handleTokenExchangeCallback,
77
} from '@repo/mcp-common/src/cloudflare-oauth-handler'
8-
import { handleDevMode } from '@repo/mcp-common/src/dev-mode'
8+
import { handleApiTokenMode, isApiTokenRequest } from '@repo/mcp-common/src/dev-mode'
99
import { getUserDetails, UserDetails } from '@repo/mcp-common/src/durable-objects/user_details.do'
1010
import { getEnv } from '@repo/mcp-common/src/env'
1111
import { RequiredScopes } from '@repo/mcp-common/src/scopes'
@@ -110,8 +110,8 @@ const ObservabilityScopes = {
110110

111111
export default {
112112
fetch: async (req: Request, env: Env, ctx: ExecutionContext) => {
113-
if (env.ENVIRONMENT === 'development' && env.DEV_DISABLE_OAUTH === 'true') {
114-
return await handleDevMode(ObservabilityMCP, req, env, ctx)
113+
if (await isApiTokenRequest(req, env)) {
114+
return await handleApiTokenMode(ObservabilityMCP, req, env, ctx)
115115
}
116116

117117
return new OAuthProvider({

0 commit comments

Comments
 (0)