Skip to content

Commit 2aba911

Browse files
committed
make file write labeling consistent
1 parent f5cd982 commit 2aba911

File tree

5 files changed

+16
-15
lines changed

5 files changed

+16
-15
lines changed

apps/sandbox-container/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14387504
4848
- `container_initialize`: (Re)start a container. Containers are intended to be ephemeral and don't save any state. Containers are only guaranteed to last 10m (this is just because I have a max of like ~5 containers per account).
4949
- `container_ping`: Ping a container for connectivity
5050
- `container_exec`: Run a command in the shell
51-
- `container_files_write`: Write to a file
51+
- `container_file_write`: Write to a file
5252
- `container_files_list`: List all files in the work directory
5353
- `container_file_read`: Read the contents of a single file or directory
54+
- `container_file_delete`: Delete a single file or directory
5455

5556
## Resources
5657

apps/sandbox-container/container/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { exec } from 'node:child_process'
2-
import * as fs from 'node:fs/promises'
3-
import path from 'node:path'
41
import { serve } from '@hono/node-server'
52
import { zValidator } from '@hono/zod-validator'
63
import { Hono } from 'hono'
74
import { streamText } from 'hono/streaming'
85
import mime from 'mime'
6+
import { exec } from 'node:child_process'
7+
import * as fs from 'node:fs/promises'
8+
import path from 'node:path'
99

10-
import { ExecParams, FilesWrite } from '../shared/schema.ts'
10+
import { ExecParams, FileWrite } from '../shared/schema.ts'
1111
import {
1212
DIRECTORY_CONTENT_TYPE,
1313
get_file_name_from_path,
@@ -96,7 +96,7 @@ app.get('/files/contents/*', async (c) => {
9696
*
9797
* Create or update file contents
9898
*/
99-
app.post('/files/contents', zValidator('json', FilesWrite), async (c) => {
99+
app.post('/files/contents', zValidator('json', FileWrite), async (c) => {
100100
const file = c.req.valid('json')
101101
const reqPath = await get_file_name_from_path(file.path)
102102

apps/sandbox-container/server/containerMcp.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
22
import { McpAgent } from 'agents/mcp'
33

44
import { OPEN_CONTAINER_PORT } from '../shared/consts'
5-
import { ExecParams, FilePathParam, FilesWrite } from '../shared/schema'
5+
import { ExecParams, FilePathParam, FileWrite } from '../shared/schema'
66
import { MAX_CONTAINERS, proxyFetch, startAndWaitForPort } from './containerHelpers'
77
import { getContainerManager } from './containerManager'
88
import { BASE_INSTRUCTIONS } from './prompts'
99
import { fileToBase64, stripProtocolFromFilePath } from './utils'
1010

11-
import type { FileList } from '../shared/schema'
1211
import type { Env, Props } from '.'
12+
import type { FileList } from '../shared/schema'
1313

1414
export class ContainerMcpAgent extends McpAgent<Env, Props> {
1515
server = new McpServer(
@@ -84,13 +84,13 @@ export class ContainerMcpAgent extends McpAgent<Env, Props> {
8484
}
8585
)
8686
this.server.tool(
87-
'container_files_write',
87+
'container_file_write',
8888
'Write file contents',
89-
{ args: FilesWrite },
89+
{ args: FileWrite },
9090
async ({ args }) => {
9191
args.path = await stripProtocolFromFilePath(args.path)
9292
return {
93-
content: [{ type: 'text', text: await this.container_files_write(args) }],
93+
content: [{ type: 'text', text: await this.container_file_write(args) }],
9494
}
9595
}
9696
)
@@ -266,7 +266,7 @@ export class ContainerMcpAgent extends McpAgent<Env, Props> {
266266
}
267267
}
268268

269-
async container_files_write(file: FilesWrite): Promise<string> {
269+
async container_file_write(file: FileWrite): Promise<string> {
270270
const res = await proxyFetch(
271271
this.env.ENVIRONMENT,
272272
this.ctx.container,

apps/sandbox-container/server/prompts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ AVOID manually reading or writing files using the \`container_exec\` tool. You s
4848
To manage container lifecycle, use the \`container_start\` and \`container_kill\` tools. If you run into errors where you can't connect to the container, attempt to kill and restart the container. If that doesn't work, the system is probably overloaded.
4949
5050
You can execute actions in the container using the \`container_exec\` tool. By default, stdout is returned back as a string.
51-
To write a file, use the \`container_files_write\` tool.
51+
To write a file, use the \`container_file_write\` tool. To delete a file, use the \`container_file_delete\` tool.
5252
5353
The \`container_files_list\` allows you to list file resources. Content is omitted from the response of this tool and all mimeTypes are \`text/plain\` even if the file ending suggests otherwise.
5454
If you want to get the file contents of a file resource, use \`container_file_read\`, which will return the file contents.

apps/sandbox-container/shared/schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ export const ExecParams = z.object({
77
streamStderr: z.boolean().default(true),
88
})
99

10-
export type FilesWrite = z.infer<typeof FilesWrite>
11-
export const FilesWrite = z.object({
10+
export type FileWrite = z.infer<typeof FileWrite>
11+
export const FileWrite = z.object({
1212
path: z.string(),
1313
text: z.string().describe('Full text content of the file you want to write.'),
1414
})

0 commit comments

Comments
 (0)