Skip to content

Commit 7e4f15d

Browse files
committed
linting
1 parent 1271f04 commit 7e4f15d

File tree

6 files changed

+63
-44
lines changed

6 files changed

+63
-44
lines changed

apps/sandbox-container/server/containerManager.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import { DurableObject } from 'cloudflare:workers'
22

3-
import type { Env } from './context'
4-
import { ContainerEvent } from './metrics'
3+
import { getEnv } from '@repo/mcp-common/src/env'
54
import { MetricsTracker } from '@repo/mcp-observability'
65

6+
import { ContainerEvent } from './metrics'
7+
8+
import type { Env } from './context'
9+
10+
const env = getEnv<Env>()
711
export class ContainerManager extends DurableObject<Env> {
8-
metrics = new MetricsTracker(this.env.MCP_METRICS, {
9-
name: this.env.MCP_SERVER_NAME,
10-
version: this.env.MCP_SERVER_VERSION
12+
metrics = new MetricsTracker(env.MCP_METRICS, {
13+
name: env.MCP_SERVER_NAME,
14+
version: env.MCP_SERVER_VERSION,
1115
})
1216

1317
constructor(
@@ -51,9 +55,11 @@ export class ContainerManager extends DurableObject<Env> {
5155
activeIds.push(c)
5256
}
5357

54-
this.metrics.logEvent(new ContainerEvent({
55-
active: activeIds.length
56-
}))
58+
this.metrics.logEvent(
59+
new ContainerEvent({
60+
active: activeIds.length,
61+
})
62+
)
5763

5864
return activeIds
5965
}

apps/sandbox-container/server/containerMcp.ts

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class ContainerMcpAgent extends McpAgent<Env, {}, Props> {
5757
const userInBlocklist = await this.env.USER_BLOCKLIST.get(this.props.user.id)
5858
if (userInBlocklist) {
5959
return {
60-
content: [{ type: 'text', text: "Blocked from intializing container." }],
60+
content: [{ type: 'text', text: 'Blocked from intializing container.' }],
6161
}
6262
}
6363
return {
@@ -66,11 +66,16 @@ export class ContainerMcpAgent extends McpAgent<Env, {}, Props> {
6666
}
6767
)
6868

69-
this.server.tool('container_ping', `Ping the container for liveliness. Use this tool to check if the container is running.`, {}, async ({}) => {
70-
return {
71-
content: [{ type: 'text', text: await this.userContainer.container_ping() }],
69+
this.server.tool(
70+
'container_ping',
71+
`Ping the container for liveliness. Use this tool to check if the container is running.`,
72+
{},
73+
async ({}) => {
74+
return {
75+
content: [{ type: 'text', text: await this.userContainer.container_ping() }],
76+
}
7277
}
73-
})
78+
)
7479
this.server.tool(
7580
'container_exec',
7681
`Run a command in a container and return the results from stdout.
@@ -106,22 +111,27 @@ export class ContainerMcpAgent extends McpAgent<Env, {}, Props> {
106111
}
107112
}
108113
)
109-
this.server.tool('container_files_list', 'List working directory file tree. This just reads the contents of the current working directory', {}, async ({}) => {
110-
// Begin workaround using container read rather than ls:
111-
const readFile = await this.userContainer.container_file_read('.')
112-
return {
113-
content: [
114-
{
115-
type: 'resource',
116-
resource: {
117-
text: readFile.type === "text" ? readFile.textOutput : readFile.base64Output,
118-
uri: `file://`,
119-
mimeType: readFile.mimeType,
114+
this.server.tool(
115+
'container_files_list',
116+
'List working directory file tree. This just reads the contents of the current working directory',
117+
{},
118+
async ({}) => {
119+
// Begin workaround using container read rather than ls:
120+
const readFile = await this.userContainer.container_file_read('.')
121+
return {
122+
content: [
123+
{
124+
type: 'resource',
125+
resource: {
126+
text: readFile.type === 'text' ? readFile.textOutput : readFile.base64Output,
127+
uri: `file://`,
128+
mimeType: readFile.mimeType,
129+
},
120130
},
121-
},
122-
],
131+
],
132+
}
123133
}
124-
})
134+
)
125135
this.server.tool(
126136
'container_file_read',
127137
'Read a specific file or directory. Use this tool if you would like to read files or display them to the user. This allow you to get a displayable image for the user if there is an image file.',
@@ -135,7 +145,7 @@ export class ContainerMcpAgent extends McpAgent<Env, {}, Props> {
135145
{
136146
type: 'resource',
137147
resource: {
138-
text: readFile.type === "text" ? readFile.textOutput : readFile.base64Output,
148+
text: readFile.type === 'text' ? readFile.textOutput : readFile.base64Output,
139149
uri: `file://${path}`,
140150
mimeType: readFile.mimeType,
141151
},

apps/sandbox-container/server/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import { MetricsTracker } from '@repo/mcp-observability'
1212

1313
import { ContainerManager } from './containerManager'
1414
import { ContainerMcpAgent } from './containerMcp'
15+
import { UserContainer } from './userContainer'
1516

1617
import type { McpAgent } from 'agents/mcp'
1718
import type { AuthProps } from '@repo/mcp-common/src/cloudflare-oauth-handler'
1819
import type { Env } from './context'
19-
import { UserContainer } from './userContainer'
2020

2121
export { ContainerManager, ContainerMcpAgent, UserContainer }
2222

apps/sandbox-container/server/metrics.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { MetricsEvent, MetricsEventIndexIds } from "@repo/mcp-observability"
1+
import { MetricsEvent, MetricsEventIndexIds } from '@repo/mcp-observability'
22

33
export class ContainerEvent extends MetricsEvent {
44
constructor(

apps/sandbox-container/server/userContainer.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { DurableObject } from "cloudflare:workers"
1+
import { DurableObject } from 'cloudflare:workers'
22

33
import { OPEN_CONTAINER_PORT } from '../shared/consts'
44
import { ExecParams, FileWrite } from '../shared/schema'
55
import { MAX_CONTAINERS, proxyFetch, startAndWaitForPort } from './containerHelpers'
66
import { getContainerManager } from './containerManager'
7+
import { fileToBase64 } from './utils'
78

89
import type { FileList } from '../shared/schema'
910
import type { Env } from './context'
10-
import { fileToBase64 } from "./utils"
1111

1212
export class UserContainer extends DurableObject<Env> {
1313
constructor(
@@ -41,7 +41,7 @@ export class UserContainer extends DurableObject<Env> {
4141
const containerManager = getContainerManager(this.env)
4242

4343
// if more than half of our containers are being used, let's try reaping
44-
if ((await containerManager.listActive()).length >= (MAX_CONTAINERS / 2)) {
44+
if ((await containerManager.listActive()).length >= MAX_CONTAINERS / 2) {
4545
await containerManager.tryKillOldContainers()
4646
if ((await containerManager.listActive()).length >= MAX_CONTAINERS) {
4747
throw new Error(
@@ -129,7 +129,10 @@ export class UserContainer extends DurableObject<Env> {
129129
}
130130
async container_file_read(
131131
filePath: string
132-
): Promise<{ type: "text", textOutput: string; mimeType: string | undefined } | { type: "base64", base64Output: string; mimeType: string | undefined }> {
132+
): Promise<
133+
| { type: 'text'; textOutput: string; mimeType: string | undefined }
134+
| { type: 'base64'; base64Output: string; mimeType: string | undefined }
135+
> {
133136
const res = await proxyFetch(
134137
this.env.ENVIRONMENT,
135138
this.ctx.container,
@@ -144,18 +147,18 @@ export class UserContainer extends DurableObject<Env> {
144147
const blob = await res.blob()
145148

146149
console.log(mimeType)
147-
150+
148151
if (mimeType && mimeType.startsWith('text')) {
149152
return {
150-
type: "text",
153+
type: 'text',
151154
textOutput: await blob.text(),
152-
mimeType
155+
mimeType,
153156
}
154157
} else {
155158
return {
156-
type: "base64",
159+
type: 'base64',
157160
base64Output: await fileToBase64(blob),
158-
mimeType
161+
mimeType,
159162
}
160163
}
161164
}

apps/sandbox-container/wrangler.jsonc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"class_name": "UserContainer",
8585
"max_instances": 5,
8686
"rollout_step_percentage": 100,
87-
"instances": 3,
87+
"instances": 3
8888
}
8989
],
9090
"durable_objects": {
@@ -123,7 +123,7 @@
123123
"binding": "USER_BLOCKLIST",
124124
"id": "68e95343ded8448db179256c68f175b2"
125125
}
126-
],
126+
]
127127
},
128128
"production": {
129129
"name": "mcp-cloudflare-container-sandbox-production",
@@ -137,7 +137,7 @@
137137
"class_name": "UserContainer",
138138
"max_instances": 50,
139139
"rollout_step_percentage": 100,
140-
"instances": 10,
140+
"instances": 10
141141
}
142142
],
143143
"durable_objects": {
@@ -176,7 +176,7 @@
176176
"binding": "USER_BLOCKLIST",
177177
"id": "b874d6ae29ec43e5afad7be8da067676"
178178
}
179-
],
180-
},
179+
]
180+
}
181181
}
182182
}

0 commit comments

Comments
 (0)