1- import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
21import { McpAgent } from 'agents/mcp'
32
3+ import { CloudflareMCPServer } from '@repo/mcp-common/src/server'
4+
45import { OPEN_CONTAINER_PORT } from '../shared/consts'
56import { ExecParams , FilePathParam , FileWrite } from '../shared/schema'
67import { MAX_CONTAINERS , proxyFetch , startAndWaitForPort } from './containerHelpers'
@@ -9,16 +10,21 @@ import { BASE_INSTRUCTIONS } from './prompts'
910import { fileToBase64 , stripProtocolFromFilePath } from './utils'
1011
1112import type { FileList } from '../shared/schema'
12- import type { Env , Props } from '.'
13+ import type { Props } from '.'
14+
15+ export class ContainerMcpAgent extends McpAgent < Env , { } , Props > {
16+ _server : CloudflareMCPServer | undefined
17+ set server ( server : CloudflareMCPServer ) {
18+ this . _server = server
19+ }
20+
21+ get server ( ) : CloudflareMCPServer {
22+ if ( ! this . _server ) {
23+ throw new Error ( 'Tried to access server before it was initialized' )
24+ }
1325
14- export class ContainerMcpAgent extends McpAgent < Env , Props > {
15- server = new McpServer (
16- {
17- name : 'Container MCP Agent' ,
18- version : '1.0.0' ,
19- } ,
20- { instructions : BASE_INSTRUCTIONS }
21- )
26+ return this . _server
27+ }
2228
2329 constructor (
2430 public ctx : DurableObjectState ,
@@ -44,6 +50,17 @@ export class ContainerMcpAgent extends McpAgent<Env, Props> {
4450 }
4551
4652 async init ( ) {
53+ this . props . user . id
54+ this . server = new CloudflareMCPServer (
55+ this . props . user . id ,
56+ this . env . MCP_METRICS ,
57+ {
58+ name : this . env . MCP_SERVER_NAME ,
59+ version : this . env . MCP_SERVER_VERSION ,
60+ } ,
61+ { instructions : BASE_INSTRUCTIONS }
62+ )
63+
4764 this . server . tool (
4865 'container_initialize' ,
4966 'Start or reset the container' ,
0 commit comments