88} from '@repo/mcp-common/src/cloudflare-oauth-handler'
99import { getUserDetails , UserDetails } from '@repo/mcp-common/src/durable-objects/user_details.do'
1010import { getEnv } from '@repo/mcp-common/src/env'
11+ import { getProps } from '@repo/mcp-common/src/get-props'
1112import { RequiredScopes } from '@repo/mcp-common/src/scopes'
1213import { CloudflareMCPServer } from '@repo/mcp-common/src/server'
1314import { registerAccountTools } from '@repo/mcp-common/src/tools/account.tools'
@@ -51,7 +52,8 @@ export class AIGatewayMCP extends McpAgent<Env, State, Props> {
5152
5253 async init ( ) {
5354 // TODO: Probably we'll want to track account tokens usage through an account identifier at some point
54- const userId = this . props . type === 'user_token' ? this . props . user . id : undefined
55+ const props = getProps ( this )
56+ const userId = props . type === 'user_token' ? props . user . id : undefined
5557
5658 this . server = new CloudflareMCPServer ( {
5759 userId,
@@ -70,13 +72,14 @@ export class AIGatewayMCP extends McpAgent<Env, State, Props> {
7072
7173 async getActiveAccountId ( ) {
7274 try {
75+ const props = getProps ( this )
7376 // account tokens are scoped to one account
74- if ( this . props . type === 'account_token' ) {
75- return this . props . account . id
77+ if ( props . type === 'account_token' ) {
78+ return props . account . id
7679 }
7780 // Get UserDetails Durable Object based off the userId and retrieve the activeAccountId from it
7881 // we do this so we can persist activeAccountId across sessions
79- const userDetails = getUserDetails ( env , this . props . user . id )
82+ const userDetails = getUserDetails ( env , props . user . id )
8083 return await userDetails . getActiveAccountId ( )
8184 } catch ( e ) {
8285 this . server . recordError ( e )
@@ -86,11 +89,12 @@ export class AIGatewayMCP extends McpAgent<Env, State, Props> {
8689
8790 async setActiveAccountId ( accountId : string ) {
8891 try {
92+ const props = getProps ( this )
8993 // account tokens are scoped to one account
90- if ( this . props . type === 'account_token' ) {
94+ if ( props . type === 'account_token' ) {
9195 return
9296 }
93- const userDetails = getUserDetails ( env , this . props . user . id )
97+ const userDetails = getUserDetails ( env , props . user . id )
9498 await userDetails . setActiveAccountId ( accountId )
9599 } catch ( e ) {
96100 this . server . recordError ( e )
0 commit comments