Skip to main content
Glama
bazinga012

MCP Code Executor

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
NameRequiredDescriptionDefault
file_pathYesFull path to the file
contentYesContent to append to the file

Implementation Reference

  • 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 }; } }
  • 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"] } },
  • 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 }] }; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/bazinga012/mcp_code_executor'

If you have feedback or need assistance with the MCP directory API, please join our Discord server