File tree Expand file tree Collapse file tree 2 files changed +23
-10
lines changed
apps/cloudflare-one-casb/src
packages/mcp-common/src/api Expand file tree Collapse file tree 2 files changed +23
-10
lines changed Original file line number Diff line number Diff line change @@ -28,12 +28,29 @@ export type Props = {
28
28
29
29
export type State = { activeAccountId : string | null }
30
30
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
+ }
35
47
36
48
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
+
37
54
registerAccountTools ( this as unknown as CloudflareMcpAgent )
38
55
registerIntegrationsTools ( this )
39
56
}
Original file line number Diff line number Diff line change 1
- import type { McpAgent } from 'agents/mcp'
2
1
import type { Cloudflare } from 'cloudflare'
3
2
import type { Account } from 'cloudflare/resources/accounts/accounts.mjs'
3
+ import type { CloudflareMcpAgent } from '../types/cloudflare-mcp-agent'
4
4
import type { ToolHandler } from '../types/tools'
5
5
6
6
export async function handleAccountsList ( { client } : { client : Cloudflare } ) : Promise < Account [ ] > {
@@ -9,12 +9,8 @@ export async function handleAccountsList({ client }: { client: Cloudflare }): Pr
9
9
return response . result
10
10
}
11
11
12
- export interface McpAgentWithAccount extends McpAgent {
13
- getActiveAccountId : ( ) => string
14
- }
15
-
16
12
export const withAccountCheck = < T extends Record < string , any > > (
17
- agent : McpAgentWithAccount ,
13
+ agent : CloudflareMcpAgent ,
18
14
handler : ToolHandler < T >
19
15
) => {
20
16
return async ( params : T ) => {
You can’t perform that action at this time.
0 commit comments