append_to_code_file
Add code to existing Python files to build larger programs incrementally within the MCP Code Executor environment.
Instructions
Append content to an existing Python code file. Use this to add more code to a file created with initialize_code_file, allowing you to build up larger code bases in parts.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | Full path to the file | |
| content | Yes | Content to append to the file |
Implementation Reference
- src/index.ts:248-276 (handler)Core handler function that checks if the file exists, appends the provided content using fs/promises.appendFile, and returns a standardized JSON response indicating success or error.async function appendToCodeFile(filePath: string, content: string) { try { // Ensure file exists await access(filePath); // Append content to file await appendFile(filePath, content, 'utf-8'); return { type: 'text', text: JSON.stringify({ status: 'success', message: 'Content appended successfully', file_path: filePath }), isError: false }; } catch (error) { return { type: 'text', text: JSON.stringify({ status: 'error', error: error instanceof Error ? error.message : String(error), file_path: filePath }), isError: true }; } }
- src/index.ts:700-703 (schema)TypeScript interface defining the expected arguments for the append_to_code_file tool handler.interface AppendToCodeFileArgs { file_path?: string; content?: string; }
- src/index.ts:570-587 (registration)Tool metadata registration in the ListTools handler, including name, description, and JSON input schema.{ name: "append_to_code_file", description: "Append content to an existing Python code file. Use this to add more code to a file created with initialize_code_file, allowing you to build up larger code bases in parts.", inputSchema: { type: "object", properties: { file_path: { type: "string", description: "Full path to the file" }, content: { type: "string", description: "Content to append to the file" } }, required: ["file_path", "content"] } },
- src/index.ts:806-824 (handler)Tool dispatcher in the CallToolRequestSchema handler that validates arguments and invokes the appendToCodeFile function.case "append_to_code_file": { const args = request.params.arguments as AppendToCodeFileArgs; if (!args?.file_path) { throw new Error("File path is required"); } if (!args?.content) { throw new Error("Content is required"); } const result = await appendToCodeFile(args.file_path, args.content); return { content: [{ type: "text", text: result.text, isError: result.isError }] }; }