Skip to main content
Glama
bazinga012

MCP Code Executor

initialize_code_file

Create a new Python file with initial content to start coding projects that may exceed token limits, enabling structured code execution in Conda environments.

Instructions

Create a new Python file with initial content. Use this as the first step for longer code that may exceed token limits. Follow with append_to_code_file for additional code.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contentYesInitial content to write to the file
filenameNoOptional: Name of the file (default: generated UUID)

Implementation Reference

  • The core handler function that creates a new Python code file in the storage directory with the provided content, generating a unique .py filename if not specified, and returns JSON response with file path.
    async function initializeCodeFile(content: string, filename?: string) {
        try {
            // Generate a filename if not provided
            let actualFilename;
            if (filename && typeof filename === 'string') {
                // Extract base name without extension
                const baseName = filename.replace(/\.py$/, '');
                // Add a random suffix to ensure uniqueness
                actualFilename = `${baseName}_${randomBytes(4).toString('hex')}.py`;
            } else {
                // Default filename if none provided
                actualFilename = `code_${randomBytes(4).toString('hex')}.py`;
            }
            
            const filePath = join(CODE_STORAGE_DIR, actualFilename);
            
            // Write initial content to file
            await writeFile(filePath, content, 'utf-8');
            
            return {
                type: 'text',
                text: JSON.stringify({
                    status: 'success',
                    message: 'File initialized successfully',
                    file_path: filePath,
                    filename: actualFilename
                }),
                isError: false
            };
        } catch (error) {
            return {
                type: 'text',
                text: JSON.stringify({
                    status: 'error',
                    error: error instanceof Error ? error.message : String(error)
                }),
                isError: true
            };
        }
    }
  • src/index.ts:552-569 (registration)
    Tool registration in the ListToolsRequestSchema handler, specifying name, description, and input schema for validation.
    {
        name: "initialize_code_file",
        description: "Create a new Python file with initial content. Use this as the first step for longer code that may exceed token limits. Follow with append_to_code_file for additional code.",
        inputSchema: {
            type: "object",
            properties: {
                content: {
                    type: "string",
                    description: "Initial content to write to the file"
                },
                filename: {
                    type: "string",
                    description: "Optional: Name of the file (default: generated UUID)"
                }
            },
            required: ["content"]
        }
    },
  • TypeScript interface defining the expected arguments for the initialize_code_file tool.
    interface InitializeCodeFileArgs {
        content?: string;
        filename?: string;
    }
  • Dispatch handler case in the CallToolRequestSchema that validates arguments and invokes the initializeCodeFile function, wrapping the result in MCP content format.
    case "initialize_code_file": {
        const args = request.params.arguments as InitializeCodeFileArgs;
        if (!args?.content) {
            throw new Error("Content is required");
        }
    
        const result = await initializeCodeFile(args.content, args.filename);
    
        return {
            content: [{
                type: "text",
                text: result.text,
                isError: result.isError
            }]
        };
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states this creates a new file (implying a write operation) and mentions token limit considerations, but doesn't specify file system permissions, error handling, or what happens if the file already exists. It adds some context but lacks comprehensive behavioral details.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise (two sentences) with zero wasted words. The first sentence states the core purpose, and the second provides crucial usage guidance. Every sentence earns its place and is front-loaded with essential information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a creation tool with no annotations and no output schema, the description does well by explaining the tool's role in a multi-step workflow and referencing its sibling. However, it doesn't mention what the tool returns (e.g., success confirmation, file path) or potential error conditions, leaving some gaps in completeness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents both parameters thoroughly. The description doesn't add any parameter-specific information beyond what's in the schema (e.g., it doesn't explain content formatting or filename conventions). Baseline 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Create a new Python file with initial content') and distinguishes it from its sibling 'append_to_code_file' by positioning it as 'the first step for longer code.' It explicitly names the resource (Python file) and verb (create), avoiding tautology.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit guidance on when to use this tool ('as the first step for longer code that may exceed token limits') and when to use an alternative ('Follow with append_to_code_file for additional code'). It clearly differentiates usage contexts between initialization and appending.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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