MCPcopy Create free account
hub / github.com/vercel/examples / create_file

Function create_file

python/vibe-coding-ide/backend/src/agent/tools/fs_ops.py:9–59  ·  view source on GitHub ↗

Create a new file with the provided content (for new features or rebuilds). Guidelines: - Provide the full file contents. Create siblings/modules as needed. - Prefer small, focused files in idiomatic locations. - Does not overwrite an existing file; returns an error instead. Use ren

(
    ctx: RunContextWrapper[IDEContext], file_path: str, content: str
)

Source from the content-addressed store, hash-verified

7
8@function_tool
9async def create_file(
10 ctx: RunContextWrapper[IDEContext], file_path: str, content: str
11) -> str:
12 """Create a new file with the provided content (for new features or rebuilds).
13
14 Guidelines:
15 - Provide the full file contents. Create siblings/modules as needed.
16 - Prefer small, focused files in idiomatic locations.
17 - Does not overwrite an existing file; returns an error instead. Use rename_* to archive or move old files first.
18
19 Args:
20 file_path: Project-relative path for the new file.
21 content: Full content of the file.
22 Returns:
23 JSON string describing the creation or an error.
24 """
25 tool_id = f"tc_{len(ctx.context.events) + 1}"
26 args = {"file_path": file_path, "content": content}
27 ctx.context.events.append(
28 {
29 "phase": "started",
30 "tool_id": tool_id,
31 "name": "create_file",
32 "arguments": args,
33 }
34 )
35
36 if file_path in ctx.context.project:
37 output = {"error": f"File already exists: {file_path}", "file_path": file_path}
38 else:
39 ctx.context.project[file_path] = str(content)
40 # best-effort autosync to running sandboxes
41 output = {
42 "file_path": file_path,
43 "new_file_content": str(content),
44 "created": True,
45 }
46 try:
47 await autosync_after_fs_change(ctx, created_or_updated=[file_path])
48 except Exception:
49 pass
50
51 ctx.context.events.append(
52 {
53 "phase": "completed",
54 "tool_id": tool_id,
55 "name": "create_file",
56 "output_data": output,
57 }
58 )
59 return json.dumps(output)
60
61
62@function_tool

Callers

nothing calls this directly

Calls 1

autosync_after_fs_changeFunction · 0.90

Tested by

no test coverage detected