11import OAuthProvider from '@cloudflare/workers-oauth-provider'
22import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
33import { McpAgent } from 'agents/mcp'
4+ import { env } from 'cloudflare:workers'
45
56import {
67 CloudflareAuthHandler ,
@@ -12,7 +13,6 @@ import { registerWorkersTools } from '@repo/mcp-common/src/tools/worker'
1213import { registerLogsTools } from './tools/logs'
1314
1415import type { AccountSchema , UserSchema } from '@repo/mcp-common/src/cloudflare-oauth-handler'
15- import type { Env } from '../worker-configuration'
1616
1717// Context from the auth process, encrypted & stored in the auth token
1818// and provided to the DurableMCP as this.props
@@ -29,9 +29,6 @@ export class MyMCP extends McpAgent<Env, State, Props> {
2929 name : 'Remote MCP Server with Workers Observability' ,
3030 version : '1.0.0' ,
3131 } )
32- // TOOO: Why does this type need to be declared again on MyMCP?
33- // @ts -ignore
34- env ! : Env
3532
3633 initialState : State = {
3734 activeAccountId : null ,
@@ -77,7 +74,8 @@ export default new OAuthProvider({
7774 defaultHandler : CloudflareAuthHandler ,
7875 authorizeEndpoint : '/oauth/authorize' ,
7976 tokenEndpoint : '/token' ,
80- tokenExchangeCallback : handleTokenExchangeCallback ,
77+ tokenExchangeCallback : ( options ) =>
78+ handleTokenExchangeCallback ( options , env . CLOUDFLARE_CLIENT_ID , env . CLOUDFLARE_CLIENT_SECRET ) ,
8179 // Cloudflare access token TTL
8280 accessTokenTTL : 3600 ,
8381 clientRegistrationEndpoint : '/register' ,
0 commit comments