Skip to content

Commit f963b7e

Browse files
committed
Fix Metrics Server Init
1 parent 7619dda commit f963b7e

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

apps/cloudflare-one-casb/src/index.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,29 @@ export type Props = {
2828

2929
export type State = { activeAccountId: string | null }
3030
export class CASBMCP extends McpAgent<Env, State, Props> {
31-
server = new CloudflareMCPServer(undefined, env.MCP_METRICS, {
32-
name: env.MCP_SERVER_NAME,
33-
version: env.MCP_SERVER_VERSION,
34-
})
31+
_server: CloudflareMCPServer | undefined
32+
set server(server: CloudflareMCPServer) {
33+
this._server = server
34+
}
35+
36+
get server(): CloudflareMCPServer {
37+
if (!this._server) {
38+
throw new Error('Tried to access server before it was initialized')
39+
}
40+
41+
return this._server
42+
}
43+
44+
constructor(ctx: DurableObjectState, env: Env) {
45+
super(ctx, env)
46+
}
3547

3648
async init() {
49+
this.server = new CloudflareMCPServer(this.props.user.id, this.env.MCP_METRICS, {
50+
name: this.env.MCP_SERVER_NAME,
51+
version: this.env.MCP_SERVER_VERSION,
52+
})
53+
3754
registerAccountTools(this as unknown as CloudflareMcpAgent)
3855
registerIntegrationsTools(this)
3956
}

packages/mcp-common/src/api/account.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { McpAgent } from 'agents/mcp'
21
import type { Cloudflare } from 'cloudflare'
32
import type { Account } from 'cloudflare/resources/accounts/accounts.mjs'
3+
import type { CloudflareMcpAgent } from '../types/cloudflare-mcp-agent'
44
import type { ToolHandler } from '../types/tools'
55

66
export async function handleAccountsList({ client }: { client: Cloudflare }): Promise<Account[]> {
@@ -9,12 +9,8 @@ export async function handleAccountsList({ client }: { client: Cloudflare }): Pr
99
return response.result
1010
}
1111

12-
export interface McpAgentWithAccount extends McpAgent {
13-
getActiveAccountId: () => string
14-
}
15-
1612
export const withAccountCheck = <T extends Record<string, any>>(
17-
agent: McpAgentWithAccount,
13+
agent: CloudflareMcpAgent,
1814
handler: ToolHandler<T>
1915
) => {
2016
return async (params: T) => {

0 commit comments

Comments
 (0)