Skip to main content
Glama
bazinga012

MCP Code Executor

execute_code_file

Execute Python code files to run scripts and applications, enabling automated testing and program execution within a controlled environment.

Instructions

Execute an existing Python file. Use this as the final step after building up code with initialize_code_file and append_to_code_file.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYesFull path to the Python file to execute

Implementation Reference

  • Core handler function that executes the Python code from the given file path using the configured environment, captures output and errors, and returns a structured JSON response.
    async function executeCodeFromFile(filePath: string) {
        try {
            // Ensure file exists
            await access(filePath);
    
            // Get platform-specific command with unbuffered output
            const pythonCmd = platform() === 'win32' ? `python -u "${filePath}"` : `python3 -u "${filePath}"`;
            const { command, options } = getPlatformSpecificCommand(pythonCmd);
    
            // Execute code with unbuffered Python
            const { stdout, stderr } = await execAsync(command, {
                cwd: CODE_STORAGE_DIR,
                env: { ...process.env, PYTHONUNBUFFERED: '1' },
                ...options
            });
    
            const response = {
                status: stderr ? 'error' : 'success',
                output: stderr || stdout,
                file_path: filePath
            };
    
            return {
                type: 'text',
                text: JSON.stringify(response),
                isError: !!stderr
            };
        } catch (error) {
            const response = {
                status: 'error',
                error: error instanceof Error ? error.message : String(error),
                file_path: filePath
            };
    
            return {
                type: 'text',
                text: JSON.stringify(response),
                isError: true
            };
        }
  • src/index.ts:588-602 (registration)
    Tool registration in the ListTools response, defining the name, description, and input schema.
    {
        name: "execute_code_file",
        description: "Execute an existing Python file. Use this as the final step after building up code with initialize_code_file and append_to_code_file.",
        inputSchema: {
            type: "object",
            properties: {
                file_path: {
                    type: "string",
                    description: "Full path to the Python file to execute"
                }
            },
            required: ["file_path"]
        }
    },
    {
  • TypeScript interface defining the expected input arguments for the tool.
    interface ExecuteCodeFileArgs {
        file_path?: string;
    }
  • Dispatch handler within CallToolRequestSchema that validates input and invokes the core execution function.
    case "execute_code_file": {
        const args = request.params.arguments as ExecuteCodeFileArgs;
        if (!args?.file_path) {
            throw new Error("File path is required");
        }
    
        const result = await executeCodeFromFile(args.file_path);
    
        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?

No annotations are provided, so the description carries the full burden. It mentions that it executes a Python file, implying mutation/runtime effects, but lacks details on permissions, safety (e.g., sandboxing), error handling, or output behavior. It adds some context about being a 'final step' but misses key behavioral traits for an execution tool.

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 two sentences, front-loaded with the core purpose and followed by usage guidance. Every sentence earns its place with no wasted words, making it highly efficient and well-structured.

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

Completeness3/5

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

Given the tool's complexity (executing code, which can have side effects), lack of annotations, and no output schema, the description is incomplete. It covers purpose and workflow but omits critical details like execution environment, return values, or error conditions, leaving gaps for an AI agent.

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 the 'file_path' parameter fully. The description does not add any meaning beyond what the schema provides (e.g., format examples or constraints), resulting in a baseline score of 3 as 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 ('Execute') and resource ('an existing Python file'), distinguishing it from siblings like 'execute_code' (which likely executes code directly) and 'read_code_file' (which only reads). It directly addresses what the tool does without being vague or tautological.

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?

It explicitly states when to use this tool ('as the final step after building up code with initialize_code_file and append_to_code_file'), providing clear context and naming specific alternatives (siblings) for the workflow. This gives strong guidance on its role versus other tools.

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